我在Three.js中使用ObjLoader在我的场景中加载* .obj文件,通常代码工作没有任何问题,但如果我想要一点一点地操纵对象顶点和索引,我该怎么办呢不知道如何在加载的* .obj模型中调用顶点。
运行var vertex_x = geometry.vertices[0].x
的Tryig引发异常并抱怨未定义0属性。我们将非常感谢您的指导,
var obj_geo = new THREE.OBJLoader();
obj_geo.load('new_I_Profile.obj', function(geometry){
geometry.scale.x = 2; geometry.scale.y = 2; geometry.scale.z = 20;
geometry.rotation.x = -Math.PI/2;
geometry.color = 0xff;
var lines = new THREE.Geometry();
lines.vertices.push(new THREE.Vector3(0, 0, 0));
lines.vertices.push(new THREE.Vector3(0, 120, 0));
var material = new THREE.LineBasicMaterial({ opacity: 1.0, linewidth: 1, vertexColors: THREE.VertexColors });
var main_line = new THREE.Line(lines, material);
main_line.name = 'main_line';
main_line.position.x = crs_line.position.x; main_line.position.z = crs_line.position.z;
main_line.position.y = crs_line.position.y;
main_line.add(geometry);
editor.addObject(main_line);
});
答案 0 :(得分:0)
OBJLoader
会返回Object3D
,因此您可以在代码中将 geometry 替换为 mesh ,并使用mesh.geometry访问顶点.vertices [I]