aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js165
1 files changed, 144 insertions, 21 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 852aab89..f285f24a 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,15 +253,15 @@ 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
@@ -235,7 +296,26 @@ var GeomObj = function GLGeomObj() {
235 var materialType = this.getPropertyFromString( "material: ", importStr ); 296 var materialType = this.getPropertyFromString( "material: ", importStr );
236 switch (materialType) 297 switch (materialType)
237 { 298 {
238 case "flat": mat = new FlatMaterial(); break; 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;
239 319
240 default: 320 default:
241 console.log( "material type: " + materialType + " is not supported" ); 321 console.log( "material type: " + materialType + " is not supported" );
@@ -312,6 +392,49 @@ var GeomObj = function GLGeomObj() {
312 return rtnStr; 392 return rtnStr;
313 }; 393 };
314 394
395 // Gradient stops for rgba(255,0,0,1) at 0%; rgba(0,255,0,1) at 33%; rgba(0,0,255,1) at 100% will return
396 // 255,0,0,1@0;0,255,0,1@33;0,0,255,1@100
397 this.gradientToString = function(colors) {
398 var rtnStr = "";
399 if(colors && colors.length) {
400 var c = colors[0],
401 len = colors.length;
402
403 rtnStr += String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
404 for(var i=1; i<len; i++) {
405 c = colors[i];
406 rtnStr += ";" + String(c.value.r + "," + c.value.g + "," + c.value.b + "," + c.value.a + "@" + c.position);
407 }
408 }
409 return rtnStr;
410 };
411
412 // Given a gradientStr "255,0,0,1@0;0,255,0,1@33;0,0,255,1@100" will return:
413 // colors array [{position:0, value:{r:255, g:0, b:0, a:1}},
414 // {position:33, value:{r:0, g:255, b:0, a:1}},
415 // {position:100, value:{r:0, g:0, b:255, a:1}}
416 // ]
417 this.stringToGradient = function(gradientStr) {
418 var rtnArr = [];
419
420 var i,
421 len,
422 stops,
423 stop,
424 c;
425
426 stops = gradientStr.split(";");
427 len = stops.length;
428 for(i=0; i<len; i++)
429 {
430 stop = stops[i].split("@");
431 c = stop[0].split(",");
432 rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} });
433 }
434
435 return rtnArr;
436 };
437
315 /* 438 /*