WonderlandEngine / api

Wonderland Engine's JavaScript API.
MIT License
10 stars 6 forks source link

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

Open Tajammal-Maqbool opened 6 months ago

Tajammal-Maqbool commented 6 months ago

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)

DavidPeicho commented 6 months ago

Hi, thanks for reporting!

I would think that your issue is because you are scaling the model by 2:

obj.scale([2, 2, 2]);

this will make your model span ~60-100 units depending on the axis. Could you try to use a directional light to see the result? Something pointing from the top to the bottom with a slight angle :)

Tajammal-Maqbool commented 6 months ago

I have tried to remove the scalling but it is still same. I have added multiple sun lights in the scene but it not effect the model if it loads runtime but if I load any model in editor then lights effect it correctly.

Tajammal-Maqbool commented 6 months ago

@DavidPeicho You can copy this code in any project or new project then add this component to any object into scene. Then run it and you will see this bug.