独自のモデル形式を作成したい。その目的のために、カスタム ジオメトリを作成しようとしています。ジオメトリを正しくインポートできます。バー面の法線をジオメトリに追加してもレンダリングされません。
入力ファイルは次のとおりです。
# 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
これが私がそれをインポートする方法です。
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();
コードでは、FACE4 が thee.js によって廃止されている間、面 (接続リスト) 配列の四角形を三角形に変換しています。そして、同じクワッドを共有する両方の三角形に同じ法線を割り当てています。
このボックスのレンダリング方法は次のとおりです。
何か不足していますか?