Detecting and positioning nested blocks correctly using rhino3dm.js

Has anyone had any luck working with nested blocks (instance definitions) using rhino3dm.js?
Parent blocks seem to be positioned correctly, but I am not able to detect any nested/child blocks to then account for the parent transforms.

If there is any sample code/examples/experiments anyone could share, that would be awesome!
@fraguada :folded_hands:

You can check rhino-developer-samples/rhino3dm/js/node/Samples/AddInstanceDefinition.js at 8 · mcneel/rhino-developer-samples · GitHub

Hello @nathanletwory - thanks for the note.

I am trying to read Instance Definitions from an existing Rhino file, and more specifically nested or child instance definitions (nested blocks). I am able to get the parent block information, but not able to read the nested block attributes, as the three.js parser seems to be flattening this information or completely culling it.

Do you have any guidance or examples on how to approach this?

Thanks!

I am not familiar with the three.js parser for 3dm files. That is something for @fraguada .

Hello all, I finally found a solution by comparing the coordinates of the 3dm and three.js geometries. Here are some notes on my approach, in case anyone might find it useful :folded_hands:

Key steps in post-processing the Three.js scene after Rhino3dmLoader.parse() to reconstruct the correct hierarchy:

  • Analysed raw rhino3dm structure before Three.js parsing to identify parent-child relationships and local transforms

  • For the first instance of each parent block definition: located the original nested blocks (by matching local positions) and reparented them under the correct parent

  • For duplicate instances: cloned the nested blocks using Three.js’s .clone(true) method and added them under their respective parent instances

  • Applied correct transforms: positioned all nested blocks using their local coordinates from Rhino, ensuring proper relative positioning within each parent

This approach preserves the original block hierarchy and correctly handles models with multiple instances of the same block definition.

Best,
Krishna

1 Like