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