diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/lightmanager.js')
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/lightmanager.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/lightmanager.js b/js/helper-classes/RDGE/src/core/script/lightmanager.js new file mode 100644 index 00000000..7d76ef90 --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/lightmanager.js | |||
@@ -0,0 +1,97 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | // manage light links | ||
8 | |||
9 | function LightManager( lightUniformList ) | ||
10 | { | ||
11 | // build a list of all light uniforms, contains a list of light uniform lists | ||
12 | this.lightUniforms = [ [], [], [], [] ]; | ||
13 | |||
14 | // bucket the uniforms lists | ||
15 | for(var l in lightUniformList) | ||
16 | { | ||
17 | // starts with | ||
18 | if(l.indexOf("u_light0") == 0) | ||
19 | { | ||
20 | this.lightUniforms[0][l] = l; | ||
21 | } | ||
22 | else if(l.indexOf("u_light1") == 0) | ||
23 | { | ||
24 | this.lightUniforms[1][l] = l; | ||
25 | } | ||
26 | else if(l.indexOf("u_light2") == 0) | ||
27 | { | ||
28 | this.lightUniforms[2][l] = l; | ||
29 | } | ||
30 | else if(l.indexOf("u_light3") == 0) | ||
31 | { | ||
32 | this.lightUniforms[3][l] = l; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | // maps (takes a string returns an object) | ||
37 | this.lightToMesh =[]; // pass light name, returns light of meshes | ||
38 | this.meshToLight =[]; // pass mesh name, returns list of lights | ||
39 | |||
40 | // list of light objects by type | ||
41 | this.dirLights=[]; | ||
42 | this.pointLights=[]; | ||
43 | this.spotLights = []; | ||
44 | this.ambLights = []; | ||
45 | this.unknLights = []; | ||
46 | |||
47 | // light types | ||
48 | this.typePointLight = "point_light"; | ||
49 | this.typeSpotLight = "spot_light"; | ||
50 | this.typeAmbLight = "amb_light"; | ||
51 | this.typeDirLight = "dir_light"; | ||
52 | |||
53 | this.defaultLights = | ||
54 | [ | ||
55 | createLightNode("default0"), | ||
56 | createLightNode("default1"), | ||
57 | createLightNode("default2"), | ||
58 | createLightNode("default3") | ||
59 | ]; | ||
60 | } | ||
61 | |||
62 | /* | ||
63 | * configuration function called when loading the scene | ||
64 | */ | ||
65 | LightManager.prototype.setMapping = function(theLightNode, theLinks) { | ||
66 | this.lightToMesh[theLightNode.name] = theLinks; | ||
67 | |||
68 | for (var lghtIdx = 0; lghtIdx < theLinks.length; lghtIdx++) { | ||
69 | var lightList = this.meshToLight[theLinks[lghtIdx]]; // check if mapping list exists | ||
70 | |||
71 | if (lightList !== undefined) { | ||
72 | lightList.push(theLightNode); | ||
73 | } else { | ||
74 | // create new light list and add light list mapping | ||
75 | lightList = []; | ||
76 | lightList.push(theLightNode); | ||
77 | this.meshToLight[theLinks[lghtIdx]] = lightList; | ||
78 | |||
79 | } | ||
80 | } | ||
81 | |||
82 | if (theLightNode.typeName == this.typePointLight) { | ||
83 | this.pointLights.push(theLightNode); | ||
84 | } else if (theLightNode.typeName == this.typeSpotLight) { | ||
85 | this.spotLights.push(theLightNode); | ||
86 | } else if (theLightNode.typeName == this.typeAmbLight) { | ||
87 | this.ambLights.push(theLightNode); | ||
88 | } else if (theLightNode.typeName == this.typeDirLight) { | ||
89 | this.dirLights.push(theLightNode); | ||
90 | }else{ | ||
91 | this.unknLights.push(theLightNode); | ||
92 | } | ||
93 | |||
94 | |||
95 | } | ||
96 | |||
97 | LightManager.prototype.getLightsForMesh = function(mesh) { return this.meshToLight[mesh]; } | ||