javascript - unable to get object3D in scene -
i unable object3d scene. although mesh objects shown in scene. scene.children array not show that. please have @ screenshot (link).
code:
function init(){ loadjson(function(response) { // parse json string object var jsondata = json.parse(response); materialtype = ['meshbasicmaterial','meslambertmaterial','meshphongmaterial', 'meshstandardmaterial']; (var =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 = 0; < 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); }; }
thanks.
loader.load()
asynchronous function call. why specify callback function.
in case, calling console.log( scene.children )
before models load, , before models added scene.
three.js r.77
Comments
Post a Comment