Mesh.toThreejsJSON() Source

Is the source for this method available somewhere? V curious how you do this (and thanks for providing it). Having trouble finding it in the rhino3dm repo.

Here ya go Chuck

1 Like

Thanks!

I keep asking for help finding things right in front of me. Not on purpose, I promise. :grimacing:

1 Like

Is there a simplification somewhere in this function?

My mesh seems to be incorrect when looking at it through compute.

Any advice?

I don’t know what this image is supposed to be showing. Code or sample files would help.

Hi,

I’m trying to replicate @stevebaer 's below javascript in C# but not sure where to find .NET libraries containing these methods - are they found in the Rhino3dmIO and ThreeLib libraries?

            function meshToThreejs(mesh, material) {
            let loader = new THREE.BufferGeometryLoader();
            var geometry = loader.parse(mesh.toThreejsJSON(true));
            return new THREE.Mesh(geometry, material);
        }

I don’t think I implemented them anywhere but in javascript. Why do you need this in .NET?

Ah ok, … was trying to keep as much of the methods as possible in our main app (wpf, c#) rather than spreading methods between the main app and the webpage – just make debugging a bit more familiar for us. … I guess the conversion from mesh to Threejs will be one method we’ll have to keep in the webpage for now. Not a problem.

The source for the web assembly toThreejsJson function can be found here if that is any help

Thanks Steve, will refer back to that if we need to. :+1:

Hi @stevebaer - I feel like I’m almost there :slight_smile:… I have rhino.compute recomputing my grasshopper script and returning a mesh object output “RH_OUT:MeshResult” to my c# app…


I am then successfully passing that in to my webpage javascript (this alert corresponds to line 156 of the code below ) …

But then I am falling over when attempting to convert the mesh data to a Rhino.Mesh class…

or something is going wrong because line 161 is returning an empty ThreejsMesh object and so when the scene updates it is empty.

I suspect I might have made a mistake on line 157 where I am attempting to coerce the GrasshopperData[‘data’] element of the Json (which you can see in the alert window) which I believe to be a Rhino.Mesh to a Rhino.Mesh. – but maybe it is some other kind of class?

Can you advise if line 157 seems correct to you?

rhino.CommonObject.decode() is your friend for converting that json into an instance of a geometry class in rhino3dm

let rhinoMesh = rhino.CommonObject.decode(GrasshopperData['data'])

This function take the json that you are seeing and creates an instance of a rhino3dm class that the data represents. Works for all geometry types (mesh, brep, curve, subd,…)

1 Like

Ok wow, that’s a handy method to know about! :+1:
Honestly I did try to figure it out myself before posting for help! (most of the day).
Thank you.
d