-
Notifications
You must be signed in to change notification settings - Fork 0
/
sceneNode.js
49 lines (40 loc) · 1.36 KB
/
sceneNode.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
/**
* @class SceneNode
* @desc A SceneNode is a node in the scene graph.
* @property {MeshDrawer} meshDrawer - The MeshDrawer object to draw
* @property {TRS} trs - The TRS object to transform the MeshDrawer
* @property {SceneNode} parent - The parent node
* @property {Array} children - The children nodes
*/
class SceneNode {
constructor(meshDrawer, trs, parent = null) {
this.meshDrawer = meshDrawer;
this.trs = trs;
this.parent = parent;
this.children = [];
if (parent) {
this.parent.__addChild(this);
}
}
__addChild(node) {
this.children.push(node);
}
draw(mvp, modelView, normalMatrix, modelMatrix) {
/**
* @Task1 : Implement the draw function for the SceneNode class.
*/
var Mpvval = MatrixMult(mvp, this.trs.getTransformationMatrix());
var viewer = MatrixMult(modelView, this.trs.getTransformationMatrix());
var transnorm = getNormalMatrix(viewer);
var transmod = MatrixMult(modelMatrix, this.trs.getTransformationMatrix());
// Draw the MeshDrawer
if (this.meshDrawer)
{
this.meshDrawer.draw(Mpvval, viewer, transnorm, transmod);
}
for (var k = 0; k < this.children.length; k++)
{
this.children[k].draw(Mpvval, viewer, transnorm, transmod);
}
}
}