three.js exporter 'export object' not working with jsonLoader (r58)

社会主义新天地 提交于 2019-12-11 19:21:08

问题


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?


回答1:


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




回答2:


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 );


}


来源:https://stackoverflow.com/questions/17201888/three-js-exporter-export-object-not-working-with-jsonloader-r58

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!