|
7 | 7 | #include <MRMesh/MRVector3.h> |
8 | 8 | #include <MRMesh/MRBitSet.h> |
9 | 9 | #include <MRMesh/MRId.h> |
| 10 | +#include <MRMesh/MRFillHoleNicely.h> |
| 11 | +#include <MRMesh/MRRegionBoundary.h> |
10 | 12 | #include <MRMesh/MRPositionVertsSmoothly.h> |
11 | 13 |
|
| 14 | +#include "MRPositionVertsSmoothly.h" |
| 15 | +#include "MRUtils.h" |
| 16 | + |
12 | 17 | using namespace emscripten; |
13 | 18 | using namespace MR; |
14 | 19 |
|
| 20 | +namespace MRJS |
| 21 | +{ |
| 22 | + |
| 23 | +val inflateToothRootImpl( Mesh& mesh, const InflateSettings& inflateSettings ) |
| 24 | +{ |
| 25 | + val returnObj = val::object(); |
| 26 | + |
| 27 | + |
| 28 | + /// |
| 29 | + auto holeEdges = mesh.topology.findHoleRepresentiveEdges(); |
| 30 | + EdgeId maxAreaHole; |
| 31 | + float maxHoleAreaSq = 0.0f; |
| 32 | + for ( const auto& e : holeEdges ) |
| 33 | + { |
| 34 | + float areaSq = mesh.holeDirArea( e ).lengthSq(); |
| 35 | + if ( areaSq > maxHoleAreaSq ) |
| 36 | + { |
| 37 | + maxHoleAreaSq = areaSq; |
| 38 | + maxAreaHole = e; |
| 39 | + } |
| 40 | + } |
| 41 | + /// |
| 42 | + |
| 43 | + |
| 44 | + FillHoleNicelySettings fillHoleParams; |
| 45 | + fillHoleParams.maxEdgeSplits = 1000000; // just a big number not to stop subdivision by this criteria |
| 46 | + fillHoleParams.maxEdgeLen = mesh.averageEdgeLength(); // stop subdivision by this criteria |
| 47 | + for ( const auto& e : holeEdges ) |
| 48 | + { |
| 49 | + fillHoleParams.smoothCurvature = ( e != maxAreaHole ); // The maximum aperture is not smoothed in order to facilitate subsequent expansion |
| 50 | + auto newFaces = fillHoleNicely( mesh, e, fillHoleParams ); |
| 51 | + |
| 52 | + if ( e == maxAreaHole ) |
| 53 | + { |
| 54 | + // Find the newly generated internal vertices |
| 55 | + auto newVerts = getInnerVerts( mesh.topology, newFaces ); |
| 56 | + inflate( mesh, newVerts, inflateSettings ); |
| 57 | + |
| 58 | + |
| 59 | + Mesh newFacesMesh; |
| 60 | + auto newInflatedFaces = getInnerFaces( mesh.topology, newVerts ); |
| 61 | + newFacesMesh.addMeshPart( {mesh, &newInflatedFaces} ); |
| 62 | + val newFacesMeshData = MRJS::exportMeshMemoryView( newFacesMesh ); |
| 63 | + returnObj.set( "rootMesh", newFacesMesh ); |
| 64 | + returnObj.set( "rootMeshMV", newFacesMeshData ); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + val meshData = MRJS::exportMeshMemoryView( mesh ); |
| 70 | + |
| 71 | + returnObj.set( "success", true ); |
| 72 | + returnObj.set( "mesh", mesh ); |
| 73 | + returnObj.set( "meshMV", meshData ); |
| 74 | + |
| 75 | + return returnObj; |
| 76 | +} |
| 77 | + |
| 78 | +} // namespace MRJS |
| 79 | + |
| 80 | + |
15 | 81 | EMSCRIPTEN_BINDINGS( PositionVertsSmoothlyModule ) |
16 | 82 | { |
17 | | - class_<SpacingSettings>( "SpacingSettings" ) |
18 | | - .property( "region", &SpacingSettings::region, allow_raw_pointers() ) |
19 | | - .property( "dist", &SpacingSettings::dist ) |
20 | | - .property( "numIters", &SpacingSettings::numIters ) |
21 | | - .property( "stabilizer", &SpacingSettings::stabilizer ) |
22 | | - .property( "maxSumNegW", &SpacingSettings::maxSumNegW ) |
23 | | - .property( "isInverted", &SpacingSettings::isInverted ); |
24 | | - |
25 | | - value_object<InflateSettings>("InflateSettings") |
26 | | - .field("pressure", &InflateSettings::pressure) |
27 | | - .field("iterations", &InflateSettings::iterations) |
28 | | - .field("preSmooth", &InflateSettings::preSmooth) |
29 | | - .field( "gradualPressureGrowth", &InflateSettings::gradualPressureGrowth ); |
30 | | - |
31 | | - |
32 | | - function("positionVertsSmoothly", select_overload<void( Mesh&, const VertBitSet&, EdgeWeights, VertexMass, const VertBitSet * )>( &positionVertsSmoothly ), allow_raw_pointers() ); |
33 | | - function("positionVertsSmoothlyWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, EdgeWeights, VertexMass, const VertBitSet * )>( &positionVertsSmoothly ), allow_raw_pointers() ); |
34 | | - function("positionVertsSmoothlySharpBd", select_overload<void( Mesh&, const VertBitSet&, const Vector<Vector3f, VertId>*, const VertScalars* )>( &positionVertsSmoothlySharpBd ), allow_raw_pointers() ); |
35 | | - function("positionVertsSmoothlySharpBdWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, const Vector<Vector3f, VertId>* , const VertScalars* )>( &positionVertsSmoothlySharpBd ), allow_raw_pointers()); |
36 | | - function("positionVertsWithSpacing", select_overload<void( Mesh&, const SpacingSettings& )>( &positionVertsWithSpacing )); |
37 | | - function("positionVertsWithSpacingWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const SpacingSettings& )>( &positionVertsWithSpacing )); |
38 | | - function("inflate", select_overload<void( Mesh&, const VertBitSet&, const InflateSettings&)>( &inflate )); |
39 | | - function("inflateWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, const InflateSettings& )>( &inflate )); |
40 | | - function("inflate1WithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, float )>( &inflate1 )); |
| 83 | + class_<SpacingSettings>( "SpacingSettings" ) |
| 84 | + .constructor<>() |
| 85 | + .property( "region", &SpacingSettings::region, allow_raw_pointers() ) |
| 86 | + .property( "dist", &SpacingSettings::dist ) |
| 87 | + .property( "numIters", &SpacingSettings::numIters ) |
| 88 | + .property( "stabilizer", &SpacingSettings::stabilizer ) |
| 89 | + .property( "maxSumNegW", &SpacingSettings::maxSumNegW ) |
| 90 | + .property( "isInverted", &SpacingSettings::isInverted ); |
| 91 | + |
| 92 | + value_object<InflateSettings>( "InflateSettings" ) |
| 93 | + .field( "pressure", &InflateSettings::pressure ) |
| 94 | + .field( "iterations", &InflateSettings::iterations ) |
| 95 | + .field( "preSmooth", &InflateSettings::preSmooth ) |
| 96 | + .field( "gradualPressureGrowth", &InflateSettings::gradualPressureGrowth ); |
| 97 | + |
| 98 | + |
| 99 | + /// |
| 100 | + function( "positionVertsSmoothly", select_overload<void( Mesh&, const VertBitSet&, EdgeWeights, VertexMass, const VertBitSet* )>( &positionVertsSmoothly ), allow_raw_pointers() ); |
| 101 | + function( "positionVertsSmoothlyWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, EdgeWeights, VertexMass, const VertBitSet* )>( &positionVertsSmoothly ), allow_raw_pointers() ); |
| 102 | + |
| 103 | + function( "positionVertsSmoothlySharpBd", select_overload<void( Mesh&, const VertBitSet&, const Vector<Vector3f, VertId>*, const VertScalars* )>( &positionVertsSmoothlySharpBd ), allow_raw_pointers() ); |
| 104 | + function( "positionVertsSmoothlySharpBdWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, const Vector<Vector3f, VertId>*, const VertScalars* )>( &positionVertsSmoothlySharpBd ), allow_raw_pointers() ); |
| 105 | + |
| 106 | + function( "positionVertsWithSpacing", select_overload<void( Mesh&, const SpacingSettings& )>( &positionVertsWithSpacing ) ); |
| 107 | + function( "positionVertsWithSpacingWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const SpacingSettings& )>( &positionVertsWithSpacing ) ); |
| 108 | + |
| 109 | + function( "inflate", select_overload<void( Mesh&, const VertBitSet&, const InflateSettings& )>( &inflate ) ); |
| 110 | + function( "inflateWithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, const InflateSettings& )>( &inflate ) ); |
| 111 | + function( "inflate1WithTopology", select_overload<void( const MeshTopology&, VertCoords&, const VertBitSet&, float )>( &inflate1 ) ); |
| 112 | + /// |
| 113 | + |
| 114 | + |
| 115 | + function( "inflateToothRootImpl", &MRJS::inflateToothRootImpl ); |
41 | 116 | } |
0 commit comments