2016-07-19 5 views
0

メッシュをインポートしていて、すでにそのメッシュの頂点法線を計算しています。私は、ジオメトリオブジェクトに対して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

誰でもこの方法を知っていますか?

おかげで、THREE.Geometryの場合

ジョン

+1

これは未回答です。ソースを見て、どのようにFloat32Arrayを追加するのかを理解しました。以下のネイティブ関数を参照してください:https://github.com/mrdoob/three.js/blob/302c693b27663d4d280b156b5ebe4ed38cd062e4/src/core/BufferGeometry.js#L637 649行目の "this.addAttribute"は、属性を作成するオブジェクトを作成します。 normal.arrayは665行目から入手可能です。私はこれが自分自身を追加する方法であると考えています。ここでは、 "this"はジオメトリまたはバッファーメトリーのインスタンスです。 – Radio

+0

ありがとうございます、私はコードでそれを参照してください。それがサポートされている方法なら、私はそれを探求します。 –

答えて

0

は、頂点の法線が面で記憶されているオブジェクト。 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; 


} 
関連する問題