@@ -259,17 +259,51 @@ class Control {
259
259
isObject : false
260
260
} ) , NO_STATE_INHERIT ) ;
261
261
262
- const lastCanvasPos = math . vec2 ( ) ;
262
+ const closestPointOnAxis = ( function ( ) {
263
+ const worldAxis = math . vec4 ( ) ;
264
+ const org = math . vec3 ( ) ;
265
+ const dir = math . vec3 ( ) ;
266
+ return ( canvasPos , dst ) => {
267
+ localToWorldVec ( rgb , worldAxis ) ;
268
+
269
+ const P = rootNode . position ;
270
+ const D = worldAxis ;
271
+
272
+ math . canvasPosToWorldRay ( canvas , scene . camera . viewMatrix , scene . camera . projMatrix , scene . camera . projection , canvasPos , org , dir ) ;
273
+
274
+ const d01 = math . dotVec3 ( D , dir ) ;
275
+ const v = math . subVec3 ( org , P , dst ) ;
276
+ const v0 = math . dotVec3 ( v , D ) ;
277
+ const v1 = math . dotVec3 ( v , dir ) ;
278
+ const det = 1 - d01 * d01 ;
279
+
280
+ if ( Math . abs ( det ) > 1e-10 ) { // if lines are not parallel
281
+ const s = ( v0 - d01 * v1 ) / det ;
282
+ math . addVec3 ( P , math . mulVec3Scalar ( D , s , dst ) , dst ) ;
283
+ return true ;
284
+ } else {
285
+ return false ;
286
+ }
287
+ } ;
288
+ } ) ( ) ;
289
+ const initOffset = math . vec3 ( ) ;
290
+ const tempVec3 = math . vec3 ( ) ;
263
291
handlers [ arrowHandle . id ] = handlers [ shaftHandle . id ] = {
264
292
affordanceMesh : bigArrowHead ,
265
293
initDragAction : ( initCanvasPos ) => {
266
- lastCanvasPos . set ( initCanvasPos ) ;
267
- return canvasPos => {
268
- dragTranslateSectionPlane ( rgb , lastCanvasPos , canvasPos ) ;
269
- lastCanvasPos . set ( canvasPos ) ;
270
- } ;
294
+ return closestPointOnAxis ( initCanvasPos , initOffset ) && math . subVec3 ( initOffset , rootNode . position , initOffset ) && ( ( canvasPos ) => {
295
+ if ( closestPointOnAxis ( canvasPos , tempVec3 ) ) {
296
+ math . subVec3 ( tempVec3 , initOffset , tempVec3 ) ;
297
+ rootNode . position = tempVec3 ;
298
+ if ( self . _sectionPlane ) {
299
+ self . _sectionPlane . pos = tempVec3 ;
300
+ }
301
+ }
302
+ } ) ;
271
303
}
272
304
} ;
305
+
306
+ const lastCanvasPos = math . vec2 ( ) ;
273
307
handlers [ rotateHandle . id ] = {
274
308
affordanceMesh : hoop ,
275
309
initDragAction : ( initCanvasPos ) => {
@@ -447,28 +481,6 @@ class Control {
447
481
} ;
448
482
449
483
const self = this ;
450
-
451
- const dragTranslateSectionPlane = ( function ( ) {
452
- const p1 = math . vec3 ( ) ;
453
- const p2 = math . vec3 ( ) ;
454
- const worldAxis = math . vec4 ( ) ;
455
- const planeNormal = math . vec3 ( ) ;
456
- return function ( baseAxis , fromMouse , toMouse ) {
457
- localToWorldVec ( baseAxis , worldAxis ) ;
458
- getTranslationPlane ( worldAxis , planeNormal ) ;
459
- getPointerPlaneIntersect ( fromMouse , planeNormal , p1 ) ;
460
- getPointerPlaneIntersect ( toMouse , planeNormal , p2 ) ;
461
- math . subVec3 ( p2 , p1 , p2 ) ;
462
- const dot = math . dotVec3 ( p2 , worldAxis ) ;
463
- math . mulVec3Scalar ( worldAxis , dot , p1 ) ;
464
- math . addVec3 ( rootNode . position , p1 , p1 ) ;
465
- rootNode . position = p1 ;
466
- if ( self . _sectionPlane ) {
467
- self . _sectionPlane . pos = rootNode . position ;
468
- }
469
- } ;
470
- } ) ( ) ;
471
-
472
484
var dragRotateSectionPlane = ( function ( ) {
473
485
const p1 = math . vec4 ( ) ;
474
486
const p2 = math . vec4 ( ) ;
@@ -587,9 +599,11 @@ class Control {
587
599
addCanvasEventListener ( "mousedown" , ( e ) => {
588
600
e . preventDefault ( ) ;
589
601
if ( this . _visible && ( e . which === 1 ) && nextDragAction ) { // Left button
590
- cameraControl . pointerEnabled = false ;
591
602
getClickCoordsWithinElement ( e , canvasPos ) ;
592
603
dragAction = nextDragAction ( canvasPos ) ;
604
+ if ( dragAction ) {
605
+ cameraControl . pointerEnabled = false ;
606
+ }
593
607
}
594
608
} ) ;
595
609
0 commit comments