diff options
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-x | js/helper-classes/3D/hit-record.js | 10 | ||||
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 12 | ||||
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 163 |
3 files changed, 137 insertions, 48 deletions
diff --git a/js/helper-classes/3D/hit-record.js b/js/helper-classes/3D/hit-record.js index 2c60adc6..265bf2a4 100755 --- a/js/helper-classes/3D/hit-record.js +++ b/js/helper-classes/3D/hit-record.js | |||
@@ -232,7 +232,15 @@ var HitRecord = exports.HitRecord = Object.create(Object.prototype, | |||
232 | var elt = this.getElt(); | 232 | var elt = this.getElt(); |
233 | viewUtils.pushViewportObj( elt ); | 233 | viewUtils.pushViewportObj( elt ); |
234 | var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); | 234 | var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); |
235 | var eyePt = viewUtils.getEyePoint(); | 235 | var eyePt; |
236 | if(viewUtils.getPerspectiveDistFromElement(elt)) | ||
237 | { | ||
238 | eyePt = viewUtils.getEyePoint(); | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | eyePt = [viewPt[0], viewPt[1], 1400]; | ||
243 | } | ||
236 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); | 244 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); |
237 | 245 | ||
238 | return projPt; | 246 | return projPt; |
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index a401c363..61f5bc97 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -229,7 +229,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
229 | parentPt = [quadPt[0], quadPt[1], 0.0]; | 229 | parentPt = [quadPt[0], quadPt[1], 0.0]; |
230 | else | 230 | else |
231 | parentPt = [xScreen, yScreen, 0.0]; | 231 | parentPt = [xScreen, yScreen, 0.0]; |
232 | var vec = viewUtils.parentToChildVec(parentPt, stage); | 232 | |
233 | var eyePt = []; | ||
234 | var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); | ||
233 | if (vec) | 235 | if (vec) |
234 | { | 236 | { |
235 | // activate the drag working plane | 237 | // activate the drag working plane |
@@ -241,7 +243,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
241 | var wp = currentWorkingPlane.slice(0); | 243 | var wp = currentWorkingPlane.slice(0); |
242 | var mat = viewUtils.getMatrixFromElement(stage); | 244 | var mat = viewUtils.getMatrixFromElement(stage); |
243 | wp = MathUtils.transformPlane(wp, mat); | 245 | wp = MathUtils.transformPlane(wp, mat); |
244 | var eyePt = viewUtils.getEyePoint(); | ||
245 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); | 246 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); |
246 | if (projPt) | 247 | if (projPt) |
247 | { | 248 | { |
@@ -709,8 +710,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
709 | var wp = currentWorkingPlane.slice(0); | 710 | var wp = currentWorkingPlane.slice(0); |
710 | var mat = viewUtils.getMatrixFromElement(stage); | 711 | var mat = viewUtils.getMatrixFromElement(stage); |
711 | wp = MathUtils.transformPlane(wp, mat); | 712 | wp = MathUtils.transformPlane(wp, mat); |
712 | var eyePt = viewUtils.getEyePoint(); | 713 | var eyePt = []; |
713 | var vec = viewUtils.parentToChildVec(gPt, stage); | 714 | var vec = viewUtils.parentToChildVec(gPt, stage, eyePt); |
714 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); | 715 | var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); |
715 | var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); | 716 | var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane)); |
716 | projPt[3] = 1.0; | 717 | projPt[3] = 1.0; |
@@ -1067,8 +1068,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1067 | // Snapping is done in screen space, so convert the bounds from | 1068 | // Snapping is done in screen space, so convert the bounds from |
1068 | // local element space to global screen space | 1069 | // local element space to global screen space |
1069 | var bounds3D = new Array(); | 1070 | var bounds3D = new Array(); |
1071 | var eltMat = viewUtils.getLocalToGlobalMatrix( elt ); | ||
1070 | for (var i=0; i<4; i++) | 1072 | for (var i=0; i<4; i++) |
1071 | bounds3D[i] = viewUtils.localToGlobal( bounds[i], elt ); | 1073 | bounds3D[i] = viewUtils.localToGlobal2(bounds[i], eltMat); |
1072 | 1074 | ||
1073 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); | 1075 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); |
1074 | 1076 | ||
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); | ||