diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/scenegraphNodes.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/scenegraphNodes.js | 463 |
1 files changed, 180 insertions, 283 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js b/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js index 93ee12bf..95ee2803 100755 --- a/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js +++ b/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js | |||
@@ -4,169 +4,145 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | // RDGE namespaces | ||
8 | var RDGE = RDGE || {}; | ||
7 | 9 | ||
8 | /* | 10 | /* |
9 | * Creates a unique node id | 11 | * Creates a unique node id |
10 | */ | 12 | */ |
11 | nodeIdGen = {}; | 13 | RDGE.nodeIdGen = {}; |
12 | 14 | ||
13 | nodeIdGen.counter = 0; | 15 | RDGE.nodeIdGen.counter = 0; |
14 | 16 | ||
15 | nodeIdGen.getId = function() | 17 | RDGE.nodeIdGen.getId = function () { |
16 | { | 18 | return "gen_" + RDGE.nodeIdGen.counter++; |
17 | return "gen_" + nodeIdGen.counter++; | 19 | }; |
18 | } | ||
19 | 20 | ||
20 | /* | 21 | /* |
21 | * Constructs a new transform node | 22 | * Constructs a new transform node |
22 | */ | 23 | */ |
23 | function createTransformNode(nodeName) | 24 | RDGE.createTransformNode = function (nodeName) { |
24 | { | ||
25 | node = { 'name': nodeName }; | 25 | node = { 'name': nodeName }; |
26 | 26 | ||
27 | node.transformNodeTemplate = new transformNodeTemplate(node); | 27 | node.transformNodeTemplate = new RDGE.transformNodeTemplate(node); |
28 | 28 | ||
29 | return node; | 29 | return node; |
30 | } | 30 | }; |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Constructs a new material node | 33 | * Constructs a new material node |
34 | */ | 34 | */ |
35 | function createMaterialNode(nodeName) | 35 | RDGE.createMaterialNode = function (nodeName) { |
36 | { | ||
37 | node = { 'name': nodeName }; | 36 | node = { 'name': nodeName }; |
38 | 37 | ||
39 | node.materialNodeTemplate = new materialNodeTemplate(node); | 38 | node.materialNodeTemplate = new RDGE.materialNodeTemplate(node); |
40 | 39 | ||
41 | return node; | 40 | return node; |
42 | } | 41 | }; |
43 | 42 | ||
44 | /* | 43 | /* |
45 | * Constructs a new mesh node | 44 | * Constructs a new mesh node |
46 | */ | 45 | */ |
47 | function createMeshNode(nodeName, primitive) | 46 | RDGE.createMeshNode = function (nodeName, primitive) { |
48 | { | ||
49 | meshNode = { 'mesh':{}, 'meshNodeTemplate':{} }; | 47 | meshNode = { 'mesh':{}, 'meshNodeTemplate':{} }; |
50 | 48 | ||
51 | var renderer = g_Engine.getContext().renderer; | 49 | var renderer = RDGE.globals.engine.getContext().renderer; |
52 | 50 | ||
53 | if(!primitive.built) | 51 | if (!primitive.built) { |
54 | { | ||
55 | renderer.createPrimitive(primitive); | 52 | renderer.createPrimitive(primitive); |
56 | } | 53 | } |
57 | 54 | ||
58 | var model = g_meshMan.getModelByName(nodeName); | 55 | var model = RDGE.globals.meshMan.getModelByName(nodeName); |
59 | if(!model) | 56 | if (!model) { |
60 | { | 57 | meshNode.mesh.meshNodeTemplate = new RDGE.meshNodeTemplate(meshNode.mesh, primitive, nodeName); |
61 | meshNode.mesh.meshNodeTemplate = new meshNodeTemplate(meshNode.mesh, primitive, nodeName); | ||
62 | 58 | ||
63 | g_meshMan.modelMap[nodeName] = meshNode.mesh; | 59 | RDGE.globals.meshMan.modelMap[nodeName] = meshNode.mesh; |
64 | return meshNode; // --early out-- | 60 | return meshNode; // --early out-- |
65 | } | 61 | } |
66 | else if(!renderer.buffers[model.primitive.buffersID]) | 62 | else if (!renderer.buffers[model.primitive.buffersID]) { |
67 | { | ||
68 | renderer.createPrimitive(model.primitive); | 63 | renderer.createPrimitive(model.primitive); |
69 | } | 64 | } |
70 | 65 | ||
71 | meshNode.mesh.meshNodeTemplate = new meshNodeTemplate(meshNode.mesh, model.primitive, nodeName); | 66 | meshNode.mesh.meshNodeTemplate = new RDGE.meshNodeTemplate(meshNode.mesh, model.primitive, nodeName); |
72 | |||
73 | 67 | ||
74 | return meshNode; | 68 | return meshNode; |
75 | } | 69 | }; |
76 | 70 | ||
77 | /* | 71 | /* |
78 | * Construct a light node | 72 | * Construct a light node |
79 | */ | 73 | */ |
80 | function createLightNode(nodeName) | 74 | RDGE.createLightNode = function (nodeName) { |
81 | { | ||
82 | node = { 'name': nodeName }; | 75 | node = { 'name': nodeName }; |
83 | node.lightNodeTemplate = new lightNodeTemplate(node); | 76 | node.lightNodeTemplate = new RDGE.lightNodeTemplate(node); |
84 | 77 | ||
85 | return node; | 78 | return node; |
86 | } | 79 | }; |
87 | 80 | ||
88 | /* | 81 | /* |
89 | * creates a specialized mesh node representing a screen aligned quad with identity transform | 82 | * creates a specialized mesh node representing a screen aligned quad with identity transform |
90 | */ | 83 | */ |
91 | function createScreenQuadNode() | 84 | RDGE.createScreenQuadNode = function () { |
92 | { | 85 | var trNode = RDGE.createTransformNode(); |
93 | var trNode = createTransformNode(); | 86 | trNode.attachMeshNode("screenQuad", RDGE.renderUtils.createScreenAlignedQuad()); |
94 | trNode.attachMeshNode("screenQuad", createScreenAlignedQuad()); | ||
95 | return trNode; | 87 | return trNode; |
96 | } | 88 | }; |
97 | 89 | ||
98 | function verifyTransformNode( node ) | 90 | RDGE.verifyTransformNode = function (node) { |
99 | { | 91 | if (node.transformNodeTemplate == undefined) { |
100 | if(node.transformNodeTemplate == undefined) | 92 | node.transformNodeTemplate = new RDGE.transformNodeTemplate(node); |
101 | { | ||
102 | node.transformNodeTemplate = new transformNodeTemplate(node); | ||
103 | } | ||
104 | } | 93 | } |
94 | }; | ||
105 | 95 | ||
106 | function verifyMaterialNode( node ) | 96 | RDGE.verifyMaterialNode = function (node) { |
107 | { | 97 | if (node.materialNodeTemplate == undefined) { |
108 | if(node.materialNodeTemplate == undefined) | 98 | node.materialNodeTemplate = new RDGE.materialNodeTemplate(node); |
109 | { | ||
110 | node.materialNodeTemplate = new materialNodeTemplate(node); | ||
111 | } | ||
112 | } | 99 | } |
100 | }; | ||
113 | 101 | ||
114 | function verifyLightNode( node ) | 102 | RDGE.verifyLightNode = function (node) { |
115 | { | 103 | if (node.lightNodeTemplate == undefined) { |
116 | if(node.lightNodeTemplate == undefined) | 104 | node.lightNodeTemplate = new RDGE.lightNodeTemplate(node); |
117 | { | ||
118 | node.lightNodeTemplate = new lightNodeTemplate(node); | ||
119 | } | 105 | } |
120 | } | 106 | }; |
121 | |||
122 | 107 | ||
123 | /* | 108 | /* |
124 | * Takes an object and attachs transform node | 109 | * Takes an object and attaches transform node |
125 | * functions and fields if they are not defined | 110 | * functions and fields if they are not defined |
126 | */ | 111 | */ |
127 | transformNodeTemplate = function(trNode) | 112 | RDGE.transformNodeTemplate = function (trNode) { |
128 | { | ||
129 | // Lots of checking for things that might exist and adding them when they don't | 113 | // Lots of checking for things that might exist and adding them when they don't |
130 | 114 | ||
131 | /* ------------------------------------------- */ | 115 | /* ------------------------------------------- */ |
132 | if(!trNode.children) | 116 | if (!trNode.children) { |
133 | { | ||
134 | trNode.children = []; | 117 | trNode.children = []; |
135 | } | 118 | } |
136 | 119 | ||
137 | if(!trNode.local) | 120 | if (!trNode.local) { |
138 | { | 121 | trNode.local = RDGE.mat4.identity(); |
139 | trNode.local = mat4.identity(); | ||
140 | } | 122 | } |
141 | 123 | ||
142 | if(!trNode.world) | 124 | if (!trNode.world) { |
143 | { | 125 | trNode.world = RDGE.mat4.identity(); |
144 | trNode.world = mat4.identity(); | ||
145 | } | 126 | } |
146 | 127 | ||
147 | if(!trNode.id) | 128 | if (!trNode.id) { |