1

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.

4
  • The loader is returning BufferGeometry. Commented Jun 1, 2015 at 20:39
  • 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. Commented Jun 2, 2015 at 3:01
  • Thanks, So much appreciate it , It worked perfect. Commented Jun 3, 2015 at 15:28
  • Good. Posted answer. Commented Jun 3, 2015 at 15:40

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.