Upon running the code snippet below, an error is thrown:
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
The error occurs on the last line where render() is called.
If I load the same model twice using loader.load(..), the error does not occur. It only happens when different models are selected.
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();