aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/brush-stroke.js14
-rwxr-xr-xjs/lib/geom/sub-path.js181
2 files changed, 85 insertions, 110 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index e93c9382..2a751a89 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -541,6 +541,10 @@ var BrushStroke = function GLBrushStroke() {
541 var bboxWidth = bboxMax[0] - bboxMin[0]; 541 var bboxWidth = bboxMax[0] - bboxMin[0];
542 var bboxHeight = bboxMax[1] - bboxMin[1]; 542 var bboxHeight = bboxMax[1] - bboxMin[1];
543 543
544 if (!this._canvas){
545 //set the canvas by querying the world
546 this._canvas = this.getWorld().getCanvas();
547 }
544 if (this._canvas) { 548 if (this._canvas) {
545 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth); 549 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth);
546 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight); 550 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight);
@@ -550,7 +554,7 @@ var BrushStroke = function GLBrushStroke() {
550 554
551 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 555 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
552 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 556 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
553 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 557 //this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
554 } 558 }
555 559
556 560
@@ -662,8 +666,8 @@ var BrushStroke = function GLBrushStroke() {
662 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> 666 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto>
663 667
664 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; 668 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]];
665 retObject.planeMat = [this._planeMat[0],this._planeMat[1],this._planeMat[2],this._planeMat[3]]; 669 retObject.planeMat = this._planeMat;
666 retObject.planeMatInv = [this._planeMatInv[0],this._planeMatInv[1],this._planeMatInv[2],this._planeMatInv[3]]; 670 retObject.planeMatInv = this._planeMatInv;
667 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]]; 671 retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]];
668 672
669 //stroke appearance properties 673 //stroke appearance properties
@@ -691,8 +695,8 @@ var BrushStroke = function GLBrushStroke() {
691 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto> 695 this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto>
692 696
693 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]]; 697 this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]];
694 this._planeMat = [jo.planeMat[0], jo.planeMat[1],jo.planeMat[2],jo.planeMat[3]]; 698 this._planeMat = jo.planeMat;
695 this._planeMatInv = [jo.planeMatInv[0],jo.planeMatInv[1],jo.planeMatInv[2],jo.planeMatInv[3]]; 699 this._planeMatInv = jo.planeMatInv;
696 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]]; 700 this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]];
697 701
698 //stroke appearance properties 702 //stroke appearance properties
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index d8d74928..35070915 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -95,6 +95,7 @@ var GLSubpath = function GLSubpath() {
95 this._planeMat = null; 95 this._planeMat = null;
96 this._planeMatInv = null; 96 this._planeMatInv = null;
97 this._planeCenter = null; 97 this._planeCenter = null;
98 this._dragPlane = null;
98 99
99 //used to query what the user selected, OR-able for future extensions 100 //used to query what the user selected, OR-able for future extensions
100 this.SEL_NONE = 0; //nothing was selected 101 this.SEL_NONE = 0; //nothing was selected
@@ -130,7 +131,10 @@ var GLSubpath = function GLSubpath() {
130 // get the world 131 // get the world
131 var world = this.getWorld(); 132 var world = this.getWorld();
132 if (!world) throw( "null world in subpath render" ); 133 if (!world) throw( "null world in subpath render" );
133 134 if (!this._canvas){
135 //set the canvas by querying the world
136 this._canvas = this.getWorld().getCanvas();
137 }
134 // get the context 138 // get the context
135 var ctx = world.get2DContext(); 139 var ctx = world.get2DContext();
136 if (!ctx) throw ("null context in subpath render"); 140 if (!ctx) throw ("null context in subpath render");
@@ -145,42 +149,19 @@ var GLSubpath = function GLSubpath() {
145 //build the coordinates of the samples in 2D (canvas) space (localDirty bit checked in buildLocalCoord 149 //build the coordinates of the samples in 2D (canvas) space (localDirty bit checked in buildLocalCoord
146 this.buildLocalCoord(); 150 this.buildLocalCoord();
147 151
148 // 152 //figure the size of the area we will draw into
149 var bboxWidth=0, bboxHeight=0; 153 var bboxWidth=0, bboxHeight=0;
150 //var bboxMid=[0,0,0];
151 if (useLocalCoord){ 154 if (useLocalCoord){
152 bboxWidth = this._LocalBBoxMax[0] - this._LocalBBoxMin[0]; 155 bboxWidth = this._LocalBBoxMax[0] - this._LocalBBoxMin[0];
153 bboxHeight = this._LocalBBoxMax[1] - this._LocalBBoxMin[1]; 156 bboxHeight = this._LocalBBoxMax[1] - this._LocalBBoxMin[1];
154 //bboxMid = [0.5 * (this._LocalBBoxMax[0] + this._LocalBBoxMin[0]), 0.5 * (this._LocalBBoxMax[1] + this._LocalBBoxMin[1]), 0.5 * (this._LocalBBoxMax[2] + this._LocalBBoxMin[2])];
155 } 157 }
156 else { 158 else {
157 var bboxMin = this.getBBoxMin(); 159 var bboxMin = this.getBBoxMin();
158 var bboxMax = this.getBBoxMax(); 160 var bboxMax = this.getBBoxMax();
159 bboxWidth = bboxMax[0] - bboxMin[0]; 161 bboxWidth = bboxMax[0] - bboxMin[0];
160 bboxHeight = bboxMax[1] - bboxMin[1]; 162 bboxHeight = bboxMax[1] - bboxMin[1];
161 //bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
162 } 163 }
163 164
164 if (this._canvas) {
165 /*
166 var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
167 //compute the plane center as the midpoint of the local bbox converted to stage world space
168 var planeCenter = ViewUtils.localToStageWorld(bboxMid, this._canvas);
169 planeCenter[0]+=400; planeCenter[1]+=300; //todo replace these lines with the correct call for the offset
170 console.log("PEN: local bboxMid: "+ bboxMid +", stage-world bboxMid: "+ planeCenter);
171 var newLeft = planeCenter[0] - 0.5*bboxWidth;
172 console.log("PEN: newLeft: "+ newLeft +", bboxWidth: "+bboxWidth);
173 newLeft = Math.round(newLeft);//Math.round(this._planeCenter[0] - 0.5 * bboxWidth);
174 console.log("PEN: newLeft rounded: "+ newLeft);
175 var newTop = Math.round(planeCenter[1] - 0.5 * bboxHeight);//Math.round(this._planeCenter[1] - 0.5 * bboxHeight);
176 //assign the new position, width, and height as the canvas dimensions through the canvas controller
177 CanvasController.setProperty(this._canvas, "left", newLeft+"px");
178 CanvasController.setProperty(this._canvas, "top", newTop+"px");
179 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
180 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
181 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
182 */
183 }
184 ctx.save(); 165 ctx.save();
185 ctx.clearRect(0, 0, bboxWidth, bboxHeight); 166 ctx.clearRect(0, 0, bboxWidth, bboxHeight);
186 167
@@ -354,6 +335,10 @@ GLSubpath.prototype.setPlaneMatrix = function(planeMat){
354 this._planeMat = planeMat; 335 this._planeMat = planeMat;
355}; 336};
356 337
338GLSubpath.prototype.setDragPlane = function(p){
339 this._dragPlane = p;
340};
341
357GLSubpath.prototype.setPlaneMatrixInverse = function(planeMatInv){ 342GLSubpath.prototype.setPlaneMatrixInverse = function(planeMatInv){
358 this._planeMatInv = planeMatInv; 343 this._planeMatInv = planeMatInv;
359}; 344};
@@ -867,6 +852,12 @@ GLSubpath.prototype.getStrokeWidth = function () {
867}; 852};
868 853
869GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){ 854GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){
855 if (!this._canvas){
856 if (!this.getWorld())
857 return; //cannot do anything if there is no world
858 //set the canvas by querying the world
859 this._canvas = this.getWorld().getCanvas();
860 }
870 //check if the canvas was translated 861 //check if the canvas was translated
871 var penCanvasCurrentLeft = parseInt(elemMediator.getProperty(this._canvas, "left"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "left")); 862 var penCanvasCurrentLeft = parseInt(elemMediator.getProperty(this._canvas, "left"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "left"));
872 var penCanvasCurrentTop = parseInt(elemMediator.getProperty(this._canvas, "top"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "top")); 863 var penCanvasCurrentTop = parseInt(elemMediator.getProperty(this._canvas, "top"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "top"));
@@ -1516,95 +1507,75 @@ GLSubpath.prototype.isPointInQuad2D = function(r0,r1,r2,r3,p){
1516 return false; 1507 return false;
1517}; 1508};
1518 1509
1519GLSubpath.prototype.export = function() { 1510GLSubpath.prototype.exportJSON = function() {
1520 var rtnStr = "type: " + this.geomType() + "\n"; 1511 var retObject= new Object();
1521 1512 //the type of this object
1522 rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; 1513 retObject.type = this.geomType();
1523 rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; 1514 retObject.geomType = retObject.type;
1524
1525 rtnStr += "strokeMat: ";
1526 if (this._strokeMaterial)
1527 rtnStr += this._strokeMaterial.getName();
1528 else
1529 rtnStr += "flatMaterial";
1530 rtnStr += "\n";
1531
1532 rtnStr += "fillMat: ";
1533 if (this._fillMaterial)
1534 rtnStr += this._fillMaterial.getName();
1535 else
1536 rtnStr += "flatMaterial";
1537 rtnStr += "\n";
1538
1539 var isClosedStr = "false";
1540 if (this._isClosed)
1541 isClosedStr = "true";
1542 rtnStr += "isClosed: " + isClosedStr + "\n";
1543
1544 //add the anchor points
1545 var numAnchors = this._Anchors.length;
1546 rtnStr += "numAnchors: " + numAnchors + "\n";
1547 for (var i=0;i<numAnchors;i++){
1548 rtnStr += "anchor"+i+"x: " + this._Anchors[i].getPosX() + "\n";
1549 rtnStr += "anchor"+i+"y: " + this._Anchors[i].getPosY() + "\n";
1550 rtnStr += "anchor"+i+"z: " + this._Anchors[i].getPosZ() + "\n";
1551
1552 rtnStr += "anchor"+i+"prevx: " + this._Anchors[i].getPrevX() + "\n";
1553 rtnStr += "anchor"+i+"prevy: " + this._Anchors[i].getPrevY() + "\n";
1554 rtnStr += "anchor"+i+"prevz: " + this._Anchors[i].getPrevZ() + "\n";
1555
1556 rtnStr += "anchor"+i+"nextx: " + this._Anchors[i].getNextX() + "\n";
1557 rtnStr += "anchor"+i+"nexty: " + this._Anchors[i].getNextY() + "\n";
1558 rtnStr += "anchor"+i+"nextz: " + this._Anchors[i].getNextZ() + "\n";
1559 }
1560 return rtnStr;
1561};
1562 1515
1563GLSubpath.prototype.import = function( importStr ) { 1516 //the geometry for this object (anchor points in stage world space)
1564 this._strokeWidth = this.getPropertyFromString( "strokeWidth: ", importStr ); 1517 retObject.anchors = this._Anchors.slice(0);
1565 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); 1518 retObject.isClosed = this._isClosed;
1566 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
1567 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
1568
1569 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
1570 if (!strokeMat) {
1571 console.log( "object material not found in library: " + strokeMaterialName );
1572 strokeMat = new FlatMaterial();
1573 }
1574 1519
1575 this._strokeMaterial = strokeMat;