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.js88
1 files changed, 31 insertions, 57 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js
index 00124900..a3d09404 100755
--- a/js/helper-classes/3D/view-utils.js
+++ b/js/helper-classes/3D/view-utils.js
@@ -18,18 +18,11 @@ exports.ViewUtils = Montage.create(Component, {
18 // Instance variables 18 // Instance variables
19 /////////////////////////////////////////////////////////////////////// 19 ///////////////////////////////////////////////////////////////////////
20 20
21 m_viewportObj : { value: null, writable: true}, 21 m_viewportObj : { value: null},
22 _perspectiveDist: { value: null, writable: true}, 22 _perspectiveDist: { value: null},
23 23
24 // keep a stack of viewport objects 24 // keep a stack of viewport objects
25 _viewportObjStack: { value: [], writable: true }, 25 _viewportObjStack: { value: []},
26
27 _currentDocument: { value: null , writable: true},
28 _userContentLeft: { value: null , writable: true},
29 _userContentTop: { value: null , writable: true},
30
31 _rootElement: { value: null, writable: true},
32 _stageElement: { value: null, writable: true},
33 26
34 /////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////
35 // Property accessors 28 // Property accessors
@@ -43,18 +36,6 @@ exports.ViewUtils = Montage.create(Component, {
43 }, 36 },
44 getViewportObj: { value: function() { return this.m_viewportObj; } }, 37 getViewportObj: { value: function() { return this.m_viewportObj; } },
45 38
46 setRootElement: { value: function( elt ) { this._rootElement = elt; } },
47 getRootElement: { value: function () { return this._rootElement; } },
48
49 setStageElement: { value: function( elt ) { this._stageElement = elt; } },
50 getStageElement: { value: function () { return this._stageElement; } },
51
52 setCurrentDocument: { value: function(value) { this._currentDocument = value; }},
53
54 setUserContentLeft: { value: function(value) { this._userContentLeft = value; }},
55 setUserContentTop: { value: function(value) { this._userContentTop = value; }},
56
57
58 getPerspectiveDistance: { value: function () { return this._perspectiveDist; } }, 39 getPerspectiveDistance: { value: function () { return this._perspectiveDist; } },
59 40
60 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
@@ -139,7 +120,7 @@ exports.ViewUtils = Montage.create(Component, {
139 var yVec = [0,1,0]; 120 var yVec = [0,1,0];
140 var zVec = [0,0,1]; 121 var zVec = [0,0,1];
141 122
142 var stage = this.application.ninja.currentDocument.documentRoot; 123 var stage = this.application.ninja.currentDocument.model.documentRoot;
143 var stageMat = this.getMatrixFromElement(stage); 124 var stageMat = this.getMatrixFromElement(stage);
144 125
145 var mat = glmat4.multiply( stageMat, objMat, [] ); 126 var mat = glmat4.multiply( stageMat, objMat, [] );
@@ -299,7 +280,7 @@ exports.ViewUtils = Montage.create(Component, {
299 // into stage world space. 280 // into stage world space.
300 postViewToStageWorld: { 281 postViewToStageWorld: {
301 value: function( localPt, elt ) { 282 value: function( localPt, elt ) {
302 if ((elt == null) || (elt === this._stageElement)) return localPt; 283 if ((elt == null) || (elt === this.application.ninja.currentDocument.model.documentRoot)) return localPt;
303 284
304 // get the 3D transformation and 2D offset from the element 285 // get the 3D transformation and 2D offset from the element
305 var pt = localPt.slice(0); 286 var pt = localPt.slice(0);
@@ -326,7 +307,7 @@ exports.ViewUtils = Montage.create(Component, {
326 this.popViewportObj(); 307 this.popViewportObj();
327 308
328 // check if we are done 309 // check if we are done
329 if (parent === this._stageElement) break; 310 if (parent === this.application.ninja.currentDocument.model.documentRoot) break;
330 311
331 if (this.elementHas3D( parent )) 312 if (this.elementHas3D( parent ))
332 { 313 {
@@ -351,15 +332,17 @@ exports.ViewUtils = Montage.create(Component, {
351 332
352 // transform the bounds up the tree 333 // transform the bounds up the tree
353 var child = elt; 334 var child = elt;
354 var parent = elt.offsetParent; 335 while ( child )
355 while ( parent )
356 { 336 {
357 pt = this.childToParent( pt, child ); 337 pt = this.childToParent( pt, child );
358 338
359 if (parent === this._rootElement) break; 339// if (child === this.application.ninja.currentDocument.model.documentRoot) break;
340// child = child.offsetParent;
360 341
361 child = parent; 342 if (child === this.application.ninja.currentDocument.model.documentRoot) break;
362 parent = parent.offsetParent; 343 if (child === this.application.ninja.currentDocument.model.documentRoot.parentNode) break;
344 child = child.offsetParent;
345 if (child === this.application.ninja.currentDocument.model.documentRoot.parentNode) break;
363 } 346 }
364 347
365 ///////////////////////////////////////////////////////// 348 /////////////////////////////////////////////////////////
@@ -395,7 +378,8 @@ exports.ViewUtils = Montage.create(Component, {
395 378
396 // transform the bounds up the tree 379 // transform the bounds up the tree
397 var parent = child.offsetParent; 380 var parent = child.offsetParent;
398 if ( parent ) 381 // TODO - Should have a different way to check for new template mode
382 if ( parent || (child === this.application.ninja.currentDocument.model.documentRoot) )
399 { 383 {
400 this.setViewportObj( child ); 384 this.setViewportObj( child );
401 385
@@ -408,7 +392,7 @@ exports.ViewUtils = Montage.create(Component, {
408 { 392 {
409 // TODO - Commenting out flatten support until new perspective workflow is fully working 393 // TODO - Commenting out flatten support until new perspective workflow is fully working
410 // if (flatten) pt[2] = 0; 394 // if (flatten) pt[2] = 0;
411// var flatten = (parent !== this._rootElement) && (ElementsMediator.getProperty(parent, "-webkit-transform-style") !== "preserve-3d"); 395// var flatten = (parent !== this.application.ninja.currentDocument.model.documentRoot.parentNode) && (ElementsMediator.getProperty(parent, "-webkit-transform-style") !== "preserve-3d");
412// if(flatten) 396// if(flatten)
413// { 397// {
414// pt[2] = 0; 398// pt[2] = 0;
@@ -468,7 +452,7 @@ exports.ViewUtils = Montage.create(Component, {
468 // get the four corners of the element in global space 452 // get the four corners of the element in global space
469 var bounds = this.getElementViewBounds3D( elt ); 453 var bounds = this.getElementViewBounds3D( elt );
470 var bounds3D = new Array(); 454 var bounds3D = new Array();
471 var stage = this.application.ninja.currentDocument.documentRoot; 455 var stage = this.application.ninja.currentDocument.model.documentRoot;
472 for (var i=0; i<3; i++) 456 for (var i=0; i<3; i++)
473 { 457 {
474 var gPt = this.localToGlobal( bounds[i], elt ); 458 var gPt = this.localToGlobal( bounds[i], elt );
@@ -693,7 +677,7 @@ exports.ViewUtils = Montage.create(Component, {
693 // if (elt.__ninjaXOff) xOff = elt.__ninjaXOff; 677 // if (elt.__ninjaXOff) xOff = elt.__ninjaXOff;
694 // if (elt.__ninjaYOff) yOff = elt.__ninjaYOff; 678 // if (elt.__ninjaYOff) yOff = elt.__ninjaYOff;
695 var offset = [xOff, yOff]; 679 var offset = [xOff, yOff];
696 if(elt.offsetParent && (elt.offsetParent !== this._stageElement)) 680 if(elt.offsetParent && (elt.offsetParent !== this.application.ninja.currentDocument.model.documentRoot))
697 { 681 {
698 var pS = elt.ownerDocument.defaultView.getComputedStyle(elt.offsetParent); 682 var pS = elt.ownerDocument.defaultView.getComputedStyle(elt.offsetParent);
699 683
@@ -709,12 +693,12 @@ exports.ViewUtils = Montage.create(Component, {
709 } 693 }
710 } 694 }
711 695
712 if(elt === this._stageElement) 696 if(elt === this.application.ninja.currentDocument.model.documentRoot)
713 { 697 {
714 // TODO - Call a routine from the user document controller to get the offsets/margins 698 // TODO - Call a routine from the user document controller to get the offsets/margins
715 // Once we expose the document controller to ViewUtils 699 // Once we expose the document controller to ViewUtils
716 offset[0] += this._userContentLeft; 700 offset[0] += this.application.ninja.stage._userContentLeft;
717 offset[1] += this._userContentTop; 701 offset[1] += this.application.ninja.stage._userContentTop;
718 } 702 }
719 703
720 return offset; 704 return offset;
@@ -886,7 +870,7 @@ exports.ViewUtils = Montage.create(Component, {
886 { 870 {
887 value: function() 871 value: function()
888 { 872 {
889 var stage = this.application.ninja.currentDocument.documentRoot; 873 var stage = this.application.ninja.currentDocument.model.documentRoot;
890 874
891 this.pushViewportObj( stage ); 875 this.pushViewportObj( stage );
892 // put the point into screen space of the stage - requires 876 // put the point into screen space of the stage - requires
@@ -1000,7 +984,7 @@ exports.ViewUtils = Montage.create(Component, {
1000 glmat4.multiply( v2s, mat, mat ); 984 glmat4.multiply( v2s, mat, mat );
1001 985
1002 // TODO - Commenting out flatten support until new perspective workflow is fully working 986 // TODO - Commenting out flatten support until new perspective workflow is fully working
1003// var flatten = (elt !== this._rootElement) && (elt.parentElement !== this._rootElement) && (ElementsMediator.getProperty(elt.parentElement, "-webkit-transform-style") !== "preserve-3d"); 987// var flatten = (elt !== this.application.ninja.currentDocument.model.documentRoot.parentNode) && (elt.parentElement !== this.application.ninja.currentDocument.model.documentRoot.parentNode) && (ElementsMediator.getProperty(elt.parentElement, "-webkit-transform-style") !== "preserve-3d");
1004// if(flatten) 988// if(flatten)
1005// { 989// {
1006// glmat4.multiply( zMat, mat, mat ); 990// glmat4.multiply( zMat, mat, mat );
@@ -1014,10 +998,10 @@ exports.ViewUtils = Montage.create(Component, {
1014 998
1015 this.popViewportObj(); 999 this.popViewportObj();
1016 1000
1017 if (elt === this._stageElement) break; 1001 if (elt === this.application.ninja.currentDocument.model.documentRoot) break;
1018 if (elt === this._rootElement) break; 1002 if (elt === this.application.ninja.currentDocument.model.documentRoot.parentNode) break;
1019 elt = elt.offsetParent; 1003 elt = elt.offsetParent;
1020 if (elt === this._rootElement) break; 1004 if (elt === this.application.ninja.currentDocument.model.documentRoot.parentNode) break;
1021 } 1005 }
1022 1006
1023 return mat; 1007 return mat;
@@ -1051,7 +1035,7 @@ exports.ViewUtils = Montage.create(Component, {
1051 // multiply all the matrices together 1035 // multiply all the matrices together
1052 //mat = s2v.multiply( mat ); 1036 //mat = s2v.multiply( mat );
1053 glmat4.multiply( s2v, mat, mat ); 1037 glmat4.multiply( s2v, mat, mat );
1054 if (elt === this._stageElement) break; 1038 if (elt === this.application.ninja