aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js12
-rwxr-xr-xjs/lib/geom/circle.js102
-rwxr-xr-xjs/lib/geom/geom-obj.js108
-rwxr-xr-xjs/lib/geom/line.js4
-rwxr-xr-xjs/lib/geom/rectangle.js118
-rw-r--r--js/lib/geom/shape-primitive.js4
6 files changed, 25 insertions, 323 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 22209815..26ac42e9 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -711,18 +711,6 @@ var BrushStroke = function GLBrushStroke() {
711 this.update(); //after this, the stroke is ready to be rendered 711 this.update(); //after this, the stroke is ready to be rendered
712 }; 712 };
713 713
714
715 this.export = function() {
716 var jsonObject = this.exportJSON();
717 var stringified = JSON.stringify(jsonObject);
718 return "type: " + this.geomType() + "\n" + stringified;
719 };
720
721 this.import = function( importStr ) {
722 var jsonObject = JSON.parse(importStr);
723 this.importJSON(jsonObject);
724 }
725
726 this.collidesWithPoint = function (x, y, z) { 714 this.collidesWithPoint = function (x, y, z) {
727 if (x < this._BBoxMin[0]) return false; 715 if (x < this._BBoxMin[0]) return false;
728 if (x > this._BBoxMax[0]) return false; 716 if (x > this._BBoxMax[0]) return false;
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index f74d4e57..1073c2db 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -61,8 +61,6 @@ var Circle = function GLCircle() {
61 } else { 61 } else {
62 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 62 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
63 } 63 }
64
65 this.exportMaterials();
66 }; 64 };
67 65
68 /////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////
@@ -178,7 +176,7 @@ var Circle = function GLCircle() {
178 if (!world._useWebGL) return; 176 if (!world._useWebGL) return;
179 177
180 // make sure RDGE has the correct context 178 // make sure RDGE has the correct context
181 g_Engine.setContext( world.getCanvas().rdgeid ); 179 RDGE.globals.engine.setContext( world.getCanvas().rdgeid );
182 180
183 // create the gl buffer 181 // create the gl buffer
184 var gl = world.getGLContext(); 182 var gl = world.getGLContext();
@@ -350,7 +348,7 @@ var Circle = function GLCircle() {
350 348
351 this.recalcTexMapCoords( vrts, uvs ); 349 this.recalcTexMapCoords( vrts, uvs );
352 350
353 return ShapePrimitive.create(vrts, nrms, uvs, indices, g_Engine.getContext().renderer.TRIANGLES, index); 351 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index);
354 }; 352 };
355 353
356 this.generateOvalRing = function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { 354 this.generateOvalRing = function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) {
@@ -407,7 +405,7 @@ var Circle = function GLCircle() {
407 405
408 this.recalcTexMapCoords( vrts, uvs ); 406 this.recalcTexMapCoords( vrts, uvs );
409 407
410 return ShapePrimitive.create(vrts, nrms, uvs, indices, g_Engine.getContext().renderer.TRIANGLE_STRIP, indices.length); 408 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length);
411 }; 409 };
412 410
413 this.render = function() { 411 this.render = function() {
@@ -651,100 +649,6 @@ var Circle = function GLCircle() {
651 this.importMaterialsJSON( jObj.materials ); 649 this.importMaterialsJSON( jObj.materials );
652 }; 650 };
653 651
654
655 this.export = function()
656 {
657 var rtnStr = "type: " + this.geomType() + "\n";
658
659 rtnStr += "xoff: " + this._xOffset + "\n";
660 rtnStr += "yoff: " + this._yOffset + "\n";
661 rtnStr += "width: " + this._width + "\n";
662 rtnStr += "height: " + this._height + "\n";
663 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
664 rtnStr += "innerRadius: " + this._innerRadius + "\n";
665 rtnStr += "strokeStyle: " + this._strokeStyle + "\n";
666
667 if(this._strokeColor.gradientMode) {
668 rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n";
669 rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n";
670 } else {
671 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
672 }
673
674 if(this._fillColor.gradientMode) {
675 rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n";
676 rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n";
677 } else {
678 rtnStr += "fillColor: " + String(this._fillColor) + "\n";
679 }
680
681 rtnStr += "strokeMat: ";
682 if (this._strokeMaterial) {
683 rtnStr += this._strokeMaterial.getName();
684 } else {
685 rtnStr += MaterialsModel.getDefaultMaterialName();
686 }
687
688 rtnStr += "\n";
689
690 rtnStr += "fillMat: ";
691 if (this._fillMaterial) {
692 rtnStr += this._fillMaterial.getName();
693 } else {
694 rtnStr += MaterialsModel.getDefaultMaterialName();
695 }
696 rtnStr += "\n";
697
698 rtnStr += this.exportMaterials();
699
700 return rtnStr;
701 };
702
703 this.import = function( importStr ) {
704 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
705 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) );
706 this._width = Number( this.getPropertyFromString( "width: ", importStr ) );
707 this._height = Number( this.getPropertyFromString( "height: ", importStr ) );
708 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) );
709 this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) );
710 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
711 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
712 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
713 if(importStr.indexOf("fillGradientMode: ") < 0) {
714 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
715 } else {
716 this._fillColor = {};
717 this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr );
718 this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr ));
719 }
720
721 if(importStr.indexOf("strokeGradientMode: ") < 0)
722 {
723 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
724 } else {
725 this._strokeColor = {};
726 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
727 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
728 }
729
730 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
731 if (!strokeMat) {
732 console.log( "object material not found in library: " + strokeMaterialName );
733 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
734 }
735
736 this._strokeMaterial = strokeMat;
737
738 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
739 if (!fillMat) {
740 console.log( "object material not found in library: " + fillMaterialName );
741 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
742 }
743 this._fillMaterial = fillMat;
744
745 this.importMaterials( importStr );
746 };
747
748 this.collidesWithPoint = function( x, y ) { 652 this.collidesWithPoint = function( x, y ) {
749// if(x < this._xOffset) return false; 653// if(x < this._xOffset) return false;
750// if(x > (this._xOffset + this._width)) return false; 654// if(x > (this._xOffset + this._width)) return false;
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.importMater