From 50125608bba2ebfae24c1e13ec030fe7a7128158 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 29 Mar 2012 17:13:28 -0700 Subject: merge from main --- js/panels/Splitter.js | 2 +- .../TimelinePanel.reel/css/TimelinePanel.css | 4 +- .../animations-presets.reel/animations-presets.js | 47 ++++++++++++++++++++- js/panels/presets/default-animation-presets.js | 2 + js/panels/presets/default-style-presets.js | 11 +++-- js/panels/presets/default-transition-presets.js | 8 ++++ .../presets/style-presets.reel/style-presets.js | 49 +++++++++++++++++++++- .../transitions-presets.js | 20 ++++++++- js/panels/resize-composer.js | 34 ++++----------- 9 files changed, 138 insertions(+), 39 deletions(-) diff --git a/js/panels/Splitter.js b/js/panels/Splitter.js index 6791e0d5..e92cb2dd 100755 --- a/js/panels/Splitter.js +++ b/js/panels/Splitter.js @@ -55,7 +55,7 @@ exports.Splitter = Montage.create(Component, { }, set: function(value) { this._collapsed = value; - this.needsDraw = true; + this.application.localStorage.setItem(this.element.getAttribute("data-montage-id"), {"version": this.version, "value": value}); } }, diff --git a/js/panels/Timeline/TimelinePanel.reel/css/TimelinePanel.css b/js/panels/Timeline/TimelinePanel.reel/css/TimelinePanel.css index 067285ae..129b9771 100644 --- a/js/panels/Timeline/TimelinePanel.reel/css/TimelinePanel.css +++ b/js/panels/Timeline/TimelinePanel.reel/css/TimelinePanel.css @@ -10,12 +10,12 @@ height: 100%; } .maintimeline{ + border-style: double; -webkit-box-flex: 1; display: -webkit-box; - -webkit-box-orient: horizontal; + -webkit-box-orient: horizontal height : 100%; position: relative; - margin-top:1px; } .leftinside{ height: 100%; diff --git a/js/panels/presets/animations-presets.reel/animations-presets.js b/js/panels/presets/animations-presets.reel/animations-presets.js index 6a16da54..ab200212 100644 --- a/js/panels/presets/animations-presets.reel/animations-presets.js +++ b/js/panels/presets/animations-presets.reel/animations-presets.js @@ -22,7 +22,52 @@ exports.AnimationsLibrary = Montage.create(Component, { }, handleNodeActivation: { value: function(presetData) { - this.application.ninja.presetsController.applyPreset(presetData); + //debugger; + var selection = this.application.ninja.selectedElements, + stylesController = this.application.ninja.stylesController, + selectorBase = presetData.selectorBase, + self = this; + + if(!selection || !selection.length || selection.length === 0) { + return false; + } + + selectorBase = stylesController.generateClassName(selectorBase); + + presetData.rules.forEach(function(rule) { + if(rule.isKeyFrameRule) { + this.application.ninja.stylesController.addRule( + '@-webkit-keyframes ' + presetData.selectorBase, + this.stringifyKeys(rule.keys) + ); + } else { + this.application.ninja.stylesController.addRule('.' + selectorBase + rule.selectorSuffix, rule.styles); + } + + }, this); + + selection.forEach(function(el) { + el._element.classList.add(selectorBase); + }, this); + + } + }, + + stringifyKeys : { + value: function(keysArray) { + var keysString = ''; + + keysArray.forEach(function(key) { + var styles = '', style; + + for(style in key.styles) { + styles += style + ':' + key.styles[style] + '; '; + } + + keysString += key.keyText + ' {' + styles + ' }'; + }); + + return keysString; } } }); diff --git a/js/panels/presets/default-animation-presets.js b/js/panels/presets/default-animation-presets.js index b12a94b2..64f91ea6 100644 --- a/js/panels/presets/default-animation-presets.js +++ b/js/panels/presets/default-animation-presets.js @@ -13,6 +13,7 @@ exports.animationPresets = { "text": "Border Morph", "selectorBase" : "border-morph", "rules" : [{ + "selectorSuffix" : "", "styles" : { "-webkit-animation": "border-morph 2s infinite" } @@ -90,6 +91,7 @@ exports.animationPresets = { "text": "Rotater", "selectorBase" : "rotate-with-alpha-keyframes", "rules" : [{ + "selectorSuffix" : "", "styles" : { "-webkit-animation-name": "rotate-with-alpha-keyframes", "-webkit-animation-duration": "5s", diff --git a/js/panels/presets/default-style-presets.js b/js/panels/presets/default-style-presets.js index 10b24ff4..82bec34f 100644 --- a/js/panels/presets/default-style-presets.js +++ b/js/panels/presets/default-style-presets.js @@ -11,9 +11,9 @@ exports.stylePresets = { "children": [ { "text": "Border-Radius", - "id": "njBorderRadius", "selectorBase" : "border-radius-preset", "rules" : [{ + "selectorSuffix" : "", "styles" : { "border-radius": "100px", "border" : "1px solid #333" @@ -22,9 +22,9 @@ exports.stylePresets = { }, { "text": "Drop Shadow", - "id": "njDropShadow", "selectorBase" : "drop-shadow", "rules" : [{ + "selectorSuffix" : "", "styles" : { "box-shadow": "2px 2px 50px rgba(0,0,0,0.5)", "border" : "1px solid #CCC" @@ -33,10 +33,9 @@ exports.stylePresets = { }, { "text": "Fancy Box", - "id": "njFancyBox", "selectorBase" : "fancy-box", "rules" : [{ - "selectorSuffix": "", + "selectorSuffix" : "", "styles" : { "box-shadow": "inset 0 0 0 1px #666, inset 0 0 0 2px rgba(225, 225, 225, 0.4), 0 0 20px -10px #333", "border" : "1px solid #FFF", @@ -51,9 +50,9 @@ exports.stylePresets = { "children": [ { "text": "Italic", - "id": "njItalic", "selectorBase" : "italicize", "rules" : [{ + "selectorSuffix" : "", "styles" : { "font-style": "italic" } @@ -61,9 +60,9 @@ exports.stylePresets = { }, { "text": "Text Shadow", - "id": "njTextShadow", "selectorBase" : "italicize", "rules" : [{ + "selectorSuffix" : "", "styles" : { "text-shadow": "1px 1px 3px #333" } diff --git a/js/panels/presets/default-transition-presets.js b/js/panels/presets/default-transition-presets.js index f8968085..15f4882f 100644 --- a/js/panels/presets/default-transition-presets.js +++ b/js/panels/presets/default-transition-presets.js @@ -13,6 +13,7 @@ exports.transitionPresets = { "text": "Fade In", "selectorBase" : "fade-in", "rules" : [{ + "selectorSuffix": "", "styles" : { "opacity": "0.25", "-webkit-transition": "all 0.4s ease-in" @@ -28,6 +29,7 @@ exports.transitionPresets = { "text": "Fade Out", "selectorBase" : "fade-out", "rules" : [{ + "selectorSuffix": "", "styles" : { "opacity": "1", "-webkit-transition": "all 0.4s ease-in" @@ -46,6 +48,7 @@ exports.transitionPresets = { "text": "Slide Right", "selectorBase" : "slide-right", "rules" : [{ + "selectorSuffix": "", "styles" : { "-webkit-transition": "all 0.4s ease-in" } @@ -60,6 +63,7 @@ exports.transitionPresets = { "text": "Slide Left", "selectorBase" : "slide-left", "rules" : [{ + "selectorSuffix": "", "styles" : { "-webkit-transition": "all 0.4s ease-in" } @@ -74,6 +78,7 @@ exports.transitionPresets = { "text": "Rotate", "selectorBase" : "rotate", "rules" : [{ + "selectorSuffix" : "", "styles" : { "-webkit-transition": "all 0.4s ease-in" } @@ -87,6 +92,7 @@ exports.transitionPresets = { "text": "Scale Up", "selectorBase" : "scale-up", "rules" : [{ + "selectorSuffix" : "", "styles" : { "-webkit-transition": "-webkit-transform 0.4s ease-in" } @@ -101,6 +107,7 @@ exports.transitionPresets = { "text": "Scale Down", "selectorBase" : "scale-down", "rules" : [{ + "selectorSuffix" : "", "styles" : { "-webkit-transition": "-webkit-transform 0.4s ease-in" } @@ -115,6 +122,7 @@ exports.transitionPresets = { "text": "Remove 3D", "selectorBase" : "remove-3d", "rules" : [{ + "selectorSuffix": "", "styles" : { "-webkit-transition": "all 0.4s ease-in" } diff --git a/js/panels/presets/style-presets.reel/style-presets.js b/js/panels/presets/style-presets.reel/style-presets.js index 6a28e069..11f41822 100644 --- a/js/panels/presets/style-presets.reel/style-presets.js +++ b/js/panels/presets/style-presets.reel/style-presets.js @@ -22,13 +22,60 @@ exports.StylesLibrary = Montage.create(Component, { }, handleNodeActivation: { value: function(presetData) { - this.application.ninja.presetsController.applyPreset(presetData, true); + var selection = this.application.ninja.selectedElements, + stylesController = this.application.ninja.stylesController, + selectorBase = presetData.selectorBase, + self = this, className; + + if(!selection || !selection.length || selection.length === 0) { + return false; + } + + function setStopRuleSelector(selector) { + self.application.ninja + .currentDocument.documentRoot + .elementModel.controller + .changeSelector(self.application.ninja.currentDocument.documentRoot, null, selector); + } + + selectorBase = stylesController.generateClassName(selectorBase); + + presetData.rules.forEach(function(rule) { + stylesController.addRule('.'+selectorBase + rule.selectorSuffix, rule.styles); + }, this); + + selection.forEach(function(el) { + el._element.style.webkitTransition = "all 450ms linear"; + + el._element.addEventListener("webkitTransitionEnd", function presetTransition(e) { + el._element.style.webkitTransition = ''; + setStopRuleSelector("*"); + this.removeEventListener("webkitTransitionEnd", presetTransition, true); + + }, true); + setStopRuleSelector("transitionStopRule"); + el._element.classList.add(selectorBase); + + //// Keep track of elements with presets and don't add duplicates + + }, this); + + } }, handleDragEnd : { value: function(sourceObject) { console.log(sourceObject); } + }, + shouldChangeSelection : { + value : function(controller, newSelection, oldSelection) { + // + //debugger; + console.log('1Handle should change selection'); + return false; + } } + }); diff --git a/js/panels/presets/transitions-presets.reel/transitions-presets.js b/js/panels/presets/transitions-presets.reel/transitions-presets.js index ace38dbb..f7d84085 100644 --- a/js/panels/presets/transitions-presets.reel/transitions-presets.js +++ b/js/panels/presets/transitions-presets.reel/transitions-presets.js @@ -22,7 +22,25 @@ exports.TransitionsLibrary = Montage.create(Component, { }, handleNodeActivation: { value: function(presetData) { - this.application.ninja.presetsController.applyPreset(presetData); + var selection = this.application.ninja.selectedElements, + stylesController = this.application.ninja.stylesController, + selectorBase = presetData.selectorBase, + self = this; + + if(!selection || !selection.length || selection.length === 0) { + return false; + } + + selectorBase = stylesController.generateClassName(selectorBase); + + presetData.rules.forEach(function(rule) { + this.application.ninja.stylesController.addRule('.' + selectorBase + rule.selectorSuffix, rule.styles); + }, this); + + selection.forEach(function(el) { + el._element.classList.add(selectorBase); + }, this); + } } }); diff --git a/js/panels/resize-composer.js b/js/panels/resize-composer.js index 0d1774cd..6e5e89f8 100644 --- a/js/panels/resize-composer.js +++ b/js/panels/resize-composer.js @@ -9,14 +9,6 @@ var Composer = require("montage/ui/composer/composer").Composer; exports.ResizeComposer = Montage.create(Composer, { - xAxis: { - value: true - }, - - yAxis: { - value: true - }, - enabled : { enumerable: false, value: true @@ -77,7 +69,6 @@ exports.ResizeComposer = Montage.create(Composer, { load: { value: function() { this.element.addEventListener("mousedown", this, true); - this.element.addEventListener("dblclick", this, true); } }, @@ -113,29 +104,18 @@ exports.ResizeComposer = Montage.create(Composer, { captureMousemove: { value: function(e) { - if (this.xAxis) { - this._deltaX = e.clientX - this._startX; - } - else { - this._deltaX = 0; - } - if (this.yAxis) { - this._deltaY = e.clientY - this._startY; - } - else { - this._deltaY = 0; - } + this._deltaX = e.clientX - this._startX; + this._deltaY = e.clientY - this._startY; this._executeEvent("resizeMove"); } }, - captureDblclick: { - value:function(e) { - this._reset(); - this._executeEvent("resizeReset"); + deserializedFromTemplate: { + value: function() { + if (this.component) { + this.component.addComposer(this); + } } } - - }); \ No newline at end of file -- cgit v1.2.3 From dc9650af5760b1f93d6e93a383eabceacfdc0ad8 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 15:40:25 -0700 Subject: Snapping fixes. --- js/lib/geom/line.js | 70 --------------------------------------- js/tools/Translate3DToolBase.js | 25 ++++++++++---- js/tools/TranslateObject3DTool.js | 21 ++++++------ js/tools/modifier-tool-base.js | 14 ++++++-- 4 files changed, 41 insertions(+), 89 deletions(-) diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js index e839e229..1848218d 100755 --- a/js/lib/geom/line.js +++ b/js/lib/geom/line.js @@ -140,76 +140,6 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok this.importMaterialsJSON( jObj.materials ); }; - this.export = function() { - var rtnStr = "type: " + this.geomType() + "\n"; - - rtnStr += "xoff: " + this._xOffset + "\n"; - rtnStr += "yoff: " + this._yOffset + "\n"; - rtnStr += "width: " + this._width + "\n"; - rtnStr += "height: " + this._height + "\n"; - rtnStr += "xAdj: " + this._xAdj + "\n"; - rtnStr += "yAdj: " + this._yAdj + "\n"; - rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; - - if(this._strokeColor.gradientMode) { - rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n"; - rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n"; - } else { - rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; - } - - rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; - rtnStr += "slope: " + String(this._slope) + "\n"; - - rtnStr += "strokeMat: "; - if (this._strokeMaterial) { - rtnStr += this._strokeMaterial.getName(); - } else { - rtnStr += MaterialsModel.getDefaultMaterialName(); - } - - rtnStr += "\n"; - return rtnStr; - }; - - this.import = function( importStr ) { - this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); - this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); - this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); - this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); - this._xAdj = Number( this.getPropertyFromString( "xAdj: ", importStr ) ); - this._yAdj = Number( this.getPropertyFromString( "yAdj: ", importStr ) ); - this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); - var slope = this.getPropertyFromString( "slope: ", importStr ); - - if(isNaN(Number(slope))) { - this._slope = slope; - } else { - this._slope = Number(slope); - } - - var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); - this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); - - if(importStr.indexOf("strokeGradientMode: ") < 0) - { - this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); - } else { - this._strokeColor = {}; - this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr ); - this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr )); - } - - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); - if (!strokeMat) { - console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); - } - - this._strokeMaterial = strokeMat; - - }; - /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 07b6d04d..18e2b610 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -29,6 +29,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, modifyElements : { value : function(data, event) { + //console.log( "modifyElements, data: " + data.pt0 + " => " + data.pt1 ); + // form the translation vector and post translate the matrix by it. var delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); if(this._handleMode !== null) @@ -66,15 +68,12 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, delta[0] = 0; delta[1] = 0; } - else - { - delta[2] = 0; - } this._delta = delta.slice(0); } var transMat = Matrix.Translation( delta ); + //console.log( "Translate: " + delta ); if(this._inLocalMode && (this._targets.length === 1) ) { this._translateLocally(transMat); @@ -134,6 +133,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, // We will only translate single elements locally _translateLocally: { value: function (transMat) { + //console.log( "_translateLocally, startMat: " + this._startMat ); + //console.log( "_translateLocally, transMat: " + transMat ); + //console.log( "_translateLocally, startMat: " + this._startMat + ", transMat: " + transMat ); var mat = glmat4.multiply(this._startMat, transMat, []); viewUtils.setMatrixForElement( this._target, mat, true ); if(this._mode !== 1) @@ -145,14 +147,22 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, transMat: " + transMat ); var len = this._targets.length, i = 0, item, elt, - curMat, + curMat = viewUtils.getMatrixFromElement( this._target ), matInv = glmat4.inverse(this._startMat, []), nMat = glmat4.multiply(transMat, this._startMat, [] ), qMat = glmat4.multiply(matInv, nMat, []); + + if (this._mode === 1) + { + var curInv = glmat4.inverse( curMat, [] ); + transMat = glmat4.multiply( nMat, curInv, [] ); + } var shouldUpdateStartMat = true; @@ -181,6 +191,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, if(shouldUpdateStartMat) { + //console.log( "\t\tshouldUpdateStartMat" ); this._targets[i].mat = curMat; } } @@ -188,7 +199,9 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, }, _updateTargets: { - value: function(addToUndoStack) { + value: function(addToUndoStack) + { + console.log( "_updateTargets" ); var newStyles = [], previousStyles = [], len = this.application.ninja.selectedElements.length; diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 60633e74..7163f005 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -16,6 +16,8 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { initializeSnapping : { value : function(event) { + console.log( "initializeSnapping" ); + this._mouseDownHitRec = null; this._mouseUpHitRec = null; @@ -37,8 +39,6 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { if(this._handleMode === null) { -// this.doSelection(event); - snapManager.enableElementSnap ( true ); snapManager.enableGridSnap ( true ); } @@ -107,16 +107,10 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { } if(this._handleMode === 2) - { - // TODO - not sure how to parameterize point in z-translate mode this.clickedObject = this._target; - this._snapParam = [0, 0, 0]; - } - else - { - // parameterize the snap point on the target - this._snapParam = this.parameterizeSnap( hitRec ); - } + + // parameterize the snap point on the target + this._snapParam = this.parameterizeSnap( hitRec ); if(!this._dragPlane) { @@ -132,6 +126,11 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { } + // only do quadrant snapping if the 4 corners of the element are in the drag plane + + var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + this._shouldUseQuadPt = (sign == 0); + var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); this._mouseDownHitRec = wpHitRec; this._mouseUpHitRec = null; diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 94b806fd..07b28747 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -25,6 +25,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { _snapParam: { value: null }, _snapIndex: { value: -1 }, _useQuadPt: { value: false }, + _shouldUseQuadPt: { value: false }, // we set snapping capabilities depending on the tool. // The following variables are set in a tool's initializeSnapping method called on mouse down. @@ -175,6 +176,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { // } } + // only do quadrant snapping if the 4 corners of the element are in the drag plane + var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + this._shouldUseQuadPt = (sign == 0) + var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); this._mouseDownHitRec = wpHitRec; this._mouseUpHitRec = null; @@ -236,6 +241,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } } + //console.log( "ParameterizeSnap: " + paramPt ); return paramPt; } }, @@ -284,14 +290,16 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { y = x0 + ty*dy, z = 0.0; var localPt = [x,y,z]; + globalPt = viewUtils.localToGlobal( localPt, elt ); // add in the delta var hitPt = this.GetObjectHitPoint(); var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); - var delta = [xEvent-scrPt[0], yEvent-scrPt[1]]; + var delta = [xEvent-scrPt[0], yEvent-scrPt[1], 0-scrPt[2]]; globalPt[0] += delta[0]; globalPt[1] += delta[1]; + globalPt[2] += delta[2]; } return globalPt; @@ -517,7 +525,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { // do the snap var quadPt; - if (mouseIsDown) + if (mouseIsDown && !do3DSnap && this._shouldUseQuadPt && (this._handleMode === null) && (this._mode === 0)) quadPt = this.GetQuadrantSnapPoint(x,y); var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); @@ -806,6 +814,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { HandleLeftButtonDown: { value: function(event) { + console.log( "modifier-tool-base.HandleLeftButtonDown" ); + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); this.downPoint.x = point.x; this.downPoint.y = point.y; -- cgit v1.2.3 From 8423cceac4f45f3d08d92ae969d17d488674717f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 16:28:09 -0700 Subject: Translate 3D fix for multi-selection Z translation --- js/tools/Translate3DToolBase.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 18e2b610..bd2b3af1 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -147,8 +147,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); //console.log( "_translateGlobally, transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); var len = this._targets.length, i = 0, item, @@ -160,6 +160,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, if (this._mode === 1) { + if (len > 1) curMat = this._targets[0].mat.slice(); var curInv = glmat4.inverse( curMat, [] ); transMat = glmat4.multiply( nMat, curInv, [] ); } -- cgit v1.2.3 From b6fa38e2680ccce73f4a195f9adffa552f1d237c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 12:37:43 -0700 Subject: turned off translation handles during a multi-object drag. --- js/tools/Translate3DToolBase.js | 175 ++++++++++++++++++++-------------------- js/tools/modifier-tool-base.js | 13 ++- 2 files changed, 100 insertions(+), 88 deletions(-) diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index bd2b3af1..32132c9a 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -73,13 +73,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var transMat = Matrix.Translation( delta ); - //console.log( "Translate: " + delta ); if(this._inLocalMode && (this._targets.length === 1) ) { this._translateLocally(transMat); } else { + console.log( "modifyElements delta: " + delta ); this._translateGlobally(transMat); } } @@ -147,23 +147,23 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { - //console.log( "_translateGlobally, transMat: " + transMat ); - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); var len = this._targets.length, i = 0, item, elt, curMat = viewUtils.getMatrixFromElement( this._target ), - matInv = glmat4.inverse(this._startMat, []), - nMat = glmat4.multiply(transMat, this._startMat, [] ), - qMat = glmat4.multiply(matInv, nMat, []); - - if (this._mode === 1) - { - if (len > 1) curMat = this._targets[0].mat.slice(); - var curInv = glmat4.inverse( curMat, [] ); - transMat = glmat4.multiply( nMat, curInv, [] ); - } + matInv = glmat4.inverse(this._startMat, []), + nMat = glmat4.multiply(transMat, this._startMat, [] ), + qMat = glmat4.multiply(matInv, nMat, []); + + if (this._mode === 1) + { + if (len > 1) curMat = this._targets[0].mat.slice(); + var curInv = glmat4.inverse( curMat, [] ); + transMat = glmat4.multiply( nMat, curInv, [] ); + } var shouldUpdateStartMat = true; @@ -185,27 +185,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, // glmat4.multiply(curMat, qMat, curMat); // // viewUtils.setMatrixForElement( elt, curMat, true); - curMat[12] += transMat[12]; - curMat[13] += transMat[13]; - curMat[14] += transMat[14]; - viewUtils.setMatrixForElement( elt, curMat, true); + curMat[12] += transMat[12]; + curMat[13] += transMat[13]; + curMat[14] += transMat[14]; + viewUtils.setMatrixForElement( elt, curMat, true); if(shouldUpdateStartMat) { - //console.log( "\t\tshouldUpdateStartMat" ); + //console.log( "\t\tshouldUpdateStartMat" ); this._targets[i].mat = curMat; } } } }, - _updateTargets: { + _updateTargets: { value: function(addToUndoStack) - { - console.log( "_updateTargets" ); - var newStyles = [], - previousStyles = [], - len = this.application.ninja.selectedElements.length; + { + //console.log( "_updateTargets" ); + var newStyles = [], + previousStyles = [], + len = this.application.ninja.selectedElements.length; this._targets = []; for(var i = 0; i < len; i++) { @@ -215,47 +215,47 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var curMatInv = glmat4.inverse(curMat, []); this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); - if(addToUndoStack) - { - var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; + if(addToUndoStack) + { + var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)}; - var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; + var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; - previousStyles.push(previousStyleStr); - newStyles.push(newStyleStr); - } + previousStyles.push(previousStyleStr); + newStyles.push(newStyleStr); + } } if(addToUndoStack) { - ElementsMediator.set3DProperties(this.application.ninja.selectedElements, - newStyles, - "Change", - "translateTool", - previousStyles - ); - if(this._origin && this._delta) - { - if(this._handleMode !== null) - { - this._origin[this._handleMode] += this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } - this._delta = null; - } - // Save previous value for undo/redo - this._undoArray = []; - for(i = 0, len = this._targets.length; i < len; i++) - { - var elt = this._targets[i].elt; - var _mat = viewUtils.getMatrixFromElement(elt); - var _dist = viewUtils.getPerspectiveDistFromElement(elt); - this._undoArray.push({mat:_mat, dist:_dist}); - } + ElementsMediator.set3DProperties(this.application.ninja.selectedElements, + newStyles, + "Change", + "translateTool", + previousStyles + ); + if(this._origin && this._delta) + { + if(this._handleMode !== null) + { + this._origin[this._handleMode] += this._delta; + } + else + { + this._origin[0] += this._delta[0]; + this._origin[1] += this._delta[1]; + } + } + this._delta = null; + } + // Save previous value for undo/redo + this._undoArray = []; + for(i = 0, len = this._targets.length; i < len; i++) + { + var elt = this._targets[i].elt; + var _mat = viewUtils.getMatrixFromElement(elt); + var _dist = viewUtils.getPerspectiveDistFromElement(elt); + this._undoArray.push({mat:_mat, dist:_dist}); + } } }, @@ -305,27 +305,27 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } else { - if(this._origin) - { - if(this._delta) - { - if(this._handleMode !== null) - { + if(this._origin) + { + if(this._delta) + { + if(this._handleMode !== null) + { // this._origin[this._handleMode] = this._delta; - } - else - { - this._origin[0] += this._delta[0]; - this._origin[1] += this._delta[1]; - } - } - } - else - { - this._origin = drawUtils._selectionCtr.slice(0); - this._origin[0] += this.application.ninja.stage.userContentLeft; - this._origin[1] += this.application.ninja.stage.userContentTop; - } + } + else + { + this._origin[0] += this._delta[0]; + this._origin[1] += this._delta[1]; + } + } + } + else + { + this._origin = drawUtils._selectionCtr.slice(0); + this._origin[0] += this.application.ninja.stage.userContentLeft; + this._origin[1] += this.application.ninja.stage.userContentTop; + } } } } @@ -364,10 +364,13 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } // Draw tool handles - - this._updateHandlesOrigin(); + + this._updateHandlesOrigin(); var base = this._origin.slice(0); +// if (this.isDrawing) +// console.log( "handle origin: " + base ); + var len = this.application.ninja.selectedElements.length; var lMode = this._inLocalMode; if(len === 1) @@ -397,10 +400,10 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._handles[1]._strokeStyle = 'rgba(0, 255, 0, 0.2)'; break; } - if( delta && (len > 1) ) - { - base[this._handleMode] += ~~delta; - } + if( delta && (len > 1) ) + { + base[this._handleMode] += ~~delta; + } } this._handles[0].draw(base, item, lMode); this._handles[1].draw(base, item, lMode); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 07b28747..e684f58a 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -852,8 +852,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } } - this.DrawHandles(this._delta); - if(this._canSnap) + if (!this._isDrawing || (this.application.ninja.selectedElements.length == 1)) + this.DrawHandles(this._delta); + + if(this._canSnap) { snapManager.drawLastHit(); } @@ -892,6 +894,13 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { this._delta = null; } this.endDraw(event); + + this.application.ninja.stage.draw(); + if (this._targets && (this._targets.length > 1)) + { + this._origin = null; + this._updateHandlesOrigin(); + } this.DrawHandles(); } }, -- cgit v1.2.3 From 16f62ca09cc428043e8fef8bdeea11a989e62bc0 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 16:29:16 -0700 Subject: Cap fix for vecUtils. --- js/tools/TranslateObject3DTool.js | 3 ++- js/tools/modifier-tool-base.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index 7163f005..867bec7f 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -7,6 +7,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, + vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { @@ -128,7 +129,7 @@ exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { // only do quadrant snapping if the 4 corners of the element are in the drag plane - var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0); var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index e684f58a..b6589cba 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -177,7 +177,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } // only do quadrant snapping if the 4 corners of the element are in the drag plane - var sign = MathUtils.fpSign( VecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); + var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0) var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); -- cgit v1.2.3 From 96bfeee2e6b735b87e8482d6e2cf24d5224c6417 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 5 Apr 2012 17:03:14 -0700 Subject: translate3DObject tool fixes. --- js/helper-classes/3D/hit-record.js | 46 +++++++++++++++++++++++++++++++++++- js/helper-classes/3D/snap-manager.js | 1 + js/helper-classes/3D/view-utils.js | 45 ++++++++++++++++++----------------- js/tools/Translate3DToolBase.js | 7 +++--- js/tools/modifier-tool-base.js | 2 ++ 5 files changed, 75 insertions(+), 26 deletions(-) diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js index 2c60adc6..96f87c24 100755 --- a/js/helper-classes/3D/hit-record.js +++ b/js/helper-classes/3D/hit-record.js @@ -284,6 +284,50 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype, return str; } - } + }, + + test: + { + value: function() + { + var elt = this.getElement(); + var stage = viewUtils.getStage(); + if (elt === stage) return; + + var localPt = this.calculateElementPreTransformScreenPoint(); + var stageWorldPt = this.calculateStageWorldPoint(); + var globalPt = this.getScreenPoint(); + var err = false; + + var test1 = viewUtils.localToGlobal( localPt, elt ); + var dist = vecUtils.vecDist(3, test1, globalPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 1 ***** " + dist + ", localPt: " + localPt ); + } + + var stageWorldToGlobal = viewUtils.getStageWorldToGlobalMatrix(); + var test2 = MathUtils.transformAndDivideHomogeneousPoint( stageWorldPt, stageWorldToGlobal ); + dist = vecUtils.vecDist(3, test2, globalPt); + if (MathUtils.fpSign(dist) != 0) + { + err = true; + console.log( "**** transform error 2 ***** " + dist + ", localPt: " + localPt ); + } + + var localToGlobal = viewUtils.getLocalToGlobalMatrix( elt ); + var globalToLocal = glmat4.inverse( localToGlobal, [] ); + var test3 = MathUtils.transformAndDivideHomogeneousPoint( globalPt, globalToLocal ); + dist = vecUtils.vecDist(3, test3, localPt); + if (MathUtils.fpSign( vecUtils.vecDist(3, test3, localPt)) != 0) + { + err = true; + console.log( "**** transform error 3 ***** " + dist + ", localPt: " + localPt ); + } + + if (!err) console.log( "no hitRecord error" ); + } + } }); diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 9f6b9ed1..8eafa7e9 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -300,6 +300,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { this.deactivateDragPlane(); this.setLastHit( rtnHit ); + //rtnHit.test(); // DEBUG CODE. REMOVE THIS return rtnHit; } }, diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index a72b7906..392de0be 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -112,6 +112,13 @@ exports.ViewUtils = Montage.create(Component, { var mat = this.getMatrixFromElement(elt); var plane = [mat[8], mat[9], mat[10], mat[11]]; + var stage = this.application.ninja.currentDocument.documentRoot; + if (elt === stage) + { + xVec = [1,0,0]; + yVec = [0,1,0]; + } + // The translation value is a point on the plane this.pushViewportObj( elt ); var ptOnPlane = this.getCenterOfProjection(); @@ -137,6 +144,12 @@ exports.ViewUtils = Montage.create(Component, { var stageMat = this.getMatrixFromElement(stage); var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; + if (elt === stage) + { + xVec = [1,0,0]; + yVec = [0,1,0]; + } + var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); @@ -788,35 +801,23 @@ exports.ViewUtils = Montage.create(Component, { } }, - getStageWorldToGlobalMatrix: { - value: function() { + getStageWorldToGlobalMatrix: + { + value: function() + { var stage = this.application.ninja.currentDocument.documentRoot; this.pushViewportObj( stage ); - - // get the matrix to the parent - var mat = Matrix.I(4); - //var projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(stage) ); - var p = this.getPerspectiveDistFromElement(stage); - var projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] ); - projMat[11] = -1; + + // put the point into screen space of the stage - requires + // a translation to the top/left only var cop = this.getCenterOfProjection(); var v2s = Matrix.Translation([cop[0], cop[1], 0]); - //mat = v2s.multiply( projMat ); - mat = glmat4.multiply( v2s, projMat, [] ); - - // offset to the parent - var offset = this.getElementOffset( stage ); - var offMat = Matrix.Translation([offset[0], offset[1], 0]); - //mat = offMat.multiply( mat ); - glmat4.multiply( offMat, mat, mat ); - this.popViewportObj(); - // var mat2 = this.getLocalToGlobalMatrix( stage.parentElement ); - var mat2 = this.getLocalToGlobalMatrix( this._rootElement ); - //var mat = mat2.multiply( mat ); - glmat4.multiply( mat2, mat, mat ); + // append the localToGlobal matrix of the stage. + var mat = this.getLocalToGlobalMatrix( stage ); + glmat4.multiply( mat, v2s ); return mat; } diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 4799b840..2276178c 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -71,6 +71,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._delta = delta.slice(0); } + //console.log( "modifyElements delta: " + delta ); var transMat = Matrix.Translation( delta ); if(this._inLocalMode && (this._targets.length === 1) ) @@ -79,7 +80,6 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, } else { - console.log( "modifyElements delta: " + delta ); this._translateGlobally(transMat); } } @@ -148,7 +148,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, _translateGlobally: { value: function (transMat) { //console.log( "_translateGlobally, transMat: " + transMat ); - //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat ); + //console.log( "_translateGlobally, startMat: " + this._startMat + ", transMat: " + transMat[12] + ", " + transMat[13] + ", " + transMat[14] ); var len = this._targets.length, i = 0, item, @@ -167,7 +167,8 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var shouldUpdateStartMat = true; - if(this._clickedOnStage) + //if (this._clickedOnStage) + if(this._clickedOnStage || ((this._handleMode === 2) && (this._targets.length > 1))) { shouldUpdateStartMat = false; } diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 2c9b484e..f9fd001c 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -405,6 +405,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { var index = this._snapIndex; var pt0; var useViewPoint = (this._inLocalMode && (this._targets.length === 1)); + //console.log( "useViewPoint: " + useViewPoint ); if (this._useQuadPt) { pt0 = this.GetQuadrantPoint(useViewPoint); @@ -427,6 +428,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { pt1 = MathUtils.transformPoint( pt1, this._startMat ); } + //console.log( "getMousePoints, useViewPoint: " + useViewPoint + ", " + pt0 + " => " + pt1 ); return {pt0:pt0, pt1:pt1}; } else -- cgit v1.2.3