使用OBJMTLLoader在threejs中加载我的对象,线框控件对OBJLoader单独工作,但对于OBJMTLLoader它没有工作
var loader = new THREE.OBJMTLLoader();
loader.load( 'obj/male02/male02.obj', 'obj/male02/male02_dds.mtl', function ( object ) {
object.children[0].geometry.computeFaceNormals();
var geometry = object.children[0].geometry;
console.log(geometry);
THREE.GeometryUtils.center(geometry);
geometry.dynamic = true;
var material = new THREE.MeshLambertMaterial({color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors });
mesh = new THREE.Mesh(geometry, material);
scene.add( mesh );
} );
function wireframe(){
//alert('hhhhhh');
mesh.material.wireframe = true;
mesh.material.color = new THREE.Color( 0x6893DE );
}
但它导致以下错误,所以我的模型没有显示在查看器上, 所以在这里我想知道我们可以在任何类型的3D模型上创建线框?
object.children [0] .geometry未定义
答案 0 :(得分:2)
即使OBJMTLLoader
返回THREE.Object3D
具有.children
的{{1}}对象,也不应假设.children
的类型为THREE.Mesh
。因此,您应该traverse()
THREE.Object3D
来查找THREE.Mesh
。
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh )
// do something with the geometry
} );