aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-vert-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js130
1 files changed, 102 insertions, 28 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 54e5168f..7d9dd6d6 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -4,14 +4,17 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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; 7var Material = require("js/lib/rdge/materials/material").Material;
8var Texture = require("js/lib/rdge/texture").Texture;
9
8/////////////////////////////////////////////////////////////////////// 10///////////////////////////////////////////////////////////////////////
9// Class GLMaterial 11// Class GLMaterial
10// RDGE representation of a material. 12// RDGE representation of a material.
11/////////////////////////////////////////////////////////////////////// 13///////////////////////////////////////////////////////////////////////
12function TwistVertMaterial() { 14var TwistVertMaterial = function TwistVertMaterial()
15{
13 // initialize the inherited members 16 // initialize the inherited members
14 this.inheritedFrom = GLMaterial; 17 this.inheritedFrom = Material;
15 this.inheritedFrom(); 18 this.inheritedFrom();
16 19
17 /////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////
@@ -25,6 +28,9 @@ function TwistVertMaterial() {
25 this._tex0 = 'assets/images/rocky-normal.jpg'; 28 this._tex0 = 'assets/images/rocky-normal.jpg';
26 this._tex1 = 'assets/images/metal.png'; 29 this._tex1 = 'assets/images/metal.png';
27 30
31 this._glTex0;
32 this._glTex1;
33
28 this._angle = 0.0; 34 this._angle = 0.0;
29 this._deltaTime = 0.01; 35 this._deltaTime = 0.01;
30 36
@@ -35,6 +41,7 @@ function TwistVertMaterial() {
35 this.getShaderName = function () { return this._shaderName; }; 41 this.getShaderName = function () { return this._shaderName; };
36 42
37 this.isAnimated = function () { return true; }; 43 this.isAnimated = function () { return true; };
44
38 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 45 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
39 this._hasVertexDeformation = true; 46 this._hasVertexDeformation = true;
40 this._vertexDeformationTolerance = 0.02; // should be a property 47 this._vertexDeformationTolerance = 0.02; // should be a property
@@ -43,9 +50,24 @@ function TwistVertMaterial() {
43 // Methods 50 // Methods
44 /////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////
45 // duplcate method requirde 52 // duplcate method requirde
46 this.dup = function () { return new TwistVertMaterial(); }; 53 this.dup = function() {
54 // get the current values;
55 var propNames = [], propValues = [], propTypes = [], propLabels = [];
56 this.getAllProperties(propNames, propValues, propTypes, propLabels);
57
58 // allocate a new material
59 var newMat = new TwistVertMaterial();
47 60
48 this.init = function (world) { 61 // copy over the current values;
62 var n = propNames.length;
63 for (var i = 0; i < n; i++)
64 newMat.setProperty(propNames[i], propValues[i]);
65
66 return newMat;
67 };
68
69 this.init = function (world)
70 {
49 this.setWorld(world); 71 this.setWorld(world);
50 72
51 // set up the shader 73 // set up the shader
@@ -60,6 +82,9 @@ function TwistVertMaterial() {
60 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); 82 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID());
61 this._materialNode.setShader(this._shader); 83 this._materialNode.setShader(this._shader);
62 84
85 // set up the texture maps
86 this.updateTextures();
87
63 // initialize the twist vert properties 88 // initialize the twist vert properties
64 this.updateShaderValues(); 89 this.updateShaderValues();
65 }; 90 };
@@ -82,9 +107,11 @@ function TwistVertMaterial() {
82 this._propValues[this._propNames[5]] = this._tex0.slice(); 107 this._propValues[this._propNames[5]] = this._tex0.slice();
83 this._propValues[this._propNames[6]] = this._tex1.slice(); 108 this._propValues[this._propNames[6]] = this._tex1.slice();
84 109
85 this.setProperty = function (prop, value) { 110 this.setProperty = function (prop, value)
111 {
86 // make sure we have legitimate input 112 // make sure we have legitimate input
87 if (this.validateProperty(prop, value)) { 113 if (this.validateProperty(prop, value))
114 {
88 switch (prop) { 115 switch (prop) {
89 case "color": 116 case "color":
90 case "u_tex1": 117 case "u_tex1":
@@ -103,7 +130,7 @@ function TwistVertMaterial() {
103 'material': this.getShaderName(), 130 'material': this.getShaderName(),
104 'name': this.getName(), 131 'name': this.getName(),
105 'color': this._propValues["color"] 132 'color': this._propValues["color"]
106 }; 133 }
107 134
108 return jObj; 135 return jObj;
109 }; 136 };
@@ -121,56 +148,100 @@ function TwistVertMaterial() {
121 } 148 }
122 }; 149 };
123 150
124 this.update = function (time) { 151 this.update = function (time)
125 if (this._shader && this._shader.twistMe) { 152 {
126 var angle = this._angle; 153 if (this._shader && this._shader.twistMe)
154 {
155 var technique = this._shader.twistMe;
156
157 var angle = this._angle;
127 angle += this._deltaTime; 158 angle += this._deltaTime;
128 if (angle > this._propValues["u_twistAmount"]) { 159 if (angle > this._propValues["u_twistAmount"])
160 {
129 angle = this._propValues["u_twistAmount"]; 161 angle = this._propValues["u_twistAmount"];
130 this._deltaTime = -this._deltaTime; 162 this._deltaTime = -this._deltaTime;
131 } 163 }
132 else if (angle < 0.0) { 164 else if (angle < 0.0)
165 {
133 angle = 0; 166 angle = 0;
134 this._deltaTime = -this._deltaTime; 167 this._deltaTime = -this._deltaTime;
135 } 168 }
136 this._angle = angle; 169 this._angle = angle;
137 this._shader.twistMe["u_twistAmount"].set([angle]); 170 this._shader.twistMe["u_twistAmount"].set([angle]);
171
172 var tex;
173 if (this._glTex0)
174 {
175 if (this._glTex0.isAnimated())
176 this._glTex0.render();
177 tex = this._glTex0.getTexture();
178 if (tex)
179 technique.u_tex0.set( tex );
180 }
181 if (this._glTex1)
182 {
183 if (this._glTex1.isAnimated())
184 this._glTex1.render();
185 tex = this._glTex1.getTexture();
186 if (tex)
187 technique.u_tex1.set( tex );
188 }
189
138 } 190 }
139 }; 191 };
140 192
141 this.updateShaderValues = function () { 193 this.updateShaderValues = function ()
142 if (this._shader && this._shader.twistMe) { 194 {
195 if (this._shader && this._shader.twistMe)
196 {
143 var nProps = this._propNames.length; 197 var nProps = this._propNames.length;
144 for (var i = 0; i < nProps; i++) { 198 for (var i = 0; i < nProps; i++)
199 {
145 var propName = this._propNames[i]; 200 var propName = this._propNames[i];
146 var propValue = this._propValues[propName]; 201 var propValue = this._propValues[propName];
147 switch (propName) { 202 switch (propName)
203 {
148 case "u_tex0": 204 case "u_tex0":
149 case "u_tex1": 205 case "u_tex1":
150 case "color": this._shader.twistMe[propName].set(propValue); break; 206 break;
151 default: this._shader.twistMe[propName].set([propValue]); break; 207
208 case "color":
209 this._shader.twistMe[propName].set(propValue);
210 break;
211
212 default:
213 this._shader.twistMe[propName].set([propValue]);
214 break;
152 } 215 }
153 } 216 }
154 } 217 }
155 }; 218 };
156 219
157 this.updateTextures = function () { 220 this.updateTextures = function ()
221 {
158 var material = this._materialNode; 222 var material = this._materialNode;
159 if (material) { 223 if (material)
160 var technique = material.shaderProgram['default']; 224 {
225 var technique = material.shaderProgram['twistMe'];
161