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 | 1016 |
1 files changed, 456 insertions, 560 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js b/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js index e80a14fb..56199556 100755 --- a/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js +++ b/js/helper-classes/RDGE/src/core/script/scenegraphNodes.js | |||
@@ -4,646 +4,542 @@ 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 RDGE.transformNodeTemplate(node); | |
27 | node.transformNodeTemplate = new 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 | { | 36 | node = { 'name': nodeName }; |
37 | node = { 'name': nodeName }; | 37 | |
38 | 38 | node.materialNodeTemplate = new RDGE.materialNodeTemplate(node); | |
39 | node.materialNodeTemplate = new materialNodeTemplate(node); | 39 | |
40 | 40 | return node; | |
41 | return node; | 41 | }; |
42 | } | ||
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 | { | 47 | meshNode = { 'mesh': {}, 'meshNodeTemplate': {} }; |
49 | meshNode = { 'mesh':{}, 'meshNodeTemplate':{} }; | 48 | |
50 | 49 | var renderer = RDGE.globals.engine.getContext().renderer; | |
51 | var renderer = g_Engine.getContext().renderer; | 50 | |
52 | 51 | if (!primitive.built) { | |
53 | 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 | { | 63 | renderer.createPrimitive(model.primitive); |
68 | renderer.createPrimitive(model.primitive); | 64 | } |
69 | } | 65 | |
70 | 66 | meshNode.mesh.meshNodeTemplate = new RDGE.meshNodeTemplate(meshNode.mesh, model.primitive, nodeName); | |
71 | meshNode.mesh.meshNodeTemplate = new meshNodeTemplate(meshNode.mesh, model.primitive, nodeName); | 67 | |
72 | 68 | return meshNode; | |
73 | 69 | }; | |
74 | return meshNode; | ||
75 | } | ||
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()); | 87 | return trNode; |
95 | return trNode; | 88 | }; |
96 | } | ||
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 | } | 93 | } |
104 | } | 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 | } | 99 | } |
112 | } | 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 | { | 117 | trNode.children = []; |
134 | trNode.children = []; | 118 | } |
135 | } | 119 | |
136 | 120 | if (!trNode.local) { | |
137 | if(!trNode.local) | 121 | trNode.local = RDGE.mat4.identity(); |
138 | { | 122 | } |
139 | trNode.local = mat4.identity(); | 123 | |
140 | } | 124 | if (!trNode.world) { |
141 | 125 | trNode.world = RDGE.mat4.identity(); | |
142 | if(!trNode.world) | 126 | } |
143 | { | 127 | |
144 | trNode.world = mat4.identity(); | 128 | if (!trNode.id) { |
145 | } | 129 | trNode.id = RDGE.nodeIdGen.getId(); |
146 | 130 |