고유 한 모델 형식을 만들고 싶습니다. 그 목적을 위해 사용자 지정 지오메트리를 만들려고합니다. 지오메트리를 올바르게 가져올 수 있습니다. 버 얼굴 법선은 도형에 추가하더라도 렌더링되지 않습니다. 여기 Three.js면 법선이 올바르게 렌더링되지 않습니다.
# Coordinates
0e+0 0e+0 0e+0
1e+0 0e+0 0e+0
1e+0 0e+0 1e+0
0e+0 0e+0 1e+0
0e+0 1e+0 0e+0
1e+0 1e+0 0e+0
1e+0 1e+0 1e+0
0e+0 1e+0 1e+0
# Normals
0e+0 0e+0 -1e+0
0e+0 -1e+0 0e+0
0e+0 0e+0 1e+0
0e+0 1e+0 0e+0
1e+0 0e+0 0e+0
-1e+0 0e+0 0e+0
# Connectivity List
1 2 6 5
1 2 3 4
3 4 8 7
6 5 8 7
2 6 7 3
1 5 8 4
내가 그것을 가져 오는 방법입니다 :
여기에 입력 파일입니다. I는 얼굴 삼각형 쿼드로 변환하고 코드 (연결리스트) FACE4 동안 어레이에서
var geometry = new THREE.Geometry();
//Add all positions to geometry
for (var g=0;g<coordinates.length;g++){
geometry.vertices.push(coordinates[g]);
}
for(var l=0;l<connectivity.length;l++){
//sml file have rectangular faces but three js uses triangular faces (THREE.Face4 is deprecated) so converting 4 vertex faces to 3 verex faces
var index0= connectivity[l][3]-1;
var index1= connectivity[l][4]-1;
var index2= connectivity[l][5]-1;
var index3= connectivity[l][6]-1;
//If normals is exist thenaddthem to face array too
if(normals.length==connectivity.length){
console.log("Normals are exist");
var face0= new THREE.Face3(index0,index1,index2);
face0.normal.set(normals[l]);
geometry.faces.push(face0);
var face1= new THREE.Face3(index2,index3,index0);
face1.normal.set(normals[l]);
geometry.faces.push(face1);
} else{
console.log("Normals are not exist");
var face0= new THREE.Face3(index0,index1,index2);
geometry.faces.push(face0);
var face1= new THREE.Face3(index2,index3,index0);
geometry.faces.push(face1);
}
}
geometry.computeBoundingBox();
// geometry.compteVertexNormals();
geometry.computeFaceNormals();
는 thee.js. 의해 사용되지 그리고 저는 같은 쿼드를 공유하는 두 삼각형 모두에 동일한 법선을 할당하고 있습니다. 여기
는이 상자를 렌더링하는 방법입니다 :
오전 내가 모르는 뭔가가?
얼굴 법선 목록이 있거나 그렇지 않은 경우 얼굴 법선을 계산해도 문제가 발생하지 않습니다. 나는 코드 스 니펫'geometry.computeFaceNormals();'의 끝 부분에서이 줄로 인해 묻습니다. – prisoner849
예, 그 선 앞에 조건을 넣어야합니다. 하지만 그것은 현재의 문제와 관련이 없습니다. 어쨌든 고마워. – user3160302
'.computeFaceNormals()'는 호출 될 때 지오메트리의면에 대한 법선을 자동으로 계산합니다. 또한 조건 블록에서 동일한 작업을 두 번 수행합니다. 두 개의 얼굴을 만듭니다. 유일한 차이점은 법선을 추가한다는 것입니다. 따라서 조건 블럭에서 얼굴을 생성하고 조건이 '참'일 때 법선을 추가하는 것이 더 나을 것입니다. – prisoner849