Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# examples? #3739

Open
seghier opened this issue Nov 24, 2024 · 2 comments
Open

C# examples? #3739

seghier opened this issue Nov 24, 2024 · 2 comments
Assignees

Comments

@seghier
Copy link

seghier commented Nov 24, 2024

Hi
Is there any examples how to create mesh from pointcloud, and how to use remesh and read openvdb file?
And in this example i don't find Mesh.FromAnySupportedFormat

using MR.DotNet;
using System;
using System.Reflection;
 
class Program
{
    static void Main(string[] args)
    {
        if (args.Length != 1 && args.Length != 2)
        {           
            Console.WriteLine("Usage: {0} INPUT [OUTPUT]", Assembly.GetExecutingAssembly().GetName().Name);
            return;
        }
 
        try
        {
            string input = args[0];
            string output = args.Length == 2 ? args[1] : args[0];
 
            var mesh = Mesh.FromAnySupportedFormat( input );
 
            DecimateParameters dp = new DecimateParameters();
            dp.strategy = DecimateStrategy.MinimizeError;
            dp.maxError = 1e-5f * mesh.BoundingBox.Diagonal();
            dp.tinyEdgeLength = 1e-3f;
            dp.packMesh = true;
 
            var result = [MeshDecimate](https://meshlib.io/documentation/namespaceMeshDecimate.html).Decimate(mesh, dp);
            Mesh.ToAnySupportedFormat(mesh, output);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error: {0}", e.Message);
        }
    }
}
@seghier
Copy link
Author

seghier commented Nov 24, 2024

I try this to open vdb file or fbx file but i get an error

1. An error occurred: unsupported file extension

Rhino.Geometry.Mesh MeshLidToRhinoMesh(MR.DotNet.Mesh mesh)
{
    var rhinoMesh = new Rhino.Geometry.Mesh();

    foreach (var point in mesh.Points)
    {
        rhinoMesh.Vertices.Add(point.X, point.Y, point.Z);
    }

    foreach (var triangle in mesh.Triangulation)
    {
        rhinoMesh.Faces.AddFace(triangle.v0.Id, triangle.v1.Id, triangle.v2.Id);
    }
    rhinoMesh.Compact();
    return rhinoMesh;
}

Rhino.Geometry.Mesh ReadFile(string file)
{
    MR.DotNet.Mesh mesh = MR.DotNet.MeshLoad.FromAnySupportedFormat(file);
    var rhinoMesh = MeshLidToRhinoMesh(mesh);
    return rhinoMesh;
}

@astrowander astrowander self-assigned this Nov 25, 2024
@astrowander
Copy link
Contributor

Hi

Could you please clarify a couple of questions:

  1. What do you mean by creating mesh from point cloud? Just triangulation or something else? Triangulation is supported in MeshLib but it is not exported to C# version yet, as well as Remesh.

  2. FBX file format is not now supported by MeshLib. VDB contains volumetric data, not meshes. That's why it's impossible to read it with MeshLoad class. So what exactly would you like to do? Read a volume from VDB and convert it to a mesh? This is possible with MeshLib, but no voxel-related are exported to C# yet.

We can plan to add these features to C# version of MeshLib, but we need more info about your request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants