Mesh.createFromThreejsJSON() arguments Rhino3dm Javascript

Hello, for rhino3dm meshes there is the rhino3dm mesh.toThreejsJSON method. How should it’s “reverse function” rhino.Mesh.createFromThreejsJSON() be called?

Documentation: https://mcneel.github.io/rhino3dm/javascript/api/Mesh.html#.createFromThreejsJSON

When using the result of mesh.toThreejsJSON or threejsmesh.toJSON as argument in createFromThreejsJSON, I get undefined as result.

I’d have provided a working example on how to do it, but coudn’t make it work due to CORS.
Nevertheless, here is my edited example from https://github.com/mcneel/rhino3dm/tree/master/docs/javascript/samples/viewer/01_basic

basic_example.html (4.0 KB)

We have an example that uses the rhino.Mesh.createFromThreejsJSON() method: https://github.com/mcneel/rhino3dm/blob/master/docs/javascript/samples/compute/clash_detection/app.js#L71

If you don’t mind a bit of cpp, you can always check out the source here: https://github.com/mcneel/rhino3dm/blob/master/src/bindings/bnd_mesh.cpp#L364

So the call expects an object with the following structure: {data: bufferGeometry}

So your line 50 should be

rhino_mesh = rhino.Mesh.createFromThreejsJSON({data: threeMesh}); // CHANGED

Give that a try and let us know if it works for you.

1 Like

Hello Luis,

thanks for your quick response!

Your example works indeed, but it does not with my own THREE mesh. I can visualize my THREE mesh in the canvas, so it’s probably not broken I think.

What could be a reason for this error?

You might be passing the whole threejs Mesh object (derivative of THREE.Object3d) when you should be passing the geometry (THREE.BufferGeometry).

Try threemesh.geometry:

rhino_mesh = rhino.Mesh.createFromThreejsJSON({data: threeMesh.geometry});
1 Like

Yes, that’s it!
Thank you :smiley:

1 Like