diff options
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r-- | js/lib/rdge/materials/twist-vert-material.js | 87 |
1 files changed, 65 insertions, 22 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 54e5168f..b27c0b11 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 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var Material = require("js/lib/rdge/materials/material").Material; |
8 | var 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 | /////////////////////////////////////////////////////////////////////// |
12 | function TwistVertMaterial() { | 14 | var 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 |
@@ -43,9 +47,24 @@ function TwistVertMaterial() { | |||
43 | // Methods | 47 | // Methods |
44 | /////////////////////////////////////////////////////////////////////// | 48 | /////////////////////////////////////////////////////////////////////// |
45 | // duplcate method requirde | 49 | // duplcate method requirde |
46 | this.dup = function () { return new TwistVertMaterial(); }; | 50 | this.dup = function() { |
51 | // get the current values; | ||
52 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
53 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
54 | |||
55 | // allocate a new material | ||
56 | var newMat = new TwistVertMaterial(); | ||
57 | |||
58 | // copy over the current values; | ||
59 | var n = propNames.length; | ||
60 | for (var i = 0; i < n; i++) | ||
61 | newMat.setProperty(propNames[i], propValues[i]); | ||
47 | 62 | ||
48 | this.init = function (world) { | 63 | return newMat; |
64 | }; | ||
65 | |||
66 | this.init = function (world) | ||
67 | { | ||
49 | this.setWorld(world); | 68 | this.setWorld(world); |
50 | 69 | ||
51 | // set up the shader | 70 | // set up the shader |
@@ -82,9 +101,11 @@ function TwistVertMaterial() { | |||
82 | this._propValues[this._propNames[5]] = this._tex0.slice(); | 101 | this._propValues[this._propNames[5]] = this._tex0.slice(); |
83 | this._propValues[this._propNames[6]] = this._tex1.slice(); | 102 | this._propValues[this._propNames[6]] = this._tex1.slice(); |
84 | 103 | ||
85 | this.setProperty = function (prop, value) { | 104 | this.setProperty = function (prop, value) |
105 | { | ||
86 | // make sure we have legitimate input | 106 | // make sure we have legitimate input |
87 | if (this.validateProperty(prop, value)) { | 107 | if (this.validateProperty(prop, value)) |
108 | { | ||
88 | switch (prop) { | 109 | switch (prop) { |
89 | case "color": | 110 | case "color": |
90 | case "u_tex1": | 111 | case "u_tex1": |
@@ -103,7 +124,7 @@ function TwistVertMaterial() { | |||
103 | 'material': this.getShaderName(), | 124 | 'material': this.getShaderName(), |
104 | 'name': this.getName(), | 125 | 'name': this.getName(), |
105 | 'color': this._propValues["color"] | 126 | 'color': this._propValues["color"] |
106 | }; | 127 | } |
107 | 128 | ||
108 | return jObj; | 129 | return jObj; |
109 | }; | 130 | }; |
@@ -121,15 +142,19 @@ function TwistVertMaterial() { | |||
121 | } | 142 | } |
122 | }; | 143 | }; |
123 | 144 | ||
124 | this.update = function (time) { | 145 | this.update = function (time) |
125 | if (this._shader && this._shader.twistMe) { | 146 | { |
147 | if (this._shader && this._shader.twistMe) | ||
148 | { | ||
126 | var angle = this._angle; | 149 | var angle = this._angle; |
127 | angle += this._deltaTime; | 150 | angle += this._deltaTime; |
128 | if (angle > this._propValues["u_twistAmount"]) { | 151 | if (angle > this._propValues["u_twistAmount"]) |
152 | { | ||
129 | angle = this._propValues["u_twistAmount"]; | 153 | angle = this._propValues["u_twistAmount"]; |
130 | this._deltaTime = -this._deltaTime; | 154 | this._deltaTime = -this._deltaTime; |
131 | } | 155 | } |
132 | else if (angle < 0.0) { | 156 | else if (angle < 0.0) |
157 | { | ||
133 | angle = 0; | 158 | angle = 0; |
134 | this._deltaTime = -this._deltaTime; | 159 | this._deltaTime = -this._deltaTime; |
135 | } | 160 | } |
@@ -138,28 +163,42 @@ function TwistVertMaterial() { | |||
138 | } | 163 | } |
139 | }; | 164 | }; |
140 | 165 | ||
141 | this.updateShaderValues = function () { | 166 | this.updateShaderValues = function () |
142 | if (this._shader && this._shader.twistMe) { | 167 | { |
168 | if (this._shader && this._shader.twistMe) | ||
169 | { | ||
143 | var nProps = this._propNames.length; | 170 | var nProps = this._propNames.length; |
144 | for (var i = 0; i < nProps; i++) { | 171 | for (var i = 0; i < nProps; i++) |
172 | { | ||
145 | var propName = this._propNames[i]; | 173 | var propName = this._propNames[i]; |
146 | var propValue = this._propValues[propName]; | 174 | var propValue = this._propValues[propName]; |
147 | switch (propName) { | 175 | switch (propName) |
176 | { | ||
148 | case "u_tex0": | 177 | case "u_tex0": |
149 | case "u_tex1": | 178 | case "u_tex1": |
150 | case "color": this._shader.twistMe[propName].set(propValue); break; | 179 | break; |
151 | default: this._shader.twistMe[propName].set([propValue]); break; | 180 | |
181 | case "color": | ||
182 | this._shader.twistMe[propName].set(propValue); | ||
183 | break; | ||
184 | |||
185 | default: | ||
186 | this._shader.twistMe[propName].set([propValue]); | ||
187 | break; | ||
152 | } | 188 | } |
153 | } | 189 | } |
154 | } | 190 | } |
155 | }; | 191 | }; |
156 | 192 | ||
157 | this.updateTextures = function () { | 193 | this.updateTextures = function () |
194 | { | ||
158 | var material = this._materialNode; | 195 | var material = this._materialNode; |
159 | if (material) { | 196 | if (material) |
197 | { | ||
160 | var technique = material.shaderProgram['default']; | 198 | var technique = material.shaderProgram['default']; |
161 | var renderer = RDGE.globals.engine.getContext().renderer; | 199 | var renderer = RDGE.globals.engine.getContext().renderer; |
162 | if (renderer && technique) { | 200 | if (renderer && technique) |
201 | { | ||
163 | var texMapName = this._propValues[this._propNames[5]]; | 202 | var texMapName = this._propValues[this._propNames[5]]; |
164 | var wrap = 'REPEAT', mips = true; | 203 | var wrap = 'REPEAT', mips = true; |
165 | var tex = this.loadTexture(texMapName, wrap, mips); | 204 | var tex = this.loadTexture(texMapName, wrap, mips); |
@@ -170,7 +209,7 @@ function TwistVertMaterial() { | |||
170 | if (tex) technique.u_tex1.set(tex); | 209 | if (tex) technique.u_tex1.set(tex); |
171 | } | 210 | } |
172 | } | 211 | } |
173 | }; | 212 | } |
174 | }; | 213 | }; |
175 | 214 | ||
176 | /////////////////////////////////////////////////////////////////////////////////////// | 215 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -214,3 +253,7 @@ twistVertShaderDef = | |||
214 | } | 253 | } |
215 | }; | 254 | }; |
216 | 255 | ||
256 | if (typeof exports === "object") { | ||
257 | exports.TwistVertMaterial = TwistVertMaterial; | ||
258 | } | ||
259 | |||