aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/TaperMaterial.js
diff options
context:
space:
mode:
authorJon Reid2012-03-06 14:15:18 -0800
committerJon Reid2012-03-06 14:15:18 -0800
commit78d42c7cbf9205ed2e4faee1d8ddf02a4725edd3 (patch)
treec395b703f21431dcb4432c725f4c860431add61b /js/helper-classes/RDGE/Materials/TaperMaterial.js
parentfa8b81d4f436c0b8564c8dcdd22d8dd6d5bccfaa (diff)
parent60bba95eaffa8b5c741c6c85fb84b327cd75d6c3 (diff)
downloadninja-78d42c7cbf9205ed2e4faee1d8ddf02a4725edd3.tar.gz
Merge branch 'Timeline-uber' into timeline-serialized
Diffstat (limited to 'js/helper-classes/RDGE/Materials/TaperMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/TaperMaterial.js223
1 files changed, 0 insertions, 223 deletions
<
diff --git a/js/helper-classes/RDGE/Materials/TaperMaterial.js b/js/helper-classes/RDGE/Materials/TaperMaterial.js
deleted file mode 100644
index e8cc7a49..00000000
--- a/js/helper-classes/RDGE/Materials/TaperMaterial.js
+++ /dev/null
@@ -1,223 +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// Class GLMaterial
10// RDGE representation of a material.
11///////////////////////////////////////////////////////////////////////
12function TaperMaterial()
13{
14 // initialize the inherited members
15 this.inheritedFrom = GLMaterial;
16 this.inheritedFrom();
17
18 ///////////////////////////////////////////////////////////////////////
19 // Instance variables
20 ///////////////////////////////////////////////////////////////////////
21 this._name = "TaperMaterial";
22 this._shaderName = "taper";
23
24 this._color = [1,0,0,1];
25
26 this._deltaTime = 0.0;
27
28 ///////////////////////////////////////////////////////////////////////
29 // Property Accessors
30 ///////////////////////////////////////////////////////////////////////
31 this.getColor = function() { return this._color; }
32 this.getShaderName = function() { return this._shaderName; }
33
34 this.isAnimated = function() { return true; }
35 this.hasVertexDeformation = function() { return this._hasVertexDeformation; }
36 this._hasVertexDeformation = true;
37 this._vertexDeformationTolerance = 0.02; // should be a property
38
39 ///////////////////////////////////////////////////////////////////////
40 // Methods
41 ///////////////////////////////////////////////////////////////////////
42 // duplcate method requirde
43 this.dup = function() { return new TaperMaterial(); }
44
45 this.init = function()
46 {
47 // set up the shader
48 this._shader = new jshader();
49 this._shader.def = taperShaderDef;
50 this._shader.init();
51
52 // set the defaults
53 this._shader.colorMe.color.set( this.getColor() );
54
55 // set up the material node
56 this._materialNode = createMaterialNode("taperMaterial");
57 this._materialNode.setShader(this._shader);
58
59 // initialize the taper properties
60 this.updateShaderValues();
61 }
62
63
64 ///////////////////////////////////////////////////////////////////////
65 // Material Property Accessors
66 ///////////////////////////////////////////////////////////////////////
67 this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount" ];
68 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"];
69 this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"];
70 this._propValues = [];
71
72 // initialize the property values
73 this._propValues[ this._propNames[0] ] = this._color.slice();
74 this._propValues[ this._propNames[1] ] = 0.25;
75 this._propValues[ this._propNames[2] ] = 0.50;
76 this._propValues[ this._propNames[3] ] = 0.75;
77 this._propValues[ this._propNames[4] ] = -1;
78 this._propValues[ this._propNames[5] ] = 1;
79 this._propValues[ this._propNames[6] ] = 0.0;
80 this._propValues[ this._propNames[7] ] = 0.9;
81
82 this.setProperty = function( prop, value )
83 {
84 // make sure we have legitimate input
85 if (this.validateProperty( prop, value ))
86 {
87 switch (prop)
88 {
89 case "color": this._propValues[prop] = value.slice(); break;
90 default: this._propValues[prop] = value; break;
91 }
92
93 this.updateShaderValues();
94 }
95 }
96 ///////////////////////////////////////////////////////////////////////
97
98 this.export = function()
99 {
100 // this function should be overridden by subclasses
101 var exportStr = "material: " + this.getShaderName() + "\n";
102 exportStr += "name: " + this.getName() + "\n";
103
104 if (this._shader)
105 exportStr += "color: " + String(this._shader.colorMe.color) + "\n";
106 else
107 exportStr += "color: " + this.getColor() + "\n";
108 exportStr += "endMaterial\n";
109
110 return exportStr;
111 }
112
113 this.import = function( importStr )
114 {
115 var pu = new ParseUtils( importStr );
116 var material = pu.nextValue( "material: " );
117 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
118 this.setName( pu.nextValue( "name: ") );
119
120 var rtnStr;
121 try
122 {
123 var color = eval( "[" + pu.nextValue( "color: " ) + "]" );
124
125 this.setProperty( "color", color);
126
127 var endKey = "endMaterial\n";
128 var index = importStr.indexOf( endKey );
129 index += endKey.length;
130 rtnStr = importStr.substr( index );
131 }
132 catch (e)
133 {
134 throw new Error( "could not import material: " + importStr );
135 }
136
137 return rtnStr;
138 }
139
140 this.update = function( time )
141 {
142 //var speed = 0.01;
143 //time *= speed;
144 this._deltaTime += 0.01;
145
146 if (this._shader && this._shader.colorMe)
147 {
148 var t3 = this._propValues[ this._propNames[3] ] - this._deltaTime;
149 if (t3 < 0)
150 {
151 this._deltaTime = this._propValues[ this._propNames[1] ] - 1.0;
152 t3 = this._propValues[ this._propNames[3] ] - this._deltaTime;
153 }
154 var t1 = this._propValues[ this._propNames[1] ] - this._deltaTime,
155 t2 = this._propValues[ this._propNames[2] ] - this._deltaTime;
156
157
158 this._shader.colorMe[this._propNames[1]].set( [t1] );
159 this._shader.colorMe[this._propNames[2]].set( [t2] );
160 this._shader.colorMe[this._propNames[3]].set( [t3] );
161 }
162 }
163
164 this.updateShaderValues = function()
165 {
166 if (this._shader && this._shader.colorMe)
167 {
168 var nProps = this._propNames.length;
169 for (var i=0; i<nProps; i++)
170 {
171 var propName = this._propNames[i];
172 var propValue = this._propValues[propName];
173 switch (propName)
174 {
175 case "color": this._shader.colorMe[propName].set( propValue ); break;
176 default: this._shader.colorMe[propName].set( [propValue] ); break;
177 }
178 }
179 }
180 }
181}
182
183///////////////////////////////////////////////////////////////////////////////////////
184// RDGE shader
185
186// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
187taperShaderDef =
188{
189 'shaders': { // shader files
190 'defaultVShader':"assets/shaders/Taper.vert.glsl",
191 'defaultFShader':"assets/shaders/Taper.frag.glsl"
192 },
193 'techniques': { // rendering control
194 'colorMe':[ // simple color pass
195 {
196 'vshader' : 'defaultVShader',
197 'fshader' : 'defaultFShader',
198
199 // attributes
200 'attributes' :
201 {
202 'vert' : { 'type' : 'vec3' },
203 'normal' : { 'type' : 'vec3' },
204 'texcoord' : { 'type' : 'vec2' },
205 },