aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/cloud-material.js
diff options
context:
space:
mode:
authorJohn Mayhew2012-04-02 16:28:39 -0700
committerJohn Mayhew2012-04-02 16:28:39 -0700
commitb4155fb4c33675a8a7cd37473513718043fdf0ba (patch)
tree3d8c802473f2395d53d599ec9d8b70b60a4db50c /js/lib/rdge/materials/cloud-material.js
parent5ba9aeac94c86049423fd5d4b37b277263939c13 (diff)
parentc6de22bf42be90b403491b5f87b1818d9020310c (diff)
downloadninja-b4155fb4c33675a8a7cd37473513718043fdf0ba.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Conflicts: js/helper-classes/RDGE/rdge-compiled.js js/helper-classes/RDGE/runtime/GLRuntime.js js/helper-classes/RDGE/src/core/script/MeshManager.js js/helper-classes/RDGE/src/core/script/engine.js js/helper-classes/RDGE/src/core/script/fx/ssao.js js/helper-classes/RDGE/src/core/script/init_state.js js/helper-classes/RDGE/src/core/script/run_state.js js/helper-classes/RDGE/src/core/script/scenegraphNodes.js js/helper-classes/RDGE/src/core/script/utilities.js js/helper-classes/RDGE/src/tools/compile-rdge-core.bat js/helper-classes/RDGE/src/tools/compile-rdge-core.sh js/helper-classes/RDGE/src/tools/rdge-compiled.js js/lib/drawing/world.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/deform-material.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/linear-gradient-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-blur-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/relief-tunnel-material.js js/lib/rdge/materials/square-tunnel-material.js js/lib/rdge/materials/star-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/tunnel-material.js js/lib/rdge/materials/twist-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/uber-material.js js/lib/rdge/materials/water-material.js js/lib/rdge/materials/z-invert-material.js js/preloader/Preloader.js
Diffstat (limited to 'js/lib/rdge/materials/cloud-material.js')
-rw-r--r--js/lib/rdge/materials/cloud-material.js300
1 files changed, 300 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
new file mode 100644
index 00000000..85088f91
--- /dev/null
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -0,0 +1,300 @@
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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material;
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13var CloudMaterial = function CloudMaterial() {
14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables
16 ///////////////////////////////////////////////////////////////////////
17 this._name = "CloudMaterial";
18 this._shaderName = "cloud";
19
20 this._texMap = 'assets/images/cloud2.jpg';
21 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
22
23 this._time = 0.0;
24 this._dTime = 0.01;
25
26 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors
28 ///////////////////////////////////////////////////////////////////////
29 this.getName = function() { return this._name; };
30 this.getShaderName = function() { return this._shaderName; };
31
32 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
33 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
34
35 this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); };
36 this.getDiffuseColor = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; };
37
38 this.isAnimated = function() { return true; };
39
40 ///////////////////////////////////////////////////////////////////////
41 // Material Property Accessors
42 ///////////////////////////////////////////////////////////////////////
43 this._propNames = ["texmap", "diffusecolor"];
44 this._propLabels = ["Texture map", "Diffuse Color"];
45 this._propTypes = ["file", "color"];
46 this._propValues = [];
47
48 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
49 this._propValues[ this._propNames[1] ] = this._diffuseColor.slice();
50
51 this.setProperty = function( prop, value )
52 {
53 if (prop === 'color') prop = 'diffusecolor';
54
55 // make sure we have legitimate imput
56 var ok = this.validateProperty( prop, value );
57 if (!ok) {
58 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
59 }
60
61 switch (prop)
62 {
63 case "texmap":
64 this.setTextureMap(value);
65 break;
66
67 case "diffusecolor":
68 this.setDiffuseColor( value );
69 break;
70
71 case "color":
72 break;
73 }
74 };
75 ///////////////////////////////////////////////////////////////////////
76
77
78 ///////////////////////////////////////////////////////////////////////
79 // Methods
80 ///////////////////////////////////////////////////////////////////////
81 // duplcate method requirde
82 this.dup = function( world )
83 {
84 // save the world
85 if (world) this.setWorld( world );
86
87 // allocate a new uber material
88 var newMat = new CloudMaterial();
89
90 // copy over the current values;
91 var propNames = [], propValues = [], propTypes = [], propLabels = [];
92 this.getAllProperties( propNames, propValues, propTypes, propLabels);
93 var n = propNames.length;
94 for (var i=0; i<n; i++) {
95 newMat.setProperty( propNames[i], propValues[i] );
96 }
97
98 return newMat;
99 };
100
101 this.init = function( world )
102 {
103 // save the world
104 if (world) this.setWorld( world );
105
106 // this variable declared above is inherited set to a smaller delta.
107 // the cloud material runs a little faster
108 this._dTime = 0.01;
109
110 // set up the shader
111 this._shader = new jshader();
112 this._shader.def = cloudMaterialDef;
113 this._shader.init();
114
115 // set up the material node
116 this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID());
117 this._materialNode.setShader(this._shader);
118
119 this._time = 0;
120 if (this._shader && this._shader['default']) {
121 this._shader['default'].u_time.set( [this._time] );
122 this._shader['default'].u_DiffuseColor.set( this._diffuseColor );
123 }
124
125 // set the shader values in the shader
126 this.updateTexture();
127 this.update( 0 );
128 };
129
130 this.updateColor = function()
131 {
132 var material = this._materialNode;
133 if (material)
134 {
135 var technique = material.shaderProgram['default'];
136 var renderer = g_Engine.getContext().renderer;
137 if (renderer && technique) {
138 var color = this._propValues[this._propNames[1]];
139 technique.u_DiffuseColor.set( this._diffuseColor );
140 }
141 }
142 }
143
144 this.updateTexture = function() {
145 var material = this._materialNode;
146 if (material) {
147 var technique = material.shaderProgram['default'];
148 var renderer = g_Engine.getContext().renderer;
149 if (renderer && technique) {
150 var texMapName = this._propValues[this._propNames[0]];
151 var wrap = 'REPEAT', mips = true;
152 var tex = this.loadTexture( texMapName, wrap, mips );
153
154 if (tex) {
155 technique.u_tex0.set( tex );
156 }
157 }
158 }
159 };
160
161 this.update = function( time )
162 {
163 var material = this._materialNode;
164 if (material)
165 {
166 var technique = material.shaderProgram['default'];
167 var renderer = g_Engine.getContext().renderer;
168 if (renderer && technique) {
169 if (this._shader && this._shader['default']) {
170 this._shader['default'].u_time.set( [this._time] );
171 }
172 this._time += this._dTime;
173
174 if (this._time > 200.0) this._time = 0.0;
175 }
176 }
177 };
178
179 // JSON export
180 this.exportJSON = function()
181 {
182 var jObj =
183 {
184 'material' : this.getShaderName(),
185 'name' : this.getName(),
186 'texture' : this._propValues[this._propNames[0]]
187 };
188
189 return jObj;
190 };
191
192 this.importJSON = function( jObj )
193 {
194 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" );
195 this.setName( jObj.name );
196
197 try {
198 this._propValues[this._propNames[0]] = jObj.texture;
199 }
200 catch (e)
201 {
202 throw new Error( "could not import material: " + jObj );
203 }
204 }
205
206
207 this.export = function() {
208 // every material needs the base type and instance name
209 var exportStr = "material: " + this.getShaderName() + "\n";
210 exportStr += "name: " + this.getName() + "\n";