@@ -36,19 +36,7 @@ class BoolResults {
3636 }
3737};
3838
39- /* *
40- *@brief Cut mesh with polyline
41- *
42- * 1. Project points of polyline to mesh
43- * 2. Convert result vector to `cutMesh()` input type
44- * 3. Do `cutMesh()` (it works only with contours without self-intersections)
45- *
46- * @param mesh
47- * @param coordinates Must be closed
48- * @param coordinatesLength
49- * @return val
50- */
51- val cutMeshWithPolylineImpl ( Mesh& mesh, const std::vector<float >& coordinates )
39+ val cutMeshWithPolylineImplTest ( Mesh& mesh, const std::vector<float >& coordinates )
5240{
5341 std::vector<Vector3f> polyline;
5442
@@ -121,22 +109,15 @@ val cutMeshWithPolylineImpl( Mesh& mesh, const std::vector<float>& coordinates )
121109 }
122110 }
123111
124- // FIXME:
125- // auto [innerMesh, outerMesh] = returnParts_( mesh, cutResults.resultCut );
126-
127- auto innerBitSet = fillContourLeft ( mesh.topology , cutResults.resultCut );
128- Mesh innerMesh = mesh.cloneRegion ( innerBitSet );
129-
112+ auto [innerMesh, outerMesh] = MRJS::returnParts ( mesh, cutResults.resultCut );
130113 val innerMeshData = MRJS::exportMeshMemoryView ( innerMesh );
131- // val outerMeshData = MRJS::exportMeshMemoryView( outerMesh );
132-
133-
114+ val outerMeshData = MRJS::exportMeshMemoryView ( outerMesh );
134115
135116
136117 val obj = val::object ();
137118 obj.set ( " success" , true );
138119 obj.set ( " innerMesh" , innerMeshData );
139- // obj.set( "outerMesh", outerMeshData );
120+ obj.set ( " outerMesh" , outerMeshData );
140121 obj.set ( " jsTestProjectedPoint" , jsTestProjectedPoint );
141122 obj.set ( " jsTestProjectedContour" , jsTestProjectedContour );
142123 obj.set ( " jsTestCutPoints" , jsTestCutPoints );
@@ -153,6 +134,78 @@ val cutMeshWithPolylineImpl( Mesh& mesh, const std::vector<float>& coordinates )
153134 }
154135}
155136
137+ /* *
138+ *@brief Cut mesh with polyline
139+ *
140+ * 1. Project points of polyline to mesh
141+ * 2. Convert result vector to `cutMesh()` input type
142+ * 3. Do `cutMesh()` (it works only with contours without self-intersections)
143+ *
144+ * @param mesh
145+ * @param coordinates Must be closed
146+ * @param coordinatesLength
147+ * @return val
148+ */
149+ val cutMeshWithPolylineImpl ( Mesh& mesh, const std::vector<float >& coordinates )
150+ {
151+ std::vector<Vector3f> polyline;
152+
153+ int coordinatesLength = coordinates.size ();
154+ if (coordinatesLength % 3 != 0 ) {
155+ val obj = val::object ();
156+ obj.set ( " success" , false );
157+ obj.set ( " error" , " Coordinates length must be a multiple of 3!" );
158+
159+ return obj;
160+ }
161+
162+ polyline.reserve ( coordinatesLength / 3 );
163+
164+ for ( size_t i = 0 ; i < coordinatesLength; i += 3 )
165+ {
166+ polyline.emplace_back ( coordinates[i], coordinates[i + 1 ], coordinates[i + 2 ] );
167+ }
168+ Polyline3 initialPolyline;
169+ initialPolyline.addFromPoints ( polyline.data (), polyline.size (), true );
170+
171+ std::vector<MeshTriPoint> projectedPolyline;
172+ projectedPolyline.reserve ( initialPolyline.points .size () );
173+ MeshPart m = MeshPart ( mesh, nullptr );
174+
175+ mesh.getAABBTree (); // Create tree in parallel before loop
176+ for ( Vector3f pt : initialPolyline.points )
177+ {
178+ MeshProjectionResult mpr = findProjection ( pt, m );
179+ projectedPolyline.push_back ( mpr.mtp );
180+ }
181+
182+ auto meshContour = convertMeshTriPointsToMeshContour ( mesh, projectedPolyline );
183+ if ( meshContour )
184+ {
185+ CutMeshResult cutResults = cutMesh ( mesh, { *meshContour } );
186+
187+ auto [innerMesh, outerMesh] = MRJS::returnParts ( mesh, cutResults.resultCut );
188+ val innerMeshData = MRJS::exportMeshMemoryView ( innerMesh );
189+ val outerMeshData = MRJS::exportMeshMemoryView ( outerMesh );
190+
191+
192+ val obj = val::object ();
193+ obj.set ( " success" , true );
194+ obj.set ( " innerMesh" , innerMeshData );
195+ obj.set ( " outerMesh" , outerMeshData );
196+
197+ return obj;
198+ } else {
199+ std::string error = meshContour.error ();
200+
201+ val obj = val::object ();
202+ obj.set ( " success" , false );
203+ obj.set ( " error" , " convertMeshTriPointsToMeshContour: " + error );
204+
205+ return obj;
206+ }
207+ }
208+
156209/* *
157210 *@brief Cut and extrude mesh with polyline
158211 *
@@ -285,4 +338,5 @@ EMSCRIPTEN_BINDINGS( ContoursCutModule )
285338 .field ( " fbsWithContourIntersections" , &CutMeshResult::fbsWithContourIntersections );
286339
287340 function ( " cutMeshWithPolylineImpl" , &cutMeshWithPolylineImpl );
341+ function ( " cutMeshWithPolylineImplTest" , &cutMeshWithPolylineImplTest );
288342}
0 commit comments