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.js185
1 files changed, 65 insertions, 120 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index f26aa16c..155bd8a9 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -4,17 +4,25 @@
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
17 this._name = "PulseMaterial"; 18 // initialize the inherited members
19 this.inheritedFrom = Material;
20 this.inheritedFrom();
21
22 ///////////////////////////////////////////////////////////////////////
23 // Instance variables
24 ///////////////////////////////////////////////////////////////////////
25 this._name = "Pulse";
18 this._shaderName = "pulse"; 26 this._shaderName = "pulse";
19 27
20 this._texMap = 'assets/images/cubelight.png'; 28 this._texMap = 'assets/images/cubelight.png';
@@ -22,70 +30,42 @@ 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._glTextures = [];
26 // Property Accessors
27 ///////////////////////////////////////////////////////////////////////
28 this.getName = function() { return this._name; };
29 this.getShaderName = function() { return this._shaderName; };
30
31 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
32 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
33 34
34 this.isAnimated = function() { return true; }; 35 ///////////////////////////////////////////////////////////////////////
36 // Property Accessors
37 ///////////////////////////////////////////////////////////////////////
38 this.isAnimated = function() { return true; };
39 this.getShaderDef = function() { return pulseMaterialDef; }
35 40
36 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
37 // Material Property Accessors 42 // Material Property Accessors
38 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
39 this._propNames = ["texmap"];
40 this._propLabels = ["Texture map"];
41 this._propTypes = ["file"];
42 this._propValues = [];
43 44
44 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 45 var u_tex0_index = 0,
46 u_xScale_index = 1,
47 u_yScale_index = 2,
48 u_speed_index = 3;
45 49
46 this.setProperty = function( prop, value ) { 50 this._propNames = ["u_tex0", "u_xscale", "u_yscale", "u_speed" ];
47 // make sure we have legitimate imput 51 this._propLabels = ["Texture map", "X Range", "Y Range", "Speed" ];
48 var ok = this.validateProperty( prop, value ); 52 this._propTypes = ["file", "float", "float", "float"];
49 if (!ok) { 53 this._propValues = [];
50 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
51 }
52
53 switch (prop)
54 {
55 case "texmap":
56 this.setTextureMap(value);
57 break;
58 54
59 case "color": 55 this._propValues[ this._propNames[ u_tex0_index] ] = this._texMap.slice(0);
60 break; 56 this._propValues[ this._propNames[u_xScale_index] ] = 0.5;
61 } 57 this._propValues[ this._propNames[u_yScale_index] ] = 0.4;
62 }; 58 this._propValues[ this._propNames[ u_speed_index] ] = 1.0;
63 /////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////
64 60
65 61
66 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
67 // Methods 63 // Methods
68 /////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////
69 // duplicate method required 65 // duplicate method required
70 this.dup = function( world ) {
71 // save the world
72 if (world) this.setWorld( world );
73 66
74 // allocate a new uber material 67 this.init = function( world )
75 var newMat = new PulseMaterial(); 68 {
76
77 // copy over the current values;
78 var propNames = [], propValues = [], propTypes = [], propLabels = [];
79 this.getAllProperties( propNames, propValues, propTypes, propLabels);
80 var n = propNames.length;
81 for (var i=0; i<n; i++) {
82 newMat.setProperty( propNames[i], propValues[i] );
83 }
84
85 return newMat;
86 };
87
88 this.init = function( world ) {
89 // save the world 69 // save the world
90 if (world) this.setWorld( world ); 70 if (world) this.setWorld( world );
91 71
@@ -105,32 +85,14 @@ var PulseMaterial = function PulseMaterial() {
105 this._time = 0; 85 this._time = 0;
106 if (this._shader && this._shader['default']) { 86 if (this._shader && this._shader['default']) {
107 this._shader['default'].u_time.set( [this._time] ); 87 this._shader['default'].u_time.set( [this._time] );
108 } 88 }
109
110 89
111 // set the shader values in the shader 90 // set the shader values in the shader
112 this.updateTexture(); 91 this.setShaderValues();
113 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 92 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
114 this.update( 0 ); 93 this.update( 0 );
115 }; 94 };
116 95
117 this.updateTexture = function() {
118 var material = this._materialNode;
119 if (material) {
120 var technique = material.shaderProgram['default'];
121 var renderer = RDGE.globals.engine.getContext().renderer;
122 if (renderer && technique) {
123 var texMapName = this._propValues[this._propNames[0]];
124 var wrap = 'REPEAT', mips = true;
125 var tex = this.loadTexture( texMapName, wrap, mips );
126
127 if (tex) {
128 technique.u_tex0.set( tex );
129 }
130 }
131 }
132 };
133
134 this.update = function( time ) 96 this.update = function( time )
135 { 97 {
136 var material = this._materialNode; 98 var material = this._materialNode;
@@ -138,13 +100,23 @@ var PulseMaterial = function PulseMaterial() {
138 { 100 {
139 var technique = material.shaderProgram['default']; 101 var technique = material.shaderProgram['default'];
140 var renderer = RDGE.globals.engine.getContext().renderer; 102 var renderer = RDGE.globals.engine.getContext().renderer;
141 if (renderer && technique) { 103 if (renderer && technique)
104 {
105 var glTex = this._glTextures["u_tex0"];
106 if (glTex)
107 {
108 //this.updateTexture();
109 if (glTex.isAnimated())
110 glTex.render();
111 tex = glTex.getTexture();
112 if (tex)
113 technique.u_tex0.set( tex );
114 }
115
142 if (this._shader && this._shader['default']) { 116 if (this._shader && this._shader['default']) {
143 this._shader['default'].u_time.set( [this._time] ); 117 this._shader['default'].u_time.set( [this._time] );
144 } 118 }
145 this._time += this._dTime; 119 this._time += this._dTime;
146
147 if (this._time > 200.0) this._time = 0.0;
148 } 120 }
149 } 121 }
150 }; 122 };
@@ -160,36 +132,6 @@ var PulseMaterial = function PulseMaterial() {
160 } 132 }
161 }; 133 };
162 134
163 // JSON export
164 this.exportJSON = function()
165 {
166 var jObj =
167 {
168 'material' : this.getShaderName(),
169 'name' : this.getName(),