@playcanvas/inspector 0.1.0

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.
Files changed (77) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +110 -0
  3. package/package.json +62 -0
  4. package/src/asset-usage.js +108 -0
  5. package/src/asset-view.js +370 -0
  6. package/src/camera-view.js +128 -0
  7. package/src/debug.js +31 -0
  8. package/src/describe.js +302 -0
  9. package/src/entity-inspector-script.js +130 -0
  10. package/src/frame-graph-view.js +767 -0
  11. package/src/hierarchy-view.js +475 -0
  12. package/src/index.js +4 -0
  13. package/src/input/fly-controller.js +116 -0
  14. package/src/input/input.js +299 -0
  15. package/src/input/math.js +8 -0
  16. package/src/input/orbit-controller.js +158 -0
  17. package/src/input/pose.js +207 -0
  18. package/src/inspector.js +3293 -0
  19. package/src/instance-survey.js +50 -0
  20. package/src/list-view.js +410 -0
  21. package/src/material-view.js +197 -0
  22. package/src/memory-view.js +344 -0
  23. package/src/mesh-view.js +235 -0
  24. package/src/model.js +170 -0
  25. package/src/node-model.js +404 -0
  26. package/src/physics-debug.js +527 -0
  27. package/src/physics-view.js +314 -0
  28. package/src/picker/picker.js +545 -0
  29. package/src/picker/render-pass-picker.js +206 -0
  30. package/src/property-view.js +628 -0
  31. package/src/render-target-view.js +288 -0
  32. package/src/renderers/texture-renderer-shaders.js +139 -0
  33. package/src/renderers/texture-renderer.js +430 -0
  34. package/src/renderers/wire-renderer.js +954 -0
  35. package/src/script-view.js +288 -0
  36. package/src/shader-view.js +287 -0
  37. package/src/styles.js +918 -0
  38. package/src/texture-view.js +186 -0
  39. package/src/tooltip.js +72 -0
  40. package/src/viewport-tools.js +695 -0
  41. package/types/asset-usage.d.ts +23 -0
  42. package/types/asset-view.d.ts +94 -0
  43. package/types/camera-view.d.ts +45 -0
  44. package/types/debug.d.ts +14 -0
  45. package/types/describe.d.ts +43 -0
  46. package/types/entity-inspector-script.d.ts +87 -0
  47. package/types/frame-graph-view.d.ts +155 -0
  48. package/types/hierarchy-view.d.ts +172 -0
  49. package/types/index.d.ts +3 -0
  50. package/types/input/fly-controller.d.ts +42 -0
  51. package/types/input/input.d.ts +192 -0
  52. package/types/input/math.d.ts +1 -0
  53. package/types/input/orbit-controller.d.ts +63 -0
  54. package/types/input/pose.d.ts +126 -0
  55. package/types/inspector.d.ts +1304 -0
  56. package/types/instance-survey.d.ts +35 -0
  57. package/types/list-view.d.ts +151 -0
  58. package/types/material-view.d.ts +63 -0
  59. package/types/memory-view.d.ts +95 -0
  60. package/types/mesh-view.d.ts +89 -0
  61. package/types/model.d.ts +104 -0
  62. package/types/node-model.d.ts +54 -0
  63. package/types/physics-debug.d.ts +254 -0
  64. package/types/physics-view.d.ts +81 -0
  65. package/types/picker/picker.d.ts +255 -0
  66. package/types/picker/render-pass-picker.d.ts +47 -0
  67. package/types/property-view.d.ts +189 -0
  68. package/types/render-target-view.d.ts +98 -0
  69. package/types/renderers/texture-renderer-shaders.d.ts +9 -0
  70. package/types/renderers/texture-renderer.d.ts +231 -0
  71. package/types/renderers/wire-renderer.d.ts +347 -0
  72. package/types/script-view.d.ts +56 -0
  73. package/types/shader-view.d.ts +46 -0
  74. package/types/styles.d.ts +22 -0
  75. package/types/texture-view.d.ts +30 -0
  76. package/types/tooltip.d.ts +17 -0
  77. package/types/viewport-tools.d.ts +237 -0
