@@ -236,8 +236,8 @@ export class SceneInfra {
236
236
_angle = typeof angle === 'number' ? angle : getAngle ( from , to )
237
237
}
238
238
239
- const x = ( vector . x * 0.5 + 0.5 ) * window . innerWidth
240
- const y = ( - vector . y * 0.5 + 0.5 ) * window . innerHeight
239
+ const x = ( vector . x * 0.5 + 0.5 ) * this . renderer . domElement . clientWidth
240
+ const y = ( - vector . y * 0.5 + 0.5 ) * this . renderer . domElement . clientHeight
241
241
const pathToNodeString = JSON . stringify ( group . userData . pathToNode )
242
242
return {
243
243
type : 'set-one' ,
@@ -450,9 +450,14 @@ export class SceneInfra {
450
450
}
451
451
}
452
452
onMouseMove = async ( mouseEvent : MouseEvent ) => {
453
- this . currentMouseVector . x = ( mouseEvent . clientX / window . innerWidth ) * 2 - 1
453
+ if ( ! ( mouseEvent . currentTarget instanceof HTMLElement ) ) {
454
+ console . error ( 'unexpected targetless event' )
455
+ return
456
+ }
457
+ this . currentMouseVector . x =
458
+ ( mouseEvent . clientX / mouseEvent . currentTarget . clientWidth ) * 2 - 1
454
459
this . currentMouseVector . y =
455
- - ( mouseEvent . clientY / window . innerHeight ) * 2 + 1
460
+ - ( mouseEvent . clientY / mouseEvent . currentTarget . clientHeight ) * 2 + 1
456
461
457
462
const planeIntersectPoint = this . getPlaneIntersectPoint ( )
458
463
const intersects = this . raycastRing ( )
@@ -582,8 +587,14 @@ export class SceneInfra {
582
587
// Check the ring points
583
588
for ( let i = 0 ; i < rayRingCount ; i ++ ) {
584
589
const angle = ( i / rayRingCount ) * Math . PI * 2
585
- const offsetX = ( ( pixelRadius * Math . cos ( angle ) ) / window . innerWidth ) * 2
586
- const offsetY = ( ( pixelRadius * Math . sin ( angle ) ) / window . innerHeight ) * 2
590
+ const offsetX =
591
+ ( ( pixelRadius * Math . cos ( angle ) ) /
592
+ this . renderer . domElement . clientWidth ) *
593
+ 2
594
+ const offsetY =
595
+ ( ( pixelRadius * Math . sin ( angle ) ) /
596
+ this . renderer . domElement . clientHeight ) *
597
+ 2
587
598
const ringVector = new Vector2 (
588
599
mouseDownVector . x + offsetX ,
589
600
mouseDownVector . y - offsetY
@@ -607,8 +618,14 @@ export class SceneInfra {
607
618
}
608
619
609
620
onMouseDown = ( event : MouseEvent ) => {
610
- this . currentMouseVector . x = ( event . clientX / window . innerWidth ) * 2 - 1
611
- this . currentMouseVector . y = - ( event . clientY / window . innerHeight ) * 2 + 1
621
+ if ( ! ( event . currentTarget instanceof HTMLElement ) ) {
622
+ console . error ( 'unexpected targetless event' )
623
+ return
624
+ }
625
+ this . currentMouseVector . x =
626
+ ( event . clientX / event . currentTarget . clientWidth ) * 2 - 1
627
+ this . currentMouseVector . y =
628
+ - ( event . clientY / event . currentTarget . clientHeight ) * 2 + 1
612
629
613
630
const mouseDownVector = this . currentMouseVector . clone ( )
614
631
const intersect = this . raycastRing ( ) [ 0 ]
@@ -626,9 +643,14 @@ export class SceneInfra {
626
643
}
627
644
628
645
onMouseUp = async ( mouseEvent : MouseEvent ) => {
629
- this . currentMouseVector . x = ( mouseEvent . clientX / window . innerWidth ) * 2 - 1
646
+ if ( ! ( mouseEvent . currentTarget instanceof HTMLElement ) ) {
647
+ console . error ( 'unexpected targetless event' )
648
+ return
649
+ }
650
+ this . currentMouseVector . x =
651
+ ( mouseEvent . clientX / mouseEvent . currentTarget . clientWidth ) * 2 - 1
630
652
this . currentMouseVector . y =
631
- - ( mouseEvent . clientY / window . innerHeight ) * 2 + 1
653
+ - ( mouseEvent . clientY / mouseEvent . currentTarget . clientHeight ) * 2 + 1
632
654
const planeIntersectPoint = this . getPlaneIntersectPoint ( )
633
655
const intersects = this . raycastRing ( )
634
656
0 commit comments