Volumetrics-io / mrjs

An extensible WebComponents library for the Spatial Web
https://mrjs.io
MIT License
148 stars 9 forks source link

children of a custom entities are not visible #618

Closed lobau closed 1 month ago

lobau commented 2 months ago

If you add children to a custom entity you define as extending MREntity, it's DOM children are not visible in the MRjs scene.

For example, in this sample code: https://codepen.io/lobau/pen/wvZVLw

<mr-app orbital="true">
    <!-- Left one -->
    <mr-div data-position='-0.3 0 0'>
        <mr-model src='https://assets.codepen.io/686746/koi_fish.glb' style="scale: 0.1"></model>
    </mr-div>

    <!-- Right one -->
    <mr-foo data-position='0.3 0 0'>
        <mr-model src='https://assets.codepen.io/686746/koi_fish.glb' style="scale: 0.1"></model>
    </mr-foo>

</mr-app>

The defined custom element, mr-foo:

class MRFoo extends MREntity {

    constructor() {
        super()
    }

    connected() {
        this.boxMesh = new THREE.Mesh(
            new THREE.BoxGeometry(0.2, 0.2, 0.2),
            new THREE.MeshPhongMaterial({
                color: "#ff9900",
                transparent: true,
                opacity: 0.4,
            }));
        this.object3D.add(this.boxMesh);
    }

}

customElements.define('mr-foo', MRFoo);

On the left, you have an mr-model as a child of an mr-div and it works as expected. On the right, you have a custom element (mr-foo) that is defined as class MRFoo extends MREntity. The child mr-model is not on the MRjs scene.

image

My assumption is that it has to do with adding the slotted elements in the shadowDOM maybe?

hanbollar commented 2 months ago

odd that that's having issues - i'll take a look 🤔

hanbollar commented 1 month ago

closing this as resolved by noodling in #619 - see https://github.com/Volumetrics-io/mrjs/pull/619#issuecomment-2108731844