aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/cloud-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/cloud-material.js')
-rw-r--r--js/lib/rdge/materials/cloud-material.js247
1 files changed, 126 insertions, 121 deletions
<
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index 4200c1b2..0cf428b0 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/> 2This 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/> 3No 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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material; 8var Material = require("js/lib/rdge/materials/material").Material;
@@ -15,25 +15,27 @@ var TagTool = require("js/tools/TagTool").TagTool;
15// Class GLMaterial 15// Class GLMaterial
16// RDGE representation of a material. 16// RDGE representation of a material.
17/////////////////////////////////////////////////////////////////////// 17///////////////////////////////////////////////////////////////////////
18var CloudMaterial = function CloudMaterial() { 18var CloudMaterial = function CloudMaterial()
19{
19 /////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////
20 // Instance variables 21 // Instance variables
21 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
22 this._name = "CloudMaterial"; 23 this._name = "CloudMaterial";
23 this._shaderName = "cloud"; 24 this._shaderName = "cloud";
24 25
25 this._texMap = 'assets/images/cloud10.png'; 26 this._texMap = 'assets/images/cloud10.png';
27 this._texMap = 'assets/images/cloud2.jpg';
26 //this._texMap = 'assets/images/CL13.png'; 28 //this._texMap = 'assets/images/CL13.png';
27 //this._texMap = 'assets/images/material_paint.png'; 29 //this._texMap = 'assets/images/material_paint.png';
28 //this._texMap = 'assets/images/us_flag.png'; 30 //this._texMap = 'assets/images/us_flag.png';
29 //this._texMap = 'assets/images/cubelight.png'; 31 //this._texMap = 'assets/images/cubelight.png';
30 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 32 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
31 33
32 // base size of cloud polygons. Random adjustments made to each quad 34 // base size of cloud polygons. Random adjustments made to each quad
33 this._cloudSize = 40; 35 this._cloudSize = 40;
34 36
35 this._time = 0.0; 37 this._time = 0.0;
36 this._dTime = 0.001; 38 this._dTime = 0.01;
37 39
38 // parameter initial values 40 // parameter initial values
39 this._time = 0.0; 41 this._time = 0.0;
@@ -54,73 +56,75 @@ var CloudMaterial = function CloudMaterial() {
54 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
55 // Property Accessors 57 // Property Accessors
56 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
57 this.getName = function() { return this._name; }; 59 this.getName = function () { return this._name; };
58 this.getShaderName = function() { return this._shaderName; }; 60 this.getShaderName = function () { return this._shaderName; };
59 61
60 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; 62 this.getTextureMap = function () { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
61 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; 63 this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
62 64
63 this.isAnimated = function() { return true; }; 65 this.setDiffuseColor = function (c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); };
66 this.getDiffuseColor = function () { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; };
67 this.isAnimated = function () { return true; };
64 68
65 /////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////
66 // Material Property Accessors 70 // Material Property Accessors
67 /////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////
68 this._propNames = ["texmap", "diffusecolor"]; 72 this._propNames = ["texmap", "diffusecolor"];
69 this._propLabels = ["Texture map", "Diffuse Color"]; 73 this._propLabels = ["Texture map", "Diffuse Color"];
70 this._propTypes = ["file", "color"]; 74 this._propTypes = ["file", "color"];
71 this._propValues = []; 75 this._propValues = [];
72 76
73 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 77 this._propValues[this._propNames[0]] = this._texMap.slice(0);
74 this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); 78 this._propValues[this._propNames[1]] = this._diffuseColor.slice();
75 79
76 this.setProperty = function( prop, value ) 80 this.setProperty = function (prop, value) {
77 { 81 if (prop === 'color') prop = 'diffusecolor';
78 if (prop === 'color') prop = 'diffusecolor';
79 82
80 // make sure we have legitimate imput 83 // make sure we have legitimate imput
81 var ok = this.validateProperty( prop, value ); 84 var ok = this.validateProperty(prop, value);
82 if (!ok) { 85 if (!ok) {
83 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value ); 86 console.log("invalid property in Radial Gradient Material:" + prop + " : " + value);
84 } 87 }
85 88
86 switch (prop) 89 switch (prop) {
87 { 90 case "texmap":
88 case "texmap": 91 this.setTextureMap(value);
89 this.setTextureMap(value); 92 break;
90 break;
91 93
92 case "color": 94 case "diffusecolor":
93 break; 95 this.setDiffuseColor(value);
94 } 96 break;
95 }; 97 case "color":
98 break;
99 }
100 };
96 /////////////////////////////////////////////////////////////////////// 101 ///////////////////////////////////////////////////////////////////////
97 102
98 103
99 /////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////
100 // Methods 105 // Methods
101 /////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////
102 // duplcate method requirde 107 // duplicate method required
103 this.dup = function( world ) 108 /**************************************************************/
104 { 109 this.dup = function (world) {
105 // save the world 110 // save the world
106 if (world) this.setWorld( world ); 111 if (world) this.setWorld(world);
107 112
108 // allocate a new uber material 113 // allocate a new uber material
109 var newMat = new CloudMaterial(); 114 var newMat = new CloudMaterial();
110 115
111 // copy over the current values; 116 // copy over the current values;
112 var propNames = [], propValues = [], propTypes = [], propLabels = []; 117 var propNames = [], propValues = [], propTypes = [], propLabels = [];
113 this.getAllProperties( propNames, propValues, propTypes, propLabels); 118 this.getAllProperties(propNames, propValues, propTypes, propLabels);
114 var n = propNames.length; 119 var n = propNames.length;
115 for (var i=0; i<n; i++) { 120 for (var i = 0; i < n; i++) {
116 newMat.setProperty( propNames[i], propValues[i] ); 121 newMat.setProperty(propNames[i], propValues[i]);
117 } 122 }
118 123
119 return newMat; 124 return newMat;
120 }; 125 };
121 126
122 this.init = function( world ) 127 this.init = function (world) {
123 {
124 var GLWorld = require("js/lib/drawing/world").World, 128 var GLWorld = require("js/lib/drawing/world").World,
125 NJUtils = require("js/lib/NJUtils").NJUtils; 129 NJUtils = require("js/lib/NJUtils").NJUtils;
126 130
@@ -152,12 +156,12 @@ var CloudMaterial = function CloudMaterial() {
152 this.buildSource(); 156 this.buildSource();
153 157
154 // set up the shader 158 // set up the shader
155 this._shader = new jshader(); 159 this._shader = new RDGE.jshader();
156 this._shader.def = cloudMapMaterialDef; 160 this._shader.def = cloudMapMaterialDef;
157 this._shader.init(); 161 this._shader.init();
158 162
159 // set up the material node 163 // set up the material node
160 this._materialNode = createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID()); 164 this._materialNode = RDGE.createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID());
161 this._materialNode.setShader(this._shader); 165 this._materialNode.setShader(this._shader);
162 166
163 // initialize the time 167 // initialize the time
@@ -170,34 +174,34 @@ var CloudMaterial = function CloudMaterial() {
170 // set the shader values in the shader 174 // set the shader values in the shader
171 this.updateTexture(); 175 this.updateTexture();
172 this.update( 0 ); 176 this.update( 0 );
173 }; 177 };
178 /**************************************************************/
174 179
175 this.updateTexture = function() 180 this.updateTexture = function ()
176 { 181 {
177 var material = this._materialNode; 182 var material = this._materialNode;
178 if (material) 183 if (material)
179 { 184 {
180 // save the current context 185 var technique = material.shaderProgram['default'];
181 var saveContext = g_Engine.getContext(); 186 var renderer = RDGE.globals.engine.getContext().renderer;
182