@viamrobotics/motion-tools 1.15.3 → 1.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CameraControlsRef } from '@threlte/extras'
|
|
3
3
|
|
|
4
|
-
import { useTask } from '@threlte/core'
|
|
4
|
+
import { isInstanceOf, useTask } from '@threlte/core'
|
|
5
5
|
import { PressedKeys } from 'runed'
|
|
6
|
-
import { MathUtils } from 'three'
|
|
6
|
+
import { MathUtils, Vector3 } from 'three'
|
|
7
7
|
|
|
8
8
|
import { useFocusedEntity, useSelectedEntity } from '../hooks/useSelection.svelte'
|
|
9
9
|
import { useSettings } from '../hooks/useSettings.svelte'
|
|
@@ -35,7 +35,36 @@
|
|
|
35
35
|
const left = $derived(keys.has('arrowleft'))
|
|
36
36
|
const down = $derived(keys.has('arrowdown'))
|
|
37
37
|
const right = $derived(keys.has('arrowright'))
|
|
38
|
-
const
|
|
38
|
+
const anyKeysPressed = $derived(w || s || a || d || r || f || up || left || down || right)
|
|
39
|
+
|
|
40
|
+
const target = new Vector3()
|
|
41
|
+
|
|
42
|
+
const PERSPECTIVE_DISTANCE_FACTOR = 0.0001
|
|
43
|
+
const PERSPECTIVE_MIN_SPEED = 0.00001
|
|
44
|
+
|
|
45
|
+
const ORTHOGRAPHIC_ZOOM_FACTOR = 0.1
|
|
46
|
+
const ORTHOGRAPHIC_MIN_SPEED = 0.00005
|
|
47
|
+
|
|
48
|
+
const FALLBACK_SPEED = 0.001
|
|
49
|
+
|
|
50
|
+
const getMovementScale = () => {
|
|
51
|
+
const camera = cameraControls.camera
|
|
52
|
+
|
|
53
|
+
if (isInstanceOf(camera, 'PerspectiveCamera')) {
|
|
54
|
+
cameraControls.getTarget(target)
|
|
55
|
+
|
|
56
|
+
const distance = camera.position.distanceTo(target)
|
|
57
|
+
const scaled = distance * PERSPECTIVE_DISTANCE_FACTOR
|
|
58
|
+
return Math.max(scaled, PERSPECTIVE_MIN_SPEED)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (isInstanceOf(camera, 'OrthographicCamera')) {
|
|
62
|
+
const scaled = ORTHOGRAPHIC_ZOOM_FACTOR / camera.zoom
|
|
63
|
+
return Math.max(scaled, ORTHOGRAPHIC_MIN_SPEED)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return FALLBACK_SPEED
|
|
67
|
+
}
|
|
39
68
|
|
|
40
69
|
const { start, stop } = useTask(
|
|
41
70
|
(delta) => {
|
|
@@ -46,44 +75,58 @@
|
|
|
46
75
|
return
|
|
47
76
|
}
|
|
48
77
|
|
|
78
|
+
const moveSpeed = getMovementScale() * dt
|
|
79
|
+
const rotateSpeed = 0.1 * MathUtils.DEG2RAD * dt
|
|
80
|
+
const tiltSpeed = 0.05 * MathUtils.DEG2RAD * dt
|
|
81
|
+
const dollySpeed = 0.005 * dt
|
|
82
|
+
const zoomSpeed = 0.5 * dt
|
|
83
|
+
|
|
49
84
|
if (a) {
|
|
50
|
-
cameraControls.truck(-
|
|
85
|
+
cameraControls.truck(-moveSpeed * dt, 0, true)
|
|
51
86
|
}
|
|
52
87
|
|
|
53
88
|
if (d) {
|
|
54
|
-
cameraControls.truck(
|
|
89
|
+
cameraControls.truck(moveSpeed * dt, 0, true)
|
|
55
90
|
}
|
|
56
91
|
|
|
57
92
|
if (w) {
|
|
58
|
-
cameraControls.forward(
|
|
93
|
+
cameraControls.forward(moveSpeed * dt, true)
|
|
59
94
|
}
|
|
60
95
|
|
|
61
96
|
if (s) {
|
|
62
|
-
cameraControls.forward(-
|
|
97
|
+
cameraControls.forward(-moveSpeed * dt, true)
|
|
63
98
|
}
|
|
64
99
|
|
|
65
100
|
if (r) {
|
|
66
|
-
cameraControls.
|
|
101
|
+
if (isInstanceOf(cameraControls.camera, 'PerspectiveCamera')) {
|
|
102
|
+
cameraControls.dolly(dollySpeed, true)
|
|
103
|
+
} else {
|
|
104
|
+
cameraControls.zoom(zoomSpeed, true)
|
|
105
|
+
}
|
|
67
106
|
}
|
|
68
107
|
|
|
69
108
|
if (f) {
|
|
70
|
-
cameraControls.
|
|
109
|
+
if (isInstanceOf(cameraControls.camera, 'PerspectiveCamera')) {
|
|
110
|
+
cameraControls.dolly(-dollySpeed, true)
|
|
111
|
+
} else {
|
|
112
|
+
cameraControls.zoom(-zoomSpeed, true)
|
|
113
|
+
}
|
|
71
114
|
}
|
|
72
115
|
|
|
73
116
|
if (left) {
|
|
74
|
-
cameraControls.rotate(-
|
|
117
|
+
cameraControls.rotate(-rotateSpeed, 0, true)
|
|
75
118
|
}
|
|
76
119
|
|
|
77
120
|
if (right) {
|
|
78
|
-
cameraControls.rotate(
|
|
121
|
+
cameraControls.rotate(rotateSpeed, 0, true)
|
|
79
122
|
}
|
|
80
123
|
|
|
81
124
|
if (up) {
|
|
82
|
-
cameraControls.rotate(0, -
|
|
125
|
+
cameraControls.rotate(0, -tiltSpeed, true)
|
|
83
126
|
}
|
|
84
127
|
|
|
85
128
|
if (down) {
|
|
86
|
-
cameraControls.rotate(0,
|
|
129
|
+
cameraControls.rotate(0, tiltSpeed, true)
|
|
87
130
|
}
|
|
88
131
|
},
|
|
89
132
|
{
|
|
@@ -93,7 +136,7 @@
|
|
|
93
136
|
)
|
|
94
137
|
|
|
95
138
|
$effect.pre(() => {
|
|
96
|
-
if (
|
|
139
|
+
if (anyKeysPressed) {
|
|
97
140
|
start()
|
|
98
141
|
} else {
|
|
99
142
|
stop()
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
intersection = event.intersections[0]
|
|
36
36
|
|
|
37
37
|
// Only handle axis restrictions if a first point has been placed
|
|
38
|
-
if (!p1) {
|
|
38
|
+
if (!p1 || !intersection) {
|
|
39
39
|
return
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
{#if enabled}
|
|
128
128
|
{#if intersection && step !== 'p2'}
|
|
129
129
|
<MeasurePoint
|
|
130
|
-
position={intersection
|
|
130
|
+
position={intersection.point.toArray()}
|
|
131
131
|
opacity={0.5}
|
|
132
132
|
/>
|
|
133
133
|
{/if}
|