ObjLoader 在我的场景中加载了一个对象。但随后我需要读取该对象顶点。但我仍然不知道该怎么做。在我在three.js 中制作的普通立方体上,我可以毫无问题地读取和更改顶点,但在ObjLoader 加载的对象上它不起作用。我还尝试使用 FaceNormalsHelper,它也适用于立方体,但不适用于我的对象。
这是我的代码:
//My cube this works
var geometry = new THREE.BoxGeometry(20, 20, 20);
var color = new THREE.Color("rgba(188, 141, 190, 1)");
var material = new THREE.MeshNormalMaterial({color: color.getHex()});
var cube = new THREE.Mesh(geometry, material);
var helpeer = new THREE.FaceNormalsHelper( cube, 20, 0x00ff00, 1 );
var vert = cube.geometry.vertices[1].y;
scene.add( cube );
scene.add( helpeer );
//Loading my object
var manager = new THREE.LoadingManager();
manager.onProgress = function ( item, loaded, total ) {
console.log( item, loaded, total );
};
var texture = new THREE.Texture();
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round(percentComplete, 2) + '% downloaded' );
}
};
var onError = function ( xhr ) {
};
var loader = new THREE.ImageLoader( manager );
loader.load( 'objects/textura.jpg', function ( image ) {
texture.image = image;
texture.needsUpdate = true;
} );
var loader = new THREE.OBJLoader( manager );
loader.load( 'objects/scan_leg_repair.obj', function ( object ) {
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material.map = texture;
}
} );
object.position.y = - 100;
object.rotation.x = -1.5;
object.rotation.z = 3;
scene.add( object );
//That is what i tried. Without success :(
//var vert2 = object.geometry.vertices[1].y;
//var vert3 = object.children[0].geometry.vertices[1].y;
//var helper = new THREE.FaceNormalsHelper( object, 20, 0x00ff00, 1 );
//var helper = new THREE.FaceNormalsHelper( object.children[0], 20, 0x00ff00, 1 );
//scene.add( helper );
}, onProgress, onError );
非常感谢