Nested Rhino layers in Three.js via 3DMLoader

I have a Rhino file with a nested layers structure:

The same sub-layer structure is repeated (with some variations) under different top-level layers. When I load the same file via Three.js (slightly modifying the sample code here: three.js/examples/webgl_loader_3dm.html at master · mrdoob/three.js · GitHub), the layers hierarchy is flattened, resulting in duplicate layers:

Acting on either layer with the same name hides all objects belonging to any layer with the same name, regardless of the original top-level layer.

Is it possible to preserve the layers’ nesting hierarchy somehow?

Pinging @fraguada, in case you are still in charge of this.

bump… @fraguada … or anyone who dabbles in three.js?

I’ll be getting back to rhino3dm in the next week or so. I will take a look at this and see what we can do.

@ale2x72 I think I was lazy in the example and only match by layer name, not the fully qualified layer name with parent info. Maybe this will work:

function initGUI( layers ) {
    gui = new GUI( { title: 'layers' } );

    for ( let i = 0; i < layers.length; i ++ ) {
        const layer = layers[ i ];
        const layerIndex = i;                       // unique per layer

        // use fullPath so duplicate-named layers are distinguishable in the panel
        gui.add( layer, 'visible' ).name( layer.fullPath ?? layer.name )
            .onChange( function ( val ) {
                scene.traverse( function ( child ) {
                    const attr = child.userData?.attributes;
                    if ( attr && 'layerIndex' in attr && attr.layerIndex === layerIndex ) {
                        child.visible = val;
                    }
                } );
            } );
    }
}