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.js88
1 files changed, 36 insertions, 52 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 4b8e1c69..3cd3a89b 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -215,27 +216,10 @@ exports.GeomObj = Object.create(Object.prototype, {
215 nMats = this._materialArray.length; 216 nMats = this._materialArray.length;
216 } 217 }
217 218
218 var stops = [], 219 if (nMats === this._materialTypeArray.length) {
219 colors = c.color; 220 for (i = 0; i < nMats; i++) {
220 221 if (this._materialTypeArray[i] == type) {
221 var len = colors.length; 222 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 } 223 }
240 } 224 }
241 } 225 }
@@ -305,13 +289,13 @@ exports.GeomObj = Object.create(Object.prototype, {
305 this._materialArray.push(strokeMaterial); 289 this._materialArray.push(strokeMaterial);
306 this._materialTypeArray.push("stroke"); 290 this._materialTypeArray.push("stroke");
307 291
308 // don't set the value here. The material editor may set a color directly 292 // 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 293 // to the material without setting this value in the obj. The following
310 // lines of code will clobber the value in the material 294 // lines of code will clobber the value in the material
311 //if (this._strokeColor) 295 //if (this._strokeColor)
312 // this.setStrokeColor(this._strokeColor); 296 // this.setStrokeColor(this._strokeColor);
313 297
314 this._strokeMaterial = strokeMaterial; 298 this._strokeMaterial = strokeMaterial;
315 299
316 return strokeMaterial; 300 return strokeMaterial;
317 } 301 }
@@ -332,14 +316,14 @@ exports.GeomObj = Object.create(Object.prototype, {
332 316
333 this._materialArray.push(fillMaterial); 317 this._materialArray.push(fillMaterial);
334 this._materialTypeArray.push("fill"); 318 this._materialTypeArray.push("fill");
335 319
336 // don't set the value here. The material editor may set a color directly 320 // 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 321 // to the material without setting this value in the obj. The following
338 // lines of code will clobber the value in the material 322 // lines of code will clobber the value in the material
339 //if (this._fillColor) 323 //if (this._fillColor)
340 // this.setFillColor(this._fillColor); 324 // this.setFillColor(this._fillColor);
341 325
342 this._fillMaterial = fillMaterial; 326 this._fillMaterial = fillMaterial;
343 327
344 return fillMaterial; 328 return fillMaterial;
345 } 329 }
@@ -347,7 +331,7 @@ exports.GeomObj = Object.create(Object.prototype, {
347 331
348 exportMaterialsJSON: { 332 exportMaterialsJSON: {
349 value: function() { 333 value: function() {
350 MaterialsModel = require("js/models/materials-model").MaterialsModel; 334 MaterialsModel = require("js/models/materials-model").MaterialsModel;
351 335
352 var jObj; 336 var jObj;
353 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { 337 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) {
@@ -379,7 +363,7 @@ exports.GeomObj = Object.create(Object.prototype, {
379 363
380 importMaterialsJSON: { 364 importMaterialsJSON: {
381 value: function(jObj) { 365 value: function(jObj) {
382 MaterialsModel = require("js/models/materials-model").MaterialsModel; 366 MaterialsModel = require("js/models/materials-model").MaterialsModel;
383 367
384 this._materialArray = []; 368 this._materialArray = [];
385 this._materialTypeArray = []; 369 this._materialTypeArray = [];
@@ -406,7 +390,7 @@ exports.GeomObj = Object.create(Object.prototype, {
406 case "tunnel": 390 case "tunnel":
407 case "reliefTunnel": 391 case "reliefTunnel":
408 case "squareTunnel": 392 case "squareTunnel":
409 case "flag": 393 case "flag":
410 case "twist": 394 case "twist":
411 case "fly": 395 case "fly":
412 case "julia": 396 case "julia":
@@ -416,8 +400,8 @@ exports.GeomObj = Object.create(Object.prototype, {
416 case "keleidoscope": 400 case "keleidoscope":
417 case "radialBlur": 401 case "radialBlur":
418 case "pulse": 402 case "pulse":
419 case "twistVert": 403 case "twistVert":
420 case "taper": 404 case "taper":
421 mat = MaterialsModel.getMaterialByShader(shaderName); 405 mat = MaterialsModel.getMaterialByShader(shaderName);
422 if (mat) mat = mat.dup(); 406 if (mat) mat = mat.dup();
423 break; 407 break;
@@ -471,12 +455,12 @@ exports.GeomObj = Object.create(Object.prototype, {
471 // get the normalized device coordinates (NDC) for 455 // get the normalized device coordinates (NDC) for
472 // all position and dimensions. 456 // all position and dimensions.
473 var world = this.getWorld(); 457 var world = this.getWorld();
474 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 458 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
475 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph; 459 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph;
476 460
477 var aspect = world.getAspect(); 461 var aspect = world.getAspect();
478 var zn = world.getZNear(), zf = world.getZFar(); 462 var zn = world.getZNear(), zf = world.getZFar();
479 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 463 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
480 b = -t, 464 b = -t,
481 r = aspect*t, 465 r = aspect*t,
482 l = -r; 466 l = -r;
@@ -501,12 +485,12 @@ exports.GeomObj = Object.create(Object.prototype, {
501 // get the normalized device coordinates (NDC) for 485 // get the normalized device coordinates (NDC) for
502 // all position and dimensions. 486 // all position and dimensions.
503 var world = this.getWorld(); 487 var world = this.getWorld();
504 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 488 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
505 var xNDC = 2*preViewPt[0]/vpw, yNDC = -2*preViewPt[1]/vph; 489 var xNDC = 2*preViewPt[0]/vpw, yNDC = -2*preViewPt[1]/vph;
506 490
507 var aspect = world.getAspect(); 491 var aspect = world.getAspect();
508 var zn = world.getZNear(), zf = world.getZFar(); 492 var zn = world.getZNear(), zf = world.getZFar();
509 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 493 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
510 b = -t, 494 b = -t,
511 r = aspect*t, 495 r = aspect*t,
512 l = -r; 496 l = -r;