javascript - Loading Multiple Collada Objects in THREE.js -
i loading multiple car models using loop in three.js, problem sometime loads objects time not load objects. example if loop of 3 iteration, load 2 objects sometime, sometime loads 1 , sometime loads 3 objects. don't know why? searched lot can't find thing useful. here code.
for (var k = 1; k <= myworld.noofenemies(); k++) { myworld.setworldenemycar(k); loader2.load('obj/us/us_police_car.dae', function colladaready(collada) { object3 = collada.scene; object3.scale.x = object3.scale.y = object3.scale.z = 2; object3.updatematrix(); object3.position.x = myworld.enemycar.position.x; object3.position.y = myworld.enemycar.position.y; object3.position.z = myworld.enemycar.position.z; object3.rotation.x = -(math.pi / 2); object3.rotation.z = (math.pi / 2); enemymodels.push(object3); //localobject.rotation.z = -(math.pi / 2); //collidablemeshlist3 = localobject; //console.log(collidablemeshlist3); // init(); // animate(); }); }
after 1 more loader in have init()
, animate()
functions
loader2.load('obj/us/us_police_car.dae', function colladaready(collada) { localobject = collada.scene; localobject.scale.x = localobject.scale.y = localobject.scale.z = 2; localobject.updatematrix(); localobject.position.x = 0; localobject.position.y = 0; localobject.position.z = 0; localobject.rotation.x = -(math.pi / 2); localobject.rotation.z = (math.pi / 2); //localobject.rotation.z = -(math.pi / 2); //collidablemeshlist3 = localobject; //console.log(collidablemeshlist3); //scene.add(localobject); init(); animate(); });
this works fine, can't figure out problem above one.
there seems known issue when re-using same instance of collada loader load multiple collada files.
the following code works reliably me (at least in chrome , firefox):
scene = new three.scene(); // setup lighting etc. load('/path/somecolladamodel.dae'); load("/path/someothercolladamodel.dae"); load("/path/yetanothercolladamodel.dae"); function load(daelocation){ var manager = new three.loadingmanager(); manager.onprogress = function(item, loaded, total) { console.log(item, loaded, total); }; var loader = new three.colladaloader(manager); loader.options.convertupaxis = true; loader.load(daelocation, function(collada) { dae = collada.scene; dae.position.set(0, 0, 0); scene.add(dae); render(); }, function(progress) { // show progress }); }
note instantiating new loader every time load model.
Comments
Post a Comment