scope - How can I prevent an object to be destroyed after I used the function: .load() in javascript (three.js) -
i trying prevent destroying of object after loaded it.
var loader = new three.colladaloader(); var rescue; loader.load( 'improved_person_maker_better_quality.dae', function(collada) { scene.add(collada.scene); collada.scene.position.set(-25, 1, 25); collada.scene.rotation.x = -math.pi / 2; rescue = collada.scene; }, function(xhr) { console.log((xhr.loaded / xhr.total * 100) + '% loaded'); } ); rescue.position.set(-20, 1, 25);
the last statement not possible, because loaded mesh not exist more. there way rescue collada.scene?
the loader asynchronous.
that means rescue.position.set()
being called before rescue
defined in loader callback.
just set position in callback, have done.
if must refer rescue
later in code, can use pattern
if ( rescue !== undefined ) { // code }
three.js r.75
Comments
Post a Comment