diff options
Diffstat (limited to 'js/helper-classes')
-rw-r--r-- | js/helper-classes/3D/draw-utils.js | 47 | ||||
-rw-r--r-- | js/helper-classes/3D/math-utils.js | 54 | ||||
-rw-r--r-- | js/helper-classes/3D/snap-manager.js | 15 | ||||
-rw-r--r-- | js/helper-classes/RDGE/GLBrushStroke.js | 1 | ||||
-rw-r--r-- | js/helper-classes/RDGE/GLSubpath.js | 1 |
5 files changed, 82 insertions, 36 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index fd96af4d..c07391db 100644 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js | |||
@@ -71,6 +71,9 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
71 | 71 | ||
72 | _selectionCtr : {value: null, writable: true }, | 72 | _selectionCtr : {value: null, writable: true }, |
73 | 73 | ||
74 | // Properties that require element planes to be updated | ||
75 | _updatePlaneProps : {value: ["matrix", "left", "top", "width", "height"], writable: false }, | ||
76 | |||
74 | /////////////////////////////////////////////////////////////////////// | 77 | /////////////////////////////////////////////////////////////////////// |
75 | // Property accessors | 78 | // Property accessors |
76 | /////////////////////////////////////////////////////////////////////// | 79 | /////////////////////////////////////////////////////////////////////// |
@@ -107,6 +110,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
107 | 110 | ||
108 | this.eventManager.addEventListener("elementAdded", this, false); | 111 | this.eventManager.addEventListener("elementAdded", this, false); |
109 | this.eventManager.addEventListener("elementDeleted", this, false); | 112 | this.eventManager.addEventListener("elementDeleted", this, false); |
113 | this.eventManager.addEventListener("deleteSelection", this, false); | ||
110 | this.eventManager.addEventListener("elementChange", this, false); | 114 | this.eventManager.addEventListener("elementChange", this, false); |
111 | } | 115 | } |
112 | }, | 116 | }, |
@@ -124,11 +128,44 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
124 | } | 128 | } |
125 | }, | 129 | }, |
126 | 130 | ||
131 | handleDeleteSelection: { | ||
132 | value: function(event) { | ||
133 | this.drawWorkingPlane(); | ||
134 | } | ||
135 | }, | ||
136 | |||
137 | _shouldUpdatePlanes: { | ||
138 | value: function(props) { | ||
139 | if(!props) | ||
140 | { | ||
141 | return false; | ||
142 | } | ||
143 | else if (typeof props === "string") | ||
144 | { | ||
145 | return (this._updatePlaneProps.indexOf(props) !== -1); | ||
146 | } | ||
147 | |||
148 | for (var p in props) | ||
149 | { | ||
150 | if(this._updatePlaneProps.indexOf(p) !== -1) | ||
151 | { | ||
152 | return true; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return false; | ||
157 | } | ||
158 | }, | ||
127 | 159 | ||
160 | // TODO - Check why handleElementChange is being fired before handleAddElement | ||
128 | handleElementChange: { | 161 | handleElementChange: { |
129 | value: function(event) { | 162 | value: function(event) { |
163 | if(!event.detail || !event.detail.data) | ||
164 | { | ||
165 | return; | ||
166 | } | ||
130 | var els = event.detail.data.els; | 167 | var els = event.detail.data.els; |
131 | if(els) | 168 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) |
132 | { | 169 | { |
133 | var len = els.length, | 170 | var len = els.length, |
134 | i = 0, | 171 | i = 0, |
@@ -138,10 +175,15 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
138 | for(i=0; i < len; i++) { | 175 | for(i=0; i < len; i++) { |
139 | item = els[i]; | 176 | item = els[i]; |
140 | el = item._element || item; | 177 | el = item._element || item; |
141 | el.elementModel.props3D.elementPlane.init(); | 178 | if(el.elementModel.props3D.elementPlane) |
179 | { | ||
180 | el.elementModel.props3D.elementPlane.init(); | ||
181 | } | ||
142 | } | 182 | } |
143 | 183 | ||
184 | this.application.ninja.stage.layout.draw(); | ||
144 | this.drawWorkingPlane(); | 185 | this.drawWorkingPlane(); |
186 | this.draw3DCompass(); | ||
145 | } | 187 | } |
146 | } | 188 | } |
147 | }, | 189 | }, |
@@ -1065,7 +1107,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
1065 | var tmpCanvas = this.application.ninja.stage.canvas; | 1107 | var tmpCanvas = this.application.ninja.stage.canvas; |
1066 | var tmpStage = this.application.ninja.currentDocument.documentRoot; | 1108 | var tmpStage = this.application.ninja.currentDocument.documentRoot; |
1067 | this.viewUtils.pushViewportObj( tmpCanvas ); | 1109 | this.viewUtils.pushViewportObj( tmpCanvas ); |
1068 | var tmpStage = this.application.ninja.currentDocument.documentRoot; | ||
1069 | 1110 | ||
1070 | // save the source space object and set to the target object | 1111 | // save the source space object and set to the target object |
1071 | var saveSource = this._sourceSpaceElt; | 1112 | var saveSource = this._sourceSpaceElt; |
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 49c77c41..71ed62a0 100644 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js | |||
@@ -891,36 +891,32 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
891 | } | 891 | } |
892 | }, | 892 | }, |
893 | 893 | ||
894 | /** | ||
895 | * decompose matrix in javascript found at https://github.com/joelambert/morf/blob/master/js/src/WebkitCSSMatrix.ext.js | ||
896 | * used with permission from Joe Lambert: "as long as the original licence text and attribution is left in then you're | ||
897 | * good to use it as you see fit." | ||
898 | * | ||
899 | * WebKitCSSMatrix Extensions | ||
900 | * | ||
901 | * Copyright 2011, Joe Lambert (http://www.joelambert.co.uk) | ||
902 | * Free to use under the MIT license. | ||
903 | * http://joelambert.mit-license.org/ | ||
904 | */ | ||
905 | |||
906 | /** | ||
907 | * Decomposes the matrix into its component parts. | ||
908 | * A Javascript implementation of the pseudo code available from http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition | ||
909 | * @author Joe Lambert | ||
910 | * @returns {Object} An object with each of the components of the matrix (perspective, translate, skew, scale, rotate) or identity matrix on failure | ||
911 | */ | ||
912 | |||
894 | // Input: matrix ; a 4x4 matrix | 913 | // Input: matrix ; a 4x4 matrix |
895 | // Output: translation ; a 3 component vector | 914 | // Output: translation ; a 3 component vector |
896 | // rotation ; Euler angles, represented as a 3 component vector | 915 | // rotation ; Euler angles, represented as a 3 component vector |
897 | // scale ; a 3 component vector | 916 | // scale ; a 3 component vector |
898 | // skew ; skew factors XY,XZ,YZ represented as a 3 component vector | 917 | // skew ; skew factors XY,XZ,YZ represented as a 3 component vector |
899 | // perspective ; a 4 component vector | 918 | // perspective ; a 4 component vector |
900 | // Returns false if the matrix cannot be decomposed, an object with the above output values if it can | 919 | // Returns false if the matrix cannot be decomposed. An object with the above output values if it can. |
901 | // | ||
902 | // Supporting functions (point is a 3 component vector, matrix is a 4x4 matrix): | ||
903 | // float determinant(matrix) returns the 4x4 determinant of the matrix | ||
904 | // matrix inverse(matrix) returns the inverse of the passed matrix | ||
905 | // matrix transpose(matrix) returns the transpose of the passed matrix | ||
906 | // point multVecMatrix(point, matrix) multiplies the passed point by the passed matrix | ||
907 | // and returns the transformed point | ||
908 | // float length(point) returns the length of the passed vector | ||
909 | // point normalize(point) normalizes the length of the passed point to 1 | ||
910 | // float dot(point, point) returns the dot product of the passed points | ||
911 | // float cos(float) returns the cosine of the passed angle in radians | ||
912 | // float asin(float) returns the arcsine in radians of the passed value | ||
913 | // float atan2(float y, float x) returns the principal value of the arc tangent of | ||
914 | // y/x, using the signs of both arguments to determine | ||
915 | // the quadrant of the return value | ||
916 | // | ||
917 | // Decomposition also makes use of the following function: | ||
918 | // point combine(point a, point b, float ascl, float bscl) | ||
919 | // result[0] = (ascl * a[0]) + (bscl * b[0]) | ||
920 | // result[1] = (ascl * a[1]) + (bscl * b[1]) | ||
921 | // result[2] = (ascl * a[2]) + (bscl * b[2]) | ||
922 | // return result | ||
923 | // | ||
924 | decomposeMatrix2: { | 920 | decomposeMatrix2: { |
925 | value: function(m) | 921 | value: function(m) |
926 | { | 922 | { |
@@ -1077,7 +1073,6 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
1077 | rotate[2] = 0; | 1073 | rotate[2] = 0; |
1078 | } | 1074 | } |
1079 | 1075 | ||
1080 | // return true; | ||
1081 | return {translation: translate, | 1076 | return {translation: translate, |
1082 | rotation: rotate, | 1077 | rotation: rotate, |
1083 | scale: scale, | 1078 | scale: scale, |
@@ -1087,6 +1082,15 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
1087 | } | 1082 | } |
1088 | }, | 1083 | }, |
1089 | 1084 | ||
1085 | /** | ||
1086 | * Helper function required for matrix decomposition | ||
1087 | * A Javascript implementation of pseudo code available from http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition | ||
1088 | * @param {Vector4} aPoint A 3D point | ||
1089 | * @param {float} ascl | ||
1090 | * @param {float} bscl | ||
1091 | * @author Joe Lambert | ||
1092 | * @returns {Vector4} | ||
1093 | */ | ||
1090 | combine: { | 1094 | combine: { |
1091 | value: function(a, b, ascl, bscl) | 1095 | value: function(a, b, ascl, bscl) |
1092 | { | 1096 | { |
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 8819f637..3af7d8cf 100644 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -9,14 +9,13 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
9 | // Class to do hit testing of objects in the html page | 9 | // Class to do hit testing of objects in the html page |
10 | /////////////////////////////////////////////////////////////////////// | 10 | /////////////////////////////////////////////////////////////////////// |
11 | var Montage = require("montage/core/core").Montage, | 11 | var Montage = require("montage/core/core").Montage, |
12 | Component = require("montage/ui/component").Component; | 12 | Component = require("montage/ui/component").Component, |
13 | 13 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | |
14 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; | 14 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, |
15 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | 15 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, |
16 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | 16 | HitRecord = require("js/helper-classes/3D/hit-record").HitRecord, |
17 | var HitRecord = require("js/helper-classes/3D/hit-record").HitRecord; | 17 | Snap2DRecord = require("js/helper-classes/3D/snap-2d-record").Snap2DRecord, |
18 | var Snap2DRecord = require("js/helper-classes/3D/snap-2d-record").Snap2DRecord; | 18 | NJUtils = require("js/lib/NJUtils").NJUtils; |
19 | var NJUtils = require("js/lib/NJUtils").NJUtils; | ||
20 | 19 | ||