diff options
author | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
commit | c253192a08b499ea7be46fa5438d273e51f7ec5a (patch) | |
tree | 18a1f0e3679c0eb993a9dedb537035d3861f49ac /js/lib/rdge/materials | |
parent | e19376c54eedd1f1c457ba405b2f110be376a559 (diff) | |
parent | 4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff) | |
download | ninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/lib/rdge/materials')
25 files changed, 2676 insertions, 2418 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index fa6f5300..27d5793c 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -107,16 +107,18 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
107 | this.init = function( world ) | 107 | this.init = function( world ) |
108 | { | 108 | { |
109 | // save the world | 109 | // save the world |
110 | if (world) this.setWorld( world ); | 110 | if (world) { |
111 | this.setWorld( world ); | ||
112 | } | ||
111 | 113 | ||
112 | // set up the shader | 114 | // set up the shader |
113 | this._shader = new jshader(); | 115 | this._shader = new RDGE.jshader(); |
114 | this._shader.def = bumpMetalMaterialDef; | 116 | this._shader.def = bumpMetalMaterialDef; |
115 | this._shader.init(); | 117 | this._shader.init(); |
116 | this._shader['default'].u_light0Diff.set( this.getLightDiff() ); | 118 | this._shader['default'].u_light0Diff.set( this.getLightDiff() ); |
117 | 119 | ||
118 | // set up the material node | 120 | // set up the material node |
119 | this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | 121 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); |
120 | this._materialNode.setShader(this._shader); | 122 | this._materialNode.setShader(this._shader); |
121 | 123 | ||
122 | // set some image maps | 124 | // set some image maps |
@@ -131,7 +133,7 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
131 | if (material) | 133 | if (material) |
132 | { | 134 | { |
133 | var technique = material.shaderProgram['default']; | 135 | var technique = material.shaderProgram['default']; |
134 | var renderer = g_Engine.getContext().renderer; | 136 | var renderer = RDGE.globals.engine.getContext().renderer; |
135 | if (renderer && technique) | 137 | if (renderer && technique) |
136 | { | 138 | { |
137 | var texMapName = this._propValues[this._propNames[index]]; | 139 | var texMapName = this._propValues[this._propNames[index]]; |
@@ -152,58 +154,44 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
152 | } | 154 | } |
153 | }; | 155 | }; |
154 | 156 | ||
155 | this.export = function() | 157 | this.exportJSON = function() |
156 | { | 158 | { |
157 | // every material needs the base type and instance name | 159 | var jObj = |
158 | var exportStr = "material: " + this.getShaderName() + "\n"; | 160 | { |
159 | exportStr += "name: " + this.getName() + "\n"; | 161 | 'material' : this.getShaderName(), |
160 | 162 | 'name' : this.getName(), | |
161 | var world = this.getWorld(); | 163 | 'lightDiff' : this.getLightDiff(), |
162 | if (!world) | 164 | 'diffuseTexture' : this.getDiffuseTexture(), |
163 | throw new Error( "no world in material.export, " + this.getName() ); | 165 | 'specularTexture' : this.getSpecularTexture(), |
164 | 166 | 'normalMap' : this.getNormalTexture() | |
165 | exportStr += "lightDiff: " + this.getLightDiff() + "\n"; | 167 | }; |
166 | exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; | 168 | |
167 | exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; | 169 | return jObj; |
168 | exportStr += "normalMap: " + this.getNormalTexture() + "\n"; | ||
169 | |||
170 | // every material needs to terminate like this | ||
171 | exportStr += "endMaterial\n"; | ||
172 | |||
173 | return exportStr; | ||
174 | }; | 170 | }; |
175 | 171 | ||
176 | this.import = function( importStr ) | 172 | this.importJSON = function( jObj ) |
177 | { | 173 | { |
178 | var pu = new MaterialParser( importStr ); | 174 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); |
179 | var material = pu.nextValue( "material: " ); | 175 | this.setName( jObj.name ); |
180 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); | ||
181 | this.setName( pu.nextValue( "name: ") ); | ||
182 | 176 | ||
183 | var rtnStr; | ||
184 | try | 177 | try |
185 | { | 178 | { |
186 | var lightDiff = eval( "[" + pu.nextValue( "lightDiff: " ) + "]" ), | 179 | var lightDiff = jObj.lightDiff, |
187 | dt = pu.nextValue( "diffuseTexture: " ), | 180 | dt = jObj.diffuseTexture, |
188 | st = pu.nextValue( "specularTexture: " ), | 181 | st = jObj.specularTexture, |
189 | nt = pu.nextValue( "normalMap: " ); | 182 | nt = jObj.normalMap; |
190 | 183 | ||
191 | this.setProperty( "lightDiff", lightDiff); | 184 | this.setProperty( "lightDiff", lightDiff); |
192 | this.setProperty( "diffuseTexture", dt ); | 185 | this.setProperty( "diffuseTexture", dt ); |
193 | this.setProperty( "specularTexture", st ); | 186 | this.setProperty( "specularTexture", st ); |
194 | this.setProperty( "normalMap", nt ); | 187 | this.setProperty( "normalMap", nt ); |
195 | |||
196 | var endKey = "endMaterial\n"; | ||
197 | var index = importStr.indexOf( endKey ); | ||
198 | index += endKey.length; | ||
199 | rtnStr = importStr.substr( index ); | ||
200 | } | 188 | } |
201 | catch (e) | 189 | catch (e) |
202 | { | 190 | { |
203 | throw new Error( "could not import material: " + importStr ); | 191 | throw new Error( "could not import BumpMetal material: " + jObj ); |
204 | } | 192 | } |
205 | 193 | ||
206 | return rtnStr; | 194 | return; |
207 | }; | 195 | }; |
208 | }; | 196 | }; |
209 | 197 | ||
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js new file mode 100644 index 00000000..bde42ac3 --- /dev/null +++ b/js/lib/rdge/materials/cloud-material.js | |||
@@ -0,0 +1,247 @@ | |||
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 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | ||
8 | var Material = require("js/lib/rdge/materials/material").Material; | ||
9 | /////////////////////////////////////////////////////////////////////// | ||
10 | // Class GLMaterial | ||
11 | // RDGE representation of a material. | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | var 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"]; | ||