aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/view-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-xjs/helper-classes/3D/view-utils.js81
1 files changed, 45 insertions, 36 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index 55ecbc59..ee822f1f 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.js
@@ -135,6 +135,12 @@ exports.ViewUtils = Montage.create(Component, {
135 var stageMat = this.getMatrixFromElement(stage); 135 var stageMat = this.getMatrixFromElement(stage);
136 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]]; 136 var stagePlane = [stageMat[8], stageMat[9], stageMat[10], stageMat[11]];
137 137
138 if (elt === stage)
139 {
140 xVec = [1,0,0];
141 yVec = [0,1,0];
142 }
143
138 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane)); 144 var xDot = Math.abs(vecUtils.vecDot(3, xVec, stagePlane));
139 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane)); 145 var yDot = Math.abs(vecUtils.vecDot(3, yVec, stagePlane));
140 146
@@ -259,7 +265,7 @@ exports.ViewUtils = Montage.create(Component, {
259 265
260 // transform the point up the tree 266 // transform the point up the tree
261 var child = elt; 267 var child = elt;
262 var parent = elt.parentElement; 268 var parent = elt.offsetParent;
263 while ( parent ) 269 while ( parent )
264 { 270 {
265 // go to screen space of the current child 271 // go to screen space of the current child
@@ -287,7 +293,7 @@ exports.ViewUtils = Montage.create(Component, {
287 } 293 }
288 294
289 child = parent; 295 child = parent;
290 parent = parent.parentElement; 296 parent = parent.offsetParent;
291 } 297 }
292 298
293 return pt; 299 return pt;
@@ -303,7 +309,7 @@ exports.ViewUtils = Montage.create(Component, {
303 309
304 // transform the bounds up the tree 310 // transform the bounds up the tree
305 var child = elt; 311 var child = elt;
306 var parent = elt.parentElement; 312 var parent = elt.offsetParent;
307 while ( parent ) 313 while ( parent )
308 { 314 {
309 pt = this.childToParent( pt, child ); 315 pt = this.childToParent( pt, child );
@@ -311,7 +317,7 @@ exports.ViewUtils = Montage.create(Component, {
311 if (parent === this._rootElement) break; 317 if (parent === this._rootElement) break;
312 318
313 child = parent; 319 child = parent;
314 parent = parent.parentElement; 320 parent = parent.offsetParent;
315 } 321 }
316 322
317 ///////////////////////////////////////////////////////// 323 /////////////////////////////////////////////////////////
@@ -346,7 +352,7 @@ exports.ViewUtils = Montage.create(Component, {
346 if (pt.length == 2) pt[2] = 0; 352 if (pt.length == 2) pt[2] = 0;
347 353
348 // transform the bounds up the tree 354 // transform the bounds up the tree
349 var parent = child.parentElement; 355 var parent = child.offsetParent;
350 if ( parent ) 356 if ( parent )
351 { 357 {
352 this.setViewportObj( child ); 358 this.setViewportObj( child );
@@ -394,7 +400,7 @@ exports.ViewUtils = Montage.create(Component, {
394 pt[3] = 1; 400 pt[3] = 1;
395 401
396 // transform the bounds up the tree 402 // transform the bounds up the tree
397 var parent = child.parentElement; 403 var parent = child.offsetParent;
398 if ( parent ) 404 if ( parent )
399 { 405 {
400 this.setViewportObj( child ); 406 this.setViewportObj( child );
@@ -429,7 +435,7 @@ exports.ViewUtils = Montage.create(Component, {
429 435
430 /* 436 /*
431 this.pushViewportObj( elt ); 437 this.pushViewportObj( elt );
432 var parent = elt.parentElement; 438 var parent = elt.offsetParent;
433 var offset = this.getElementOffset( elt ); 439 var offset = this.getElementOffset( elt );
434 offset[2] = 0; 440 offset[2] = 0;
435 var localEyePt = this.getCenterOfProjection(); 441 var localEyePt = this.getCenterOfProjection();
@@ -603,19 +609,6 @@ exports.ViewUtils = Montage.create(Component, {
603 w = elt.offsetWidth, 609 w = elt.offsetWidth,
604 h = elt.offsetHeight; 610 h = elt.offsetHeight;
605 611
606 if(elt.width)
607 w = elt.width;
608 if(elt.height)
609 h = elt.height;
610
611 if (elt.style)
612 {
613 if (elt.style.left) left = MathUtils.styleToNumber(elt.style.left);
614 if (elt.style.top) top = MathUtils.styleToNumber(elt.style.top);
615 if (elt.style.width) w = MathUtils.styleToNumber(elt.style.width);
616 if (elt.style.height) h = MathUtils.styleToNumber(elt.style.height);
617 }
618
619// if (elt instanceof SVGSVGElement) { 612// if (elt instanceof SVGSVGElement) {
620 if(elt.nodeName.toLowerCase() === "svg") { 613 if(elt.nodeName.toLowerCase() === "svg") {
621 if(w instanceof SVGAnimatedLength) 614 if(w instanceof SVGAnimatedLength)
@@ -658,6 +651,21 @@ exports.ViewUtils = Montage.create(Component, {
658 // if (elt.__ninjaXOff) xOff = elt.__ninjaXOff; 651 // if (elt.__ninjaXOff) xOff = elt.__ninjaXOff;
659 // if (elt.__ninjaYOff) yOff = elt.__ninjaYOff; 652 // if (elt.__ninjaYOff) yOff = elt.__ninjaYOff;
660 var offset = [xOff, yOff]; 653 var offset = [xOff, yOff];
654 if(elt.offsetParent && (elt.offsetParent !== this._stageElement))
655 {
656 var pS = elt.ownerDocument.defaultView.getComputedStyle(elt.offsetParent);
657
658 var border = parseInt(pS.getPropertyValue("border"));
659
660 if(border)
661 {
662 var bl = parseInt(pS.getPropertyValue("border-left-width")),
663 bt = parseInt(pS.getPropertyValue("border-top-width"));
664
665 offset[0] += bl;
666 offset[1] += bt;
667 }
668 }
661 669
662 if(elt === this._stageElement) 670 if(elt === this._stageElement)
663 { 671 {
@@ -832,42 +840,43 @@ exports.ViewUtils = Montage.create(Component, {
832 } 840 }
833 }, 841 },
834 842
835 getStageWorldToGlobalMatrix: { 843 getStageWorldToGlobalMatrix:
836 value: function() { 844 {
837 var stage = this.application.ninja.currentDocument.documentRoot, 845 value: function()
838 projMat; 846 {
839 this.pushViewportObj( stage ); 847 var stage = this.application.ninja.currentDocument.documentRoot;
840 848 //projMat;
849
841 // get the matrix to the parent 850 // get the matrix to the parent
842 var mat = Matrix.I(4); 851 //var mat = Matrix.I(4);
843 852
853 this.pushViewportObj( stage );
844 var cop = this.getCenterOfProjection(); 854 var cop = this.getCenterOfProjection();
845 var v2s = Matrix.Translation([cop[0], cop[1], 0]); 855 var v2s = Matrix.Translation([cop[0], cop[1], 0]);
856 this.popViewportObj();
846 857
858 /*
847 var p = this.getPerspectiveDistFromElement(stage); 859 var p = this.getPerspectiveDistFromElement(stage);
848 if(p) 860 if(p)
849 { 861 {
850 projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] ); 862 projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] );
851 projMat[11] = -1; 863 projMat[11] = -1;
852 mat = glmat4.multiply( v2s, projMat, [] );
853 } 864 }
854 else 865 else
855 { 866 {
856 mat = v2s; 867 mat = v2s;
857 } 868 }
858
859 // offset to the parent 869 // offset to the parent
860 var offset = this.getElementOffset( stage ); 870 var offset = this.getElementOffset( stage );
861 var offMat = Matrix.Translation([offset[0], offset[1], 0]); 871 var offMat = Matrix.Translation([offset[0], offset[1], 0]);
862 //mat = offMat.multiply( mat ); 872 //mat = offMat.multiply( mat );
863 glmat4.multiply( offMat, mat, mat ); 873 glmat4.multiply( offMat, mat, mat );
864
865 this.popViewportObj(); 874 this.popViewportObj();
875 */
866 876
867 // var mat2 = this.getLocalToGlobalMatrix( stage.parentElement ); 877 // append the localToGlobal matrix of the stage.
868 var mat2 = this.getLocalToGlobalMatrix( this._rootElement ); 878 var mat = this.getLocalToGlobalMatrix( stage );
869 //var mat = mat2.multiply( mat ); 879 glmat4.multiply( mat, v2s );
870 glmat4.multiply( mat2, mat, mat );
871 880
872 return mat; 881 return mat;
873 } 882 }
@@ -987,7 +996,7 @@ exports.ViewUtils = Montage.create(Component, {
987 996
988 if (elt === this._stageElement) break; 997 if (elt === this._stageElement) break;
989 if (elt === this._rootElement) break; 998 if (elt === this._rootElement) break;
990 elt = elt.parentElement; 999 elt = elt.offsetParent;
991 if (elt === this._rootElement) break; 1000 if (elt === this._rootElement) break;
992 } 1001 }
993 1002
@@ -1040,7 +1049,7 @@ exports.ViewUtils = Montage.create(Component, {
1040 //mat = offMat.multiply( mat ); 1049 //mat = offMat.multiply( mat );
1041 glmat4.multiply( offMat, mat, mat ); 1050 glmat4.multiply( offMat, mat, mat );
1042 1051
1043