Currently facing an issue where I am unable to retrieve Object3D from the scene, despite the mesh objects being displayed within the scene. Strangely, the scene.children array does not reflect this.
Take a look at the screenshot here
Here is the code snippet:
function init(){
loadJSON(function(response) {
// Parse JSON string into object
var jsonData = JSON.parse(response);
materialType = ['MeshBasicMaterial','MesLambertMaterial','MeshPhongMaterial', 'MeshStandardMaterial'];
for (var i =0; i< jsonData.materials.length; i++){
var matName = jsonData.materials[i].name;
materialArray[matName] = new THREE.MeshLambertMaterial();
materialArray[matName].name = matName;
}
var loader = new THREE.OBJLoader();
for(var i = 0; i < jsonData.models.length;i++){
parentGroup = new THREE.Object3D();
parentGroup.name = jsonData.models[i].name;
for(var j = 0; j < jsonData.models[i].children.length;j++){
childName = jsonData.models[i].children[j].name;
matType = jsonData.models[i].children[j].material;
loader.load( "models/" + childName, makeHandler( childName , materialArray[matType],parentGroup), false );
}
scene.add(parentGroup);
}
});//loadJSON
console.log(scene.children); //-- SCREENSHOT OUTPUT --
}//init function
// HANDLER FUNCTION
function makeHandler(meshName, material,parentObj) {
return function(geometry) {
object3d = new THREE.Mesh( geometry, material);
object3d.name = meshName;
parentObj.add(object3d);
};
}
Thank you for your assistance.