[英]How to work with vertices of object loaded by ObjLoader in Three.js
I have a object loaded in my scene by ObjLoader. ObjLoader 在我的场景中加载了一个对象。 But then i need to read that object vertices.
但随后我需要读取该对象顶点。 But i still cant find out how to do it.
但我仍然无法找到如何去做。 On normal cube what i made in three.js I can read and change vertices without problem but on object loaded by ObjLoader it do not work.
在我在three.js中制作的普通立方体上,我可以毫无问题地读取和更改顶点,但在ObjLoader加载的对象上它不起作用。 I also tried to use FaceNormalsHelper which also works on cube but dont on my object.
我还尝试使用 FaceNormalsHelper,它也适用于立方体,但不适用于我的对象。
Here is my code:这是我的代码:
//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 );
Thanks a lot非常感谢
OBJLoader create object as THREE.group
. OBJLoader 创建对象为
THREE.group
。 So you can access vertices below way.所以你可以通过下面的方式访问顶点。
object.children[0].geometry.attributes.position
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.