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.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 4cb21a25..803dbb53 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -11,6 +11,7 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel;
11// Super class for all geometry classes 11// Super class for all geometry classes
12/////////////////////////////////////////////////////////////////////// 12///////////////////////////////////////////////////////////////////////
13exports.GeomObj = Object.create(Object.prototype, { 13exports.GeomObj = Object.create(Object.prototype, {
14{
14 /////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////
15 // Constants 16 // Constants
16 /////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////
@@ -186,6 +187,8 @@ exports.GeomObj = Object.create(Object.prototype, {
186 nMats = 0; 187 nMats = 0;
187 if (c) { 188 if (c) {
188 if (c.gradientMode) { 189 if (c.gradientMode) {
190 if (c.gradientMode)
191 {
189 // Gradient support 192 // Gradient support
190 if (this._materialArray && this._materialTypeArray) { 193 if (this._materialArray && this._materialTypeArray) {
191 nMats = this._materialArray.length; 194 nMats = this._materialArray.length;
@@ -201,6 +204,7 @@ exports.GeomObj = Object.create(Object.prototype, {
201 } 204 }
202 205
203 for (var n = 0; n < len; n++) { 206 for (var n = 0; n < len; n++) {
207 {
204 var position = colors[n].position / 100; 208 var position = colors[n].position / 100;
205 var cs = colors[n].value; 209 var cs = colors[n].value;
206 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a]; 210 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a];
@@ -209,6 +213,9 @@ exports.GeomObj = Object.create(Object.prototype, {
209 if (nMats === this._materialTypeArray.length) { 213 if (nMats === this._materialTypeArray.length) {
210 for (i = 0; i < nMats; i++) { 214 for (i = 0; i < nMats; i++) {
211 if (this._materialTypeArray[i] == type) { 215 if (this._materialTypeArray[i] == type) {
216 {
217 if (this._materialTypeArray[i] == type)
218 {
212 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0)); 219 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0));
213 this._materialArray[i].setProperty("colorStop" + (n + 1), position); 220 this._materialArray[i].setProperty("colorStop" + (n + 1), position);
214 } 221 }
@@ -218,12 +225,15 @@ exports.GeomObj = Object.create(Object.prototype, {
218 if (type === "fill") { 225 if (type === "fill") {
219 this._fillColor = c; 226 this._fillColor = c;
220 } else { 227 } else {
228 else {
221 this._strokeColor = c; 229 this._strokeColor = c;
222 } 230 }
223 } else { 231 } else {
232 else {
224 if (type === "fill") { 233 if (type === "fill") {
225 this._fillColor = c.slice(0); 234 this._fillColor = c.slice(0);
226 } else { 235 } else {
236 else {
227 this._strokeColor = c.slice(0); 237 this._strokeColor = c.slice(0);
228 } 238 }
229 239
@@ -231,6 +241,7 @@ exports.GeomObj = Object.create(Object.prototype, {
231 nMats = this._materialArray.length; 241 nMats = this._materialArray.length;
232 if (nMats === this._materialTypeArray.length) { 242 if (nMats === this._materialTypeArray.length) {
233 for (i = 0; i < nMats; i++) { 243 for (i = 0; i < nMats; i++) {
244 {
234 if (this._materialTypeArray[i] == type) { 245 if (this._materialTypeArray[i] == type) {
235 this._materialArray[i].setProperty("color", c.slice(0)); 246 this._materialArray[i].setProperty("color", c.slice(0));
236 } 247 }
@@ -239,17 +250,24 @@ exports.GeomObj = Object.create(Object.prototype, {
239 } 250 }
240 } 251 }
241 } else { 252 } else {
253 else
254 {
242 if (type === "fill") { 255 if (type === "fill") {
243 this._fillColor = null; 256 this._fillColor = null;
244 } else { 257 } else {
258 else {
245 this._strokeColor = null; 259 this._strokeColor = null;
246 } 260 }
247 261
248 if (this._materialArray && this._materialTypeArray) { 262 if (this._materialArray && this._materialTypeArray) {
263 {
249 nMats = this._materialArray.length; 264 nMats = this._materialArray.length;
250 if (nMats === this._materialTypeArray.length) { 265 if (nMats === this._materialTypeArray.length) {
251 for (i = 0; i < nMats; i++) { 266 for (i = 0; i < nMats; i++) {
252 if (this._materialTypeArray[i] == type) { 267 if (this._materialTypeArray[i] == type) {
268 {
269 if (this._materialTypeArray[i] == type)
270 {
253 // TODO - Not sure how to set color to null values in shaders 271 // TODO - Not sure how to set color to null values in shaders
254 this._materialArray[i].setProperty("color", [0, 0, 0, 0]); 272 this._materialArray[i].setProperty("color", [0, 0, 0, 0]);
255 } 273 }
@@ -271,6 +289,7 @@ exports.GeomObj = Object.create(Object.prototype, {
271 if (this.getStrokeMaterial()) { 289 if (this.getStrokeMaterial()) {
272 strokeMaterial = this.getStrokeMaterial().dup(); 290 strokeMaterial = this.getStrokeMaterial().dup();
273 } else { 291 } else {
292 else {
274 strokeMaterial = MaterialsModel.exportFlatMaterial(); 293 strokeMaterial = MaterialsModel.exportFlatMaterial();
275 } 294 }
276 295
@@ -285,6 +304,8 @@ exports.GeomObj = Object.create(Object.prototype, {
285 this.setStrokeColor(this._strokeColor); 304 this.setStrokeColor(this._strokeColor);
286 } 305 }
287 306
307 this._strokeMaterial = strokeMaterial;
308
288 return strokeMaterial; 309 return strokeMaterial;
289 } 310 }
290 }, 311 },
@@ -295,6 +316,7 @@ exports.GeomObj = Object.create(Object.prototype, {
295 if (this.getFillMaterial()) { 316 if (this.getFillMaterial()) {
296 fillMaterial = this.getFillMaterial().dup(); 317 fillMaterial = this.getFillMaterial().dup();
297 } else { 318 } else {
319 else {
298 fillMaterial = MaterialsModel.exportFlatMaterial(); 320 fillMaterial = MaterialsModel.exportFlatMaterial();
299 } 321 }
300 322
@@ -309,19 +331,25 @@ exports.GeomObj = Object.create(Object.prototype, {
309 this.setFillColor(this._fillColor); 331 this.setFillColor(this._fillColor);
310 } 332 }
311 333
334 this._fillMaterial = fillMaterial;
335
312 return fillMaterial; 336 return fillMaterial;
313 } 337 }
314 }, 338 },
315 339
316 exportMaterialsJSON: { 340 exportMaterialsJSON: {
317 value: function() { 341 value: function() {
342 MaterialsModel = require("js/models/materials-model").MaterialsModel;
343
318 var jObj; 344 var jObj;
319 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { 345 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) {
320 var nMats = this._materialArray.length; 346 var nMats = this._materialArray.length;
321 if (nMats > 0) { 347 if (nMats > 0) {
348 {
322 var arr = []; 349 var arr = [];
323 350
324 for (var i = 0; i < nMats; i++) { 351 for (var i = 0; i < nMats; i++) {
352 {
325 var matObj = 353 var matObj =
326 { 354 {
327 'materialNodeName':this._materialNodeArray[i].name, 355 'materialNodeName':this._materialNodeArray[i].name,
@@ -345,6 +373,8 @@ exports.GeomObj = Object.create(Object.prototype, {
345 373
346 importMaterialsJSON: { 374 importMaterialsJSON: {
347 value: function(jObj) { 375 value: function(jObj) {
376 MaterialsModel = require("js/models/materials-model").MaterialsModel;
377
348 this._materialArray = []; 378 this._materialArray = [];
349 this._materialTypeArray = []; 379 this._materialTypeArray = [];
350 380
@@ -353,10 +383,12 @@ exports.GeomObj = Object.create(Object.prototype, {
353 var nMaterials = jObj.nMaterials; 383 var nMaterials = jObj.nMaterials;
354 var matArray = jObj.materials; 384 var matArray = jObj.materials;
355 for (var i = 0; i < nMaterials; i++) { 385 for (var i = 0; i < nMaterials; i++) {
386 {
356 var mat; 387 var mat;
357 var matObj = matArray[i].material; 388 var matObj = matArray[i].material;
358 var shaderName = matObj.material; 389 var shaderName = matObj.material;
359 switch (shaderName) { 390 switch (shaderName) {
391 {
360 case "flat": 392 case "flat":
361 case "radialGradient": 393 case "radialGradient":
362 case "linearGradient": 394 case "linearGradient":
@@ -370,6 +402,7 @@ exports.GeomObj = Object.create(Object.prototype, {
370 case "tunnel": 402 case "tunnel":
371 case "reliefTunnel": 403 case "reliefTunnel":
372 case "squareTunnel": 404 case "squareTunnel":
405 case "flag":
373 case "twist": 406 case "twist":
374 case "fly": 407 case "fly":
375 case "julia": 408 case "julia":