Hi!
I`m trying to get a mesh from 2 imported scenes created by independent from one another artists. I can do it without a problem in ThreeJS, but in Babylon I get both null if I use any of the scene.getMesh… methods, and also the scene.meshes property does not appear or behave as a proper array that I can traverse.
However if I add additional, lets say BOX mesh to scene, I can easily access it with scene.getMeshByName("arbitraryboxmeshname")
for instance.
One of the scenes I`m using is a GLTF model from this article here: Three.js Loading a .GLTF File
What am I doing incorrectly here?
window.addEventListener('DOMContentLoaded', function() {
var canvas = document.getElementById('renderCanvas');
var engine = new BABYLON.Engine(canvas, true);
// All the following code is entered below here.
var createScene = function() {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.FreeCamera('camera', new BABYLON.Vector3(0, 5,-10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
BABYLON.SceneLoader.Append("", "bab_test_02.gltf", scene, function (scene) {
scene.createDefaultCameraOrLight(true, true, true);
});
return scene;
}
// All the following code is entered above.
var scene = createScene();
var blueBox = BABYLON.Mesh.CreateBox("blue", 20, scene);
var blueMat = new BABYLON.StandardMaterial("ground", scene);
blueMat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
blueMat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
blueMat.emissiveColor = BABYLON.Color3.Blue();
blueBox.material = blueMat;
blueBox.position.x += 100;
var car = scene.getMeshByName("Object004_primitive0");
console.log(scene.meshes); //shows [] that I can open in debugger, but it does not work as an array
console.log(car); //Shows null
scene.render();
engine.runRenderLoop(function() {
scene.render();
});
});
Thank you in advance!