aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/pulse-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r--js/lib/rdge/materials/pulse-material.js74
1 files changed, 59 insertions, 15 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index f26aa16c..bb8833b4 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -4,13 +4,21 @@
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;
8var Material = require("js/lib/rdge/materials/material").Material; 7var Material = require("js/lib/rdge/materials/material").Material;
8var Texture = require("js/lib/rdge/texture").Texture;
9
9/////////////////////////////////////////////////////////////////////// 10///////////////////////////////////////////////////////////////////////
10// Class GLMaterial 11// Class GLMaterial
11// RDGE representation of a material. 12// RDGE representation of a material.
12/////////////////////////////////////////////////////////////////////// 13///////////////////////////////////////////////////////////////////////
13var PulseMaterial = function PulseMaterial() { 14var PulseMaterial = function PulseMaterial()
15{
16 var MaterialLibrary = require("js/models/materials-model").MaterialsModel;
17
18 // initialize the inherited members
19 this.inheritedFrom = Material;
20 this.inheritedFrom();
21
14 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
15 // Instance variables 23 // Instance variables
16 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
@@ -18,6 +26,8 @@ var PulseMaterial = function PulseMaterial() {
18 this._shaderName = "pulse"; 26 this._shaderName = "pulse";
19 27
20 this._texMap = 'assets/images/cubelight.png'; 28 this._texMap = 'assets/images/cubelight.png';
29 //this._texMap = 'assets/images/cloud10.png';
30 //this._texMap = 'texture';
21 31
22 this._time = 0.0; 32 this._time = 0.0;
23 this._dTime = 0.01; 33 this._dTime = 0.01;
@@ -71,18 +81,19 @@ var PulseMaterial = function PulseMaterial() {
71 // save the world 81 // save the world
72 if (world) this.setWorld( world ); 82 if (world) this.setWorld( world );
73 83
74 // allocate a new uber material 84 // get the current values;
75 var newMat = new PulseMaterial(); 85 var propNames = [], propValues = [], propTypes = [], propLabels = [];
86 this.getAllProperties(propNames, propValues, propTypes, propLabels);
87
88 // allocate a new material
89 var newMat = new PulseMaterial();
76 90
77 // copy over the current values; 91 // copy over the current values;
78 var propNames = [], propValues = [], propTypes = [], propLabels = []; 92 var n = propNames.length;
79 this.getAllProperties( propNames, propValues, propTypes, propLabels); 93 for (var i = 0; i < n; i++)
80 var n = propNames.length; 94 newMat.setProperty(propNames[i], propValues[i]);
81 for (var i=0; i<n; i++) {
82 newMat.setProperty( propNames[i], propValues[i] );
83 }
84 95
85 return newMat; 96 return newMat;
86 }; 97 };
87 98
88 this.init = function( world ) { 99 this.init = function( world ) {
@@ -107,6 +118,9 @@ var PulseMaterial = function PulseMaterial() {
107 this._shader['default'].u_time.set( [this._time] ); 118 this._shader['default'].u_time.set( [this._time] );
108 } 119 }
109 120
121 // set up the texture
122 var texMapName = this._propValues[this._propNames[0]];
123 this._glTex = new Texture( world, texMapName );
110 124
111 // set the shader values in the shader 125 // set the shader values in the shader
112 this.updateTexture(); 126 this.updateTexture();
@@ -120,9 +134,14 @@ var PulseMaterial = function PulseMaterial() {
120 var technique = material.shaderProgram['default']; 134 var technique = material.shaderProgram['default'];
121 var renderer = RDGE.globals.engine.getContext().renderer; 135 var renderer = RDGE.globals.engine.getContext().renderer;
122 if (renderer && technique) { 136 if (renderer && technique) {
123 var texMapName = this._propValues[this._propNames[0]];
124 var wrap = 'REPEAT', mips = true; 137 var wrap = 'REPEAT', mips = true;
125 var tex = this.loadTexture( texMapName, wrap, mips ); 138 var tex;
139 if (this._glTex)
140 {
141 if (this._glTex.isAnimated())
142 this._glTex.render();
143 tex = this._glTex.getTexture();
144 }
126 145
127 if (tex) { 146 if (tex) {
128 technique.u_tex0.set( tex ); 147 technique.u_tex0.set( tex );
@@ -131,6 +150,20 @@ var PulseMaterial = function PulseMaterial() {
131 } 150 }
132 }; 151 };
133 152
153
154 this.updateTextures = function()
155 {
156 if (this._glTex)
157 {
158 if (!this._glTex.isAnimated())
159 {
160 this._glTex.render();
161 this.updateTexture();
162 }
163 }
164 }
165
166
134 this.update = function( time ) 167 this.update = function( time )
135 { 168 {
136 var material = this._materialNode; 169 var material = this._materialNode;
@@ -138,7 +171,18 @@ var PulseMaterial = function PulseMaterial() {
138 { 171 {
139 var technique = material.shaderProgram['default']; 172 var technique = material.shaderProgram['default'];
140 var renderer = RDGE.globals.engine.getContext().renderer; 173 var renderer = RDGE.globals.engine.getContext().renderer;
141 if (renderer && technique) { 174 if (renderer && technique)
175 {
176 if (this._glTex)
177 {
178 //this.updateTexture();
179 if (this._glTex.isAnimated())
180 this._glTex.render();
181 tex = this._glTex.getTexture();
182 if (tex)
183 technique.u_tex0.set( tex );
184 }
185
142 if (this._shader && this._shader['default']) { 186 if (this._shader && this._shader['default']) {
143 this._shader['default'].u_time.set( [this._time] ); 187 this._shader['default'].u_time.set( [this._time] );
144 } 188 }
@@ -235,7 +279,7 @@ var pulseMaterialDef =
235 } 279 }
236}; 280};
237 281
238PulseMaterial.prototype = new Material(); 282//PulseMaterial.prototype = new Material();
239 283
240if (typeof exports === "object") { 284if (typeof exports === "object") {
241 exports.PulseMaterial = PulseMaterial; 285 exports.PulseMaterial = PulseMaterial;