MeshLib Documentation
Loading...
Searching...
No Matches
Mesh modification

Some examples of mesh modification are presented here

  • C++
    #include <MRMesh/MRMesh.h>
    #include <MRMesh/MRTorus.h>
    int main()
    {
    // Relax mesh (5 iterations)
    MR::relax( mesh, {{ .iterations = 5 }} );
    // Subdivide mesh
    props.maxDeviationAfterFlip = 0.5f;
    // Rotate mesh
    MR::AffineXf3f rotationXf = MR::AffineXf3f::linear( MR::Matrix3f::rotation( MR::Vector3f::plusZ(), MR::PI_F * 0.5f ) );
    mesh.transform( rotationXf );
    return 0;
    }
    int main()
    Definition LaplacianDeformation.cpp:4
    Mesh makeTorus(float primaryRadius=1.0f, float secondaryRadius=0.1f, int primaryResolution=16, int secondaryResolution=16, std::vector< Vector3f > *points=nullptr)
    const std::shared_ptr< const Mesh > & mesh() const
    bool relax(Mesh &mesh, const MeshRelaxParams &params={}, const ProgressCallback &cb={})
    int subdivideMesh(Mesh &mesh, const SubdivideSettings &settings={})
  • Python
    import math
    import meshlib.mrmeshpy as mrmeshpy
    mesh = mrmeshpy.makeTorus()
    # Relax mesh (5 iterations)
    relax_params = mrmeshpy.MeshRelaxParams()
    relax_params.iterations = 5
    mrmeshpy.relax(mesh, relax_params)
    # Subdivide mesh
    props = mrmeshpy.SubdivideSettings()
    props.maxDeviationAfterFlip = 0.5
    mrmeshpy.subdivideMesh(mesh, props)
    # Rotate mesh
    rotation_xf = mrmeshpy.AffineXf3f.linear(mrmeshpy.Matrix3f.rotation(mrmeshpy.Vector3f.plusZ(), math.pi * 0.5))
    mesh.transform(rotation_xf)
  • C
    #include <MRCMesh/MRAffineXf.h>
    #include <MRCMesh/MRMatrix3.h>
    #include <MRCMesh/MRMesh.h>
    #include <MRCMesh/MRMeshRelax.h>
    #include <MRCMesh/MRMeshSubdivide.h>
    #include <MRCMesh/MRTorus.h>
    #include <math.h>
    #include <stdlib.h>
    int main( void )
    {
    MR_Mesh* mesh = MR_makeTorus( NULL, NULL, NULL, NULL, NULL );
    // Relax mesh (5 iterations)
    MR_MeshRelaxParams* meshRelaxParams = MR_MeshRelaxParams_DefaultConstruct();
    MR_MeshRelaxParams_Set_iterations( meshRelaxParams, 5 );
    MR_relax( mesh, meshRelaxParams, NULL );
    MR_MeshRelaxParams_Destroy( meshRelaxParams );
    // Subdivide mesh
    MR_SubdivideSettings* subdivideSettings = MR_SubdivideSettings_DefaultConstruct();
    MR_SubdivideSettings_Set_maxDeviationAfterFlip( subdivideSettings, 0.5f );
    MR_subdivideMesh_MR_Mesh( mesh, subdivideSettings );
    MR_SubdivideSettings_Destroy( subdivideSettings );
    // Rotate mesh
    MR_Vector3f plusZ = MR_Vector3f_plusZ();
    MR_Matrix3f rotMat = MR_Matrix3f_rotation_float( &plusZ, 1.57079632679489661923 ); // pi/2
    MR_AffineXf3f rotXf = MR_AffineXf3f_linear( &rotMat );
    MR_Mesh_transform( mesh, &rotXf, NULL );
    MR_Mesh_Destroy( mesh );
    return EXIT_SUCCESS;
    }
    static constexpr Vector3 plusZ() noexcept
  • C#
    public static class MeshModificationExample
    {
    public static void Main(string[] args)
    {
    var mesh = MR.makeTorus();
    // Relax mesh (5 iterations)
    MR.MeshRelaxParams relaxParams = new();
    relaxParams.iterations = 5;
    MR.relax(mesh, relaxParams);
    // Subdivide mesh
    MR.SubdivideSettings props = new();
    props.maxDeviationAfterFlip = 0.5f;
    MR.subdivideMesh(mesh, props);
    // Rotate mesh
    var rotationXf = MR.AffineXf3f.linear(MR.Matrix3f.rotation(MR.Vector3f.plusZ(), MathF.PI * 0.5f));
    mesh.transform(rotationXf);
    }
    }
  • JavaScript
    import createMeshLib from '@meshinspector/meshlib';
    const ml = await createMeshLib();
    using mesh = ml.makeTorus(1.0, 0.1, 16, 16);
    // Relax mesh (5 iterations)
    using relaxParams = new ml.MeshRelaxParams();
    relaxParams.iterations = 5;
    ml.relax(mesh, relaxParams);
    // Subdivide mesh
    using subdivideSettings = new ml.SubdivideSettings();
    subdivideSettings.maxDeviationAfterFlip = 0.5;
    ml.subdivideMesh(mesh, subdivideSettings);
    // Rotate mesh
    using rotation = ml.Matrix3f.rotation(ml.Vector3.plusZ(), Math.PI * 0.5);
    using rotationXf = ml.AffineXf3f.linear(rotation);
    mesh.transform(rotationXf);
    Note
    The using declaration requires Node.js 24+ or a modern browser. On older runtimes, call .delete() on each object instead (see Memory Management in the JavaScript Setup Guide).
  • Rust
    use meshlib::{AffineXf3f, Matrix3f, MeshRelaxParams, SubdivideSettings, Vector3f};
    fn main()
    {
    let mut mesh = meshlib::make_torus(None, None, None, None, None);
    // Relax mesh (5 iterations)
    let mut relax_params = MeshRelaxParams::new();
    relax_params.set_iterations(5);
    meshlib::relax(&mut mesh, Some(&relax_params), None);
    // Subdivide mesh
    let mut props = SubdivideSettings::new();
    props.set_max_deviation_after_flip(0.5);
    meshlib::subdivide_mesh_mr_mesh(&mut mesh, Some(&props));
    // Rotate mesh
    let rotation_xf = AffineXf3f::linear(&Matrix3f::rotation_float(&Vector3f::plus_z(), std::f32::consts::PI * 0.5));
    mesh.transform(&rotation_xf, None);
    }
  • Java
    import meshlib.AffineXf3f;
    import meshlib.Functions;
    import meshlib.Matrix3f;
    import meshlib.Mesh;
    import meshlib.MeshRelaxParams;
    import meshlib.SubdivideSettings;
    import meshlib.Vector3f;
    // The class isn't public because of the `.dox.java` file name, the launcher doesn't mind.
    class MeshModification
    {
    public static void main(String[] args)
    {
    Mesh mesh = Functions.makeTorus(null, null, null, null, null);
    // Relax mesh (5 iterations)
    MeshRelaxParams relaxParams = new MeshRelaxParams();
    relaxParams.setIterations(5);
    Functions.relax(mesh, relaxParams, null);
    // Subdivide mesh
    SubdivideSettings props = new SubdivideSettings();
    props.setMaxDeviationAfterFlip(0.5f);
    Functions.subdivideMesh(mesh, props);
    // Rotate mesh
    AffineXf3f rotationXf = AffineXf3f.linear(Matrix3f.rotation(Vector3f.plusZ(), (float)Math.PI * 0.5f));
    mesh.transform(rotationXf, null);
    }
    }