2016-07-19 3 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; 


} 
관련 문제