0
votes

I use ObjLoader in Three.js to load a *.obj file in my scene, normally code is working without any problem but how am I supposed to do if I want to manipulate the object vertices and indices bit by bit, I don't knwo exactly how to call the vertices in the loaded *.obj model.

Tryig to run var vertex_x = geometry.vertices[0].x raises an exception and complains that 0 property is not defined. Your guidance will be appreciated,

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);
});
1

1 Answers

0
votes

OBJLoader returns an Object3D, so in your code you can replace geometry with mesh for instance, and access vertices with mesh.geometry.vertices[i]