.vertices array does not give the vertices in THREE.js

丶灬走出姿态 提交于 2019-12-11 04:49:16

问题


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:


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.71



来源:https://stackoverflow.com/questions/30580997/vertices-array-does-not-give-the-vertices-in-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!