aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
authorEric Guzman2012-03-17 00:05:14 -0700
committerEric Guzman2012-03-17 00:05:14 -0700
commita3192d8bc0f8c0698265817c14dcd2284fd89d7d (patch)
tree497ac55f550ed52f9d73b464aafb2aa6cb5f5038 /js/lib/geom/geom-obj.js
parenta6a6f9bcc5ff92f5bb5e9275336dfaec2d8e8f4c (diff)
parent954f5a13e371febcb1c0fb8015c577ee51c23130 (diff)
downloadninja-a3192d8bc0f8c0698265817c14dcd2284fd89d7d.tar.gz
Merge branch 'refs/heads/master' into AddAnimationsLibrary
Conflicts: js/panels/presets/default-transition-presets.js
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js212
1 files changed, 192 insertions, 20 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index c5880843..a64980e0 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -5,6 +5,27 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var MaterialsModel = require("js/models/materials-model").MaterialsModel; 7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
9var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial;
10var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial;
11var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial;
12var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial;
13var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial;
14var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial;
15var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
16var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial;
17var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial;
18var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial;
19var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial;
20var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial;
21var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial;
22var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial;
23var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial;
24var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial;
25var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial;
26var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial;
27var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial;
28
8/////////////////////////////////////////////////////////////////////// 29///////////////////////////////////////////////////////////////////////
9// Class GLGeomObj 30// Class GLGeomObj
10// Super class for all geometry classes 31// Super class for all geometry classes
@@ -138,22 +159,61 @@ var GeomObj = function GLGeomObj() {
138 // Methods 159 // Methods
139 /////////////////////////////////////////////////////////////////////// 160 ///////////////////////////////////////////////////////////////////////
140 this.setMaterialColor = function(c, type) { 161 this.setMaterialColor = function(c, type) {
141 if (type == "fill") { 162 var i = 0,
142 this._fillColor = c.slice(0); 163 nMats = 0;
164 if(c.gradientMode) {
165 // Gradient support
166 if (this._materialArray && this._materialTypeArray) {
167 nMats = this._materialArray.length;
168 }
169
170 var stops = [],
171 colors = c.color;
172
173 var len = colors.length;
174 // TODO - Current shaders only support 4 color stops
175 if(len > 4) {
176 len = 4;
177 }
178
179 for(var n=0; n<len; n++) {
180 var position = colors[n].position/100;
181 var cs = colors[n].value;
182 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
183 stops.push(stop);
184
185 if (nMats === this._materialTypeArray.length) {
186 for (i=0; i<nMats; i++) {
187 if (this._materialTypeArray[i] == type) {
188 this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) );
189 this._materialArray[i].setProperty( "colorStop"+(n+1), position );
190 }
191 }
192 }
193 }
194 if (type === "fill") {
195 this._fillColor = c;
196 } else {
197 this._strokeColor = c;
198 }
143 } else { 199 } else {
144 this._strokeColor = c.slice(0); 200 if (type === "fill") {
145 } 201 this._fillColor = c.slice(0);
202 } else {
203 this._strokeColor = c.slice(0);
204 }
146 205
147 if (this._materialArray && this._materialTypeArray) { 206 if (this._materialArray && this._materialTypeArray) {
148 var nMats = this._materialArray.length; 207 nMats = this._materialArray.length;
149 if (nMats === this._materialTypeArray.length) { 208 if (nMats === this._materialTypeArray.length) {
150 for (var i=0; i<nMats; i++) { 209 for (i=0; i<nMats; i++) {
151 if (this._materialTypeArray[i] == type) { 210 if (this._materialTypeArray[i] == type) {
152 this._materialArray[i].setProperty( "color", c.slice(0) ); 211 this._materialArray[i].setProperty( "color", c.slice(0) );
212 }
153 } 213 }
154 } 214 }
155 } 215 }
156 } 216 }
157 217
158 var world = this.getWorld(); 218 var world = this.getWorld();
159 if (world) { 219 if (world) {
@@ -171,14 +231,15 @@ var GeomObj = function GLGeomObj() {
171 231
172 if (strokeMaterial) { 232 if (strokeMaterial) {
173 strokeMaterial.init( this.getWorld() ); 233 strokeMaterial.init( this.getWorld() );
174 if(this._strokeColor) {
175 strokeMaterial.setProperty("color", this._strokeColor);
176 }
177 } 234 }
178 235
179 this._materialArray.push( strokeMaterial ); 236 this._materialArray.push( strokeMaterial );
180 this._materialTypeArray.push( "stroke" ); 237 this._materialTypeArray.push( "stroke" );
181 238
239 if(this._strokeColor) {
240 this.setStrokeColor(this._strokeColor);
241 }
242
182 return strokeMaterial; 243 return strokeMaterial;
183 }; 244 };
184 245
@@ -192,18 +253,86 @@ var GeomObj = function GLGeomObj() {
192 253
193 if (fillMaterial) { 254 if (fillMaterial) {
194 fillMaterial.init( this.getWorld() ); 255 fillMaterial.init( this.getWorld() );
195 //if(!this.getFillMaterial() && this._fillColor)
196 if (this._fillColor) {
197 fillMaterial.setProperty("color", this._fillColor);
198 }
199 } 256 }
200 257
201 this._materialArray.push( fillMaterial ); 258 this._materialArray.push( fillMaterial );
202 this._materialTypeArray.push( "fill" ); 259 this._materialTypeArray.push( "fill" );
203 260
261 if (this._fillColor) {
262 this.setFillColor(this._fillColor);
263 }
264
204 return fillMaterial; 265 return fillMaterial;
205 }; 266 };
206 267
268 this.exportMaterials = function()
269 {
270 var rtnStr = "";
271 if (this._materialArray && this._materialNodeArray)
272 {
273 var nMats = this._materialArray.length;
274 rtnStr += "nMaterials: " + nMats + "\n";
275 for (var i=0; i<nMats; i++)
276 {
277 var matNode = this._materialNodeArray[i];
278 rtnStr += "materialNodeName: " + matNode.name + "\n";
279
280 var material = this._materialArray[i];
281 rtnStr += material.export();
282 }
283 }
284 else
285 rtnStr += "nMaterials: 0\n" ;
286
287 return rtnStr;
288 }
289
290 this.importMaterials = function(importStr)
291 {
292 var nMaterials = Number( this.getPropertyFromString( "nMaterials: ", importStr ) );
293 for (var i=0; i<nMaterials; i++)
294 {
295 var mat;
296 var materialType = this.getPropertyFromString( "material: ", importStr );
297 switch (materialType)
298 {
299 case "flat": mat = new FlatMaterial(); break;
300 case "radialGradient": mat = new RadialGradientMaterial(); break;
301 case "linearGradient": mat = new LinearGradientMaterial(); break;
302 case "bumpMetal": mat = new BumpMetalMaterial(); break;
303 case "uber": mat = new UberMaterial(); break;
304 case "plasma": mat = new PlasmaMaterial(); break;
305 case "deform": mat = new DeformMaterial(); break;
306 case "water": mat = new WaterMaterial(); break;
307 case "tunnel": mat = new TunnelMaterial(); break;
308 case "reliefTunnel": mat = new ReliefTunnelMaterial(); break;
309 case "squareTunnel": mat = new SquareTunnelMaterial(); break;
310 case "twist": mat = new TwiseMaterial(); break;
311 case "fly": mat = new FlyMaterial(); break;
312 case "julia": mat = new JuliaMaterial(); break;
313 case "mandel": mat = new MandelMaterial(); break;
314 case "star": mat = new StarMaterial(); break;
315 case "zinvert": mat = new ZInvertMaterial(); break;
316 case "keleidoscope": mat = new KeleidoscopeMaterial(); break;
317 case "radialBlur": mat = new RadialBlurMaterial(); break;
318 case "pulse": mat = new PulseMaterial(); break;
319
320 default:
321 console.log( "material type: " + materialType + " is not supported" );
322 break;
323 }
324
325 if (mat)
326 mat.import( importStr );
327
328 // pull off the end of the material
329 var endMat = "endMaterial\n";
330 var endIndex = importStr.indexOf( endMat );
331 if (endIndex < 0) break;
332 importStr = importStr.substr( endIndex + endMat.length );
333 }
334 }
335
207 this.translate = function(v) { 336 this.translate = function(v) {
208 var mat = Matrix.Translation( v ); 337 var mat = Matrix.Translation( v );