Preview mesh for created Objects in rhinocommon File3dm

When exporting a 3dm file from rhinocommon (ghpython); and loading that with ThreeJS 3dm loader. the brep objects don’t have a “mesh” attribute.
If I open this file in Rhino and save again. They would have the mesh for preview in threeJS.

My guess is that the objects don’t have a “Preview” mesh by default. Is there a way to add that to the attributes?
here is my code:

import Rhino

# create new rhino file
rh_file = Rhino.FileIO.File3dm()

# add layers
part_layer_index = rh_file.AllLayers.AddLayer("part", part_color)

# add objects to layer
attributes = Rhino.DocObjects.ObjectAttributes()

# add breps
attributes.LayerIndex = part_layer_index
for part in parts:
    rh_file.Objects.AddBrep(part, attributes)

Possible duplicate of: Three.js 3DM Loader fails to load BREPs


If you are creating objects programmatically, they won’t have render meshes by default. You need to call to generate these before you export. Notice this is on a BrepObject, so you need to add the Brep to the doc first then get the BrepObject and run CreateMeshes on it.

1 Like

yes! thank you. sorry i did not see that.

alternatively, for loading to ThreeJS, I could convert the brep object to a mesh and then save the file with mesh objects.


mesh_part = Rhino.Geometry.Mesh.CreateFromBrep(part, meshingParameters)
rh_file.Objects.AddMesh(mesh_part , attributes)

Yes, as long as you put meshes in the file, you can visualize them with three.js