aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js15
-rwxr-xr-xjs/lib/geom/circle.js113
-rwxr-xr-xjs/lib/geom/geom-obj.js533
-rwxr-xr-xjs/lib/geom/line.js82
-rwxr-xr-xjs/lib/geom/rectangle.js125
-rw-r--r--js/lib/geom/shape-primitive.js4
6 files changed, 285 insertions, 587 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 22209815..743dab85 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -44,6 +44,9 @@ var BrushStroke = function GLBrushStroke() {
44 this._strokeAngle = 0; 44 this._strokeAngle = 0;
45 this._strokeAmountSmoothing = 0; 45 this._strokeAmountSmoothing = 0;
46 46
47 // currently, brush does not support a fill region
48 this.canFill = false;
49
47 //threshold that tells us whether two samples are too far apart 50 //threshold that tells us whether two samples are too far apart
48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5; 51 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5;
49 52
@@ -711,18 +714,6 @@ var BrushStroke = function GLBrushStroke() {
711 this.update(); //after this, the stroke is ready to be rendered 714 this.update(); //after this, the stroke is ready to be rendered
712 }; 715 };
713 716
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) { 717 this.collidesWithPoint = function (x, y, z) {
727 if (x < this._BBoxMin[0]) return false; 718 if (x < this._BBoxMin[0]) return false;
728 if (x > this._BBoxMax[0]) return false; 719 if (x > this._BBoxMax[0]) return false;
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index d48bf98b..1073c2db 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -42,8 +42,8 @@ var Circle = function GLCircle() {
42 42
43 this._strokeWidth = strokeSize; 43 this._strokeWidth = strokeSize;
44 this._innerRadius = innerRadius; 44 this._innerRadius = innerRadius;
45 if (strokeColor) this._strokeColor = strokeColor; 45 this._strokeColor = strokeColor;
46 if (fillColor) this._fillColor = fillColor; 46 this._fillColor = fillColor;
47 47
48 this._strokeStyle = strokeStyle; 48 this._strokeStyle = strokeStyle;
49 } 49 }
@@ -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() {
@@ -633,101 +631,22 @@ var Circle = function GLCircle() {
633 this._strokeStyle = jObj.strokeStyle; 631 this._strokeStyle = jObj.strokeStyle;
634 var strokeMaterialName = jObj.strokeMat; 632 var strokeMaterialName = jObj.strokeMat;
635 var fillMaterialName = jObj.fillMat; 633 var fillMaterialName = jObj.fillMat;
636 this.importMaterialsJSON( jObj.materials );
637 };
638
639 634
640 this.export = function() 635 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
641 { 636 if (!strokeMat) {
642 var rtnStr = "type: " + this.geomType() + "\n"; 637 console.log( "object material not found in library: " + strokeMaterialName );
643 638 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
644 rtnStr += "xoff: " + this._xOffset + "\n";
645 rtnStr += "yoff: " + this._yOffset + "\n";
646 rtnStr += "width: " + this._width + "\n";
647 rtnStr += "height: " + this._height + "\n";
648 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
649 rtnStr += "innerRadius: " + this._innerRadius + "\n";
650 rtnStr += "strokeStyle: " + this._strokeStyle + "\n";
651
652 if(this._strokeColor.gradientMode) {
653 rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n";
654 rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n";
655 } else {
656 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
657 } 639 }
640 this._strokeMaterial = strokeMat;
658 641
659 if(this._fillColor.gradientMode) { 642 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
660 rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n"; 643 if (!fillMat) {
661 rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n"; 644 console.log( "object material not found in library: " + fillMaterialName );
662 } else { 645 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
663 rtnStr += "fillColor: " + String(this._fillColor) + "\n";
664 } 646 }
647 this._fillMaterial = fillMat;
665 648
666 rtnStr += "strokeMat: "; 649 this.importMaterialsJSON( jObj.materials );
667 if (this._strokeMaterial) {
668 rtnStr += this._strokeMaterial.getName();
669 } else {
670 rtnStr += MaterialsModel.getDefaultMaterialName();
671 }
672
673 rtnStr += "\n";
674
675 rtnStr += "fillMat: ";
676 if (this._fillMaterial) {
677 rtnStr += this._fillMaterial.getName();
678 } else {
679 rtnStr += MaterialsModel.getDefaultMaterialName();
680 }
681 rtnStr += "\n";
682
683 rtnStr += this.exportMaterials();
684
685 return rtnStr;
686 };
687
688 this.import = function( importStr ) {
689 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
690 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) );
691 this._width = Number( this.getPropertyFromString( "width: ", importStr ) );
692 this._height = Number( this.getPropertyFromString( "height: ", importStr ) );
693 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) );
694 this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) );
695 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
696 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
697 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
698 if(importStr.indexOf("fillGradientMode: ") < 0) {
699 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
700 } else {
701 this._fillColor = {};
702 this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr );
703 this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr ));
704 }
705
706 if(importStr.indexOf("strokeGradientMode: ") < 0)
707 {
708 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
709 } else {
710 this._strokeColor = {};
711 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
712 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
713 }
714
715 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
716 if (!strokeMat) {
717 console.log( "object material not found in library: " + strokeMaterialName );
718 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
719 }
720
721 this._strokeMaterial = strokeMat;
722
723 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
724 if (!fillMat) {
725 console.log( "object material not found in library: " + fillMaterialName );
726 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
727 }
728 this._fillMaterial = fillMat;
729
730 this.importMaterials( importStr );
731 }; 650 };
732 651
733 this.collidesWithPoint = function( x, y ) { 652 this.collidesWithPoint = function( x, y ) {
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index f1aa9f8a..f2991bdb 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -1,8 +1,8 @@
1/* <copyright> 1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5 </copyright> */
6 6
7var MaterialsModel = require("js/models/materials-model").MaterialsModel; 7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8 8
@@ -14,19 +14,19 @@ var GeomObj = function GLGeomObj() {
14 /////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////
15 // Constants