gpt4 book ai didi

javascript - 三个 JS OBJloader - obj 未正确导入

转载 作者:行者123 更新时间:2023-12-03 01:16:58 34 4
gpt4 key购买 nike

我正在尝试使用 OBJLoader 导入 o​​bj,但它未正确导入

目标是这样的 -对象img
Obj img

它正在导入这个 -三个js中的Obj
Obj in three js

发生的情况是整个 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 );
});

谢谢。

最佳答案

问题是:

                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.

不要覆盖该对象。此外,您不需要遍历对象,因为您会将整个对象添加到场景中。无论如何,你对你的网格物体什么也不做:)

所以试试这个:

                object.position.y = -0.05;
object.position.x = 0;
object.position.z = 0;

object.name = "salto";
scene.add(object);

关于javascript - 三个 JS OBJloader - obj 未正确导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51965869/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com