Skip to content

Issue in Lights - When loaded a model at runtime. #22

@Tajammal-Maqbool

Description

@Tajammal-Maqbool

Hi,
I am using Wonderland Engine for a game but I am facing a bug in it. I have loaded a model at runtime but lightning doesn’t work properly on it, If i add this same model directly from the editor then lightning applied correctly.

Here is code:

import { Component, Property } from '@wonderlandengine/api';

export class LoadPlaygroundComponent extends Component {
    static TypeName = 'load-playground';
    static Properties = {
        light1: Property.object(""),
        light2: Property.object(""),
    };

    init() {
        let glbFile = 'https://sos-at-vie-1.exo.io/vrex-dev/2022/12/31/I-yiXGJTiD-rBIYVogAI-ID29_Modern%20Art%20Gallery%20and%20Photo%20StudioV3.glb';
        this.engine.scene.append(glbFile).then((obj) => {
            console.log("GLB file loaded:", obj);
            obj.scale([2, 2, 2]);
            let meshes = this.findMeshComponents(obj);
            for (let mesh of meshes) {
                console.log("Mesh:", mesh.material);
                mesh.material = mesh.material.clone();
            }
        })
            .catch((error) => {
                console.error("Failed to load GLB file:", error);
            });
    }
    findMeshComponents(parentObj) {
        let meshes = [];
        if (parentObj.getComponent("mesh")) {
            meshes.push(parentObj.getComponent("mesh"));
        }

        parentObj.children.forEach(child => {
            meshes = meshes.concat(this.findMeshComponents(child));
        });

        return meshes;
    }
}

See the attached image:
image (1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions