0
votes

I'm trying to load a model I got from 3DWarehouse into three.js. I was unable to get the Collada Loader to work, so instead I imported it into THREEJS Editor and exported it using the "export object" function. When I loaded the object into my app using the following code:

var kiss = new THREE.Object3D(), loader = new THREE.JSONLoader(true);
loader.load("model/kiss/kiss.js", function (geometry, meshKiss) {
    meshKiss = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial());
    kiss.addChild(meshKiss);
});
scene.add(kiss);

I got the error:

Uncaught TypeError: Cannot read property 'length' of undefined

which refers to the line in THREE.JSONLoader.prototype.parse where it asks for the first paramater's uvs length.

The object file 'geometries' has no uvs (it does have vertices, normals, and faces):

geometries: data: uvs: [[]]

I am also finding this issue when importing older JSON format files into the THREEJS Exporter (I tested the Ginger models).

Is my process valid, and if so, why is the json object not importing into THREE.JS?

2

2 Answers

1
votes

This appears to be under development. As a work-around, you can export the geometry only from the Editor so your JSON looks like this:

{
"metadata": {
    "version": 4,
    "type": "geometry",
    "generator": "GeometryExporter"
},
"vertices": [ ... ]
"normals": [ ... ]
"uvs": [[]],
"faces": [ ... ]
}

Then do this:

loader.load( "Kiss2.js", function ( geometry, materials ) {
    var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { color: 0xff0000, ambient: 0xff0000 } ) );
    scene.add( mesh );
});

three.js.r.58

0
votes

User ObjectLoader instead. You will get an array of Mesh as response

var loader = new THREE.ObjectLoader;

loader.load('http://localhost/threetest/assets/weaponThree.js', createScene);

var material = null;

var mesh = null;

function createScene( json ) {

    material    = new THREE.MeshLambertMaterial( json.material );

    mesh        = new THREE.Mesh( json.geometry, material );

    //scene.add( json[0] );
    scene.add( mesh );


}