我导入了一个网格,并且已经为它计算了顶点法线。我想使用我的法线而不是为几何对象调用computeVertexNormals()。现在我有
var geometry = THREE.Geometry();
// fill in vertex, face and texture
// ...
// compute normals
geometry.computeFaceNormals();
geometry.computeVertexNormals(); // <-- Would like to replace this
文档中有一个使用缓冲区属性但没有示例的引用。 http://threejs.org/docs/index.html?q=vertex#Reference/Core/BufferAttribute
有谁知道怎么做?
感谢,
约翰
答案 0 :(得分:0)
对于THREE.Geometry对象,顶点法线与面存储在一起。如果NormalList包含顶点的法线向量,则此循环将执行此操作。
/*
* Add the normals. They are added to the face array
*/
for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
var face = geometry.faces[ f ];
var ndx = face.a;
var normal = new THREE.Vector3();
normal.x = NormalList[ndx].x;
normal.y = NormalList[ndx].y;
normal.z = NormalList[ndx].z;
face.vertexNormals[ 0 ] = normal;
ndx = face.b;
normal = new THREE.Vector3();
normal.x = NormalList[ndx].x;
normal.y = NormalList[ndx].y;
normal.z = NormalList[ndx].z;
face.vertexNormals[ 1 ] = normal;
ndx = face.c;
normal = new THREE.Vector3();
normal.x = NormalList[ndx].x;
normal.y = NormalList[ndx].y;
normal.z = NormalList[ndx].z;
face.vertexNormals[ 2 ] = normal;
}