1
votes

I am using OBJloader to load an .obj file in WEBGL , Three.js. I want to access the vertices and faces of the objects but the geometry.vertices does not return the vertices positions and it gives me undefined.

Here is a piece of code:

 var tool= new THREE.OBJLoader();
 tool.load( '../obj/tool.obj', function ( object ) {
            var material = new THREE.MeshLambertMaterial({color:0xA0A0A0});             
            object.traverse( function ( child ) {
                if ( child instanceof THREE.Mesh ) {
                   child.material = material;
                   console.log( "child" + child.geometry.vertices);} }

r.70

I am thankful for your helps in advance.

1
The loader is returning BufferGeometry.WestLangley
I have checked some samples using geometry.vertices with OBJloader but it does not work in my code. Besides, i need to move the object later and update the vertices positions and also access to the faces. But it does not have access to faces in buffergeometry attributes.Arezoo Tony
Thanks, So much appreciate it , It worked perfect.Arezoo Tony
Good. Posted answer.WestLangley

1 Answers

5
votes

This answer only applies to versions of three.js prior to r.125.

If the loader you are using is returning BufferGeometry, you can convert the returned geometry to Geometry in the loader callback using a pattern like so:

var geometry = new THREE.Geometry().fromBufferGeometry( bufferGeometry );

three.js r.124