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.js197
1 files changed, 34 insertions, 163 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index cc232444..6cffa29f 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -26,9 +26,6 @@ var TwistVertMaterial = function TwistVertMaterial()
26 this._tex0 = 'assets/images/rocky-normal.jpg'; 26 this._tex0 = 'assets/images/rocky-normal.jpg';
27 this._tex1 = 'assets/images/metal.png'; 27 this._tex1 = 'assets/images/metal.png';
28 28
29 this._glTex0;
30 this._glTex1;
31
32 this._angle = 0.0; 29 this._angle = 0.0;
33 this._deltaTime = 0.01; 30 this._deltaTime = 0.01;
34 this._speed = 1.0; 31 this._speed = 1.0;
@@ -37,32 +34,34 @@ var TwistVertMaterial = function TwistVertMaterial()
37 // Property Accessors 34 // Property Accessors
38 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
39 this.getShaderName = function () { return this._shaderName; }; 36 this.getShaderName = function () { return this._shaderName; };
40
41 this.isAnimated = function () { return true; }; 37 this.isAnimated = function () { return true; };
38 this.getShaderDef = function() { return twistVertShaderDef; };
39 this.getTechniqueName = function() { return 'twistMe' };
42 40
43 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 41 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
44 this._hasVertexDeformation = true; 42 this._hasVertexDeformation = true;
45 this._vertexDeformationTolerance = 0.02; // should be a property 43 this._vertexDeformationTolerance = 0.02; // should be a property
46 44
47 /////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////
48 // Methods 46 // Material Property Accessors
49 /////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////
50 // duplcate method requirde 48 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"];
51 this.dup = function() { 49 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"];
52 // get the current values; 50 this._propTypes = [ "float", "float", "angle", "float", "file", "file"];
53 var propNames = [], propValues = [], propTypes = [], propLabels = []; 51 this._propValues = [];
54 this.getAllProperties(propNames, propValues, propTypes, propLabels);
55
56 // allocate a new material
57 var newMat = new TwistVertMaterial();
58 52
59 // copy over the current values; 53 // initialize the property values
60 var n = propNames.length; 54 this._propValues[this._propNames[0]] = 0.0;
61 for (var i = 0; i < n; i++) 55 this._propValues[this._propNames[1]] = 1.0;
62 newMat.setProperty(propNames[i], propValues[i]); 56 this._propValues[this._propNames[2]] = 2.0 * Math.PI;
57 this._propValues[this._propNames[3]] = this._speed;
58 this._propValues[this._propNames[4]] = this._tex0.slice();
59 this._propValues[this._propNames[5]] = this._tex1.slice();
60 ///////////////////////////////////////////////////////////////////////
63 61
64 return newMat; 62 ///////////////////////////////////////////////////////////////////////
65 }; 63 // Methods
64 ///////////////////////////////////////////////////////////////////////
66 65
67 this.init = function (world) 66 this.init = function (world)
68 { 67 {
@@ -77,90 +76,9 @@ var TwistVertMaterial = function TwistVertMaterial()
77 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); 76 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID());
78 this._materialNode.setShader(this._shader); 77 this._materialNode.setShader(this._shader);
79 78
80 // set up the texture maps
81 this.updateTextures();
82 79
83 // initialize the twist vert properties 80 // initialize the twist vert properties
84 this.updateShaderValues(); 81 this.setShaderValues();
85 };
86
87
88 ///////////////////////////////////////////////////////////////////////
89 // Material Property Accessors
90 ///////////////////////////////////////////////////////////////////////
91 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"];
92 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"];
93 this._propTypes = [ "float", "float", "angle", "float", "file", "file"];
94 this._propValues = [];
95
96 // initialize the property values
97 this._propValues[this._propNames[0]] = 0.0;
98 this._propValues[this._propNames[1]] = 1.0;
99 this._propValues[this._propNames[2]] = 2.0 * Math.PI;
100 this._propValues[this._propNames[3]] = this._speed;
101 this._propValues[this._propNames[4]] = this._tex0.slice();
102 this._propValues[this._propNames[5]] = this._tex1.slice();
103
104 this.setProperty = function (prop, value)
105 {
106 // make sure we have legitimate input
107 if (this.validateProperty(prop, value))
108 {
109 switch (prop) {
110 case "u_tex1":
111 case "u_tex0": this._propValues[prop] = value ? value.slice() : null;
112 this.updateTextures();
113 break;
114
115 default:
116 this._propValues[prop] = value;
117 break;
118 }
119
120 this.updateShaderValues();
121 }
122 };
123 ///////////////////////////////////////////////////////////////////////
124
125 this.exportJSON = function () {
126 var jObj =
127 {
128 'material' : this.getShaderName(),
129 'name' : this.getName(),
130
131 'tex0' : this._propValues[this._propNames[4]],
132 'tex1' : this._propValues[this._propNames[5]],
133
134 'speed' : this._propValues[this._propNames[3]],
135
136 'limit1' : this._propValues[this._propNames[0]],
137 'limit2' : this._propValues[this._propNames[1]],
138 'angle' : this._propValues[this._propNames[2]]
139 }
140
141 return jObj;
142 };
143
144 this.importJSON = function (jObj) {
145 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
146 this.setName(jObj.name);
147
148 try {
149
150 this._propValues[this._propNames[4]] = jObj.tex0;
151 this._propValues[this._propNames[5]] = jObj.tex1;
152
153 this._propValues[this._propNames[3]] = jObj.speed;
154
155 this._propValues[this._propNames[0]] = jObj.limit1;
156 this._propValues[this._propNames[1]] = jObj.limit2;
157 this._propValues[this._propNames[2]] = jObj.angle;
158
159 this.updateShaderValues();
160 }
161 catch (e) {
162 throw new Error("could not import material: " + importStr);
163 }
164 }; 82 };
165 83
166 this.update = function (time) 84 this.update = function (time)
@@ -185,80 +103,30 @@ var TwistVertMaterial = function TwistVertMaterial()
185 this._shader.twistMe["u_twistAmount"].set([angle]); 103 this._shader.twistMe["u_twistAmount"].set([angle]);
186 104
187 var tex; 105 var tex;
188 if (this._glTex0) 106 var glTex = this._glTextures["u_tex0"];
107 if (glTex)
189 { 108 {
190 if (this._glTex0.isAnimated()) 109 //if (glTex.isAnimated())
191 this._glTex0.render(); 110 glTex.render();
192 tex = this._glTex0.getTexture(); 111 tex = glTex.getTexture();
193 if (tex) 112 if (tex)
194 technique.u_tex0.set( tex ); 113 technique.u_tex0.set( tex );
195 } 114 }
196 if (this._glTex1) 115
116 glTex = this._glTextures["u_tex1"];
117 if (glTex)
197 { 118 {
198 if (this._glTex1.isAnimated()) 119 //if (glTex.isAnimated())
199 this._glTex1.render(); 120 glTex.render();
200 tex = this._glTex1.getTexture(); 121 tex = glTex.getTexture();
201 if (tex) 122 if (tex)
202 technique.u_tex1.set( tex ); 123 technique.u_tex1.set( tex );
203 } 124 }
204 125
205 } 126 }
206 };
207
208 this.updateShaderValues = function ()
209 {
210 if (this._shader && this._shader.twistMe)
211 {
212 var nProps = this._propNames.length;
213 for (var i = 0; i < nProps; i++)
214 {
215 var propName = this._propNames[i];
216 var propValue = this._propValues[propName];
217