-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.pde
58 lines (50 loc) · 1.38 KB
/
Entity.pde
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
53
54
55
56
57
58
class Entity {
String name = "Entity";
Transform transform;
Material material;
Mesh mesh;
// For local use.
protected Coord v = new Coord();
protected Normal vn = new Normal();
protected Coord vt = new Coord();
protected Quaternion wr = new Quaternion();
Entity() {
}
Entity(Transform transform, Material material, Mesh shape) {
this.transform = transform;
this.material = material;
this.mesh = shape;
}
Entity draw(PGraphics3D r) {
Coord[] coords = mesh.coords;
Coord[] texCoords = mesh.texCoords;
int[][][] faces = mesh.faces;
int[] vertex;
transform.worldRotation(wr);
Normal[] normals = mesh.normals;
r.pushStyle();
material.drawStyle(r);
for (int i = 0, sz0 = faces.length, j; i < sz0; ++i) {
int sz1 = faces[i].length;
r.beginShape(sz1 == 3 ? TRIANGLES :
sz1 == 4 ? QUADS : POLYGON);
material.draw(r);
for (j = 0; j < sz1; ++j) {
vertex = faces[i][j];
v.set(coords[vertex[0]]);
v.mult(transform);
vt.set(texCoords[vertex[1]]);
vt.mult(material);
// If normal is not called, Processing
// will auto-calculate normals.
vn.set(normals[vertex[2]]);
vn.mult(wr);
r.normal(vn.x, vn.y, vn.z);
r.vertex(v.x, v.y, v.z, vt.x, vt.y);
}
r.endShape(CLOSE);
}
r.popStyle();
return this;
}
}