简体   繁体   English

ThreeJs加载的顶点比obj文件中的顶点多

[英]ThreeJs Loads more vertices than there are in an obj file

I have this code: 我有以下代码:

function render_obj(objPath){
  var loader = new THREE.OBJLoader();
  loader.load(
    objPath,
    function ( object ) {
      child = object.children[0];
      var geometry = new THREE.Geometry().fromBufferGeometry( child.geometry );      
      var material = new THREE.MeshBasicMaterial({wireframe: true});
      model = new THREE.Mesh(geometry, material);
      scene.add(model);
    },
    function ( xhr ) {
      console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
    },
    function ( error ) {
      console.log( 'An error happened' );
    }
  );
};

now man.obj has 214 vertices and 332 faces. 现在man.obj有214个顶点和332个面。 When I check the faces by doing this: model.geometry.faces.length I get 332 which is correct. 当我通过执行以下操作检查脸部: model.geometry.faces.length我得到332是正确的。 When I do model.geometry.vertices.length I get 996, where I should get 214... 当我执行model.geometry.vertices.length我得到996,我应该得到214 ...

Why is that ? 这是为什么 ?

The loader that you are using is creating something called “triangle soup”. 您正在使用的装载程序正在创建称为“三角汤”的东西。 This means that your N triangles are actually defined by N * 3 vertices. 这意味着您的N个三角形实际上是由N * 3个顶点定义的。 A triangle itself doesn't really exist, it's just interpreted from the vertices. 三角形本身并不真正存在,只是从顶点进行解释。 The first three make a triangle, the next three and so on. 前三个组成一个三角形,下三个组成,依此类推。 If you have a continuous smooth mesh, a lot of vertices will be duplicated. 如果您拥有连续的平滑网格,则将复制许多顶点。

What you are probably interested in is “indexed” geometry. 您可能感兴趣的是“索引”几何。 In this type of geometry, you have an actual triangle buffer holding the index is for the vertices. 在这种类型的几何图形中,您有一个实际的三角形缓冲区,其中包含用于顶点的索引。 In a continuous smooth mesh, one vertex can be shared by many triangles. 在连续的平滑网格中,一个顶点可以被许多三角形共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM