aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D')
-rw-r--r--js/helper-classes/3D/draw-utils.js71
-rw-r--r--js/helper-classes/3D/math-utils.js54
-rw-r--r--js/helper-classes/3D/snap-manager.js26
3 files changed, 115 insertions, 36 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index 3fd6e8fc..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,8 @@ 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);
114 this.eventManager.addEventListener("elementChange", this, false);
110 } 115 }
111 }, 116 },
112 117
@@ -123,6 +128,65 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
123 } 128 }
124 }, 129 },
125 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 },
159
160 // TODO - Check why handleElementChange is being fired before handleAddElement
161 handleElementChange: {
162 value: function(event) {
163 if(!event.detail || !event.detail.data)
164 {
165 return;
166 }
167 var els = event.detail.data.els;
168 if(els && this._shouldUpdatePlanes(event.detail.data.prop))
169 {
170 var len = els.length,
171 i = 0,
172 item,
173 el;
174
175 for(i=0; i < len; i++) {
176 item = els[i];
177 el = item._element || item;
178 if(el.elementModel.props3D.elementPlane)
179 {
180 el.elementModel.props3D.elementPlane.init();
181 }
182 }
183
184 this.application.ninja.stage.layout.draw();
185 this.drawWorkingPlane();
186 this.draw3DCompass();
187 }
188 }
189 },
126 190
127 /////////////////////////////////////////////////////////////////////// 191 ///////////////////////////////////////////////////////////////////////
128 // Methods 192 // Methods
@@ -150,6 +214,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
150 plane.setElement( elt ); 214 plane.setElement( elt );
151 plane.init(); 215 plane.init();
152 this._planesArray.push( plane ); 216 this._planesArray.push( plane );
217 elt.elementModel.props3D.elementPlane = plane;
153 } 218 }
154 }, 219 },
155 220
@@ -166,6 +231,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
166 231
167 // Then remove the element 232 // Then remove the element
168 this._eltArray.splice(i, 1); 233 this._eltArray.splice(i, 1);
234
235 // TODO - May need to delete props3D and elementPlane as well
169 return; 236 return;
170 } 237 }
171 } 238 }
@@ -1040,7 +1107,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
1040 var tmpCanvas = this.application.ninja.stage.canvas; 1107 var tmpCanvas = this.application.ninja.stage.canvas;
1041 var tmpStage = this.application.ninja.currentDocument.documentRoot; 1108 var tmpStage = this.application.ninja.currentDocument.documentRoot;
1042 this.viewUtils.pushViewportObj( tmpCanvas ); 1109 this.viewUtils.pushViewportObj( tmpCanvas );
1043 var tmpStage = this.application.ninja.currentDocument.documentRoot;
1044 1110
1045 // save the source space object and set to the target object 1111 // save the source space object and set to the target object
1046 var saveSource = this._sourceSpaceElt; 1112 var saveSource = this._sourceSpaceElt;
@@ -1064,7 +1130,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
1064 var resMat = glmat4.multiply( tMat, mat, [] ); 1130 var resMat = glmat4.multiply( tMat, mat, [] );
1065 var origin = [0,0,0,1]; 1131 var origin = [0,0,0,1];
1066 1132
1067 var arrowSize = 50; 1133 var zoomFactor = this.application.ninja.documentBar.zoomFactor/100.0;
1134 var arrowSize = 50 / zoomFactor;
1068 var xAxis = [arrowSize,0,0,1]; 1135 var xAxis = [arrowSize,0,0,1];
1069 //var rO = resMat.multiply(origin); 1136 //var rO = resMat.multiply(origin);
1070 var rO = glmat4.multiplyVec3( resMat, origin, []); 1137 var rO = glmat4.multiplyVec3( resMat, origin, []);
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