diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/lightmanager.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/lightmanager.js | 238 |
1 files changed, 119 insertions, 119 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/lightmanager.js b/js/helper-classes/RDGE/src/core/script/lightmanager.js index e38418f5..74ab3e03 100755 --- a/js/helper-classes/RDGE/src/core/script/lightmanager.js +++ b/js/helper-classes/RDGE/src/core/script/lightmanager.js | |||
@@ -1,119 +1,119 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, are permitted provided that the following conditions are met: |
8 | 8 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 9 | - Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 10 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | - Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the | 12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. | 13 | documentation and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | - Neither the name of Motorola Mobility nor the names of its contributors |
15 | may be used to endorse or promote products derived from this software | 15 | may be used to endorse or promote products derived from this software |
16 | without specific prior written permission. | 16 | without specific prior written permission. |
17 | 17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | // RDGE namespaces | 31 | // RDGE namespaces |
32 | var RDGE = RDGE || {}; | 32 | var RDGE = RDGE || {}; |
33 | 33 | ||
34 | // manage light links | 34 | // manage light links |
35 | RDGE.LightManager = function (lightUniformList) { | 35 | RDGE.LightManager = function (lightUniformList) { |
36 | // build a list of all light uniforms, contains a list of light uniform lists | 36 | // build a list of all light uniforms, contains a list of light uniform lists |
37 | this.lightUniforms = [[], [], [], []]; | 37 | this.lightUniforms = [[], [], [], []]; |
38 | 38 | ||
39 | // bucket the uniforms lists | 39 | // bucket the uniforms lists |
40 | for (var l in lightUniformList) { | 40 | for (var l in lightUniformList) { |
41 | // starts with | 41 | // starts with |
42 | if (l.indexOf("u_light0") == 0) { | 42 | if (l.indexOf("u_light0") == 0) { |
43 | this.lightUniforms[0][l] = l; | 43 | this.lightUniforms[0][l] = l; |
44 | } | 44 | } |
45 | else if (l.indexOf("u_light1") == 0) { | 45 | else if (l.indexOf("u_light1") == 0) { |
46 | this.lightUniforms[1][l] = l; | 46 | this.lightUniforms[1][l] = l; |
47 | } | 47 | } |
48 | else if (l.indexOf("u_light2") == 0) { | 48 | else if (l.indexOf("u_light2") == 0) { |
49 | this.lightUniforms[2][l] = l; | 49 | this.lightUniforms[2][l] = l; |
50 | } | 50 | } |
51 | else if (l.indexOf("u_light3") == 0) { | 51 | else if (l.indexOf("u_light3") == 0) { |
52 | this.lightUniforms[3][l] = l; | 52 | this.lightUniforms[3][l] = l; |
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | // maps (takes a string returns an object) | 56 | // maps (takes a string returns an object) |
57 | this.lightToMesh = []; // pass light name, returns light of meshes | 57 | this.lightToMesh = []; // pass light name, returns light of meshes |
58 | this.meshToLight = []; // pass mesh name, returns list of lights | 58 | this.meshToLight = []; // pass mesh name, returns list of lights |
59 | 59 | ||
60 | // list of light objects by type | 60 | // list of light objects by type |
61 | this.dirLights = []; | 61 | this.dirLights = []; |
62 | this.pointLights = []; | 62 | this.pointLights = []; |
63 | this.spotLights = []; | 63 | this.spotLights = []; |
64 | this.ambLights = []; | 64 | this.ambLights = []; |
65 | this.unknLights = []; | 65 | this.unknLights = []; |
66 | 66 | ||
67 | // light types | 67 | // light types |
68 | this.typePointLight = "point_light"; | 68 | this.typePointLight = "point_light"; |
69 | this.typeSpotLight = "spot_light"; | 69 | this.typeSpotLight = "spot_light"; |
70 | this.typeAmbLight = "amb_light"; | 70 | this.typeAmbLight = "amb_light"; |
71 | this.typeDirLight = "dir_light"; | 71 | this.typeDirLight = "dir_light"; |
72 | 72 | ||
73 | this.defaultLights = | 73 | this.defaultLights = |
74 | [ | 74 | [ |
75 | RDGE.createLightNode("default0"), | 75 | RDGE.createLightNode("default0"), |
76 | RDGE.createLightNode("default1"), | 76 | RDGE.createLightNode("default1"), |
77 | RDGE.createLightNode("default2"), | 77 | RDGE.createLightNode("default2"), |
78 | RDGE.createLightNode("default3") | 78 | RDGE.createLightNode("default3") |
79 | ]; | 79 | ]; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * configuration function called when loading the scene | 83 | * configuration function called when loading the scene |
84 | */ | 84 | */ |
85 | RDGE.LightManager.prototype.setMapping = function (theLightNode, theLinks) { | 85 | RDGE.LightManager.prototype.setMapping = function (theLightNode, theLinks) { |
86 | this.lightToMesh[theLightNode.name] = theLinks; | 86 | this.lightToMesh[theLightNode.name] = theLinks; |
87 | 87 | ||
88 | for (var lghtIdx = 0; lghtIdx < theLinks.length; lghtIdx++) { | 88 | for (var lghtIdx = 0; lghtIdx < theLinks.length; lghtIdx++) { |
89 | var lightList = this.meshToLight[theLinks[lghtIdx]]; // check if mapping list exists | 89 | var lightList = this.meshToLight[theLinks[lghtIdx]]; // check if mapping list exists |
90 | 90 | ||
91 | if (lightList !== undefined) { | 91 | if (lightList !== undefined) { |
92 | lightList.push(theLightNode); | 92 | lightList.push(theLightNode); |
93 | } else { | 93 | } else { |
94 | // create new light list and add light list mapping | 94 | // create new light list and add light list mapping |
95 | lightList = []; | 95 | lightList = []; |
96 | lightList.push(theLightNode); | 96 | lightList.push(theLightNode); |
97 | this.meshToLight[theLinks[lghtIdx]] = lightList; | 97 | this.meshToLight[theLinks[lghtIdx]] = lightList; |
98 | 98 | ||
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | if (theLightNode.typeName == this.typePointLight) { | 102 | if (theLightNode.typeName == this.typePointLight) { |
103 | this.pointLights.push(theLightNode); | 103 | this.pointLights.push(theLightNode); |
104 | } else if (theLightNode.typeName == this.typeSpotLight) { | 104 | } else if (theLightNode.typeName == this.typeSpotLight) { |
105 | this.spotLights.push(theLightNode); | 105 | this.spotLights.push(theLightNode); |
106 | } else if (theLightNode.typeName == this.typeAmbLight) { | 106 | } else if (theLightNode.typeName == this.typeAmbLight) { |
107 | this.ambLights.push(theLightNode); | 107 | this.ambLights.push(theLightNode); |
108 | } else if (theLightNode.typeName == this.typeDirLight) { | 108 | } else if (theLightNode.typeName == this.typeDirLight) { |
109 | this.dirLights.push(theLightNode); | 109 | this.dirLights.push(theLightNode); |
110 | } else { | 110 | } else { |
111 | this.unknLights.push(theLightNode); | 111 | this.unknLights.push(theLightNode); |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | }; | 115 | }; |
116 | 116 | ||
117 | RDGE.LightManager.prototype.getLightsForMesh = function (mesh) { | 117 | RDGE.LightManager.prototype.getLightsForMesh = function (mesh) { |
118 | return this.meshToLight[mesh]; | 118 | return this.meshToLight[mesh]; |
119 | }; | 119 | }; |