Reputation: 27
If I run the example below it gives me this error:
Uncaught TypeError: Cannot read property 'x' of undefinedt @ three.min.js:462renderBuffer @ three.min.js:549k @ three.min.js:450render @ three.min.js:561render @ loaderTest.html:46
This is the last line where it calls render()
If I load two times the same model with loader.load(..) the error does not happen, it only occurs when I choose different models.
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var light = new THREE.AmbientLight( 0xFFFFFF );
scene.add( light );
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load("models/model1.dae", function(colladaModel){
var model = colladaModel.scene;
model.position.set(0,0,0);
scene.add(model);
});
loader.load("models/model2.dae", function(colladaModel){
var model = colladaModel.scene;
model.position.set(20,0,0);
scene.add(model);
});
camera.position.z = 100;
var render = function () {
requestAnimationFrame( render );
renderer.render(scene, camera);
};
render();
Upvotes: 0
Views: 112
Reputation: 3837
You're trampling on the model
variable. The callback that you've provided doesn't run until the model is loaded, but it has already started loading the other one as well.
model = colladaModel.scene;
You didn't declare your variable model
, which makes it a global variable which is thus shared browser-wide and between those two callbacks). It's actually window.model
that you're using there.
Change them to:
var model = colladaModel.scene;
Upvotes: 1