Files
UnrealEngineUWP/Engine/Plugins/Editor/MeshEditor/Source/PolygonModeling/SplitPolygon.cpp

417 lines
16 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SplitPolygon.h"
#include "IMeshEditorModeEditingContract.h"
#include "IMeshEditorModeUIContract.h"
#include "Framework/Commands/UICommandInfo.h"
#include "EditableMesh.h"
#include "StaticMeshAttributes.h"
#include "MeshElement.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "Framework/Commands/UICommandList.h"
#include "ViewportInteractor.h"
#define LOCTEXT_NAMESPACE "MeshEditorMode"
void USplitPolygonFromVertexCommand::RegisterUICommand( FBindingContext* BindingContext )
{
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "SplitPolygonFromVertex", "Split Polygon", "Splits a polygon by clicking on a selected vertex and dragging to create an edge along the surface of a neighboring polygon.", EUserInterfaceActionType::RadioButton, FInputChord() );
}
void USplitPolygonFromEdgeCommand::RegisterUICommand( FBindingContext* BindingContext )
{
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "SplitPolygonFromEdge", "Split Polygon", "Splits a polygon by clicking on a selected edge and dragging to create an edge along the surface of a neigboring polygon.", EUserInterfaceActionType::RadioButton, FInputChord() );
}
void USplitPolygonFromPolygonCommand::RegisterUICommand( FBindingContext* BindingContext )
{
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "SplitPolygonFromPolygon", "Split", "Splits a polygon by clicking on a selected polygon and dragging to create an edge along the surface of the polygon or it's neighbor.", EUserInterfaceActionType::RadioButton, FInputChord() );
}
bool USplitPolygonCommand::TryStartingToDrag( IMeshEditorModeEditingContract& MeshEditorMode, UViewportInteractor* ViewportInteractor )
{
Component = nullptr;
EditableMesh = nullptr;
StartingEdgeID = FEdgeID::Invalid;
StartingVertexID = FVertexID::Invalid;
EdgeSplit = 0.0f;
// Figure out what to split
static TMap<class UEditableMesh*, TArray<FMeshElement>> SelectedMeshesAndEdges;
MeshEditorMode.GetSelectedMeshesAndEdges( /* Out */ SelectedMeshesAndEdges );
if( SelectedMeshesAndEdges.Num() == 0 )
{
// No edges were selected directly, so try selected polygons' edges
MeshEditorMode.GetSelectedMeshesAndPolygonsPerimeterEdges( /* Out */ SelectedMeshesAndEdges );
}
if( SelectedMeshesAndEdges.Num() > 0 )
{
for( auto& MeshAndEdges : SelectedMeshesAndEdges )
{
UEditableMesh* EdgeEditableMesh = MeshAndEdges.Key;
const TArray<FMeshElement>& EdgeElements = MeshAndEdges.Value;
// Figure out where to split
FEdgeID ClosestEdgeID = FEdgeID::Invalid;
float Split = 0.0f;
const bool bFoundSplit = MeshEditorMode.FindEdgeSplitUnderInteractor( ViewportInteractor, EdgeEditableMesh, EdgeElements, /* Out */ ClosestEdgeID, /* Out */ Split );
if( bFoundSplit )
{
// OK, we have an edge position to start dragging from!
Component = EdgeElements[ 0 ].Component.Get();
EditableMesh = EdgeEditableMesh;
StartingEdgeID = ClosestEdgeID;
EdgeSplit = Split;
// No need to search other meshes
break;
}
}
}
else
{
static TMap<class UEditableMesh*, TArray<FMeshElement>> SelectedMeshesAndVertices;
MeshEditorMode.GetSelectedMeshesAndVertices( /* Out */ SelectedMeshesAndVertices );
for( auto& MeshAndVertices : SelectedMeshesAndVertices )
{
UEditableMesh* VertexEditableMesh = MeshAndVertices.Key;
const TArray<FMeshElement>& VertexElements = MeshAndVertices.Value;
for( const FMeshElement& VertexElement : VertexElements )
{
// OK, we have a vertex to start dragging from!
Component = VertexElements[ 0 ].Component.Get();
EditableMesh = VertexEditableMesh;
StartingVertexID = FVertexID( VertexElement.ElementAddress.ElementID );
break;
}
}
}
return EditableMesh != nullptr;
}
void USplitPolygonCommand::ApplyDuringDrag( IMeshEditorModeEditingContract& MeshEditorMode, UViewportInteractor* ViewportInteractor )
{
if( EditableMesh != nullptr )
{
check( Component != nullptr );
MeshEditorMode.DeselectAllMeshElements();
static TArray<FMeshElement> MeshElementsToSelect;
MeshElementsToSelect.Reset();
verify( !EditableMesh->AnyChangesToUndo() );
// We'll always be trying to split one of the polygons that share the starting vertex. But we need to figure
// out which one of those polygons the user is hovering over (either the polygon itself, or one of it's edges
// or vertices.)
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
static TArray<FPolygonID> CandidatePolygonIDs;
CandidatePolygonIDs.Reset();
if( StartingEdgeID != FEdgeID::Invalid )
{
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
EditableMesh->GetEdgeConnectedPolygons( StartingEdgeID, /* Out */ CandidatePolygonIDs );
}
else if( ensure( StartingVertexID != FVertexID::Invalid ) )
{
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
EditableMesh->GetVertexConnectedPolygons( StartingVertexID, /* Out */ CandidatePolygonIDs );
}
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
FPolygonID PolygonToSplit = FPolygonID::Invalid;
FVertexID ToVertexID = FVertexID::Invalid;
{
FVector LaserPointerStart, LaserPointerEnd;
if( ViewportInteractor->GetLaserPointer( /* Out */ LaserPointerStart, /* Out */ LaserPointerEnd ) )
{
New attribute array API. Fixed some flaws in the original API, deprecated various methods, and introduced some new features. - Now attribute arrays are accessed via TAttributesRef or TAttributesView (and corresponding const versions). These value types hold references to attribute arrays, and individual elements can be accessed by their element ID and attribute index. Using a value type is safer than the previous method which required assignment to a const-ref (and not doing so would take a temporary copy of the attribute array). - The attribute set has been totally flattened, so all attributes of different types are added to the same container. This greatly improves compile times, prevents attributes from being created with the same name but different types, and permits the view feature. - The class hierarchy has changed to have generic base classes where possible with no particular ElementID type. This reduces the code footprint by no longer generating nearly identical copies of templated methods. - A TAttributesView allows the user to access an attribute array by the type of their choosing, regardless of its actual type. For example, the Normal attribute may be registered with type FPackedVector, but accessed as if it was an FVector. This allows us to move away from very strong typing, and instead transparently store attributes of a more efficient size, while the user is not affected. - A transient attribute flag has been added, to denote that a particular attribute should not be saved. #rb none [CL 4226081 by Richard TalbotWatkin in Dev-Editor branch]
2018-07-20 18:58:37 -04:00
const TVertexAttributesRef<FVector> VertexPositions = EditableMesh->GetMeshDescription()->VertexAttributes().GetAttributesRef<FVector>( MeshAttribute::Vertex::Position );
Total revamp of mesh element attribute model. Attributes now have a number of possible types (FVector, FVector4, FVector2D, float, int, bool, FName, UObject*) and are exposed as individual flat arrays, indexed by element ID. For example, vertex positions are essentially exposed as an array of FVector which can be directly accessed and modified. This has a number of advantages: - It is completely extensible: new attributes can be created (even by a third party) and added to a mesh description without requiring a serialization version bump, or any change to the parent structures. - This is more efficient in batch operations which deal with a number of mesh elements in one go. - These attribute buffers can potentially be passed directly to third-party libraries without requiring any kind of transformation. - The distinct types allow for a better representation of the attribute being specified, without invalid values being possible (cf representing a bool value in an FVector4). Attributes also have default values, and a flags field which confers use-specific properties to them. Editable Mesh currently uses this to determine whether an attribute's value can be automatically initialized by lerping the values of its neighbours, as well as for identifying auto-generated attributes such as tangents/normals. This is desirable as it means that even unknown / third-party attributes can potentially be handled transparently by Editable Mesh, without requiring the code to be extended. Certain higher-level operations in EditableMesh have been optimized to make full use of vertex instances where possible. The welding/splitting of identical vertex instances has been removed from here, as the aim is to unify this with mesh utility code elsewhere. Various bug fixes. #rb Alexis.Matte [CL 3794563 by Richard TalbotWatkin in Dev-Geometry branch]
2017-12-07 13:02:12 -05:00
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
for( const FPolygonID CandidatePolygonID : CandidatePolygonIDs )
{
const FTransform ComponentToWorld = Component->GetComponentToWorld();
FVector SplitStartLocation;
if( StartingVertexID != FVertexID::Invalid )
{
Total revamp of mesh element attribute model. Attributes now have a number of possible types (FVector, FVector4, FVector2D, float, int, bool, FName, UObject*) and are exposed as individual flat arrays, indexed by element ID. For example, vertex positions are essentially exposed as an array of FVector which can be directly accessed and modified. This has a number of advantages: - It is completely extensible: new attributes can be created (even by a third party) and added to a mesh description without requiring a serialization version bump, or any change to the parent structures. - This is more efficient in batch operations which deal with a number of mesh elements in one go. - These attribute buffers can potentially be passed directly to third-party libraries without requiring any kind of transformation. - The distinct types allow for a better representation of the attribute being specified, without invalid values being possible (cf representing a bool value in an FVector4). Attributes also have default values, and a flags field which confers use-specific properties to them. Editable Mesh currently uses this to determine whether an attribute's value can be automatically initialized by lerping the values of its neighbours, as well as for identifying auto-generated attributes such as tangents/normals. This is desirable as it means that even unknown / third-party attributes can potentially be handled transparently by Editable Mesh, without requiring the code to be extended. Certain higher-level operations in EditableMesh have been optimized to make full use of vertex instances where possible. The welding/splitting of identical vertex instances has been removed from here, as the aim is to unify this with mesh utility code elsewhere. Various bug fixes. #rb Alexis.Matte [CL 3794563 by Richard TalbotWatkin in Dev-Geometry branch]
2017-12-07 13:02:12 -05:00
SplitStartLocation = ComponentToWorld.TransformPosition( VertexPositions[ StartingVertexID ] );
}
else if( ensure( StartingEdgeID != FEdgeID::Invalid ) )
{
FVertexID EdgeVertex0, EdgeVertex1;
EditableMesh->GetEdgeVertices( StartingEdgeID, /* Out */ EdgeVertex0, /* Out */ EdgeVertex1 );
Total revamp of mesh element attribute model. Attributes now have a number of possible types (FVector, FVector4, FVector2D, float, int, bool, FName, UObject*) and are exposed as individual flat arrays, indexed by element ID. For example, vertex positions are essentially exposed as an array of FVector which can be directly accessed and modified. This has a number of advantages: - It is completely extensible: new attributes can be created (even by a third party) and added to a mesh description without requiring a serialization version bump, or any change to the parent structures. - This is more efficient in batch operations which deal with a number of mesh elements in one go. - These attribute buffers can potentially be passed directly to third-party libraries without requiring any kind of transformation. - The distinct types allow for a better representation of the attribute being specified, without invalid values being possible (cf representing a bool value in an FVector4). Attributes also have default values, and a flags field which confers use-specific properties to them. Editable Mesh currently uses this to determine whether an attribute's value can be automatically initialized by lerping the values of its neighbours, as well as for identifying auto-generated attributes such as tangents/normals. This is desirable as it means that even unknown / third-party attributes can potentially be handled transparently by Editable Mesh, without requiring the code to be extended. Certain higher-level operations in EditableMesh have been optimized to make full use of vertex instances where possible. The welding/splitting of identical vertex instances has been removed from here, as the aim is to unify this with mesh utility code elsewhere. Various bug fixes. #rb Alexis.Matte [CL 3794563 by Richard TalbotWatkin in Dev-Geometry branch]
2017-12-07 13:02:12 -05:00
const FVector EdgeVertex0Location = ComponentToWorld.TransformPosition( VertexPositions[ EdgeVertex0 ] );
const FVector EdgeVertex1Location = ComponentToWorld.TransformPosition( VertexPositions[ EdgeVertex1 ] ) ;
SplitStartLocation = FMath::Lerp( EdgeVertex0Location, EdgeVertex1Location, EdgeSplit );
}
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
const FPlane PolygonPlane = EditableMesh->ComputePolygonPlane( CandidatePolygonID ).TransformBy( ComponentToWorld.ToMatrixWithScale() );
const FVector LaserImpactOnPolygonPlane = FMath::LinePlaneIntersection( LaserPointerStart, LaserPointerEnd, PolygonPlane );
// @todo mesheditor splitpolygon: Ideally this would be more "fuzzy", and allow the interactor to extend beyond the range of the polygon. But it will make figuring out which polygon to split more tricky.
// @todo mesheditor urgent: Can crash with "Colinear points in FMath::ComputeBaryCentric2D()" Needs repro.
FVector TriangleVertexWeights;
FTriangleID TriangleID = EditableMesh->ComputeBarycentricWeightForPointOnPolygon( CandidatePolygonID, ComponentToWorld.InverseTransformPosition( LaserImpactOnPolygonPlane ), /* Out */ TriangleVertexWeights );
if( TriangleID != FTriangleID::Invalid )
{
const FVector SplitDirection = ( LaserImpactOnPolygonPlane - SplitStartLocation ).GetSafeNormal();
// Trace out within the polygon to figure out where the split should connect to
float ClosestEdgeDistance = TNumericLimits<float>::Max();
FEdgeID ClosestEdgeID = FEdgeID::Invalid;
static TArray<FEdgeID> PolygonPerimeterEdgeIDs;
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
EditableMesh->GetPolygonPerimeterEdges( CandidatePolygonID, /* Out */ PolygonPerimeterEdgeIDs );
for( const FEdgeID TargetEdgeID : PolygonPerimeterEdgeIDs )
{
bool bIsDisqualified = false;
if( StartingEdgeID != FEdgeID::Invalid )
{
if( StartingEdgeID == TargetEdgeID )
{
// The edge we dragged from is disqualified as a target
bIsDisqualified = true;
}
}
else if( ensure( StartingVertexID != FVertexID::Invalid ) )
{
static TArray<FEdgeID> AdjacentEdgeIDs;
EditableMesh->GetVertexConnectedEdges( StartingVertexID, /* Out */ AdjacentEdgeIDs );
if( AdjacentEdgeIDs.Contains( TargetEdgeID ) )
{
// Never split an edge that's directly connected to the starting vertex
bIsDisqualified = true;
}
}
FVertexID EdgeVertex0, EdgeVertex1;
EditableMesh->GetEdgeVertices( TargetEdgeID, /* Out */ EdgeVertex0, /* Out */ EdgeVertex1 );
Total revamp of mesh element attribute model. Attributes now have a number of possible types (FVector, FVector4, FVector2D, float, int, bool, FName, UObject*) and are exposed as individual flat arrays, indexed by element ID. For example, vertex positions are essentially exposed as an array of FVector which can be directly accessed and modified. This has a number of advantages: - It is completely extensible: new attributes can be created (even by a third party) and added to a mesh description without requiring a serialization version bump, or any change to the parent structures. - This is more efficient in batch operations which deal with a number of mesh elements in one go. - These attribute buffers can potentially be passed directly to third-party libraries without requiring any kind of transformation. - The distinct types allow for a better representation of the attribute being specified, without invalid values being possible (cf representing a bool value in an FVector4). Attributes also have default values, and a flags field which confers use-specific properties to them. Editable Mesh currently uses this to determine whether an attribute's value can be automatically initialized by lerping the values of its neighbours, as well as for identifying auto-generated attributes such as tangents/normals. This is desirable as it means that even unknown / third-party attributes can potentially be handled transparently by Editable Mesh, without requiring the code to be extended. Certain higher-level operations in EditableMesh have been optimized to make full use of vertex instances where possible. The welding/splitting of identical vertex instances has been removed from here, as the aim is to unify this with mesh utility code elsewhere. Various bug fixes. #rb Alexis.Matte [CL 3794563 by Richard TalbotWatkin in Dev-Geometry branch]
2017-12-07 13:02:12 -05:00
const FVector EdgeVertex0Location = ComponentToWorld.TransformPosition( VertexPositions[ EdgeVertex0 ] );
const FVector EdgeVertex1Location = ComponentToWorld.TransformPosition( VertexPositions[ EdgeVertex1 ] );
if( !bIsDisqualified )
{
// Don't bother trying to split unless the laser impact point is reasonably close to the target edge. Otherwise it just feels
// bad, because our split direction will be unstable as the interactor moves along the polygon
const float Distance = FMath::PointDistToSegment( LaserImpactOnPolygonPlane, EdgeVertex0Location, EdgeVertex1Location );
if( Distance > 20.0f ) // @todo mesheditor tweak: Should be based on polygon area or edge size, and probably scale with distance like other fuzzy tests. Also, consider making this a distance *from* the impact point instead.
{
bIsDisqualified = true;
}
}
if( !bIsDisqualified )
{
// Don't allow connecting to edges that are either degenerate or colinear to the split direction
const FVector EdgeDirection = ( EdgeVertex1Location - EdgeVertex0Location ).GetSafeNormal();
if( FMath::IsNearlyZero( EdgeDirection.SizeSquared() ) || FMath::IsNearlyEqual( FMath::Abs( FVector::DotProduct( SplitDirection, EdgeDirection ) ), 1.0f ) )
{
bIsDisqualified = true;
}
if( !bIsDisqualified )
{
FVector ClosestPointOnSplitLine, ClosestPointOnEdge;
FMath::SegmentDistToSegmentSafe(
SplitStartLocation, SplitStartLocation + SplitDirection * 99999.0f,
EdgeVertex0Location, EdgeVertex1Location,
/* Out */ ClosestPointOnSplitLine,
/* Out */ ClosestPointOnEdge );
// Closest points should be the same if there was actually an intersection
if( ClosestPointOnSplitLine.Equals( ClosestPointOnEdge ) )
{
const float DistanceToEdgeImpact = ( ClosestPointOnEdge - SplitStartLocation ).Size();
if( DistanceToEdgeImpact < ClosestEdgeDistance )
{
ClosestEdgeDistance = DistanceToEdgeImpact;
ClosestEdgeID = TargetEdgeID;
}
}
}
}
}
if( ClosestEdgeID != FEdgeID::Invalid )
{
FVertexID EdgeVertex0, EdgeVertex1;
EditableMesh->GetEdgeVertices( ClosestEdgeID, /* Out */ EdgeVertex0, /* Out */ EdgeVertex1 );
Total revamp of mesh element attribute model. Attributes now have a number of possible types (FVector, FVector4, FVector2D, float, int, bool, FName, UObject*) and are exposed as individual flat arrays, indexed by element ID. For example, vertex positions are essentially exposed as an array of FVector which can be directly accessed and modified. This has a number of advantages: - It is completely extensible: new attributes can be created (even by a third party) and added to a mesh description without requiring a serialization version bump, or any change to the parent structures. - This is more efficient in batch operations which deal with a number of mesh elements in one go. - These attribute buffers can potentially be passed directly to third-party libraries without requiring any kind of transformation. - The distinct types allow for a better representation of the attribute being specified, without invalid values being possible (cf representing a bool value in an FVector4). Attributes also have default values, and a flags field which confers use-specific properties to them. Editable Mesh currently uses this to determine whether an attribute's value can be automatically initialized by lerping the values of its neighbours, as well as for identifying auto-generated attributes such as tangents/normals. This is desirable as it means that even unknown / third-party attributes can potentially be handled transparently by Editable Mesh, without requiring the code to be extended. Certain higher-level operations in EditableMesh have been optimized to make full use of vertex instances where possible. The welding/splitting of identical vertex instances has been removed from here, as the aim is to unify this with mesh utility code elsewhere. Various bug fixes. #rb Alexis.Matte [CL 3794563 by Richard TalbotWatkin in Dev-Geometry branch]
2017-12-07 13:02:12 -05:00
const FVector EdgeVertex0Location = ComponentToWorld.TransformPosition( VertexPositions[ EdgeVertex0 ] );
const FVector EdgeVertex1Location = ComponentToWorld.TransformPosition( VertexPositions[ EdgeVertex1 ] );
const FVector ImpactOnEdge = SplitStartLocation + SplitDirection * ClosestEdgeDistance;
const float EdgeLength = ( EdgeVertex1Location - EdgeVertex0Location ).Size();
const float ImpactProgressAlongEdge = ( ImpactOnEdge - EdgeVertex0Location ).Size() / EdgeLength;
// If we're really close to one side or the other of an edge, try to connect with an existing vertex instead
const float EdgeProgressVertexSnapThreshold = 0.075f; // @todo mesheditor splitpolygon: Should be actual 'fuzzy' distance consistent with MeshEditorMode, in world/screen units, not percentage of edge progress
const bool bIsCloseToEdgeVertex0 = ImpactProgressAlongEdge < EdgeProgressVertexSnapThreshold;
const bool bIsCloseToEdgeVertex1 = ImpactProgressAlongEdge > 1.0f - EdgeProgressVertexSnapThreshold;
if( bIsCloseToEdgeVertex0 || bIsCloseToEdgeVertex1 )
{
// Prefer connecting to a vertex
const FVertexID TargetVertexID = bIsCloseToEdgeVertex0 ? EdgeVertex0 : EdgeVertex1;
bool bIsDisqualified = false;
if( StartingEdgeID != FEdgeID::Invalid )
{
FVertexID StartingEdgeVertex0, StartingEdgeVertex1;
EditableMesh->GetEdgeVertices( StartingEdgeID, /* Out */ StartingEdgeVertex0, /* Out */ StartingEdgeVertex1 );
if( TargetVertexID == StartingEdgeVertex0 || TargetVertexID == StartingEdgeVertex1 )
{
// We're dragging from an edge. We never want to use that edge's vertices as targets.
bIsDisqualified = true;
}
}
else if( ensure( StartingVertexID != FVertexID::Invalid ) )
{
if( TargetVertexID == StartingVertexID )
{
// The vertex we dragged from is disqualified as a target
bIsDisqualified = true;
}
else
{
// The vertices that share an edge with our starting vertex are disqualified, because we don't want
// to create an edge that's colinear with an existing edge
static TArray<FVertexID> AdjacentVertexIDs;
EditableMesh->GetVertexAdjacentVertices( StartingVertexID, /* Out */ AdjacentVertexIDs );
if( AdjacentVertexIDs.Contains( TargetVertexID ) )
{
bIsDisqualified = true;
}
}
}
if( !bIsDisqualified )
{
// Don't allow connecting to vertices that are colinear to the split direction
Total revamp of mesh element attribute model. Attributes now have a number of possible types (FVector, FVector4, FVector2D, float, int, bool, FName, UObject*) and are exposed as individual flat arrays, indexed by element ID. For example, vertex positions are essentially exposed as an array of FVector which can be directly accessed and modified. This has a number of advantages: - It is completely extensible: new attributes can be created (even by a third party) and added to a mesh description without requiring a serialization version bump, or any change to the parent structures. - This is more efficient in batch operations which deal with a number of mesh elements in one go. - These attribute buffers can potentially be passed directly to third-party libraries without requiring any kind of transformation. - The distinct types allow for a better representation of the attribute being specified, without invalid values being possible (cf representing a bool value in an FVector4). Attributes also have default values, and a flags field which confers use-specific properties to them. Editable Mesh currently uses this to determine whether an attribute's value can be automatically initialized by lerping the values of its neighbours, as well as for identifying auto-generated attributes such as tangents/normals. This is desirable as it means that even unknown / third-party attributes can potentially be handled transparently by Editable Mesh, without requiring the code to be extended. Certain higher-level operations in EditableMesh have been optimized to make full use of vertex instances where possible. The welding/splitting of identical vertex instances has been removed from here, as the aim is to unify this with mesh utility code elsewhere. Various bug fixes. #rb Alexis.Matte [CL 3794563 by Richard TalbotWatkin in Dev-Geometry branch]
2017-12-07 13:02:12 -05:00
const FVector VertexLocation = ComponentToWorld.TransformPosition( VertexPositions[ TargetVertexID ] );
const FVector VertexDirection = ( VertexLocation - SplitStartLocation ).GetSafeNormal();
if( FMath::IsNearlyZero( VertexDirection.SizeSquared() ) || FMath::IsNearlyEqual( FMath::Abs( FVector::DotProduct( SplitDirection, VertexDirection ) ), 1.0f ) )
{
bIsDisqualified = true;
}
if( !bIsDisqualified )
{
// Connect to this vertex!
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
PolygonToSplit = CandidatePolygonID;
ToVertexID = TargetVertexID;
}
}
}
// If a vertex wasn't eligible, go ahead and connect to the edge
if( ToVertexID == FVertexID::Invalid )
{
// Split the edge to create a new vertex that we'll connect to
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
PolygonToSplit = CandidatePolygonID;
// Go ahead and split the target edge
static TArray<FVertexID> NewVertexIDs;
NewVertexIDs.Reset();
static TArray<float> SplitEdgeSplitList;
SplitEdgeSplitList.SetNumUninitialized( 1 );
SplitEdgeSplitList[ 0 ] = ImpactProgressAlongEdge;
EditableMesh->SplitEdge( ClosestEdgeID, SplitEdgeSplitList, /* Out */ NewVertexIDs );
check( NewVertexIDs.Num() == 1 );
// Great! We now have a vertex to connect with
ToVertexID = NewVertexIDs[ 0 ];
}
}
}
}
}
}
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
if( PolygonToSplit != FPolygonID::Invalid )
{
check( ToVertexID != FVertexID::Invalid );
FVertexID FromVertexID = FVertexID::Invalid;
if( StartingEdgeID != FEdgeID::Invalid )
{
// First, split the edge
static TArray<FVertexID> NewVertexIDs;
NewVertexIDs.Reset();
static TArray<float> SplitEdgeSplitList;
SplitEdgeSplitList.SetNumUninitialized( 1 );
SplitEdgeSplitList[ 0 ] = EdgeSplit;
EditableMesh->SplitEdge( StartingEdgeID, SplitEdgeSplitList, /* Out */ NewVertexIDs );
check( NewVertexIDs.Num() == 1 );
FromVertexID = NewVertexIDs[ 0 ];
}
else if( ensure( StartingVertexID != FVertexID::Invalid ) )
{
FromVertexID = StartingVertexID;
}
check( FromVertexID != FVertexID::Invalid );
static TArray< FPolygonToSplit > PolygonsToSplit;
PolygonsToSplit.Reset();
PolygonsToSplit.SetNum( 1, false );
Copying //Tasks/UE4/Dev-Geometry-Refactor to Dev-Geometry (//UE4/Dev-Geometry) CL 3365379: Beginnings of 'uber mesh'. Moved mesh description across to UEditableMesh. Renamed Rendering Vertices to Vertex Instances, they will form a fundamental part of the mesh description, in representing shared vertices. CL 3365385: Renamed Sections to PolygonGroups. This prevents confusion between editable mesh sections and rendering sections (from the static mesh). It also means we can potentially open up the concept of 'polygon groups' to represent more than static mesh sections if we wish to. CL 3365387: Removed FPolygonRef and flattened Polygons container. Added new methods to act on the entire Polygons container. Added RenderingPolygons, RenderingTriangles, RenderingPolygonGroups containers which will eventually live on the adapter, and which are solely involved in maintaining the render buffers. Fixed Quadrangulate so that it doesn't merge across polygon groups. CL 3365390: Started to remove virtuals from EditableMesh. First separation of ubermesh intrinsic properties from implementation details in EditableStaticMesh. CL 3396167: Picking out generic functionality from the _Internal methods, moving them into UEditableMesh code, ready to remove the inheritance entirely. Implemented adapter interface (currently living within UEditableStaticMesh) and calling into it from UEditableMesh. Big revamp to handling of rendering vertices; now exist as vertex instances, which are dynamically shared / split, depending on whether colors / textures are identical. Normal/tangent is handled separately as it is autogenerated. Whether neighboring edges are hard or not determines whether a vertex will be automatically instanced, regardless of other attributes. We infer whether a vertex is 'hard' from whether the mesh is split by hard edges at that point (done by tracing adjacent polygons through only soft edges); hard vertices are always instanced for that poly. This simplifies the autogeneration of normals, as it now simply iterates through stale vertex instances, applying the weighted contribution from each connected polygon. Polygon normals are now cached as a read-only attribute, to make this process even quicker. Rewrite of the basic primitive operations (Create/Delete polygon / edges / vertices / vertex instances). Added a new primitive operation to substitute vertex instances on a polygon contour. Setting edge hardness attribute now potentially instances or deletes vertex instances, as does setting vertex instance attributes. CL 3396229: Intermediate check-in (phase 2). Removed a whole load of dead code. Broke functionality, until InitEditableStaticMesh is rewritten to use the public UEditableMesh API. CL 3401798: Intermediate check-in (phase 3). Implemented a simple alternative to tangent basis generation as MikkTSpace doesn't quite fit our model currently (but with a view to revisiting it in the future; nothing has been removed for now). Fixed edge hardness setting. Added missing hash function for FVertexInstanceID. CL 3403360: Fixed some bugs in tangent/normal handling. Now correctly includes contributions from adjacent polygons in the same smoothing group but different vertex instance when calculating a vertex instance normal. CL 3411429: Fixed a bunch of bugs: - Fixed issue where adjacent polygons the other side of a UV seam were not contributing to vertex instance normal calculation. - Fixed various issues where out arrays weren't being reset, and mesh change actions were not being called after setting up the input array. - Various changes to converting static meshes to editable meshes. - Removed old ContourVertices arrays from polygon contours; now polygons exclusively use an array of vertex instances. - Updated natvis to parse new element ID types. CL 3418022: More bug fixes: - Sorted an issue with undo where vertex instance merging / splitting was happening twice, once due to the parent operation, and another time due to the revert transactions which are created. - Added options to delete orphaned vertex instances in DeletePolygons and other operations which remove vertex instances. - Fixed issue with SplitEdge due to subtle bug where connected edges were duplicated in a vertex, instead of being added uniquely. - Changed order that undo items are added to the stack so that the revert operation works smoothly. CL 3427887: Fixed issue which occurs in certain circumstances with Split Edge. Fixed regression which was causing various operations to fail when setting edge hardness. CL 3430665: Specify polygon edge hardness policy when creating a polygon. Simplified some existing uses of CreatePolygons. Changed behavior to match original behavior so that only *new* edge IDs are returned by CreatePolygons. CL 3430927: Corrected normal/tangent generation for polygons and adjacent polygons. CL 3431134: Fixed small issue with remove vertex in certain circumstances. CL 3446929: - Added a triangle list to the FMeshPolygon struct, making triangulation a first-class operation instead of an implementation detail. - Repurposed UEditableStaticMesh as an editable mesh adapter, in a separate class hierarchy. - Tidied up interfaces - Moved serialization, compact/uncompact into UEditableMesh - Currently broken: instance changes. This is pending a rethink on how we scope objects in the assets. CL 3446954: Renamed EditableStaticMesh.* to EditableStaticMeshAdapter.* to reflect its new role and place in the class hierarchy. CL 3449133: Fixed issue with splitting vertices due to the wrong polygon ID being used by GetPolygonsInSameSmoothingGroup. Also fixed an error where the list being iterated was potentially being mutated by the split operation. CL 3449362: Fixed ChangePolygonsVertexInstances to fix up the triangle list after replacing vertex instances. Not sure where this code went! CL 3458823: - Deferred normals calculation until the end of the transaction for efficiency - Fixed a bug in inserting edge loops - Fixed a bug in splitting vertex instances when hardening an edge - Moved verbose logging into a LogEditableMesh category. CL 3461128: Included a bunch of required header files (IWYU). CL 3464397: Change to handling of triangulation and normal/tangent generation. Now this is done as a deferred process during EndTransaction. This achieves three goals: 1) Polygons are not repeatedly triangulated unnecessarily as a consequence of suboperations. 2) We are able to calculate and cache the polygon tangent basis upfront, which is then used for every connected vertex instance tangent basis - this is quickerthan repeatedly calculating it each time it's needed. 3) We no longer need to treat triangulation or vertex generation as a special FChange. Instead it is rolled into the FStartOrEndTransaction change. Hence we can remove the awkward code which was triangulating polygons before or after other actions, depending on whether undo was being processed. Note: seem to have introduced a bug which is getting the tangents subtly wrong in certain cases; need to investigate. CL 3465738: Fixed regression introduced in tangent calculations. Results now match previous version. Stripped out redundant code, and removed superfluous logging. When building the editable mesh, the tangent basis for all polygons is now precached. CL 3465744: Removed old debugging code. CL 3472569: Reinstated Compact (currently after every topology-changing transaction; will make it much more infrequent when I'm sure it works perfectly). Made some changes to fixing up element IDs. Added a new method in the Adapter interface to reindex elements on compact/uncompact. CL 3476078: Fixed issue when loading edited meshes. They now must always have their render mesh rebuilt on PostLoad. (This seems to arise from the way the circular dependency between Engine and MeshEditingRuntime has been resolved). CL 3476104: Reinstated instanced editable meshes. CL 3484401: Added missing file (EditableMeshAdapter.h) CL 3484699: Added new adapter method OnCreateEmptyVertexRange, now needed again by extrude (I removed this action, but Mike's new extrude requires it) #codereview Mike.Fricker #rb none [CL 3490308 by Richard TalbotWatkin in Dev-Geometry branch]
2017-06-14 16:31:26 -04:00
PolygonsToSplit[ 0 ].PolygonID = PolygonToSplit;
FVertexPair& VertexPair = *new( PolygonsToSplit[ 0 ].VertexPairsToSplitAt ) FVertexPair();
VertexPair.VertexID0 = FromVertexID;
VertexPair.VertexID1 = ToVertexID;
static TArray<FEdgeID> NewEdgeIDs;
EditableMesh->SplitPolygons( PolygonsToSplit, /* Out */ NewEdgeIDs );
// Select the new edges that were created
{
for( const FEdgeID NewEdgeID : NewEdgeIDs )
{
FMeshElement MeshElementToSelect;
{
MeshElementToSelect.Component = Component;
MeshElementToSelect.ElementAddress.SubMeshAddress = EditableMesh->GetSubMeshAddress();
MeshElementToSelect.ElementAddress.ElementType = EEditableMeshElementType::Edge;
MeshElementToSelect.ElementAddress.ElementID = NewEdgeID;
}
MeshElementsToSelect.Add( MeshElementToSelect );
}
}
}
MeshEditorMode.TrackUndo( EditableMesh, EditableMesh->MakeUndo() );
MeshEditorMode.SelectMeshElements( MeshElementsToSelect );
}
}
#undef LOCTEXT_NAMESPACE