MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / divideMeshWithPlane

Function divideMeshWithPlane

source/MRMesh/MRMeshDivideWithPlane.cpp:11–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9{
10
11void divideMeshWithPlane( ObjectMeshData& data, const Plane3f& plane, const DivideMeshWithPlaneParams& params )
12{
13 MR_TIMER;
14 if ( !data.mesh )
15 {
16 assert( false );
17 if ( params.errors )
18 *params.errors = { "Invalid function input: empty mesh" };
19 return;
20 }
21
22 std::function<void( EdgeId, EdgeId, float )> onEdgeSplitCallback;
23
24 auto& mesh = *data.mesh;
25
26 const bool updateUV = !data.uvCoordinates.empty();
27 const bool updateVertColor = !data.vertColors.empty();
28 const bool updateEdgeSelection = data.selectedEdges.any();
29 const bool updateCreases = data.creases.any();
30
31 UndirectedEdgeBitSet newSelectEdge;
32 UndirectedEdgeBitSet otherNewSelectEdge;
33 UndirectedEdgeBitSet newCreases;
34 UndirectedEdgeBitSet otherNewCreases;
35
36 if ( updateUV || updateVertColor || updateEdgeSelection || updateCreases )
37 {
38 onEdgeSplitCallback = [&] ( EdgeId oldEdge, EdgeId newEdge, float ratio )
39 {
40 const auto vo = mesh.topology.org( newEdge );
41 const auto vd = mesh.topology.dest( oldEdge );
42 const auto newVertId = mesh.topology.dest( newEdge );
43 if ( updateUV )
44 data.uvCoordinates.autoResizeSet( newVertId, lerp( data.uvCoordinates[vo], data.uvCoordinates[vd], ratio ) );
45
46 if ( updateVertColor )
47 data.vertColors.autoResizeSet( newVertId, lerp( data.vertColors[vo], data.vertColors[vd], ratio ) );
48
49 if ( updateEdgeSelection )
50 {
51 if ( data.selectedEdges.test( oldEdge.undirected() ) )
52 {
53 newSelectEdge.autoResizeSet( newEdge.undirected(), true );
54 if ( params.otherPart )
55 otherNewSelectEdge.autoResizeSet( oldEdge.undirected(), true );
56 }
57 }
58 if ( updateCreases )
59 {
60 if ( data.creases.test( oldEdge.undirected() ) )
61 {
62 newCreases.autoResizeSet( newEdge.undirected(), true );
63 if ( params.otherPart )
64 otherNewCreases.autoResizeSet( oldEdge.undirected(), true );
65 }
66 }
67 };
68 }

Callers

nothing calls this directly

Calls 15

lerpFunction · 0.85
fillPlanarHoleFunction · 0.85
subdivideMeshFunction · 0.85
undirectedMethod · 0.80
rightMethod · 0.80
push_backMethod · 0.80
errorMethod · 0.80
trimWithPlaneFunction · 0.70
unexpectedFunction · 0.70
emptyMethod · 0.45
anyMethod · 0.45

Tested by

no test coverage detected