Covert Rhino Mesh to Karamba Mesh3


I’m building some functionalities with the KarambaCommon API for my thesis. It’s been really fun. I have a question about the convertion of a rhino Mesh datastructure to a karamba Mesh3 datastructure.

I want to convert the mesh so that I can input a List of Mesh3 into the MeshToshell module (first input).

I wrote a simple script to do this conversion with available KarambaCommon functionalities. Script below

      List<Mesh3> slabMeshElements = new List<Mesh3>();
      Mesh3 kSlabMesh = new Mesh3();

      foreach (MeshFace f in rhinoSlabMesh.Faces)
        kSlabMesh.AddFace(f.A, f.B, f.C);
      foreach (Point3d v in this.SlabGeo.Vertices)
        kSlabMesh.AddVertex(new Point3(v.X, v.Y, v.Z));

however, I think the mesh needs welding as the end result is not a water-tight mesh.

Further, I noticed that Karamba.gha has some operations to perform the Mesh to Mesh3 conversion but I have a development setup in Visual Studio and I am unable to add Karamba.gha to my solution file references.

I have also attached the file to recreate the error. (31.8 KB)

any suggestions would be greatly helpful

Hi @keerthana,
you can add ‘karamba.gha’ to a VS project by editing the corresponding ‘.csproj’-file. Add e.g. ‘karambaCommon.dll’ as a reference, then search for it in the ‘.csproj’-file, duplicate the entry and change it to ‘karamba.gha’.

The Convert() extension method for the conversion from RhinoCommon mesh to K3D mesh3 can be found in Karamba.GHopper.Geometry. See here: (32.8 KB)

It is not necessary to add each mesh face individually (see in above file).

– Clemens

Thank you Clemens!

I am yet to try the gha reference to the VS project. For now I’m just taking a Karamba mesh as an input.

Many thanks!

Thank you so much for your time and sharing the code fix.
An additional question, I ran your code with the Karamba Mesh to Mesh3 convert method (as attached above with no changes).
The output mesh when in crossection view continues to show a mesh with a few fliped faces.
Wondering if this is just a visualization issue or if it affects the calculations.
Thank you!
image attached below

The flipped mesh faces are just a problem with the visualization and do not affect calculations. However I thought that I had fixed that bug. Do you use the latest version of Karamba3D (see here)? If yes, could you send me a minimum GH definition which reproduces the problem for debugging?
– Clemens

Thank you so much for clarifying @cp1 !
I am using version
I will update to the latest version for the bug fix. however, I might not be able to update and test it until the end of October 2022 as I currently cannot risk breaking my code which is dependent on karamba version
Thank you!