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.js60
1 files changed, 41 insertions, 19 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 54e5168f..892e975f 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 ///////////////////////////////////////////////////////////////////////
@@ -35,6 +38,7 @@ function TwistVertMaterial() {
35 this.getShaderName = function () { return this._shaderName; }; 38 this.getShaderName = function () { return this._shaderName; };
36 39
37 this.isAnimated = function () { return true; }; 40 this.isAnimated = function () { return true; };
41
38 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 42 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
39 this._hasVertexDeformation = true; 43 this._hasVertexDeformation = true;
40 this._vertexDeformationTolerance = 0.02; // should be a property 44 this._vertexDeformationTolerance = 0.02; // should be a property
@@ -45,7 +49,8 @@ function TwistVertMaterial() {
45 // duplcate method requirde 49 // duplcate method requirde
46 this.dup = function () { return new TwistVertMaterial(); }; 50 this.dup = function () { return new TwistVertMaterial(); };
47 51
48 this.init = function (world) { 52 this.init = function (world)
53 {
49 this.setWorld(world); 54 this.setWorld(world);
50 55
51 // set up the shader 56 // set up the shader
@@ -82,9 +87,11 @@ function TwistVertMaterial() {
82 this._propValues[this._propNames[5]] = this._tex0.slice(); 87 this._propValues[this._propNames[5]] = this._tex0.slice();
83 this._propValues[this._propNames[6]] = this._tex1.slice(); 88 this._propValues[this._propNames[6]] = this._tex1.slice();
84 89
85 this.setProperty = function (prop, value) { 90 this.setProperty = function (prop, value)
91 {
86 // make sure we have legitimate input 92 // make sure we have legitimate input
87 if (this.validateProperty(prop, value)) { 93 if (this.validateProperty(prop, value))
94 {
88 switch (prop) { 95 switch (prop) {
89 case "color": 96 case "color":
90 case "u_tex1": 97 case "u_tex1":
@@ -103,7 +110,7 @@ function TwistVertMaterial() {
103 'material': this.getShaderName(), 110 'material': this.getShaderName(),
104 'name': this.getName(), 111 'name': this.getName(),
105 'color': this._propValues["color"] 112 'color': this._propValues["color"]
106 }; 113 }
107 114
108 return jObj; 115 return jObj;
109 }; 116 };
@@ -121,15 +128,19 @@ function TwistVertMaterial() {
121 } 128 }
122 }; 129 };
123 130
124 this.update = function (time) { 131 this.update = function (time)
125 if (this._shader && this._shader.twistMe) { 132 {
133 if (this._shader && this._shader.twistMe)
134 {
126 var angle = this._angle; 135 var angle = this._angle;
127 angle += this._deltaTime; 136 angle += this._deltaTime;
128 if (angle > this._propValues["u_twistAmount"]) { 137 if (angle > this._propValues["u_twistAmount"])
138 {
129 angle = this._propValues["u_twistAmount"]; 139 angle = this._propValues["u_twistAmount"];
130 this._deltaTime = -this._deltaTime; 140 this._deltaTime = -this._deltaTime;
131 } 141 }
132 else if (angle < 0.0) { 142 else if (angle < 0.0)
143 {
133 angle = 0; 144 angle = 0;
134 this._deltaTime = -this._deltaTime; 145 this._deltaTime = -this._deltaTime;
135 } 146 }
@@ -138,13 +149,17 @@ function TwistVertMaterial() {
138 } 149 }
139 }; 150 };
140 151
141 this.updateShaderValues = function () { 152 this.updateShaderValues = function ()
142 if (this._shader && this._shader.twistMe) { 153 {
154 if (this._shader && this._shader.twistMe)
155 {
143 var nProps = this._propNames.length; 156 var nProps = this._propNames.length;
144 for (var i = 0; i < nProps; i++) { 157 for (var i = 0; i < nProps; i++)
158 {
145 var propName = this._propNames[i]; 159 var propName = this._propNames[i];
146 var propValue = this._propValues[propName]; 160 var propValue = this._propValues[propName];
147 switch (propName) { 161 switch (propName)
162 {
148 case "u_tex0": 163 case "u_tex0":
149 case "u_tex1": 164 case "u_tex1":
150 case "color": this._shader.twistMe[propName].set(propValue); break; 165 case "color": this._shader.twistMe[propName].set(propValue); break;
@@ -154,12 +169,15 @@ function TwistVertMaterial() {
154 } 169 }
155 }; 170 };
156 171
157 this.updateTextures = function () { 172 this.updateTextures = function ()
173 {
158 var material = this._materialNode; 174 var material = this._materialNode;
159 if (material) { 175 if (material)
176 {
160 var technique = material.shaderProgram['default']; 177 var technique = material.shaderProgram['default'];
161 var renderer = RDGE.globals.engine.getContext().renderer; 178 var renderer = RDGE.globals.engine.getContext().renderer;
162 if (renderer && technique) { 179 if (renderer && technique)
180 {
163 var texMapName = this._propValues[this._propNames[5]]; 181 var texMapName = this._propValues[this._propNames[5]];
164 var wrap = 'REPEAT', mips = true; 182 var wrap = 'REPEAT', mips = true;
165 var tex = this.loadTexture(texMapName, wrap, mips); 183 var tex = this.loadTexture(texMapName, wrap, mips);
@@ -170,7 +188,7 @@ function TwistVertMaterial() {
170 if (tex) technique.u_tex1.set(tex); 188 if (tex) technique.u_tex1.set(tex);
171 } 189 }
172 } 190 }
173 }; 191 }
174}; 192};
175 193
176/////////////////////////////////////////////////////////////////////////////////////// 194///////////////////////////////////////////////////////////////////////////////////////
@@ -214,3 +232,7 @@ twistVertShaderDef =
214 } 232 }
215}; 233};
216 234
235if (typeof exports === "object") {
236 exports.TwistVertMaterial = TwistVertMaterial;
237}
238