aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/PulseMaterial.js
diff options
context:
space:
mode:
authorArmen Kesablyan2012-02-13 13:36:52 -0800
committerArmen Kesablyan2012-02-13 13:36:52 -0800
commitda32190d5dd91fa2c26f8cabb746980c3d06035c (patch)
treed923299208c84b1071b58e7eb9c0515b2e1c844a /js/helper-classes/RDGE/Materials/PulseMaterial.js
parent36cefa3526988cb4dfea107fedaa954a2703260d (diff)
parent90d0c8c0e98d062c628c061fe5765ce991fda409 (diff)
downloadninja-da32190d5dd91fa2c26f8cabb746980c3d06035c.tar.gz
Merge branch 'refs/heads/master' into text-tool
Diffstat (limited to 'js/helper-classes/RDGE/Materials/PulseMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/PulseMaterial.js226
1 files changed, 0 insertions, 226 deletions
diff --git a/js/helper-classes/RDGE/Materials/PulseMaterial.js b/js/helper-classes/RDGE/Materials/PulseMaterial.js
deleted file mode 100644
index 5bee818e..00000000
--- a/js/helper-classes/RDGE/Materials/PulseMaterial.js
+++ /dev/null
@@ -1,226 +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._texMap.slice(0); }
37 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }
38
39 ///////////////////////////////////////////////////////////////////////
40 // Material Property Accessors
41 ///////////////////////////////////////////////////////////////////////
42 this._propNames = ["texmap"];
43 this._propLabels = ["Texture map"];
44 this._propTypes = ["file"];
45 this._propValues = [];
46
47 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
48
49 this.setProperty = function( prop, value )
50 {
51 // make sure we have legitimate imput
52 var ok = this.validateProperty( prop, value );
53 if (!ok)
54 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
55
56 switch (prop)
57 {
58 case "texmap":
59 this.setTextureMap(value);
60 break;
61
62 case "color":
63 break;
64 }
65 }
66 ///////////////////////////////////////////////////////////////////////
67
68
69 ///////////////////////////////////////////////////////////////////////
70 // Methods
71 ///////////////////////////////////////////////////////////////////////
72 // duplcate method requirde
73 this.dup = function( world )
74 {
75 // allocate a new uber material
76 var newMat = new PulseMaterial();
77
78 // copy over the current values;
79 var propNames = [], propValues = [], propTypes = [], propLabels = [];
80 this.getAllProperties( propNames, propValues, propTypes, propLabels);
81 var n = propNames.length;
82 for (var i=0; i<n; i++)
83 newMat.setProperty( propNames[i], propValues[i] );
84
85 return newMat;
86 }
87
88 this.init = function( world )
89 {
90 // set up the shader
91 this._shader = new jshader();
92 this._shader.def = pulseMaterialDef;
93 this._shader.init();
94
95 // set up the material node
96 this._materialNode = createMaterialNode("pulseMaterial");
97 this._materialNode.setShader(this._shader);
98
99 this._time = 0;
100 if (this._shader && this._shader.default)
101 this._shader.default.u_time.set( [this._time] );
102
103 // set the shader values in the shader
104 this.updateTexture();
105 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
106 this.update( 0 );
107 }
108
109 this.updateTexture = function()
110 {
111 var material = this._materialNode;
112 if (material)
113 {
114 var technique = material.shaderProgram.default;
115 var renderer = g_Engine.getContext().renderer;
116 if (renderer && technique)
117 {
118 var texMapName = this._propValues[this._propNames[0]];
119 var tex = renderer.getTextureByName(texMapName, 'REPEAT');
120 if (tex)
121 technique.u_tex0.set( tex );
122 }
123 }
124 }
125
126 this.update = function( time )
127 {
128 var material = this._materialNode;
129 if (material)
130 {
131 var technique = material.shaderProgram.default;
132 var renderer = g_Engine.getContext().renderer;
133 if (renderer && technique)
134 {
135 if (this._shader && this._shader.default)
136 this._shader.default.u_time.set( [this._time] );
137 this._time += this._dTime;
138 }
139 }
140 }
141
142 this.setResolution = function( res )
143 {
144 var material = this._materialNode;
145 if (material)
146 {
147 var technique = material.shaderProgram.default;
148 var renderer = g_Engine.getContext().renderer;
149 if (renderer && technique)
150 {
151 technique.u_resolution.set( res );
152 }
153 }
154 }
155
156 this.export = function()
157 {
158 // every material needs the base type and instance name
159 var exportStr = "material: " + this.getShaderName() + "\n";
160 exportStr += "name: " + this.getName() + "\n";
161
162 // every material needs to terminate like this
163 exportStr += "endMaterial\n";
164
165 return exportStr;
166 }
167
168 this.import = function( importStr )
169 {
170 var pu = new ParseUtils( importStr );
171 var material = pu.nextValue( "material: " );
172 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
173 this.setName( pu.nextValue( "name: ") );
174
175 var rtnStr;
176
177 return rtnStr;
178 }
179}
180
181///////////////////////////////////////////////////////////////////////////////////////
182// RDGE shader
183
184// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
185var pulseMaterialDef =
186{'shaders':
187 {
188 'defaultVShader':"assets/shaders/Basic.vert.glsl",
189 'defaultFShader':"assets/shaders/Pulse.frag.glsl"
190 },
191 'techniques':
192 {
193 'default':
194 [
195 {
196 'vshader' : 'defaultVShader',
197 'fshader' : 'defaultFShader',
198 // attributes
199 'attributes' :
200 {
201 'vert' : { 'type' : 'vec3' },
202 'normal' : { 'type' : 'vec3' },
203 'texcoord' : { 'type' : 'vec2' }
204 },
205 // parameters
206 'params' :
207 {
208 'u_tex0': { 'type' : 'tex2d' },
209 'u_time' : { 'type' : 'float' },
210 'u_resoluti