Rhino3DM 3JS Missing Mesh

Hi all,

I am trying to load a 3dm file into 3js and having an issue displaying extrusions. The extrusions are there in the 3dm but don’t get displayed in the 3js.

This is the error in console:

This is the 3js

This is the code I use to create these extrusions

for feature in building_layerMB['features']:
                geometry_type = feature['geometry']['type']
                height = feature['properties']['height']
                if geometry_type == 'Polygon':
                    geometry = feature['geometry']['coordinates']
                    for ring in geometry:
                        points = []
                        for coord in ring:
                            x_val, y_val = coord[0], coord[1]
                            x_prop = (x_val / 4096)
                            y_prop = (y_val / 4096)
                            lon_delta = lon2 - lon1
                            lat_delta = lat2 - lat1
                            lon_mapped = lon1 + \
                                (x_prop * lon_delta)
                            lat_mapped = lat1 + \
                                (y_prop * lat_delta)
                            lon_mapped, lat_mapped = transformer.transform(
                                lon_mapped, lat_mapped)
                            point = rh.Point3d(
                                lon_mapped, lat_mapped, 0)
                            points.append(point)
                        polyline = rh.Polyline(points)
                        curve = polyline.ToNurbsCurve()
                        orientation = curve.ClosedCurveOrientation()
                        if str(orientation) == 'CurveOrientation.Clockwise':
                            curve.Reverse()
                        att_bf = rh.ObjectAttributes()
                        att_bf.LayerIndex = buildingfootprint_LayerIndex
                        model.Objects.AddCurve(curve, att_bf)
                        extrusion = rh.Extrusion.Create(
                            curve, height, True)
                        att = rh.ObjectAttributes()
                        att.LayerIndex = building_layerIndex
                        att.SetUserString(
                            "Building Height", str(height))
                        model.Objects.AddExtrusion(
                            extrusion, att)
                        buildings.append(extrusion)

Do I need to fix my python code to generate the extrusions or is there something I need to do in JS code itself?

Thanks

If you create these extrusions outside of Rhino, or if you never add them to a Rhino document and have them shaded, they will not have any associated render mesh, as the warning is telling you. If your extrusions are simple enough, you could set a mesh like I show in this example: rhino-developer-samples/rhino3dm/py/SampleExtrusionSetMesh.py at 8 · mcneel/rhino-developer-samples · GitHub

(though I cheat a bit because I get the mesh from a 3dm file. Making a simple mesh box in python is straightforward)

I’m not sure this will work. I’m creating the extrusions from a curve which is created from points, so essentially creating the extrusions from scratch outside of Rhino. Is there another way to set a mesh outside of rhino?

I recently exposed SetMesh for Extrusions and Breps in Rhino3dm, which is what I described in my reply. This would allow you to generate your mesh with your own logic and set it as the render mesh for those objects. I understand this is not a trivial step for complicated geometry.

In order to take advantage of Rhino’s general purpose mesher, you need to pass the geometry through Rhino, either through the Rhino Desktop app, or via Rhino.Compute as is done in this example: rhino-developer-samples/compute/js/SampleBrepMesher/index.html at 8 · mcneel/rhino-developer-samples · GitHub

1 Like