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