aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/PulseMaterial.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-13 21:43:51 -0800
committerValerio Virgillito2012-02-13 21:43:51 -0800
commit081f17954c735fc8b946d72a25b0ee60d370ef9b (patch)
treede7b50f2d02365df897ef4356f953d3833c9cabd /js/helper-classes/RDGE/Materials/PulseMaterial.js
parent47df0aff81c25334b129047bb227ea5015357eda (diff)
parent1d82f1a041612f32bbf6c9f20d9fb14e2d11fcc7 (diff)
downloadninja-081f17954c735fc8b946d72a25b0ee60d370ef9b.tar.gz
Merge branch 'refs/heads/master' into components
Conflicts: js/components/treeview/ninja-leaf.reel/ninja-leaf.js Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/Materials/PulseMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/PulseMaterial.js237
1 files changed, 0 insertions, 237 deletions
diff --git a/js/helper-classes/RDGE/Materials/PulseMaterial.js b/js/helper-classes/RDGE/Materials/PulseMaterial.js
deleted file mode 100644
index 3d6107fb..00000000
--- a/js/helper-classes/RDGE/Materials/PulseMaterial.js
+++ /dev/null
@@ -1,237 +0,0 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7
8
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13function PulseMaterial()
14{
15 // initialize the inherited members
16 this.inheritedFrom = GLMaterial;
17 this.inheritedFrom();
18
19 ///////////////////////////////////////////////////////////////////////
20 // Instance variables
21 ///////////////////////////////////////////////////////////////////////
22 this._name = "PulseMaterial";
23 this._shaderName = "pulse";
24
25 this._texMap = 'assets/images/cubelight.png';
26
27 this._time = 0.0;
28 this._dTime = 0.01;
29
30 ///////////////////////////////////////////////////////////////////////
31 // Property Accessors
32 ///////////////////////////////////////////////////////////////////////
33 this.getName = function() { return this._name; }
34 this.getShaderName = function() { return this._shaderName; }
35
36 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }
37 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }
38
39 this.isAnimated = function() { return true; }
40
41 ///////////////////////////////////////////////////////////////////////
42 // Material Property Accessors
43 ///////////////////////////////////////////////////////////////////////
44 this._propNames = ["texmap"];
45 this._propLabels = ["Texture map"];
46 this._propTypes = ["file"];
47 this._propValues = [];
48
49 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
50
51 this.setProperty = function( prop, value )
52 {
53 // make sure we have legitimate imput
54 var ok = this.validateProperty( prop, value );
55 if (!ok)
56 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
57
58 switch (prop)
59 {
60 case "texmap":
61 this.setTextureMap(value);
62 break;
63
64 case "color":
65 break;
66 }
67 }
68 ///////////////////////////////////////////////////////////////////////
69
70
71 ///////////////////////////////////////////////////////////////////////
72 // Methods
73 ///////////////////////////////////////////////////////////////////////
74 // duplcate method requirde
75 this.dup = function( world )
76 {
77 // save the world
78 if (world) this.setWorld( world );
79
80 // allocate a new uber material
81 var newMat = new PulseMaterial();
82
83 // copy over the current values;
84 var propNames = [], propValues = [], propTypes = [], propLabels = [];
85 this.getAllProperties( propNames, propValues, propTypes, propLabels);
86 var n = propNames.length;
87 for (var i=0; i<n; i++)
88 newMat.setProperty( propNames[i], propValues[i] );
89
90 return newMat;
91 }
92
93 this.init = function( world )
94 {
95 // save the world
96 if (world) this.setWorld( world );
97
98 // set up the shader
99 this._shader = new jshader();
100 this._shader.def = pulseMaterialDef;
101 this._shader.init();
102
103 // set up the material node
104 this._materialNode = createMaterialNode("pulseMaterial");
105 this._materialNode.setShader(this._shader);
106
107 this._time = 0;
108 if (this._shader && this._shader.default)
109 this._shader.default.u_time.set( [this._time] );
110
111 // set the shader values in the shader
112 this.updateTexture();
113 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
114 this.update( 0 );
115 }
116
117 this.updateTexture = function()
118 {
119 var material = this._materialNode;
120 if (material)
121 {
122 var technique = material.shaderProgram.default;
123 var renderer = g_Engine.getContext().renderer;
124 if (renderer && technique)
125 {
126 var texMapName = this._propValues[this._propNames[0]];
127 var wrap = 'REPEAT', mips = true;
128 //var tex = renderer.getTextureByName(texMapName, wrap, mips );
129 //this.registerTexture( tex );
130 var tex = this.loadTexture( texMapName, wrap, mips );
131 if (tex)
132 technique.u_tex0.set( tex );
133 }
134 }
135 }
136
137 this.update = function( time )
138 {
139 var material = this._materialNode;
140 if (material)
141 {
142 var technique = material.shaderProgram.default;
143 var renderer = g_Engine.getContext().renderer;
144 if (renderer && technique)
145 {
146 if (this._shader && this._shader.default)
147 this._shader.default.u_time.set( [this._time] );
148 this._time += this._dTime;
149 }
150 }
151 }
152
153 this.setResolution = function( res )
154 {
155 var material = this._materialNode;
156 if (material)
157 {
158 var technique = material.shaderProgram.default;
159 var renderer = g_Engine.getContext().renderer;
160 if (renderer && technique)
161 {
162 technique.u_resolution.set( res );
163 }
164 }
165 }
166
167 this.export = function()
168 {
169 // every material needs the base type and instance name
170 var exportStr = "material: " + this.getShaderName() + "\n";
171 exportStr += "name: " + this.getName() + "\n";
172
173 // every material needs to terminate like this
174 exportStr += "endMaterial\n";
175
176 return exportStr;
177 }
178
179 this.import = function( importStr )
180 {
181 var pu = new ParseUtils( importStr );
182 var material = pu.nextValue( "material: " );
183 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
184 this.setName( pu.nextValue( "name: ") );
185
186 var rtnStr;
187
188 return rtnStr;
189 }
190}
191
192///////////////////////////////////////////////////////////////////////////////////////
193// RDGE shader
194
195// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
196var pulseMaterialDef =
197{'shaders':
198 {
199 'defaultVShader':"assets/shaders/Basic.vert.glsl",
200 'defaultFShader':"assets/shaders/Pulse.frag.glsl"
201 },
202 'techniques':
203 {
204 'default':
205 [
206 {
207 'vshader' : 'defaultVShader',
208 'fshader' : 'defaultFShader',
209 // attributes