-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFace.js
52 lines (46 loc) · 1.2 KB
/
Face.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var idCounter = 0;
function Face(edge1, edge2, edge3, flip) {
this.edges = flip ? [edge1, edge2, edge3] : [edge3, edge2, edge1];
var _this = this;
this.edges.forEach(function(edge){
edge.addFace(_this);
})
this.id = idCounter;
idCounter++;
}
var normal = new THREE.Vector3();
var tempVec3 = new THREE.Vector3();
Face.prototype = {
getFace: function() {
var verts = [
this.edges[0].getSharedVertex(this.edges[1]),
this.edges[1].getSharedVertex(this.edges[2]),
this.edges[2].getSharedVertex(this.edges[0])
];
return new THREE.Face3(verts[0], verts[1], verts[2]);
},
getPrevEdge: function(edge) {
return this.edges[(this.edges.indexOf(edge)+2)%3];
},
getNextEdge: function(edge) {
return this.edges[(this.edges.indexOf(edge)+1)%3];
},
getVertexOpposingEdge: function(edge) {
return this.getNextEdge(edge).getUnsharedVertex(edge);
},
removeItselfFromEdges: function() {
var _this = this;
this.edges.forEach(function(edge){
edge.removeFace(_this);
})
},
getNormal: function() {
var face = this.getFace();
normal.subVectors( face.c, face.b );
tempVec3.subVectors( face.a, face.b );
normal.cross( tempVec3 );
normal.normalize();
return normal;
}
}
module.exports = Face;