diff options
Diffstat (limited to 'js/lib/rdge/materials')
25 files changed, 2443 insertions, 3168 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 2ef83227..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]]; |
@@ -191,60 +193,6 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
191 | 193 | ||
192 | return; | 194 | return; |
193 | }; | 195 | }; |
194 | |||
195 | this.export = function() | ||
196 | { | ||
197 | // every material needs the base type and instance name | ||
198 | var exportStr = "material: " + this.getShaderName() + "\n"; | ||
199 | exportStr += "name: " + this.getName() + "\n"; | ||
200 | |||
201 | var world = this.getWorld(); | ||
202 | if (!world) | ||
203 | throw new Error( "no world in material.export, " + this.getName() ); | ||
204 | |||
205 | exportStr += "lightDiff: " + this.getLightDiff() + "\n"; | ||
206 | exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; | ||
207 | exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; | ||
208 | exportStr += "normalMap: " + this.getNormalTexture() + "\n"; | ||
209 | |||
210 | // every material needs to terminate like this | ||
211 | exportStr += "endMaterial\n"; | ||
212 | |||
213 | return exportStr; | ||
214 | }; | ||
215 | |||
216 | this.import = function( importStr ) | ||
217 | { | ||
218 | var pu = new MaterialParser( importStr ); | ||
219 | var material = pu.nextValue( "material: " ); | ||
220 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); | ||
221 | this.setName( pu.nextValue( "name: ") ); | ||
222 | |||
223 | var rtnStr; | ||
224 | try | ||
225 | { | ||
226 | var lightDiff = eval( "[" + pu.nextValue( "lightDiff: " ) + "]" ), | ||
227 | dt = pu.nextValue( "diffuseTexture: " ), | ||
228 | st = pu.nextValue( "specularTexture: " ), | ||
229 | nt = pu.nextValue( "normalMap: " ); | ||
230 | |||
231 | this.setProperty( "lightDiff", lightDiff); | ||
232 | this.setProperty( "diffuseTexture", dt ); | ||
233 | this.setProperty( "specularTexture", st ); | ||
234 | this.setProperty( "normalMap", nt ); | ||
235 | |||
236 | var endKey = "endMaterial\n"; | ||
237 | var index = importStr.indexOf( endKey ); | ||
238 | index += endKey.length; | ||
239 | rtnStr = importStr.substr( index ); | ||
240 | } | ||
241 | catch (e) | ||
242 | { | ||
243 | throw new Error( "could not import material: " + importStr ); | ||
244 | } | ||
245 | |||
246 | return rtnStr; | ||
247 | }; | ||
248 | }; | 196 | }; |
249 | 197 | ||
250 | /////////////////////////////////////////////////////////////////////////////////////// | 198 | /////////////////////////////////////////////////////////////////////////////////////// |
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js index 85088f91..bde42ac3 100644 --- a/js/lib/rdge/materials/cloud-material.js +++ b/js/lib/rdge/materials/cloud-material.js | |||
@@ -1,8 +1,8 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 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/> | 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. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
@@ -14,275 +14,222 @@ var CloudMaterial = function CloudMaterial() { | |||
14 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
15 | // Instance variables | 15 | // Instance variables |
16 | /////////////////////////////////////////////////////////////////////// | 16 | /////////////////////////////////////////////////////////////////////// |
17 | this._name = "CloudMaterial"; | 17 | this._name = "CloudMaterial"; |
18 | this._shaderName = "cloud"; | 18 | this._shaderName = "cloud"; |
19 | 19 | ||
20 | this._texMap = 'assets/images/cloud2.jpg'; | 20 | this._texMap = 'assets/images/cloud2.jpg'; |
21 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; | 21 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; |
22 | 22 | ||
23 | this._time = 0.0; | 23 | this._time = 0.0; |
24 | this._dTime = 0.01; | 24 | this._dTime = 0.01; |
25 | 25 | ||
26 | /////////////////////////////////////////////////////////////////////// | 26 | /////////////////////////////////////////////////////////////////////// |
27 | // Property Accessors | 27 | // Property Accessors |
28 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
29 | this.getName = function() { return this._name; }; | 29 | this.getName = function () { return this._name; }; |
30 | this.getShaderName = function() { return this._shaderName; }; | 30 | this.getShaderName = function () { return this._shaderName; }; |
31 | 31 | ||
32 | this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; | 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(); }; | 33 | this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; |
34 | 34 | ||
35 | this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); }; | 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; }; | 36 | this.getDiffuseColor = function () { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; }; |
37 | 37 | ||
38 | this.isAnimated = function() { return true; }; | 38 | this.isAnimated = function () { return true; }; |
39 | 39 | ||
40 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
41 | // Material Property Accessors | 41 | // Material Property Accessors |
42 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
43 | this._propNames = ["texmap", "diffusecolor"]; | 43 | this._propNames = ["texmap", "diffusecolor"]; |
44 | this._propLabels = ["Texture map", "Diffuse Color"]; | 44 | this._propLabels = ["Texture map", "Diffuse Color"]; |
45 | this._propTypes = ["file", "color"]; | 45 | this._propTypes = ["file", "color"]; |
46 | this._propValues = []; | 46 | this._propValues = []; |
47 | 47 | ||
48 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | 48 | this._propValues[this._propNames[0]] = this._texMap.slice(0); |
49 | this._propValues[ this._propNames[1] |