Skip to content

Commit d45b8b9

Browse files
committed
Attempt to fix sketch mode rendering, something's still weird
1 parent 7f0b3b8 commit d45b8b9

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/clientSideScene/CameraControls.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,13 @@ export class CameraControls {
395395

396396
onWindowResize = () => {
397397
if (this.camera instanceof PerspectiveCamera) {
398-
this.camera.aspect = window.innerWidth / window.innerHeight
398+
this.camera.aspect =
399+
this.engineCommandManager.streamDimensions.width /
400+
this.engineCommandManager.streamDimensions.height
399401
} else if (this.camera instanceof OrthographicCamera) {
400-
const aspect = window.innerWidth / window.innerHeight
402+
const aspect =
403+
this.engineCommandManager.streamDimensions.width /
404+
this.engineCommandManager.streamDimensions.height
401405
this.camera.left = -ORTHOGRAPHIC_CAMERA_SIZE * aspect
402406
this.camera.right = ORTHOGRAPHIC_CAMERA_SIZE * aspect
403407
this.camera.top = ORTHOGRAPHIC_CAMERA_SIZE
@@ -586,7 +590,9 @@ export class CameraControls {
586590
const { x: px, y: py, z: pz } = this.camera.position
587591
const { x: qx, y: qy, z: qz, w: qw } = this.camera.quaternion
588592
const oldCamUp = this.camera.up.clone()
589-
const aspect = window.innerWidth / window.innerHeight
593+
const aspect =
594+
this.engineCommandManager.streamDimensions.width /
595+
this.engineCommandManager.streamDimensions.height
590596
this.lastPerspectiveFov = this.camera.fov
591597
const { z_near, z_far } = calculateNearFarFromFOV(this.lastPerspectiveFov)
592598
this.camera = new OrthographicCamera(
@@ -624,7 +630,8 @@ export class CameraControls {
624630
const previousCamUp = this.camera.up.clone()
625631
this.camera = new PerspectiveCamera(
626632
this.lastPerspectiveFov,
627-
window.innerWidth / window.innerHeight,
633+
this.engineCommandManager.streamDimensions.width /
634+
this.engineCommandManager.streamDimensions.height,
628635
z_near,
629636
z_far
630637
)

src/clientSideScene/sceneInfra.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ export class SceneInfra {
236236
_angle = typeof angle === 'number' ? angle : getAngle(from, to)
237237
}
238238

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
241241
const pathToNodeString = JSON.stringify(group.userData.pathToNode)
242242
return {
243243
type: 'set-one',
@@ -450,9 +450,14 @@ export class SceneInfra {
450450
}
451451
}
452452
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
454459
this.currentMouseVector.y =
455-
-(mouseEvent.clientY / window.innerHeight) * 2 + 1
460+
-(mouseEvent.clientY / mouseEvent.currentTarget.clientHeight) * 2 + 1
456461

457462
const planeIntersectPoint = this.getPlaneIntersectPoint()
458463
const intersects = this.raycastRing()
@@ -582,8 +587,14 @@ export class SceneInfra {
582587
// Check the ring points
583588
for (let i = 0; i < rayRingCount; i++) {
584589
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
587598
const ringVector = new Vector2(
588599
mouseDownVector.x + offsetX,
589600
mouseDownVector.y - offsetY
@@ -607,8 +618,14 @@ export class SceneInfra {
607618
}
608619

609620
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
612629

613630
const mouseDownVector = this.currentMouseVector.clone()
614631
const intersect = this.raycastRing()[0]
@@ -626,9 +643,14 @@ export class SceneInfra {
626643
}
627644

628645
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
630652
this.currentMouseVector.y =
631-
-(mouseEvent.clientY / window.innerHeight) * 2 + 1
653+
-(mouseEvent.clientY / mouseEvent.currentTarget.clientHeight) * 2 + 1
632654
const planeIntersectPoint = this.getPlaneIntersectPoint()
633655
const intersects = this.raycastRing()
634656

0 commit comments

Comments
 (0)