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.js108
1 files changed, 14 insertions, 94 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 44daa291..56cf7c98 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -111,14 +111,16 @@ var GeomObj = function GLGeomObj() {
111 return this.GEOM_TYPE_UNDEFINED; 111 return this.GEOM_TYPE_UNDEFINED;
112 }; 112 };
113 113
114 this.getPrimitiveArray = function() { return this._primArray; 114 this.getPrimitiveArray = function () {
115 return this._primArray;
115 }; 116 };
116 117
117 this.getMaterialNodeArray = function() { 118 this.getMaterialNodeArray = function() {
118 return this._materialNodeArray; 119 return this._materialNodeArray;
119 }; 120 };
120 121
121 this.getMaterialArray = function() { return this._materialArray; 122 this.getMaterialArray = function () {
123 return this._materialArray;
122 }; 124 };
123 125
124 this.getTransformNode = function() { 126 this.getTransformNode = function() {
@@ -266,18 +268,14 @@ var GeomObj = function GLGeomObj() {
266 return fillMaterial; 268 return fillMaterial;
267 }; 269 };
268 270
269 this.exportMaterialsJSON = function() 271 this.exportMaterialsJSON = function () {
270 {
271 var jObj; 272 var jObj;
272 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) 273 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) {
273 {
274 var nMats = this._materialArray.length; 274 var nMats = this._materialArray.length;
275 if (nMats > 0) 275 if (nMats > 0) {
276 {
277 var arr = []; 276 var arr = [];
278 277
279 for (var i=0; i<nMats; i++) 278 for (var i = 0; i < nMats; i++) {
280 {
281 var matObj = 279 var matObj =
282 { 280 {
283 'materialNodeName' : this._materialNodeArray[i].name, 281 'materialNodeName' : this._materialNodeArray[i].name,
@@ -298,8 +296,7 @@ var GeomObj = function GLGeomObj() {
298 return jObj; 296 return jObj;
299 } 297 }
300 298
301 this.importMaterialsJSON = function( jObj ) 299 this.importMaterialsJSON = function (jObj) {
302 {
303 this._materialArray = []; 300 this._materialArray = [];
304 this._materialTypeArray = []; 301 this._materialTypeArray = [];
305 302
@@ -307,13 +304,11 @@ var GeomObj = function GLGeomObj() {
307 304
308 var nMaterials = jObj.nMaterials; 305 var nMaterials = jObj.nMaterials;
309 var matArray = jObj.materials; 306 var matArray = jObj.materials;
310 for (var i=0; i<nMaterials; i++) 307 for (var i = 0; i < nMaterials; i++) {
311 {
312 var mat; 308 var mat;
313 var matObj = matArray[i].material; 309 var matObj = matArray[i].material;
314 var shaderName = matObj.material; 310 var shaderName = matObj.material;
315 switch (shaderName) 311 switch (shaderName) {
316 {
317 case "flat": 312 case "flat":
318 case "radialGradient": 313 case "radialGradient":
319 case "linearGradient": 314 case "linearGradient":
@@ -345,8 +340,7 @@ var GeomObj = function GLGeomObj() {
345 break; 340 break;
346 } 341 }
347 342
348 if (mat) 343 if (mat) {
349 {
350 mat.importJSON( matObj ); 344 mat.importJSON( matObj );
351 this._materialArray.push( mat ); 345 this._materialArray.push( mat );
352 this._materialTypeArray.push( matObj.type ); 346 this._materialTypeArray.push( matObj.type );
@@ -355,80 +349,7 @@ var GeomObj = function GLGeomObj() {
355 else this._strokeMaterial = mat; 349 else this._strokeMaterial = mat;
356 } 350 }
357 } 351 }
358 } 352 };
359
360 this.exportMaterials = function()
361 {
362 var rtnStr = "";
363 if (this._materialArray && this._materialNodeArray)
364 {
365 var nMats = this._materialArray.length;
366 rtnStr += "nMaterials: " + nMats + "\n";
367 for (var i=0; i<nMats; i++)
368 {
369 var matNode = this._materialNodeArray[i];
370 rtnStr += "materialNodeName: " + matNode.name + "\n";
371
372 var material = this._materialArray[i];
373 rtnStr += material.export();
374 }
375 }
376 else
377 rtnStr += "nMaterials: 0\n" ;
378
379 return rtnStr;
380 }
381
382 this.importMaterials = function(importStr)
383 {
384 var nMaterials = Number( this.getPropertyFromString( "nMaterials: ", importStr ) );
385 for (var i=0; i<nMaterials; i++)
386 {
387 var mat;
388 var materialType = this.getPropertyFromString( "material: ", importStr );
389 switch (materialType)
390 {
391 case "flat":
392 case "radialGradient":
393 case "linearGradient":
394 case "bumpMetal":
395 case "uber":
396 case "plasma":
397 case "deform":
398 case "water":
399 case "paris":
400 case "raiders":
401 case "tunnel":
402 case "reliefTunnel":
403 case "squareTunnel":
404 case "twist":
405 case "fly":
406 case "julia":
407 case "mandel":
408 case "star":
409 case "zinvert":
410 case "keleidoscope":
411 case "radialBlur":
412 case "pulse":
413 mat = MaterialsModel.getMaterialByShader( materialType );
414 if (mat) mat = mat.dup();
415 break;
416
417 default:
418 console.log( "material type: " + materialType + " is not supported" );
419 break;
420 }
421
422 if (mat)
423 mat.import( importStr );
424
425 // pull off the end of the material
426 var endMat = "endMaterial\n";
427 var endIndex = importStr.indexOf( endMat );
428 if (endIndex < 0) break;
429 importStr = importStr.substr( endIndex + endMat.length );
430 }
431 }
432 353
433 this.translate = function(v) { 354 this.translate = function(v) {
434 var mat = Matrix.Translation( v ); 355 var mat = Matrix.Translation( v );
@@ -524,8 +445,7 @@ var GeomObj = function GLGeomObj() {
524 445
525 stops = gradientStr.split(";"); 446 stops = gradientStr.split(";");
526 len = stops.length; 447 len = stops.length;
527 for(i=0; i<len; i++) 448 for (i = 0; i < len; i++) {
528 {
529 stop = stops[i].split("@"); 449 stop = stops[i].split("@");
530 c = stop[0].split(","); 450 c = stop[0].split(",");
531 rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} }); 451 rtnArr.push({ position: Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} });