mcneel / rhino3dm

Libraries based on OpenNURBS with a RhinoCommon style
MIT License
599 stars 135 forks source link

GetMesh from face return null in Rhino3dm.js #467

Closed leifriksheim closed 2 years ago

leifriksheim commented 2 years ago

Hi! I'm working with the rhino3dm.js library, trying to convert a Brep to a mesh so I can view it in Three.js.

I was looking at the implementation of the 3DMLoader and tried to use the same technique as referenced here: https://github.com/mrdoob/three.js/blob/f0e2b3453f1412b53389beb04add414e3a80023c/examples/jsm/loaders/3DMLoader.js#L1196.

In my code I seem to only get null back from each face of the Brep. Do I need RhinoCompute for this function call?

jesterKing commented 2 years ago

The rhino3dm.js itself does not contain meshing code. Instead you need to save your 3dm file with one viewport in shader or rendered mode (and all the geometry you are interested in visible) so that the library can read the mesh data generated by Rhino prior to saving.

sbaer commented 2 years ago

If the mesh is not embedded in the file using the technique described above, then yes you would need to call Rhino.Compute to get meshes from Breps

leifriksheim commented 2 years ago

Sorry to open this issue up again. Let me know if the forum is better for these kinds of questions. I'm not reading a 3dm file, but rather using rhino3dm.js to create some simple primitives and finally display the result in Threejs. I am basically trying to do something like this:

const box = new rhino.BoundingBox([0, 0, 0], [10, 10, 10]);
const brep = new rhino.Brep.createFromBox(box);
const faces = brep.faces();

Then get the mesh of each face and display this in Threejs. Would I still need Rhino.Compute to be able to display a box created in rhino3dm, or is there some other way method I can use without going through Rhino.Compute?

sbaer commented 2 years ago

The forum is best for questions like this.

You would need to create a Mesh in rhino3dm.js, then add 8 vertices and 6 faces to represent a bounding box. This mesh could then be converted into a threejs compatible mesh