xeolabs / xeogl

A WebGL-based 3D engine for technical visualization. Not actively maintained.
http://xeogl.org
Other
1.15k stars 264 forks source link

OBJModel's meshes property hasn't any content. #268

Closed horsefaced closed 6 years ago

horsefaced commented 6 years ago

Describe the bug When I use OBJModel.js to load a .obj file, the loaded model's meshes property hasn't any content.

To Reproduce Look like this code:

model.on("loaded", () => {
    for (let id in model.meshes) {
        console.info(id);
    }
});

Repair Method I review the source code and discovered the 972 line in createMeshes function in OBJModel.js file。


               var mesh = new xeogl.Mesh(model, {
                    id: model.id + "#" + object.id,
                    geometry: xeoGeometry,
                    material: material,
                    pickable: true
                });

                model.addChild(mesh);

The code just add mesh into model's children property, but not call Component._addComponent to add to compnents array, so the meshes property can't get anything. I modify this code to

               var mesh = new xeogl.Mesh(model, {
                    id: model.id + "#" + object.id,
                    geometry: xeoGeometry,
                    material: material,
                    pickable: true
                });

                model.addChild(mesh);
                model._addComponent(mesh);

Then the model.meshes can get meshes.

xeolabs commented 6 years ago

Thanks! Would you like to submit the fix via a pull request?

horsefaced commented 6 years ago

OK