aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/geom/rectangle.js30
-rw-r--r--js/lib/rdge/materials/cloud-material.js122
-rwxr-xr-xjs/models/materials-model.js3
3 files changed, 114 insertions, 41 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 51947ff1..f41c27f6 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -1280,11 +1280,41 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices;
1280RectangleGeometry.getVertex = RectangleFill.getVertex; 1280RectangleGeometry.getVertex = RectangleFill.getVertex;
1281RectangleGeometry.getUV = RectangleFill.getUV; 1281RectangleGeometry.getUV = RectangleFill.getUV;
1282 1282
1283RectangleGeometry.init = function()
1284{
1285 this.vertices = [];
1286 this.normals = [];
1287 this.uvs = [];
1288 this.indices = [];
1289}
1290
1291RectangleGeometry.addQuad = function( verts, normals, uvs )
1292{
1293 for (var i=0; i<4; i++)
1294 {
1295 RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]);
1296 RectangleGeometry.pushNormal( normals[i] );
1297 RectangleGeometry.pushUV( uvs[i] );
1298 }
1299
1300 RectangleGeometry.pushIndices( 0, 1, 2 );
1301 RectangleGeometry.pushIndices( 2, 3, 0 );
1302}
1303
1304RectangleGeometry.buildPrimitive = function()
1305{
1306 var nVertices = this.vertices.length;
1307 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1308}
1309
1310
1311
1283 1312
1284Rectangle.prototype = new GeomObj(); 1313Rectangle.prototype = new GeomObj();
1285 1314
1286if (typeof exports === "object") { 1315if (typeof exports === "object") {
1287 exports.Rectangle = Rectangle; 1316 exports.Rectangle = Rectangle;
1317 exports.RectangleGeometry = RectangleGeometry;
1288} 1318}
1289 1319
1290 1320
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index f7f4c6bb..198f7cfa 100644
--- a/js/lib/rdge/materials/cloud-material.js
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -4,8 +4,11 @@
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;
9var GLWorld = require("js/lib/drawing/world").World;
10var Texture = require("js/lib/rdge/texture").Texture;
11
9/////////////////////////////////////////////////////////////////////// 12///////////////////////////////////////////////////////////////////////
10// Class GLMaterial 13// Class GLMaterial
11// RDGE representation of a material. 14// RDGE representation of a material.
@@ -20,9 +23,19 @@ var CloudMaterial = function CloudMaterial() {
20 this._texMap = 'assets/images/cloud2.jpg'; 23 this._texMap = 'assets/images/cloud2.jpg';
21 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 24 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
22 25
26 // base size of cloud polygons. Random adjustments made to each quad
27 this._cloudSize = 40;
28
23 this._time = 0.0; 29 this._time = 0.0;
24 this._dTime = 0.01; 30 this._dTime = 0.01;
25 31
32 // parameter initial values
33 this._time = 0.0;
34 this._surfaceAlpha = 0.5;
35 this._zmin = 0.1;
36 this._zmax = 10.0;
37
38
26 /////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors 40 // Property Accessors
28 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
@@ -32,9 +45,6 @@ var CloudMaterial = function CloudMaterial() {
32 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; 45 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(); }; 46 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
34 47
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; }; 48 this.isAnimated = function() { return true; };
39 49
40 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
@@ -64,10 +74,6 @@ var CloudMaterial = function CloudMaterial() {
64 this.setTextureMap(value); 74 this.setTextureMap(value);
65 break; 75 break;
66 76
67 case "diffusecolor":
68 this.setDiffuseColor( value );
69 break;
70
71 case "color": 77 case "color":
72 break; 78 break;
73 } 79 }
@@ -100,6 +106,8 @@ var CloudMaterial = function CloudMaterial() {
100 106
101 this.init = function( world ) 107 this.init = function( world )
102 { 108 {
109 var GLWorld = require("js/lib/drawing/world").World;
110
103 // save the world 111 // save the world
104 if (world) this.setWorld( world ); 112 if (world) this.setWorld( world );
105 113
@@ -107,6 +115,18 @@ var CloudMaterial = function CloudMaterial() {
107 // the cloud material runs a little faster 115 // the cloud material runs a little faster
108 this._dTime = 0.01; 116 this._dTime = 0.01;
109 117
118 // create a canvas to render into
119 var doc = world.getCanvas().ownerDocument;
120 var canvasID = "__canvas__";
121 this._srcCanvas = doc.createElement(canvasID);
122
123 // build a world to do the rendering
124 this._srcWorld = new GLWorld( this._srcCanvas, true );
125 var srcWorld = this._srcWorld;
126
127 // build the geometry
128 var prim = this.buildGeometry();
129
110 // set up the shader 130 // set up the shader
111 this._shader = new jshader(); 131 this._shader = new jshader();
112 this._shader.def = cloudMaterialDef; 132 this._shader.def = cloudMaterialDef;
@@ -116,31 +136,34 @@ var CloudMaterial = function CloudMaterial() {
116 this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID()); 136 this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID());
117 this._materialNode.setShader(this._shader); 137 this._materialNode.setShader(this._shader);
118 138
139 // initialize the shader uniforms
119 this._time = 0; 140 this._time = 0;
120 if (this._shader && this._shader['default']) { 141 if (this._shader && this._shader['default']) {
121 this._shader['default'].u_time.set( [this._time] ); 142 var t = this._shader['default'];
122 this._shader['default'].u_DiffuseColor.set( this._diffuseColor ); 143 if (t)
144 {
145 t.u_time.set( [this._time] );
146 t.u_surfaceAlpha.set( [this._surfaceAlpha] );
147 t.u_zmin.set( [this._zmin] );
148 t.u_zmax.set( [this._zmax] );
149 }
123 } 150 }
124 151
152 // add the nodes to the tree
153 var trNode = createTransformNode("objRootNode_" + this._srcWorld._nodeCounter++);
154 srcWorld._rootNode.insertAsChild( trNode );
155 trNode.attachMeshNode(srcWorld.renderer.id + "_prim_" + srcWorld._nodeCounter++, prim);
156 trNode.attachMaterial( this._materialNode );
157
158 // create the texture
159 var wrap = 'REPEAT', mips = true;
160 this._glTex = new Texture( dstWorld, canvasID, wrap, mips );
161
125 // set the shader values in the shader 162 // set the shader values in the shader
126 this.updateTexture(); 163 this.updateTexture();
127 this.update( 0 ); 164 this.update( 0 );
128 }; 165 };
129 166
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() { 167 this.updateTexture = function() {
145 var material = this._materialNode; 168 var material = this._materialNode;
146 if (material) { 169 if (material) {
@@ -171,30 +194,45 @@ var CloudMaterial = function CloudMaterial() {
171 } 194 }
172 this._time += this._dTime; 195 this._time += this._dTime;
173 196
197 if (this._glTex)
198 {
199 this._glTex.render();
200 var tex = this._glTex.getTexture();
201 technique.u_tex0.set( tex );
202 }
203
174 if (this._time > 200.0) this._time = 0.0; 204 if (this._time > 200.0) this._time = 0.0;
175 } 205 }
176 } 206 }
177 }; 207 };
178