aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/helper-classes/3D/math-utils.js11
-rwxr-xr-xjs/tools/PenTool.js95
2 files changed, 89 insertions, 17 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 2f0283a9..35ee8112 100755
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -928,17 +928,18 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
928 return 0; 928 return 0;
929 } 929 }
930 //TODO testing...remove this block 930 //TODO testing...remove this block
931 console.log("getAxisAngleBetween3DVectors Angle: "+angle);
932 if (isNaN(angle)){ 931 if (isNaN(angle)){
933 console.log("getAxisAngleBetween3DVectors Angle is NaN"); 932 console.log("Warning! getAxisAngleBetween3DVectors Angle is NaN");
934 } 933 }
935 //TODO end testing block 934 //TODO end testing block
936 //optionally, if axis is provided, create the axis of rotation as well 935 //optionally, if axis is provided, create the axis of rotation as well
937 var rotAxis = VecUtils.vecCross(3, v1n, v2n); 936 var rotAxis = VecUtils.vecCross(3, v1n, v2n);
938 rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); 937 rotAxis = VecUtils.vecNormalize(3, rotAxis, 1);
939 axis[0] = rotAxis[0]; 938 if (axis){
940 axis[1] = rotAxis[1]; 939 axis[0] = rotAxis[0];
941 axis[2] = rotAxis[2]; 940 axis[1] = rotAxis[1];
941 axis[2] = rotAxis[2];
942 }
942 return angle; 943 return angle;
943 } 944 }
944 }, 945 },
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 8ecc9f79..d18f371a 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -273,14 +273,36 @@ exports.PenTool = Montage.create(ShapeTool, {
273 var swMousePos = hitRec.calculateStageWorldPoint(); 273 var swMousePos = hitRec.calculateStageWorldPoint();
274 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; 274 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5;
275 275
276 this._selectedSubpath.addAnchor(new AnchorPoint()); 276 //check if the mouse click location is close to the existing anchor
277 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 277 var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS);
278 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); 278 if (indexAndCode[0]>=0){
279 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); 279 //the anchor point was hit, so we do not add another anchor
280 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); 280 switch(indexAndCode[1]){
281 //set the mode so that dragging will update the next and previous locations 281 case this._selectedSubpath.SEL_ANCHOR:
282 this._editMode = this.EDIT_PREV_NEXT; 282 this._editMode = this.EDIT_ANCHOR;
283 } 283 break;
284 case this._selectedSubpath.SEL_PREV:
285 this._editMode = this.EDIT_PREV;
286 break;
287 case this._selectedSubpath.SEL_NEXT:
288 this._editMode = this.EDIT_NEXT;
289 break;
290 default:
291 this._editMode = this.EDIT_ANCHOR;
292 console.log("WARNING picked anchor point with incorrect mode");
293 break;
294 }
295
296 } else {
297 this._selectedSubpath.addAnchor(new AnchorPoint());
298 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
299 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]);
300 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]);
301 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]);
302 //set the mode so that dragging will update the next and previous locations
303 this._editMode = this.EDIT_PREV_NEXT;
304 }
305 } //if we have not yet created a canvas for this path
284 306
285 //the selected subpath has a canvas, so test within that canvas' space 307 //the selected subpath has a canvas, so test within that canvas' space
286 else 308 else
@@ -715,14 +737,24 @@ exports.PenTool = Montage.create(ShapeTool, {
715 this._isDrawing = false; 737 this._isDrawing = false;
716 this._editMode = this.EDIT_NONE; 738 this._editMode = this.EDIT_NONE;
717 739
740 //if we're not in edit_path mode and we closed the selected subpath, then we are going to start a new subpath, so we nullify the selected subpath
741 if (this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){
742 this._selectedSubpath = null;
743 }
744
718 if (this._selectedSubpath){ 745 if (this._selectedSubpath){
719 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas 746 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas
747 }else{
748 //clear the canvas
749 this.application.ninja.stage.clearDrawingCanvas();
720 } 750 }
721 751
722 if (!this._trackMouseMoveWhenUp){ 752 if (!this._trackMouseMoveWhenUp){
723 NJevent("disableStageMove"); 753 NJevent("disableStageMove");
724 } 754 }
725 this._hoveredAnchorIndex = -1; 755 this._hoveredAnchorIndex = -1;
756
757
726 } 758 }
727 }, 759 },
728 760
@@ -1256,10 +1288,45 @@ exports.PenTool = Montage.create(ShapeTool, {
1256 } //value: function() { 1288 } //value: function() {
1257 }, //DrawSubpathAnchors { 1289 }, //DrawSubpathAnchors {
1258 1290
1291 deselectPenTool:{
1292 value: function() {
1293 this._selectedSubpath = null;
1294 this._selectedSubpathCanvas = null;
1295 this._selectedSubpathPlaneMat = null;
1296 this._snapTargetIndex = -1;
1297 }
1298 },
1299 //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called
1300 handleOpenDocument: {
1301 value: function() {
1302 this.deselectPenTool();
1303 //clear the canvas
1304 this.application.ninja.stage.clearDrawingCanvas();
1305 }
1306 },
1307 //if the document is switched with the pen tool being active, we do the same thing as when configure(false) is called
1308 handleSwitchDocument: {
1309 value: function() {
1310 this.deselectPenTool();
1311 //clear the canvas
1312 this.application.ninja.stage.clearDrawingCanvas();
1313 }
1314 },
1315 //if the document is closed with the pen tool being active, we do the same thing as when configure(false) is called
1316 handleCloseDocument: {
1317 value: function() {
1318 this.deselectPenTool();
1319 //clear the canvas
1320 this.application.ninja.stage.clearDrawingCanvas();
1321 }
1322 },
1259 1323
1260 Configure: { 1324 Configure: {
1261 value: function (wasSelected) { 1325 value: function (wasSelected) {
1262 if (wasSelected) { 1326 if (wasSelected) {
1327 //first nullify any set values
1328 this.deselectPenTool();
1329
1263 defaultEventManager.addEventListener("resetPenTool", this, false); 1330 defaultEventManager.addEventListener("resetPenTool", this, false);
1264 this.application.ninja.elementMediator.deleteDelegate = this; 1331 this.application.ninja.elementMediator.deleteDelegate = this;
1265 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; 1332 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
@@ -1313,17 +1380,21 @@ exports.PenTool = Montage.create(ShapeTool, {
1313 if (this._trackMouseMoveWhenUp){ 1380 if (this._trackMouseMoveWhenUp){
1314 NJevent("enableStageMove"); 1381 NJevent("enableStageMove");
1315 } 1382 }
1383 this.eventManager.addEventListener("openDocument", this, false);
1384 this.eventManager.addEventListener("switchDocument", this, false);
1385 this.eventManager.addEventListener("closeDocument", this, false);
1316 } //if the pen tool was selected 1386 } //if the pen tool was selected
1317 else { 1387 else {
1318 if (this._trackMouseMoveWhenUp){ 1388 if (this._trackMouseMoveWhenUp){
1319 NJevent("disableStageMove"); 1389 NJevent("disableStageMove");
1320 } 1390 }
1321 this._selectedSubpath = null; 1391 this.deselectPenTool();
1322 this._selectedSubpathCanvas = null;
1323 this._selectedSubpathPlaneMat = null;
1324 this._snapTargetIndex = -1;
1325 defaultEventManager.removeEventListener("resetPenTool", this, false); 1392 defaultEventManager.removeEventListener("resetPenTool", this, false);
1326 this.application.ninja.elementMediator.deleteDelegate = null; 1393 this.application.ninja.elementMediator.deleteDelegate = null;
1394
1395 this.eventManager.removeEventListener("openDocument", this, false);
1396 this.eventManager.removeEventListener("switchDocument", this, false);
1397 this.eventManager.removeEventListener("closeDocument", this, false);
1327 } //if the pen tool was de-selected 1398 } //if the pen tool was de-selected
1328 } 1399 }
1329 }, 1400 },