The rhino3dm Simple Viewer Example does not work with other models

I am trying to use the Simple Viewer example at GitHub to load a simple 3d box, but it doesn’t render. Do I need to make changes to the code to load different models?

https://mcneel.github.io/rhino3dm/javascript/samples/viewer/01_basic/

Thank you,

Marcus

There are a couple of things that could be going wrong, either the model doesn’t have render meshes or my code isn’t properly handling extrusions. Send me the 3dm that you are trying to test and I’ll see if I can tune up the sample to handle your geometry

1 Like

Thanks Steve!

I created a mesh from the extrusion and it worked. I assumed the Rhino3dm API worked like the Rhino3d App. Can I use the information (materials, text and textures) in the .3dm file to render models using the Rhino3dm API as designed in the Rhino3d App?

Thank you,

Marcus

box.3dm (34.3 KB)

I tried to keep that specific example as simple as possible. If you look at the javascript, you’ll see that it only deals with meshes

One goal of rhino3dm is to allow you to read all of the information in a 3dm model. A lot of this information is already available in the toolkit and if you find yourself needing something that isn’t there, please ask.

Hi Steve,

then how would I need to modify this code to also work with BREP or Nurbs? Is that possible?

Thank you,
Jurgen

Here’s some code that I use to get meshes for Breps in the model.

const objectType = geometry.objectType
switch (objectType) {
    case rhino3dm.ObjectType.Point:
        break
    case rhino3dm.ObjectType.PointSet:
        break
    case rhino3dm.ObjectType.Curve:
        break
    case rhino3dm.ObjectType.Surface:
        break
    case rhino3dm.ObjectType.Brep:
    {
        // Get mesh from each face. 3dm models that have been shown in shaded
        // mode will have a cached mesh on each Brep face. An alternative would
        // be to call compute.rhino3d to calculate the meshes in cases where they
        // don't exist.
        let faces = geometry.faces()
        for (let faceIndex = 0; faceIndex < faces.count; faceIndex++) {
            let face = faces.get(faceIndex)
            let mesh = face.getMesh(rhino3dm.MeshType.Any)
            if (mesh) {
                let threeMesh = this.meshToThreejs(mesh, color, materialId)
                objectsToAdd.push([threeMesh, mesh.getBoundingBox()])
                mesh.delete()
            }
            face.delete()
        }
        faces.delete()
    }
    break

Thanks Steve!

Hi Steve,

I’ve tried again based on your feedback, unfortunately without success.

Basically I’m trying to extend the basic viewer sample to render brep and surfaces as well. I have a few very simple example files to test with.

Currently I’m stuck with the ‘getMesh’ method which always returns null ( ‘Any’ mesh type ).

I’m assuming that this is because the file does not have any ‘render meshes’ in it, but what are those exactly?

I’ve noticed in the javascript documentation that Mesh has no createFromBREP method. Does that mean it’s currently not possible to render BREP in the browser at all?

Best regards,
Jurgen

Hi @jurgen.laurijssen,

Rhino3dm will will not create a mesh from a Brep. To do that, you’ll need to call to a Compute server, or have 3dm files that already have cached render meshes, per Steve’s source code comments.

Hope this helps.

– Dale