-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySceneGraphNode.js
53 lines (44 loc) · 1.32 KB
/
MySceneGraphNode.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
53
/**
* GraphNode class, representing a graph node.
*/
class MySceneGraphNode {
constructor(scene, nodeID, childNodesID, leafs, tranfMatrix, material, texture, textureID) {
this.scene = scene;
this.nodeID = nodeID;
this.childNodesID = childNodesID;
this.childNodes = [];
this.leafs = leafs;
this.transfMatrix = tranfMatrix;
this.material = material;
this.texture = texture;
this.textureID = textureID;
}
addChildNode(child) {
this.childNodes.push(child);
}
display(material, texture){
this.scene.pushMatrix();
this.scene.multMatrix(this.transfMatrix);
let currentMaterial = material;
let currentTexture = texture;
if (this.material != null) {
currentMaterial = this.material;
}
if (this.textureID !== "null") {
currentTexture = this.texture;
}
if (currentMaterial != null) {
currentMaterial.apply();
}
if (currentTexture != null) {
currentTexture.bind();
}
for (let leaf of this.leafs) {
leaf.display();
}
for (let child of this.childNodes) {
child.display(currentMaterial, currentTexture);
}
this.scene.popMatrix();
}
}