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.js192
1 files changed, 141 insertions, 51 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index f26aa16c..28f3ee5e 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -4,16 +4,24 @@
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()
14 /////////////////////////////////////////////////////////////////////// 15{
15 // Instance variables 16 var MaterialLibrary = require("js/models/materials-model").MaterialsModel;
16 /////////////////////////////////////////////////////////////////////// 17
18 // initialize the inherited members
19 this.inheritedFrom = Material;
20 this.inheritedFrom();
21
22 ///////////////////////////////////////////////////////////////////////
23 // Instance variables
24 ///////////////////////////////////////////////////////////////////////
17 this._name = "PulseMaterial"; 25 this._name = "PulseMaterial";
18 this._shaderName = "pulse"; 26 this._shaderName = "pulse";
19 27
@@ -22,9 +30,13 @@ var PulseMaterial = function PulseMaterial() {
22 this._time = 0.0; 30 this._time = 0.0;
23 this._dTime = 0.01; 31 this._dTime = 0.01;
24 32
25 /////////////////////////////////////////////////////////////////////// 33 this._xScale = 0.5;
26 // Property Accessors 34 this._yScale = 0.4;
27 /////////////////////////////////////////////////////////////////////// 35 this._speed = 1.0;
36
37 ///////////////////////////////////////////////////////////////////////
38 // Property Accessors
39 ///////////////////////////////////////////////////////////////////////
28 this.getName = function() { return this._name; }; 40 this.getName = function() { return this._name; };
29 this.getShaderName = function() { return this._shaderName; }; 41 this.getShaderName = function() { return this._shaderName; };
30 42
@@ -33,22 +45,25 @@ var PulseMaterial = function PulseMaterial() {
33 45
34 this.isAnimated = function() { return true; }; 46 this.isAnimated = function() { return true; };
35 47
36 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
37 // Material Property Accessors 49 // Material Property Accessors
38 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
39 this._propNames = ["texmap"]; 51 this._propNames = ["texmap", "xscale", "yscale", "speed" ];
40 this._propLabels = ["Texture map"]; 52 this._propLabels = ["Texture map", "X Range", "Y Range", "Speed" ];
41 this._propTypes = ["file"]; 53 this._propTypes = ["file", "float", "float", "float"];
42 this._propValues = []; 54 this._propValues = [];
43 55
44 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 56 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
57 this._propValues[ this._propNames[1] ] = this._xScale;
58 this._propValues[ this._propNames[2] ] = this._yScale;
59 this._propValues[ this._propNames[3] ] = this._speed;
45 60
46 this.setProperty = function( prop, value ) { 61 this.setProperty = function( prop, value ) {
47 // make sure we have legitimate imput 62 // make sure we have legitimate imput
48 var ok = this.validateProperty( prop, value ); 63 var ok = this.validateProperty( prop, value );
49 if (!ok) { 64 if (!ok) {
50 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value ); 65 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
51 } 66 }
52 67
53 switch (prop) 68 switch (prop)
54 { 69 {
@@ -56,31 +71,50 @@ var PulseMaterial = function PulseMaterial() {
56 this.setTextureMap(value); 71 this.setTextureMap(value);
57 break; 72 break;
58 73
74 case "speed":
75 this._speed = value;
76 this._propValues[ this._propNames[3] ] = this._speed;
77 this.updateParameters();
78 break;
79
80 case "xscale":
81 this._xScale = value;
82 this._propValues[ this._propNames[1] ] = this._xScale;
83 this.updateParameters();
84 break;
85
86 case "yscale":
87 this._yScale = value;
88 this._propValues[ this._propNames[2] ] = this._yScale;
89 this.updateParameters();
90 break;
91
59 case "color": 92 case "color":
60 break; 93 break;
61 } 94 }
62 }; 95 };
63 /////////////////////////////////////////////////////////////////////// 96 ///////////////////////////////////////////////////////////////////////
64 97
65 98
66 /////////////////////////////////////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////
67 // Methods 100 // Methods
68 /////////////////////////////////////////////////////////////////////// 101 ///////////////////////////////////////////////////////////////////////
69 // duplicate method required 102 // duplicate method required
70 this.dup = function( world ) { 103 this.dup = function( world ) {
71 // save the world 104 // save the world
72 if (world) this.setWorld( world ); 105 if (world) this.setWorld( world );
73 106
74 // allocate a new uber material 107 // get the current values;
108 var propNames = [], propValues = [], propTypes = [], propLabels = [];
109 this.getAllProperties(propNames, propValues, propTypes, propLabels);
110
111 // allocate a new material
75 var newMat = new PulseMaterial(); 112 var newMat = new PulseMaterial();
76 113
77 // copy over the current values; 114 // copy over the current values;
78 var propNames = [], propValues = [], propTypes = [], propLabels = [];
79 this.getAllProperties( propNames, propValues, propTypes, propLabels);
80 var n = propNames.length; 115 var n = propNames.length;
81 for (var i=0; i<n; i++) { 116 for (var i = 0; i < n; i++)
82 newMat.setProperty( propNames[i], propValues[i] ); 117 newMat.setProperty(propNames[i], propValues[i]);
83 }
84 118
85 return newMat; 119 return newMat;
86 }; 120 };
@@ -105,8 +139,12 @@ var PulseMaterial = function PulseMaterial() {
105 this._time = 0; 139 this._time = 0;
106 if (this._shader && this._shader['default']) { 140 if (this._shader && this._shader['default']) {
107 this._shader['default'].u_time.set( [this._time] ); 141 this._shader['default'].u_time.set( [this._time] );
108 } 142 }
143 this.updateParameters();
109 144
145 // set up the texture
146 var texMapName = this._propValues[this._propNames[0]];
147 this._glTex = new Texture( world, texMapName );
110 148
111 // set the shader values in the shader 149 // set the shader values in the shader
112 this.updateTexture(); 150 this.updateTexture();
@@ -114,19 +152,51 @@ var PulseMaterial = function PulseMaterial() {
114 this.update( 0 ); 152 this.update( 0 );
115 }; 153 };
116 154
155 this.updateParameters = function()
156 {
157 this._propValues[ this._propNames[1] ] = this._xScale;
158 this._propValues[ this._propNames[2] ] = this._yScale;
159 this._propValues[ this._propNames[3] ] = this._speed;
160
161 var material = this._materialNode;
162 if (material)
163 {
164 var technique = material.shaderProgram['default'];
165 var renderer = RDGE.globals.engine.getContext().renderer;
166 if (renderer && technique)
167 {
168
169 if (this._shader && this._shader['default']) {
170 this._shader['default'].u_speed.set( [this._speed] );
171 this._shader['default'].u_xscale.set( [this._xScale] );
172 this._shader['default'].u_yscale.set( [this._yScale] );
173 }
174 }
175 }
176 }
177
117 this.updateTexture = function() { 178 this.updateTexture = function() {
179
180 var texMapName = this._propValues[this._propNames[0]];
181 this._glTex = new Texture( this.getWorld(), texMapName );
182
118 var material = this._materialNode; 183 var material = this._materialNode;
119 if (material) { 184 if (material) {
120 var technique = material.shaderProgram['default']; 185 var technique = material.shaderProgram['default'];
121 var renderer = RDGE.globals.engine.getContext().renderer; 186 var renderer = RDGE.globals.engine.getContext().renderer;
122 if (renderer && technique) { 187 if (renderer && technique) {