Decoding Nurbs to ThreeJS

Hello together, I’m working on a small web app using Rhino.Compute and Rhino3dm.js

Currently, I’m struggling to decode the data for ThreeJs. In this example, I have a simple Box (not converted to a mesh) and I get the following error:

I pinpointed down to CommonObject.decode(). Do I have to convert all nurbs objects to a mesh?

image

When the “decodedata” comes as a mesh, it has no problem decoding it

Rhino.Geometry.Box is a struct and does not derive from Rhino.Geometry.GeometryBase (and thus Rhino.Runtime.CommonObject) like Breps and Meshes so it has no way to be “decoded” into a CommonObject.

You could return this as a brep or mesh as you already know and it would be decoded correctly. Alternatively you could still sent it as a box. The data for the object does come through and you could handle it accordingly.

First you can check if the data has a property of ‘opennurbs’. This is a telltale sign that the object is derived from CommonObject

...
else if (typeof data === 'object' && data.hasOwnProperty( 'opennurbs' ) ) {
        return rhino.CommonObject.decode(data)
    }

So this will avoid the error you are seeing because it will skip objects that are not derived from CommonObject (like Box and Point3d)

If you want to handle boxes specifically you could add a filtering condition with any of the properties that a box has

for example:

...
else if(typeof data === 'object' && data.hasOwnProperty( 'Area' ) && data.hasOwnProperty( 'Volume' ) && data.hasOwnProperty( 'Center' )   ) {

        //this is a box
        console.log( `box info - area: ${data.Area} volume: ${data.Volume} center: ${data.Center.X },${data.Center.Y }, ${data.Center.Z }` )


    }

Thank you, Luis! That was the problem! I converted everything to a Brep, and now it can be decoded.

Now the ThreeJs loader is not happy anymore… Did I overlook another thing?

Breps made in GH don’t have any associated render mesh…threejs has very little idea about NURBS. Your best bet if you want to see them in threejs is to send a mesh.

Ahh I see, alright then I will go with that.
Thank you!

1 Like