Search code examples
colladathree.js

scene.add(object) creates an "Uncaught TypeError: Cannot read property 'length' of undefined"


Getting that error in my javascript console(in Chrome) with a collada object I'm attempting to add with a basic loader. It's specifically coming from the "scene.add( object )" chunk of it. Everything else seems to work just fine. The code for loading the object is as follows

var ltable;
var furnLoad = new THREE.ColladaLoader();

function addlt(){
        furnLoad.load('../Models/Furniture/foldingLongTable.dae', function(collada){
                ltable = collada.scene;
                ltable.scale.x=ltable.scale.y=ltable.scale.z=1;
                ltable.updateMatrix();
                ltable.position.x=ltable.position.z=ltable.position.y=0;
        });
        scene.add( ltable );
}

This function is called during the init of a page that, otherwise, works just fine. That page can be found here(version without this table has the same URL except for a 4 instead of a 3 at the end), and the specific object here.

What would be the recommended way to get past this error?


Solution

  • RESOLVED. Collada loaders just hate being part of any function and won't work when in them. So the fix is to have them outside of functions and they work just fine.