three.js - how do I get the vertices of an object?

Deadly 提交于 2019-12-13 04:43:59

问题


I am trying to import a model from blender and loop through all vertices. I am using the colladaloader for the import. It all works fine and the model is loading. But I do not want the faces of the model - I only need the vertex positions for my purposes.

Can anyone tell me if there is a way to do this? e.g. a loop that loops through all vertices of the imported model?

Thanks, Tomo


回答1:


If geo represents your geometry:

for (var i = 0; i < geo.vertices.length; i++)
{
    var v = geo.vertices[i];
    // do stuff with v...

}



回答2:


Ok now I got it...

console.log() helped me a lot to see what structure is behind the loaded .dae file.

loader.load( './models/collada/test.dae', function ( collada ) {                
    for(i = 0; i < collada.scene.children.length; i++) {
        if(collada.scene.children[i].geometry) {
            for(j = 0; j < collada.scene.children[i].geometry.vertices.length; j++) {
                //do stuff...
            }
        }
    }

    //...
} );



回答3:


Well, you import your Blender Model as a mesh, using a loader module. The mesh has a geometry it is based on. And the geometry has a vertices-Array. Just iterate over that? And maybe just don't add it to the scene if you don't want to display the model? At first glance, your question seems not very well researched. Check out the Mesh object structure and see the Three.js Examples!



来源:https://stackoverflow.com/questions/18967423/three-js-how-do-i-get-the-vertices-of-an-object

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