@@ -0,0 +1,299 @@
1
+ import { EventHandler } from 'playcanvas';
2
+
3
+ import { Pose } from './pose.js';
4
+
5
+ /** @import { HandleEventCallback } from 'playcanvas' */
6
+
7
+ /**
8
+ * Represents an input delta: a fixed-length array of numbers that accumulates input between reads.
9
+ * Sources {@link append} raw values to it as events arrive, and {@link read} returns the total and
10
+ * resets it to zero, so each read yields the change since the previous one. An {@link InputFrame}
11
+ * groups named deltas together.
12
+ *
13
+ * @category Input
14
+ * @alpha
15
+ */
16
+ class InputDelta {
17
+ /**
18
+ * @type {number[]}
19
+ * @private
20
+ */
21
+ _value;
22
+
23
+ /**
24
+ * @param {number | number[]} arg - The size of the delta or an array of initial values.
25
+ */
26
+ constructor(arg) {
27
+ if (Array.isArray(arg)) {
28
+ this._value = arg.slice();
29
+ } else {
30
+ this._value = new Array(+arg).fill(0);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Adds another InputDelta instance to this one.
36
+ *
37
+ * @param {InputDelta} other - The other InputDelta instance to add.
38
+ * @returns {InputDelta} Self for chaining.
39
+ */
40
+ add(other) {
41
+ for (let i = 0; i < this._value.length; i++) {
42
+ this._value[i] += other._value[i] || 0;
43
+ }
44
+ return this;
45
+ }
46
+
47
+ /**
48
+ * Appends offsets to the current delta values.
49
+ *
50
+ * @param {number[]} offsets - The offsets.
51
+ * @returns {InputDelta} Self for chaining.
52
+ */
53
+ append(offsets) {
54
+ for (let i = 0; i < this._value.length; i++) {
55
+ this._value[i] += offsets[i] || 0;
56
+ }
57
+ return this;
58
+ }
59
+
60
+ /**
61
+ * Copies the values from another InputDelta instance to this one.
62
+ *
63
+ * @param {InputDelta} other - The other InputDelta instance to copy from.
64
+ * @returns {InputDelta} Self for chaining.
65
+ */
66
+ copy(other) {
67
+ for (let i = 0; i < this._value.length; i++) {
68
+ this._value[i] = other._value[i] || 0;
69
+ }
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * The magnitude of the delta, calculated as the square root of the sum of squares
75
+ * of the values.
76
+ *
77
+ * @returns {number} - The magnitude of the delta.
78
+ */
79
+ length() {
80
+ let sum = 0;
81
+ for (const value of this._value) {
82
+ sum += value * value;
83
+ }
84
+ return Math.sqrt(sum);
85
+ }
86
+
87
+ /**
88
+ * Returns the current value of the delta and resets it to zero.
89
+ *
90
+ * @returns {number[]} - The current value of the delta.
91
+ */
92
+ read() {
93
+ const value = this._value.slice();
94
+ this._value.fill(0);
95
+ return value;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Represents an input frame, which contains a map of input deltas. The keys and lengths are fixed
101
+ * by the object passed to the constructor, for example `{ move: [0, 0, 0], rotate: [0, 0, 0] }`,
102
+ * and {@link read} flushes every delta at once. A frame is the unit of exchange in this input
103
+ * system: {@link InputSource}s are frames that fill themselves from a device, and an application
104
+ * combines their values into a frame with the shape an {@link InputController} expects.
105
+ *
106
+ * @category Input
107
+ * @alpha
108
+ *
109
+ * @template {Record<string, number[]>} T - The shape of the input frame.
110
+ */
111
+ class InputFrame {
112
+ /**
113
+ * @type {{ [K in keyof T]: InputDelta }}
114
+ */
115
+ deltas = /** @type {{ [K in keyof T]: InputDelta }} */ ({});
116
+
117
+ /**
118
+ * @param {T} data - The input frame data, where each key corresponds to an input delta.
119
+ */
120
+ constructor(data) {
121
+ for (const name in data) {
122
+ this.deltas[name] = new InputDelta(data[name]);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Returns the current frame state and resets the deltas to zero.
128
+ *
129
+ * @returns {{ [K in keyof T]: number[] }} - The flushed input frame with current deltas.
130
+ */
131
+ read() {
132
+ const frame = /** @type {{ [K in keyof T]: number[] }} */ ({});
133
+ for (const name in this.deltas) {
134
+ frame[name] = this.deltas[name].read();
135
+ }
136
+ return frame;
137
+ }
138
+ }
139
+
140
+ /**
141
+ * The base class for all input devices. An input source is an {@link InputFrame} that fills its own
142
+ * deltas from DOM events or device polling once {@link attach} is given an element, and stops on
143
+ * {@link detach}. Call {@link InputFrame#read} once per frame to take the accumulated deltas. The
144
+ * built-in sources are {@link KeyboardMouseSource}, {@link GamepadSource},
145
+ * {@link MultiTouchSource}, {@link SingleGestureSource} and {@link DualGestureSource}; subclass
146
+ * this to add another device.
147
+ *
148
+ * @category Input
149
+ * @alpha
150
+ *
151
+ * @template {Record<string, number[]>} T - The shape of the input source.
152
+ * @augments {InputFrame<T>}
153
+ */
154
+ class InputSource extends InputFrame {
155
+ /**
156
+ * @type {HTMLElement | null}
157
+ * @protected
158
+ */
159
+ _element = null;
160
+
161
+ /**
162
+ * @type {EventHandler}
163
+ * @private
164
+ */
165
+ _events = new EventHandler();
166
+
167
+ /**
168
+ * Adds an event listener for the specified event.
169
+ *
170
+ * @param {string} event - The event name to listen for.
171
+ * @param {HandleEventCallback} callback - The callback function to execute when the event is
172
+ * triggered.
173
+ */
174
+ on(event, callback) {
175
+ this._events.on(event, callback);
176
+ }
177
+
178
+ /**
179
+ * Removes an event listener for the specified event.
180
+ *
181
+ * @param {string} event - The event name to stop listening for.
182
+ * @param {HandleEventCallback} callback - The callback function to remove.
183
+ */
184
+ off(event, callback) {
185
+ this._events.off(event, callback);
186
+ }
187
+
188
+ /**
189
+ * Fires an event with the given name and arguments.
190
+ *
191
+ * @param {string} event - The event name to fire.
192
+ * @param {...any} args - The arguments to pass to the event listeners.
193
+ */
194
+ fire(event, ...args) {
195
+ this._events.fire(event, ...args);
196
+ }
197
+
198
+ /**
199
+ * @param {HTMLElement} element - The element.
200
+ */
201
+ attach(element) {
202
+ if (this._element) {
203
+ this.detach();
204
+ }
205
+ this._element = element;
206
+ }
207
+
208
+ detach() {
209
+ if (!this._element) {
210
+ return;
211
+ }
212
+ this._element = null;
213
+ this.read();
214
+ }
215
+
216
+ destroy() {
217
+ this.detach();
218
+ this._events.off();
219
+ }
220
+ }
221
+
222
+ /**
223
+ * The base class for all input consumers, which are used to process input frames. A consumer
224
+ * implements {@link update}, receiving an {@link InputFrame} and the frame time, and does whatever
225
+ * that input means for it. {@link InputController} is the consumer that turns input into a
226
+ * {@link Pose}.
227
+ *
228
+ * @category Input
229
+ * @alpha
230
+ */
231
+ class InputConsumer {
232
+ /**
233
+ * @param {InputFrame} frame - The input frame.
234
+ * @param {number} dt - The delta time.
235
+ */
236
+ update(frame, dt) {
237
+ // discard frame by default
238
+ frame.read();
239
+ }
240
+ }
241
+
242
+ /**
243
+ * The base class for all input controllers. A controller consumes an {@link InputFrame} carrying
244
+ * `move` and `rotate` deltas and produces a {@link Pose}: {@link attach} sets the pose it starts
245
+ * from, {@link update} applies a frame and returns the current pose, and {@link detach} releases
246
+ * it. The application applies the returned pose to an entity. {@link FlyController},
247
+ * {@link OrbitController} and {@link FocusController} implement three ways of doing this.
248
+ *
249
+ * @example
250
+ * controller.attach(pose.look(cameraPosition, target));
251
+ *
252
+ * // each frame, after filling the frame's move and rotate deltas from your sources
253
+ * const result = controller.update(frame, dt);
254
+ * camera.setPosition(result.position);
255
+ * camera.setEulerAngles(result.angles);
256
+ * @category Input
257
+ * @alpha
258
+ */
259
+ class InputController extends InputConsumer {
260
+ /**
261
+ * @type {Pose}
262
+ * @protected
263
+ */
264
+ _pose = new Pose();
265
+
266
+ /**
267
+ * @param {Pose} pose - The initial pose of the controller.
268
+ * @param {boolean} [smooth] - Whether to smooth the transition.
269
+ */
270
+ attach(pose, smooth = true) {
271
+ }
272
+
273
+ detach() {
274
+ }
275
+
276
+ /**
277
+ * @param {InputFrame} frame - The input frame.
278
+ * @param {number} dt - The delta time.
279
+ * @returns {Pose} - The controller pose.
280
+ * @override
281
+ */
282
+ update(frame, dt) {
283
+ super.update(frame, dt);
284
+
285
+ return this._pose;
286
+ }
287
+
288
+ destroy() {
289
+ this.detach();
290
+ }
291
+ }
292
+
293
+ export {
294
+ InputDelta,
295
+ InputFrame,
296
+ InputSource,
297
+ InputConsumer,
298
+ InputController
299
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculate the damp rate.
3
+ *
4
+ * @param {number} damping - The damping.
5
+ * @param {number} dt - The delta time.
6
+ * @returns {number} - The lerp rate.
7
+ */
8
+ export const damp = (damping, dt) => 1 - Math.pow(damping, dt * 1000);
@@ -0,0 +1,158 @@
1
+ import { Quat, Vec3 } from 'playcanvas';
2
+
3
+ import { InputController } from './input.js';
4
+ import { damp } from './math.js';
5
+ import { Pose } from './pose.js';
6
+
7
+ /** @import { InputFrame } from './input.js'; */
8
+
9
+ const dir = new Vec3();
10
+ const offset = new Vec3();
11
+ const angles = new Vec3();
12
+
13
+ const rotation = new Quat();
14
+
15
+ /**
16
+ * The orbit controller. The pose orbits a focus point at a distance: `rotate` deltas turn the
17
+ * view around the focus within {@link yawRange} and {@link pitchRange}, the first two `move`
18
+ * components pan the focus point, and the third scales the distance within {@link zoomRange}.
19
+ * Motion is smoothed with {@link rotateDamping}, {@link moveDamping} and {@link zoomDamping}.
20
+ *
21
+ * @category Input
22
+ * @alpha
23
+ */
24
+ class OrbitController extends InputController {
25
+ /**
26
+ * @type {Pose}
27
+ * @private
28
+ */
29
+ _targetRootPose = new Pose();
30
+
31
+ /**
32
+ * @type {Pose}
33
+ * @private
34
+ */
35
+ _rootPose = new Pose();
36
+
37
+ /**
38
+ * @type {Pose}
39
+ * @private
40
+ */
41
+ _targetChildPose = new Pose();
42
+
43
+ /**
44
+ * @type {Pose}
45
+ * @private
46
+ */
47
+ _childPose = new Pose();
48
+
49
+ /**
50
+ * The rotation damping. In the range 0 to 1, where a value of 0 means no damping and 1 means
51
+ * full damping. Default is 0.98.
52
+ */
53
+ rotateDamping = 0.98;
54
+
55
+ /**
56
+ * The movement damping. In the range 0 to 1, where a value of 0 means no damping and 1 means
57
+ * full damping. Default is 0.98.
58
+ */
59
+ moveDamping = 0.98;
60
+
61
+ /**
62
+ * The zoom damping. A higher value means more damping. A value of 0 means no damping.
63
+ */
64
+ zoomDamping = 0.98;
65
+
66
+ set pitchRange(range) {
67
+ this._targetRootPose.pitchRange.copy(range);
68
+ this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
69
+ }
70
+
71
+ get pitchRange() {
72
+ return this._targetRootPose.pitchRange;
73
+ }
74
+
75
+ set yawRange(range) {
76
+ this._targetRootPose.yawRange.copy(range);
77
+ this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
78
+ }
79
+
80
+ get yawRange() {
81
+ return this._targetRootPose.yawRange;
82
+ }
83
+
84
+ set zoomRange(range) {
85
+ this._targetChildPose.zRange.copy(range);
86
+ this._childPose.copy(this._targetChildPose.move(Vec3.ZERO));
87
+ }
88
+
89
+ get zoomRange() {
90
+ return this._targetRootPose.zRange;
91
+ }
92
+
93
+ /**
94
+ * @param {Pose} pose - The initial pose of the controller.
95
+ * @param {boolean} [smooth] - Whether to smooth the transition.
96
+ */
97
+ attach(pose, smooth = true) {
98
+ this._targetRootPose.set(pose.getFocus(dir), pose.angles, 0);
99
+ this._targetChildPose.position.set(0, 0, pose.distance);
100
+
101
+ if (!smooth) {
102
+ this._rootPose.copy(this._targetRootPose);
103
+ this._childPose.copy(this._targetChildPose);
104
+ }
105
+ }
106
+
107
+ detach() {
108
+ this._targetRootPose.copy(this._rootPose);
109
+ this._targetChildPose.copy(this._childPose);
110
+ }
111
+
112
+ /**
113
+ * @param {InputFrame<{ move: number[], rotate: number[] }>} frame - The input frame.
114
+ * @param {number} dt - The delta time.
115
+ * @returns {Pose} - The controller pose.
116
+ */
117
+ update(frame, dt) {
118
+ const { move, rotate } = frame.read();
119
+
120
+ // move
121
+ offset.set(move[0], move[1], 0);
122
+ rotation.setFromEulerAngles(this._rootPose.angles).transformVector(offset, offset);
123
+ this._targetRootPose.move(offset);
124
+ const { z: dist } = this._targetChildPose.position;
125
+ this._targetChildPose.move(offset.set(0, 0, dist * (1 + move[2]) - dist));
126
+
127
+ // rotate
128
+ this._targetRootPose.rotate(angles.set(-rotate[1], -rotate[0], 0));
129
+
130
+ // smoothing
131
+ this._rootPose.lerp(
132
+ this._rootPose,
133
+ this._targetRootPose,
134
+ damp(this.moveDamping, dt),
135
+ damp(this.rotateDamping, dt),
136
+ 1
137
+ );
138
+ this._childPose.lerp(
139
+ this._childPose,
140
+ this._targetChildPose,
141
+ damp(this.zoomDamping, dt),
142
+ 1,
143
+ 1
144
+ );
145
+
146
+ // calculate final pose
147
+ rotation.setFromEulerAngles(this._rootPose.angles)
148
+ .transformVector(this._childPose.position, offset)
149
+ .add(this._rootPose.position);
150
+ return this._pose.set(offset, this._rootPose.angles, this._childPose.position.z);
151
+ }
152
+
153
+ destroy() {
154
+ this.detach();
155
+ }
156
+ }
157
+
158
+ export { OrbitController };
@@ -0,0 +1,207 @@
1
+ import { math, Quat, Vec2, Vec3 } from 'playcanvas';
2
+
3
+ const tmpV1 = new Vec3();
4
+ const rotation = new Quat();
5
+
6
+ /**
7
+ * Represents a pose in 3D space, including position and rotation. It is what an
8
+ * {@link InputController} produces: a {@link position}, Euler {@link angles} in degrees and, for
9
+ * controllers that orbit, the {@link distance} to the focus point. Optional ranges such as
10
+ * {@link pitchRange} and {@link yRange} clamp the result of {@link rotate} and {@link move}.
11
+ *
12
+ * @category Input
13
+ * @alpha
14
+ */
15
+ class Pose {
16
+ /**
17
+ * The position of the pose.
18
+ */
19
+ position = new Vec3();
20
+
21
+ /**
22
+ * The angles of the pose in degrees calculated from the forward vector.
23
+ */
24
+ angles = new Vec3();
25
+
26
+ /**
27
+ * The focus distance from the position to the pose.
28
+ */
29
+ distance = 0;
30
+
31
+ /**
32
+ * The allowed range of pitch angles in degrees, stored as (min, max). Applied when the pose
33
+ * is rotated via {@link rotate}.
34
+ */
35
+ pitchRange = new Vec2(-Infinity, Infinity);
36
+
37
+ /**
38
+ * The allowed range of yaw angles in degrees, stored as (min, max). Applied when the pose is
39
+ * rotated via {@link rotate}.
40
+ */
41
+ yawRange = new Vec2(-Infinity, Infinity);
42
+
43
+ /**
44
+ * The allowed range of positions along the x axis, stored as (min, max). Applied when the
45
+ * pose is translated via {@link move}.
46
+ */
47
+ xRange = new Vec2(-Infinity, Infinity);
48
+
49
+ /**
50
+ * The allowed range of positions along the y axis, stored as (min, max). Applied when the
51
+ * pose is translated via {@link move}.
52
+ */
53
+ yRange = new Vec2(-Infinity, Infinity);
54
+
55
+ /**
56
+ * The allowed range of positions along the z axis, stored as (min, max). Applied when the
57
+ * pose is translated via {@link move}.
58
+ */
59
+ zRange = new Vec2(-Infinity, Infinity);
60
+
61
+ /**
62
+ * Creates a new Pose instance.
63
+ *
64
+ * @param {Vec3} [position] - The position of the pose.
65
+ * @param {Vec3} [angles] - The angles of the pose in degrees.
66
+ * @param {number} [distance] - The focus distance from the position to the pose.
67
+ */
68
+ constructor(position = Vec3.ZERO, angles = Vec3.ZERO, distance = 0) {
69
+ this.set(position, angles, distance);
70
+ }
71
+
72
+ /**
73
+ * Copies the position and rotation from another pose.
74
+ *
75
+ * @param {Pose} other - The pose to copy from.
76
+ * @returns {Pose} The updated Pose instance.
77
+ */
78
+ copy(other) {
79
+ return this.set(other.position, other.angles, other.distance);
80
+ }
81
+
82
+ /**
83
+ * Creates a clone of this pose.
84
+ *
85
+ * @returns {Pose} A new Pose instance with the same position, angles, and distance.
86
+ */
87
+ clone() {
88
+ return new Pose(this.position.clone(), this.angles.clone(), this.distance);
89
+ }
90
+
91
+ /**
92
+ * Checks if this pose is approximately equal to another pose within a given epsilon.
93
+ *
94
+ * @param {Pose} other - The pose to compare with.
95
+ * @param {number} [epsilon] - The tolerance for comparison.
96
+ * @returns {boolean} True if the poses are approximately equal, false otherwise.
97
+ */
98
+ equalsApprox(other, epsilon = 1e-6) {
99
+ return this.position.equalsApprox(other.position, epsilon) &&
100
+ this.angles.equalsApprox(other.angles, epsilon) &&
101
+ Math.abs(this.distance - other.distance) < epsilon;
102
+ }
103
+
104
+ /**
105
+ * Lerps between two poses based on the given alpha values.
106
+ *
107
+ * @param {Pose} lhs - The left-hand side pose.
108
+ * @param {Pose} rhs - The right-hand side pose.
109
+ * @param {number} alpha1 - The alpha value for position interpolation.
110
+ * @param {number} [alpha2] - The alpha value for angles interpolation.
111
+ * @param {number} [alpha3] - The alpha value for distance interpolation.
112
+ * @returns {Pose} The updated Pose instance.
113
+ */
114
+ lerp(lhs, rhs, alpha1, alpha2 = alpha1, alpha3 = alpha1) {
115
+ this.position.lerp(lhs.position, rhs.position, alpha1);
116
+ this.angles.x = math.lerpAngle(lhs.angles.x, rhs.angles.x, alpha2) % 360;
117
+ this.angles.y = math.lerpAngle(lhs.angles.y, rhs.angles.y, alpha2) % 360;
118
+ this.angles.z = math.lerpAngle(lhs.angles.z, rhs.angles.z, alpha2) % 360;
119
+ this.distance = math.lerp(lhs.distance, rhs.distance, alpha3);
120
+ return this;
121
+ }
122
+
123
+ /**
124
+ * Moves the pose by the given vector.
125
+ *
126
+ * @param {Vec3} offset - The vector to move by.
127
+ * @returns {Pose} The updated Pose instance.
128
+ */
129
+ move(offset) {
130
+ this.position.add(offset);
131
+
132
+ // clamp position
133
+ this.position.x = math.clamp(this.position.x, this.xRange.x, this.xRange.y);
134
+ this.position.y = math.clamp(this.position.y, this.yRange.x, this.yRange.y);
135
+ this.position.z = math.clamp(this.position.z, this.zRange.x, this.zRange.y);
136
+
137
+ return this;
138
+ }
139
+
140
+ /**
141
+ * Rotates the pose by the given angles in degrees.
142
+ *
143
+ * @param {Vec3} euler - The angles to rotate by.
144
+ * @returns {Pose} The updated Pose instance.
145
+ */
146
+ rotate(euler) {
147
+ this.angles.add(euler);
148
+
149
+ // wrap angles to [0, 360)
150
+ this.angles.x %= 360;
151
+ this.angles.y %= 360;
152
+ this.angles.z %= 360;
153
+
154
+ // clamp pitch and yaw
155
+ this.angles.x = math.clamp(this.angles.x, this.pitchRange.x, this.pitchRange.y);
156
+ this.angles.y = math.clamp(this.angles.y, this.yawRange.x, this.yawRange.y);
157
+
158
+ return this;
159
+ }
160
+
161
+ /**
162
+ * Sets the position and rotation of the pose.
163
+ *
164
+ * @param {Vec3} position - The new position.
165
+ * @param {Vec3} angles - The new angles in degrees.
166
+ * @param {number} distance - The new focus distance.
167
+ * @returns {Pose} The updated Pose instance.
168
+ */
169
+ set(position, angles, distance) {
170
+ this.position.copy(position);
171
+ this.angles.copy(angles);
172
+ this.distance = distance;
173
+ return this;
174
+ }
175
+
176
+ /**
177
+ * Sets the pose to look in the direction of the given vector.
178
+ *
179
+ * @param {Vec3} from - The point from which to look.
180
+ * @param {Vec3} to - The point to look at.
181
+ * @returns {Pose} The updated Pose instance.
182
+ */
183
+ look(from, to) {
184
+ this.position.copy(from);
185
+ this.distance = from.distance(to);
186
+ const dir = tmpV1.sub2(to, from).normalize();
187
+ const elev = Math.atan2(-dir.y, Math.sqrt(dir.x * dir.x + dir.z * dir.z)) * math.RAD_TO_DEG;
188
+ const azim = Math.atan2(-dir.x, -dir.z) * math.RAD_TO_DEG;
189
+ this.angles.set(-elev, azim, 0);
190
+ return this;
191
+ }
192
+
193
+ /**
194
+ * Gets the focus point of the pose, which is the position plus the forward vector scaled by the distance.
195
+ *
196
+ * @param {Vec3} [out] - The output vector to store the focus point.
197
+ * @returns {Vec3} The focus point of the pose.
198
+ */
199
+ getFocus(out) {
200
+ return rotation.setFromEulerAngles(this.angles)
201
+ .transformVector(Vec3.FORWARD, out)
202
+ .mulScalar(this.distance)
203
+ .add(this.position);
204
+ }
205
+ }
206
+
207
+ export { Pose };