我正在尝试使用OBJLoader导入obj,但是导入不正确
发生的事情是整个obj的导入效果不佳。
我该怎么办?
我正在执行的代码是
var objLoader = new THREE.OBJLoader();
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setTexturePath("obj2/");
mtlLoader.setPath( "obj2/" );
mtlLoader.load( "Mules/Base_10.mtl", function( materials ) {
materials.preload();
objLoader.setMaterials( materials );
objLoader.load( 'obj2/Mules/Base_10.obj', function ( object ) {
object.traverse( function ( child )
{
if ( child instanceof THREE.Mesh )
{
meshes.push(child);
}
});
var object = meshes[meshes.length-1];
object.position.y = -0.05;
object.position.x = 0;
object.position.z = 0;
object.name = "salto";
scene.add(object);
}, onProgress, onError );
});
谢谢。
答案 0 :(得分:1)
The problem is:
object.traverse(...);
var object = meshes[meshes.length-1]; //<-- you overriding the object, with the last mesh.
object.position.y = -0.05;
object.position.x = 0;
object.position.z = 0;
object.name = "salto";
scene.add(object); //<-- than you add the object to your scene.
do not override the object. Also you don't need to traverse through the objects, as you will add the whole thing to your scene. and you do nothing with your meshes anyway :)
so try this:
object.position.y = -0.05;
object.position.x = 0;
object.position.z = 0;
object.name = "salto";
scene.add(object);