You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
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]
414 lines
16 KiB
C++
414 lines
16 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "SplitPolygon.h"
|
|
#include "IMeshEditorModeEditingContract.h"
|
|
#include "IMeshEditorModeUIContract.h"
|
|
#include "UICommandInfo.h"
|
|
#include "EditableMesh.h"
|
|
#include "MeshElement.h"
|
|
#include "MultiBoxBuilder.h"
|
|
#include "UICommandList.h"
|
|
#include "ViewportInteractor.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "MeshEditorMode"
|
|
|
|
|
|
void USplitPolygonFromVertexCommand::RegisterUICommand( FBindingContext* BindingContext )
|
|
{
|
|
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "SplitPolygonFromVertex", "Split Polygon Mode", "Set the primary action to split a polygon.", EUserInterfaceActionType::RadioButton, FInputChord() );
|
|
}
|
|
|
|
|
|
void USplitPolygonFromEdgeCommand::RegisterUICommand( FBindingContext* BindingContext )
|
|
{
|
|
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "SplitPolygonFromEdge", "Split Polygon Mode", "Set the primary action to split a polygon.", EUserInterfaceActionType::RadioButton, FInputChord() );
|
|
}
|
|
|
|
|
|
void USplitPolygonFromPolygonCommand::RegisterUICommand( FBindingContext* BindingContext )
|
|
{
|
|
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "SplitPolygonFromPolygon", "Split Polygon Mode", "Set the primary action to split a polygon.", 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.)
|
|
static TArray<FPolygonID> CandidatePolygonIDs;
|
|
CandidatePolygonIDs.Reset();
|
|
if( StartingEdgeID != FEdgeID::Invalid )
|
|
{
|
|
EditableMesh->GetEdgeConnectedPolygons( StartingEdgeID, /* Out */ CandidatePolygonIDs );
|
|
}
|
|
else if( ensure( StartingVertexID != FVertexID::Invalid ) )
|
|
{
|
|
EditableMesh->GetVertexConnectedPolygons( StartingVertexID, /* Out */ CandidatePolygonIDs );
|
|
}
|
|
|
|
FPolygonID PolygonToSplit = FPolygonID::Invalid;
|
|
FVertexID ToVertexID = FVertexID::Invalid;
|
|
|
|
|
|
{
|
|
FVector LaserPointerStart, LaserPointerEnd;
|
|
if( ViewportInteractor->GetLaserPointer( /* Out */ LaserPointerStart, /* Out */ LaserPointerEnd ) )
|
|
{
|
|
for( const FPolygonID CandidatePolygonID : CandidatePolygonIDs )
|
|
{
|
|
const FTransform ComponentToWorld = Component->GetComponentToWorld();
|
|
|
|
FVector SplitStartLocation;
|
|
if( StartingVertexID != FVertexID::Invalid )
|
|
{
|
|
SplitStartLocation = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( StartingVertexID, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
}
|
|
else if( ensure( StartingEdgeID != FEdgeID::Invalid ) )
|
|
{
|
|
FVertexID EdgeVertex0, EdgeVertex1;
|
|
EditableMesh->GetEdgeVertices( StartingEdgeID, /* Out */ EdgeVertex0, /* Out */ EdgeVertex1 );
|
|
|
|
const FVector EdgeVertex0Location = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( EdgeVertex0, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
const FVector EdgeVertex1Location = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( EdgeVertex1, UEditableMeshAttribute::VertexPosition(), 0 ) ) ;
|
|
|
|
SplitStartLocation = FMath::Lerp( EdgeVertex0Location, EdgeVertex1Location, EdgeSplit );
|
|
}
|
|
|
|
|
|
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.
|
|
FMeshTriangle Triangle;
|
|
FVector TriangleVertexWeights;
|
|
if( EditableMesh->ComputeBarycentricWeightForPointOnPolygon( CandidatePolygonID, ComponentToWorld.InverseTransformPosition( LaserImpactOnPolygonPlane ), /* Out */ Triangle, /* Out */ TriangleVertexWeights ) )
|
|
{
|
|
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;
|
|
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 );
|
|
const FVector EdgeVertex0Location = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( EdgeVertex0, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
const FVector EdgeVertex1Location = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( EdgeVertex1, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
|
|
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 );
|
|
|
|
const FVector EdgeVertex0Location = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( EdgeVertex0, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
const FVector EdgeVertex1Location = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( EdgeVertex1, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
|
|
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
|
|
const FVector VertexLocation = ComponentToWorld.TransformPosition( EditableMesh->GetVertexAttribute( TargetVertexID, UEditableMeshAttribute::VertexPosition(), 0 ) );
|
|
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!
|
|
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
|
|
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 ];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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 );
|
|
|
|
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
|
|
|