3
votes

I am uploading a series of .obj and .mtl files for a volume rendering tool developed by WebGL and Three.js. In a part of code I am using OBJMTLLoader to upload the files:

 scapula = new THREE.OBJMTLLoader();
 scapula.load( 'obj/scapulaTWO.obj', 'obj/scapulaTWO.mtl', 
    function ( object ) {
                object.name = "scapula";
                object.scale.set (4,4,4);
                vertices = object.geometry.vertices;
                scene.add(object);
    });

However I can't get access to the vertices. Debugger says that object.geometry is undefined. I have also tried

    vertices = new THREE.Mesh(object);

but it didn't work. I would really appreciate if you could help me out.

Thanks in advance.

1

1 Answers

3
votes

The node structure of the imported 3d-model in three.js depends on the structure of the OBJ file and the grouping Elements like o or g (http://www.fileformat.info/format/wavefrontobj/egff.htm#WAVEOBJ-DMYID.2).

You can use your browser debugger to find out how three.js built your structure. In my case (where I have several object declared in the OBJ File) the structure looks like this:

model (THREE.Group) > children (Array) > child [i] (THREE.Object3D) > children (Array) > child [j] (THREE.Mesh) > geometry (THREE.Geometry) > vertices (Array)

Here you access the vertex k of the Mesh j in the object3d i:

var vertexK = object.children[i].children[j].geometry.vertices[k];