diff options
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index f26aa16c..c2969501 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 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | ||
8 | var Material = require("js/lib/rdge/materials/material").Material; | 7 | var Material = require("js/lib/rdge/materials/material").Material; |
8 | var 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 | /////////////////////////////////////////////////////////////////////// |
13 | var PulseMaterial = function PulseMaterial() { | 14 | var 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 ); |
@@ -138,7 +157,18 @@ var PulseMaterial = function PulseMaterial() { | |||
138 | { | 157 | { |
139 | var technique = material.shaderProgram['default']; | 158 | var technique = material.shaderProgram['default']; |
140 | var renderer = RDGE.globals.engine.getContext().renderer; | 159 | var renderer = RDGE.globals.engine.getContext().renderer; |
141 | if (renderer && technique) { | 160 | if (renderer && technique) |
161 | { | ||
162 | if (this._glTex) | ||
163 | { | ||
164 | //this.updateTexture(); | ||
165 | if (this._glTex.isAnimated()) | ||
166 | this._glTex.render(); | ||
167 | tex = this._glTex.getTexture(); | ||
168 | if (tex) | ||
169 | technique.u_tex0.set( tex ); | ||
170 | } | ||
171 | |||
142 | if (this._shader && this._shader['default']) { | 172 | if (this._shader && this._shader['default']) { |
143 | this._shader['default'].u_time.set( [this._time] ); | 173 | this._shader['default'].u_time.set( [this._time] ); |
144 | } | 174 | } |
@@ -235,7 +265,7 @@ var pulseMaterialDef = | |||
235 | } | 265 | } |
236 | }; | 266 | }; |
237 | 267 | ||
238 | PulseMaterial.prototype = new Material(); | 268 | //PulseMaterial.prototype = new Material(); |
239 | 269 | ||
240 | if (typeof exports === "object") { | 270 | if (typeof exports === "object") { |
241 | exports.PulseMaterial = PulseMaterial; | 271 | exports.PulseMaterial = PulseMaterial; |