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.js65
1 files changed, 24 insertions, 41 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 4b8e1c69..d859d025 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -215,27 +215,10 @@ exports.GeomObj = Object.create(Object.prototype, {
215 nMats = this._materialArray.length; 215 nMats = this._materialArray.length;
216 } 216 }
217 217
218 var stops = [], 218 if (nMats === this._materialTypeArray.length) {
219 colors = c.color; 219 for (i = 0; i < nMats; i++) {
220 220 if (this._materialTypeArray[i] == type) {
221 var len = colors.length; 221 this._materialArray[i].setGradientData(c.color);
222 // TODO - Current shaders only support 4 color stops
223 if (len > 4) {
224 len = 4;
225 }
226
227 for (var n = 0; n < len; n++) {
228 var position = colors[n].position / 100;
229 var cs = colors[n].value;
230 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a];
231 stops.push(stop);
232
233 if (nMats === this._materialTypeArray.length) {
234 for (i = 0; i < nMats; i++) {
235 if (this._materialTypeArray[i] == type) {
236 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0));
237 this._materialArray[i].setProperty("colorStop" + (n + 1), position);
238 }
239 } 222 }
240 } 223 }
241 } 224 }
@@ -305,13 +288,13 @@ exports.GeomObj = Object.create(Object.prototype, {
305 this._materialArray.push(strokeMaterial); 288 this._materialArray.push(strokeMaterial);
306 this._materialTypeArray.push("stroke"); 289 this._materialTypeArray.push("stroke");
307 290
308 // don't set the value here. The material editor may set a color directly 291 // don't set the value here. The material editor may set a color directly
309 // to the material without setting this value in the obj. The following 292 // to the material without setting this value in the obj. The following
310 // lines of code will clobber the value in the material 293 // lines of code will clobber the value in the material
311 //if (this._strokeColor) 294 //if (this._strokeColor)
312 // this.setStrokeColor(this._strokeColor); 295 // this.setStrokeColor(this._strokeColor);
313 296
314 this._strokeMaterial = strokeMaterial; 297 this._strokeMaterial = strokeMaterial;
315 298
316 return strokeMaterial; 299 return strokeMaterial;
317 } 300 }
@@ -332,14 +315,14 @@ exports.GeomObj = Object.create(Object.prototype, {
332 315
333 this._materialArray.push(fillMaterial); 316 this._materialArray.push(fillMaterial);
334 this._materialTypeArray.push("fill"); 317 this._materialTypeArray.push("fill");
335 318
336 // don't set the value here. The material editor may set a color directly 319 // don't set the value here. The material editor may set a color directly
337 // to the material without setting this value in the obj. The following 320 // to the material without setting this value in the obj. The following
338 // lines of code will clobber the value in the material 321 // lines of code will clobber the value in the material
339 //if (this._fillColor) 322 //if (this._fillColor)
340 // this.setFillColor(this._fillColor); 323 // this.setFillColor(this._fillColor);
341 324
342 this._fillMaterial = fillMaterial; 325 this._fillMaterial = fillMaterial;
343 326
344 return fillMaterial; 327 return fillMaterial;
345 } 328 }
@@ -347,7 +330,7 @@ exports.GeomObj = Object.create(Object.prototype, {
347 330
348 exportMaterialsJSON: { 331 exportMaterialsJSON: {
349 value: function() { 332 value: function() {
350 MaterialsModel = require("js/models/materials-model").MaterialsModel; 333 MaterialsModel = require("js/models/materials-model").MaterialsModel;
351 334
352 var jObj; 335 var jObj;
353 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { 336 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) {
@@ -379,7 +362,7 @@ exports.GeomObj = Object.create(Object.prototype, {
379 362
380 importMaterialsJSON: { 363 importMaterialsJSON: {
381 value: function(jObj) { 364 value: function(jObj) {
382 MaterialsModel = require("js/models/materials-model").MaterialsModel; 365 MaterialsModel = require("js/models/materials-model").MaterialsModel;
383 366
384 this._materialArray = []; 367 this._materialArray = [];
385 this._materialTypeArray = []; 368 this._materialTypeArray = [];
@@ -406,7 +389,7 @@ exports.GeomObj = Object.create(Object.prototype, {
406 case "tunnel": 389 case "tunnel":
407 case "reliefTunnel": 390 case "reliefTunnel":
408 case "squareTunnel": 391 case "squareTunnel":
409 case "flag": 392 case "flag":
410 case "twist": 393 case "twist":
411 case "fly": 394 case "fly":
412 case "julia": 395 case "julia":
@@ -416,8 +399,8 @@ exports.GeomObj = Object.create(Object.prototype, {
416 case "keleidoscope": 399 case "keleidoscope":
417 case "radialBlur": 400 case "radialBlur":
418 case "pulse": 401 case "pulse":
419 case "twistVert": 402 case "twistVert":
420 case "taper": 403 case "taper":
421 mat = MaterialsModel.getMaterialByShader(shaderName); 404 mat = MaterialsModel.getMaterialByShader(shaderName);
422 if (mat) mat = mat.dup(); 405 if (mat) mat = mat.dup();
423 break; 406 break;
@@ -471,12 +454,12 @@ exports.GeomObj = Object.create(Object.prototype, {
471 // get the normalized device coordinates (NDC) for 454 // get the normalized device coordinates (NDC) for
472 // all position and dimensions. 455 // all position and dimensions.
473 var world = this.getWorld(); 456 var world = this.getWorld();
474 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 457 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
475 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph; 458 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph;
476 459
477 var aspect = world.getAspect(); 460 var aspect = world.getAspect();
478 var zn = world.getZNear(), zf = world.getZFar(); 461 var zn = world.getZNear(), zf = world.getZFar();
479 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 462 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
480 b = -t, 463 b = -t,
481 r = aspect*t, 464 r = aspect*t,
482 l = -r; 465 l = -r;
@@ -501,12 +484,12 @@ exports.GeomObj = Object.create(Object.prototype, {
501 // get the normalized device coordinates (NDC) for 484 // get the normalized device coordinates (NDC) for
502 // all position and dimensions. 485 // all position and dimensions.
503 var world = this.getWorld(); 486 var world = this.getWorld();
504 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 487 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
505 var xNDC = 2*preViewPt[0]/vpw, yNDC = -2*preViewPt[1]/vph; 488 var xNDC = 2*preViewPt[0]/vpw, yNDC = -2*preViewPt[1]/vph;
506 489
507 var aspect = world.getAspect(); 490 var aspect = world.getAspect();
508 var zn = world.getZNear(), zf = world.getZFar(); 491 var zn = world.getZNear(), zf = world.getZFar();
509 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 492 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
510 b = -t, 493 b = -t,
511 r = aspect*t, 494 r = aspect*t,
512 l = -r; 495 l = -r;