ThreeJS: 3D Object Area Calculation (Triangulated)

我与影子孤独终老i 提交于 2020-01-11 12:27:27

问题


I need to calculate the area/surface of a whole object in threeJS. Thats what I have:

    var _len = object.geometry.faces.length,
        _area = 0.0;

    if (!_len) return 0.0;

    for (var i = 0; i < _len; i++) {
        var va = object.geometry.vertices[object.geometry.faces[i].a];
        var vb = object.geometry.vertices[object.geometry.faces[i].b];
        var vc = object.geometry.vertices[object.geometry.faces[i].c];

        var ab = vb.clone().sub(va);
        var ac = vc.clone().sub(va);

        var cross = new THREE.Vector3();
        cross.crossVectors( ab, ac );

        _area += cross.lengthSq() / 2;
    }

The results are kind of wrong. I get a floating value, fine, but comparing a very small object with a big object. The smaller could have a bigger surface with the provided code. I checked on many different objects and got not realistic values, when comparing them.

Actually the objects having the biggest faces, but being the smallest in the overall surface, seem to have to highest values with the current version of the code.

I hope someone could have a look at the code and see whats wrong. Very much appreciated!


回答1:


You are using lengthSq(), is that right? I guess you need the length of the cross vector, not the length squared.



来源:https://stackoverflow.com/questions/22518139/threejs-3d-object-area-calculation-triangulated

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