diff options
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 163 |
1 files changed, 121 insertions, 42 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 63c2cb52..55ecbc59 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js | |||
@@ -37,10 +37,8 @@ exports.ViewUtils = Montage.create(Component, { | |||
37 | setViewportObj: { | 37 | setViewportObj: { |
38 | value: function( vp ) { | 38 | value: function( vp ) { |
39 | this.m_viewportObj = vp; | 39 | this.m_viewportObj = vp; |
40 | this._perspectiveDist = 1400; | ||
41 | 40 | ||
42 | var dist = this.getPerspectiveDistFromElement( vp ); | 41 | this._perspectiveDist = this.getPerspectiveDistFromElement( vp ); |
43 | var mode = this.getPerspectiveModeFromElement( vp ); | ||
44 | } | 42 | } |
45 | }, | 43 | }, |
46 | getViewportObj: { value: function() { return this.m_viewportObj; } }, | 44 | getViewportObj: { value: function() { return this.m_viewportObj; } }, |
@@ -360,11 +358,21 @@ exports.ViewUtils = Montage.create(Component, { | |||
360 | 358 | ||
361 | if (this.elementHas3D( child )) | 359 | if (this.elementHas3D( child )) |
362 | { | 360 | { |
361 | // TODO - Commenting out flatten support until new perspective workflow is fully working | ||
363 | // if (flatten) pt[2] = 0; | 362 | // if (flatten) pt[2] = 0; |
363 | // var flatten = (parent !== this._rootElement) && (ElementsMediator.getProperty(parent, "-webkit-transform-style") !== "preserve-3d"); | ||
364 | // if(flatten) | ||
365 | // { | ||
366 | // pt[2] = 0; | ||
367 | // } | ||
364 | pt = this.screenToView( pt[0], pt[1], pt[2] ); | 368 | pt = this.screenToView( pt[0], pt[1], pt[2] ); |
365 | pt[3] = 1; | 369 | pt[3] = 1; |
366 | //var wPt = childMat.multiply( pt ); | 370 | //var wPt = childMat.multiply( pt ); |
367 | var wPt = glmat4.multiplyVec3( childMat, pt, [] ); | 371 | var wPt = glmat4.multiplyVec3( childMat, pt, [] ); |
372 | // if(flatten) | ||
373 | // { | ||
374 | // wPt[2] = 0; | ||
375 | // } | ||
368 | var scrPt = this.viewToScreen( wPt ); | 376 | var scrPt = this.viewToScreen( wPt ); |
369 | pt = scrPt; | 377 | pt = scrPt; |
370 | } | 378 | } |
@@ -480,7 +488,15 @@ exports.ViewUtils = Montage.create(Component, { | |||
480 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); | 488 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); |
481 | 489 | ||
482 | // project the view point onto the plane | 490 | // project the view point onto the plane |
483 | var eyePt = this.getEyePoint(); | 491 | var eyePt; |
492 | if(this.getPerspectiveDistFromElement(child)) | ||
493 | { | ||
494 | eyePt = this.getEyePoint(); | ||
495 | } | ||
496 | else | ||
497 | { | ||
498 | eyePt = [viewPt[0], viewPt[1], 1400]; | ||
499 | } | ||
484 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); | 500 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); |
485 | 501 | ||
486 | var childPt; | 502 | var childPt; |
@@ -522,7 +538,15 @@ exports.ViewUtils = Montage.create(Component, { | |||
522 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); | 538 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); |
523 | 539 | ||
524 | // project the view point onto the plane | 540 | // project the view point onto the plane |
525 | var eyePt = this.getEyePoint(); | 541 | var eyePt; |
542 | if(this.getPerspectiveDistFromElement(child)) | ||
543 | { | ||
544 | eyePt = this.getEyePoint(); | ||
545 | } | ||
546 | else | ||
547 | { | ||
548 | eyePt = [viewPt[0], viewPt[1], 1400]; | ||
549 | } | ||
526 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); | 550 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); |
527 | 551 | ||
528 | this.popViewportObj(); | 552 | this.popViewportObj(); |
@@ -533,7 +557,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
533 | 557 | ||
534 | 558 | ||
535 | parentToChildVec: { | 559 | parentToChildVec: { |
536 | value: function( parentPt, child ) { | 560 | value: function( parentPt, child, rtnEyePt ) { |
537 | var pt = parentPt.slice(0); | 561 | var pt = parentPt.slice(0); |
538 | if (pt.length == 2) pt[2] = 0.0; | 562 | if (pt.length == 2) pt[2] = 0.0; |
539 | 563 | ||
@@ -546,12 +570,24 @@ exports.ViewUtils = Montage.create(Component, { | |||
546 | this.setViewportObj( child ); | 570 | this.setViewportObj( child ); |
547 | pt = this.screenToView( pt[0], pt[1], pt[2] ); | 571 | pt = this.screenToView( pt[0], pt[1], pt[2] ); |
548 | 572 | ||
549 | var eyePt = this.getEyePoint(); | 573 | var eyePt; |
550 | //var eyePt = [0, 0, 0]; | 574 | if(this.getPerspectiveDistFromElement(child)) |
551 | //var vec = [pt[0], pt[1], pt[2]].subtract( eyePt ); | 575 | { |
576 | eyePt = this.getEyePoint(); | ||
577 | } | ||
578 | else | ||
579 | { | ||
580 | eyePt = [pt[0], pt[1], 1400]; | ||
581 | } | ||
552 | var vec = vecUtils.vecSubtract(3, [pt[0], pt[1], pt[2]], eyePt); | 582 | var vec = vecUtils.vecSubtract(3, [pt[0], pt[1], pt[2]], eyePt); |
553 | vec = vecUtils.vecNormalize( 3, vec ); | 583 | vec = vecUtils.vecNormalize( 3, vec ); |
554 | 584 | ||
585 | if(rtnEyePt) | ||
586 | { | ||
587 | rtnEyePt[0] = eyePt[0]; | ||
588 | rtnEyePt[1] = eyePt[1]; | ||
589 | rtnEyePt[2] = eyePt[2]; | ||
590 | } | ||
555 | return vec; | 591 | return vec; |
556 | } | 592 | } |
557 | }, | 593 | }, |
@@ -707,6 +743,10 @@ exports.ViewUtils = Montage.create(Component, { | |||
707 | 743 | ||
708 | projectToViewPlane: { | 744 | projectToViewPlane: { |
709 | value: function( viewPos ) { | 745 | value: function( viewPos ) { |
746 | if(!this._perspectiveDist) | ||
747 | { | ||
748 | return viewPos.slice(0); | ||
749 | } | ||
710 | var viewPt; | 750 | var viewPt; |
711 | var viewport = this.m_viewportObj; | 751 | var viewport = this.m_viewportObj; |
712 | if (viewport) | 752 | if (viewport) |
@@ -734,6 +774,10 @@ exports.ViewUtils = Montage.create(Component, { | |||
734 | 774 | ||
735 | unproject: { | 775 | unproject: { |
736 | value: function( pt ) { | 776 | value: function( pt ) { |
777 | if(!this._perspectiveDist) | ||
778 | { | ||
779 | return pt.slice(0); | ||
780 | } | ||
737 | var viewPt; | 781 | var viewPt; |
738 | var viewport = this.m_viewportObj; | 782 | var viewport = this.m_viewportObj; |
739 | if (viewport) | 783 | if (viewport) |
@@ -790,26 +834,33 @@ exports.ViewUtils = Montage.create(Component, { | |||
790 | 834 | ||
791 | getStageWorldToGlobalMatrix: { | 835 | getStageWorldToGlobalMatrix: { |
792 | value: function() { | 836 | value: function() { |
793 | var stage = this.application.ninja.currentDocument.documentRoot; | 837 | var stage = this.application.ninja.currentDocument.documentRoot, |
838 | projMat; | ||
794 | this.pushViewportObj( stage ); | 839 | this.pushViewportObj( stage ); |
795 | 840 | ||
796 | // get the matrix to the parent | 841 | // get the matrix to the parent |
797 | var mat = Matrix.I(4); | 842 | var mat = Matrix.I(4); |
798 | //var projMat = Matrix.I(4).multiply( this.getPerspectiveDistFromElement(stage) ); | 843 | |
799 | var p = this.getPerspectiveDistFromElement(stage); | 844 | var cop = this.getCenterOfProjection(); |
800 | var projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] ); | 845 | var v2s = Matrix.Translation([cop[0], cop[1], 0]); |
801 | projMat[11] = -1; | ||
802 | var cop = this.getCenterOfProjection(); | ||
803 | var v2s = Matrix.Translation([cop[0], cop[1], 0]); | ||
804 | 846 | ||
805 | //mat = v2s.multiply( projMat ); | 847 | var p = this.getPerspectiveDistFromElement(stage); |
848 | if(p) | ||
849 | { | ||
850 | projMat = glmat4.scale( Matrix.I(4), [p,p,p], [] ); | ||
851 | projMat[11] = -1; | ||
806 | mat = glmat4.multiply( v2s, projMat, [] ); | 852 | mat = glmat4.multiply( v2s, projMat, [] ); |
853 | } | ||
854 | else | ||
855 | { | ||
856 | mat = v2s; | ||
857 | } | ||
807 | 858 | ||
808 | // offset to the parent | 859 | // offset to the parent |
809 | var offset = this.getElementOffset( stage ); | 860 | var offset = this.getElementOffset( stage ); |
810 | var offMat = Matrix.Translation([offset[0], offset[1], 0]); | 861 | var offMat = Matrix.Translation([offset[0], offset[1], 0]); |
811 | //mat = offMat.multiply( mat ); | 862 | //mat = offMat.multiply( mat ); |
812 | glmat4.multiply( offMat, mat, mat ); | 863 | glmat4.multiply( offMat, mat, mat ); |
813 | 864 | ||
814 | this.popViewportObj(); | 865 | this.popViewportObj(); |
815 | 866 | ||
@@ -837,7 +888,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
837 | globalScreenToLocalWorld: { | 888 | globalScreenToLocalWorld: { |
838 | value: function( globalPt, elt ) { | 889 | value: function( globalPt, elt ) { |
839 | var objPt = this.globalToLocal( globalPt, elt ); | 890 | var objPt = this.globalToLocal( globalPt, elt ); |
840 | var viewPt = this.localScreenToLocalWorld( objPt, elt ) | 891 | var viewPt = this.localScreenToLocalWorld( objPt, elt ); |
841 | 892 | ||
842 | /* | 893 | /* |
843 | MathUtils.makeDimension3( objPt ); | 894 | MathUtils.makeDimension3( objPt ); |
@@ -882,7 +933,15 @@ exports.ViewUtils = Montage.create(Component, { | |||
882 | 933 | ||
883 | getLocalToGlobalMatrix: { | 934 | getLocalToGlobalMatrix: { |
884 | value: function( elt ) { | 935 | value: function( elt ) { |
885 | var mat = Matrix.I(4); | 936 | var mat = Matrix.I(4), |
937 | projMat, | ||
938 | pDist; | ||
939 | // TODO - Commenting out flatten support until new perspective workflow is fully working | ||
940 | var zMat = Matrix.I(4); | ||
941 | // zMat[9] = 0; | ||
942 | // zMat[10] = 0; | ||
943 | // zMat[11] = 0; | ||
944 | // zMat[12] = 0; | ||
886 | while (elt) | 945 | while (elt) |
887 | { | 946 | { |
888 | this.pushViewportObj( elt ); |