I want to create my own model format. For that purpose I am trying to create custom geometry. I can import geometry properly. Bur face normals doesn't get rendered even I add them to geometry.
Here is input file:
# 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
Here is the way I import it.
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();
At the code I am converting quads to triangles in face (connectivity list) array while FACE4 is deprecated by thee.js. And I am assigning same normal to both triangles that sharing same quad.
Here is how this box is rendered:
Am I missing something?