@needle-tools/engine 4.3.0-alpha → 4.3.0-alpha.3
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.
- package/CHANGELOG.md +7 -0
- package/dist/needle-engine.bundle.js +6683 -5393
- package/dist/needle-engine.bundle.light.js +6687 -5397
- package/dist/needle-engine.bundle.light.min.js +121 -118
- package/dist/needle-engine.bundle.light.umd.cjs +128 -125
- package/dist/needle-engine.bundle.min.js +119 -116
- package/dist/needle-engine.bundle.umd.cjs +124 -121
- package/dist/needle-engine.d.ts +9 -9
- package/dist/needle-engine.light.d.ts +9 -9
- package/lib/engine/engine_context.js +1 -1
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.js +2 -4
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +1 -1
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_types.d.ts +162 -17
- package/lib/engine/xr/NeedleXRSession.d.ts +6 -1
- package/lib/engine/xr/NeedleXRSession.js +6 -1
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/Animator.d.ts +129 -21
- package/lib/engine-components/Animator.js +115 -21
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +161 -32
- package/lib/engine-components/AnimatorController.js +176 -29
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioListener.d.ts +16 -5
- package/lib/engine-components/AudioListener.js +16 -5
- package/lib/engine-components/AudioListener.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +120 -28
- package/lib/engine-components/AudioSource.js +121 -40
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/AvatarLoader.d.ts +61 -0
- package/lib/engine-components/AvatarLoader.js +61 -1
- package/lib/engine-components/AvatarLoader.js.map +1 -1
- package/lib/engine-components/AxesHelper.d.ts +19 -1
- package/lib/engine-components/AxesHelper.js +19 -1
- package/lib/engine-components/AxesHelper.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
- package/lib/engine-components/BoxHelperComponent.js +26 -0
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +126 -37
- package/lib/engine-components/Camera.js +139 -37
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.js +20 -0
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +95 -21
- package/lib/engine-components/Collider.js +100 -23
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +554 -106
- package/lib/engine-components/Component.js +352 -81
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +95 -21
- package/lib/engine-components/DragControls.js +126 -32
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +99 -16
- package/lib/engine-components/DropListener.js +119 -14
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/Light.d.ts +102 -5
- package/lib/engine-components/Light.js +102 -44
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/NeedleMenu.d.ts +28 -11
- package/lib/engine-components/NeedleMenu.js +28 -11
- package/lib/engine-components/NeedleMenu.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +37 -5
- package/lib/engine-components/Networking.js +37 -5
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.js +44 -0
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +66 -1
- package/lib/engine-components/SpatialTrigger.js +74 -2
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +66 -4
- package/lib/engine-components/SpectatorCamera.js +132 -6
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.d.ts +45 -6
- package/lib/engine-components/SyncedTransform.js +45 -6
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +49 -3
- package/lib/engine-components/TransformGizmo.js +49 -3
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.js +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
- package/lib/engine-components/webxr/WebARSessionRoot.d.ts +8 -3
- package/lib/engine-components/webxr/WebARSessionRoot.js +30 -9
- package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.d.ts +156 -25
- package/lib/engine-components/webxr/WebXR.js +160 -26
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
- package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_context.ts +1 -1
- package/src/engine/engine_mainloop_utils.ts +2 -4
- package/src/engine/engine_serialization_core.ts +1 -1
- package/src/engine/engine_types.ts +179 -18
- package/src/engine/xr/NeedleXRSession.ts +7 -1
- package/src/engine-components/Animator.ts +142 -22
- package/src/engine-components/AnimatorController.ts +184 -34
- package/src/engine-components/AudioListener.ts +16 -5
- package/src/engine-components/AudioSource.ts +127 -39
- package/src/engine-components/AvatarLoader.ts +61 -2
- package/src/engine-components/AxesHelper.ts +21 -1
- package/src/engine-components/BoxHelperComponent.ts +26 -0
- package/src/engine-components/Camera.ts +147 -41
- package/src/engine-components/CameraUtils.ts +20 -0
- package/src/engine-components/Collider.ts +102 -27
- package/src/engine-components/Component.ts +605 -129
- package/src/engine-components/DragControls.ts +134 -38
- package/src/engine-components/DropListener.ts +143 -23
- package/src/engine-components/Light.ts +105 -44
- package/src/engine-components/NeedleMenu.ts +29 -11
- package/src/engine-components/Networking.ts +37 -6
- package/src/engine-components/SceneSwitcher.ts +48 -1
- package/src/engine-components/SpatialTrigger.ts +80 -3
- package/src/engine-components/SpectatorCamera.ts +136 -18
- package/src/engine-components/SyncedTransform.ts +50 -7
- package/src/engine-components/TransformGizmo.ts +49 -4
- package/src/engine-components/particlesystem/ParticleSystem.ts +2 -2
- package/src/engine-components/webxr/WebARSessionRoot.ts +31 -8
- package/src/engine-components/webxr/WebXR.ts +173 -29
- package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
|
@@ -13,8 +13,11 @@ import { RGBAColor } from "../engine/js-extensions/index.js";
|
|
|
13
13
|
import { Behaviour, GameObject } from "./Component.js";
|
|
14
14
|
import { OrbitControls } from "./OrbitControls.js";
|
|
15
15
|
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The ClearFlags enum is used to determine how the camera clears the background
|
|
18
|
+
*/
|
|
17
19
|
export enum ClearFlags {
|
|
20
|
+
/** Don't clear the background */
|
|
18
21
|
None = 0,
|
|
19
22
|
/** Clear the background with a skybox */
|
|
20
23
|
Skybox = 1,
|
|
@@ -28,16 +31,28 @@ const debug = getParam("debugcam");
|
|
|
28
31
|
const debugscreenpointtoray = getParam("debugscreenpointtoray");
|
|
29
32
|
|
|
30
33
|
/**
|
|
34
|
+
* Camera component that handles rendering from a specific viewpoint in the scene.
|
|
35
|
+
* Supports both perspective and orthographic cameras with various rendering options.
|
|
36
|
+
* Internally, this component uses {@link PerspectiveCamera} and {@link OrthographicCamera} three.js objects.
|
|
37
|
+
*
|
|
31
38
|
* @category Camera Controls
|
|
32
39
|
* @group Components
|
|
33
40
|
*/
|
|
34
41
|
export class Camera extends Behaviour implements ICamera {
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Returns whether this component is a camera
|
|
45
|
+
* @returns {boolean} Always returns true
|
|
46
|
+
*/
|
|
36
47
|
get isCamera() {
|
|
37
48
|
return true;
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Gets or sets the camera's aspect ratio (width divided by height).
|
|
53
|
+
* For perspective cameras, this directly affects the camera's projection matrix.
|
|
54
|
+
* When set, automatically updates the projection matrix.
|
|
55
|
+
*/
|
|
41
56
|
get aspect(): number {
|
|
42
57
|
if (this._cam instanceof PerspectiveCamera) return this._cam.aspect;
|
|
43
58
|
return (this.context.domWidth / this.context.domHeight);
|
|
@@ -51,7 +66,11 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
68
|
}
|
|
54
|
-
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets or sets the camera's field of view in degrees for perspective cameras.
|
|
72
|
+
* When set, automatically updates the projection matrix.
|
|
73
|
+
*/
|
|
55
74
|
get fieldOfView(): number | undefined {
|
|
56
75
|
if (this._cam instanceof PerspectiveCamera) {
|
|
57
76
|
return this._cam.fov;
|
|
@@ -74,7 +93,11 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Gets or sets the camera's near clipping plane distance.
|
|
98
|
+
* Objects closer than this distance won't be rendered.
|
|
99
|
+
* When set, automatically updates the projection matrix.
|
|
100
|
+
*/
|
|
78
101
|
get nearClipPlane(): number { return this._nearClipPlane; }
|
|
79
102
|
@serializable()
|
|
80
103
|
set nearClipPlane(val) {
|
|
@@ -87,7 +110,11 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
87
110
|
}
|
|
88
111
|
private _nearClipPlane: number = 0.1;
|
|
89
112
|
|
|
90
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Gets or sets the camera's far clipping plane distance.
|
|
115
|
+
* Objects farther than this distance won't be rendered.
|
|
116
|
+
* When set, automatically updates the projection matrix.
|
|
117
|
+
*/
|
|
91
118
|
get farClipPlane(): number { return this._farClipPlane; }
|
|
92
119
|
@serializable()
|
|
93
120
|
set farClipPlane(val) {
|
|
@@ -101,7 +128,8 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
101
128
|
private _farClipPlane: number = 1000;
|
|
102
129
|
|
|
103
130
|
/**
|
|
104
|
-
*
|
|
131
|
+
* Applies both the camera's near and far clipping planes and updates the projection matrix.
|
|
132
|
+
* This ensures rendering occurs only within the specified distance range.
|
|
105
133
|
*/
|
|
106
134
|
applyClippingPlane() {
|
|
107
135
|
if (this._cam) {
|
|
@@ -111,7 +139,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
111
139
|
}
|
|
112
140
|
}
|
|
113
141
|
|
|
114
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* Gets or sets the camera's clear flags that determine how the background is rendered.
|
|
144
|
+
* Options include skybox, solid color, or transparent background.
|
|
145
|
+
*/
|
|
115
146
|
@serializable()
|
|
116
147
|
public get clearFlags(): ClearFlags {
|
|
117
148
|
return this._clearFlags;
|
|
@@ -121,18 +152,31 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
121
152
|
this._clearFlags = val;
|
|
122
153
|
this.applyClearFlagsIfIsActiveCamera();
|
|
123
154
|
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Determines if the camera should use orthographic projection instead of perspective.
|
|
158
|
+
*/
|
|
124
159
|
@serializable()
|
|
125
160
|
public orthographic: boolean = false;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The size of the orthographic camera's view volume when in orthographic mode.
|
|
164
|
+
* Larger values show more of the scene.
|
|
165
|
+
*/
|
|
126
166
|
@serializable()
|
|
127
167
|
public orthographicSize: number = 5;
|
|
128
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Controls the transparency level of the camera background in AR mode on supported devices.
|
|
171
|
+
* Value from 0 (fully transparent) to 1 (fully opaque).
|
|
172
|
+
*/
|
|
129
173
|
@serializable()
|
|
130
174
|
public ARBackgroundAlpha: number = 0;
|
|
131
175
|
|
|
132
176
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
|
|
177
|
+
* Gets or sets the layers mask that determines which objects this camera will render.
|
|
178
|
+
* Uses the {@link https://threejs.org/docs/#api/en/core/Layers.mask|three.js layers mask} convention.
|
|
179
|
+
*/
|
|
136
180
|
@serializable()
|
|
137
181
|
public set cullingMask(val: number) {
|
|
138
182
|
this._cullingMask = val;
|
|
@@ -146,14 +190,19 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
146
190
|
}
|
|
147
191
|
private _cullingMask: number = 0xffffffff;
|
|
148
192
|
|
|
149
|
-
/**
|
|
150
|
-
*
|
|
151
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Sets only a specific layer to be active for rendering by this camera.
|
|
195
|
+
* This is equivalent to calling `layers.set(val)` on the three.js camera object.
|
|
196
|
+
* @param val The layer index to set active
|
|
197
|
+
*/
|
|
152
198
|
public set cullingLayer(val: number) {
|
|
153
199
|
this.cullingMask = (1 << val | 0) >>> 0;
|
|
154
200
|
}
|
|
155
201
|
|
|
156
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* Gets or sets the blurriness of the skybox background.
|
|
204
|
+
* Values range from 0 (sharp) to 1 (maximum blur).
|
|
205
|
+
*/
|
|
157
206
|
@serializable()
|
|
158
207
|
public set backgroundBlurriness(val: number | undefined) {
|
|
159
208
|
if (val === this._backgroundBlurriness) return;
|
|
@@ -168,7 +217,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
168
217
|
}
|
|
169
218
|
private _backgroundBlurriness?: number = undefined;
|
|
170
219
|
|
|
171
|
-
/**
|
|
220
|
+
/**
|
|
221
|
+
* Gets or sets the intensity of the skybox background.
|
|
222
|
+
* Values range from 0 (dark) to 10 (very bright).
|
|
223
|
+
*/
|
|
172
224
|
@serializable()
|
|
173
225
|
public set backgroundIntensity(val: number | undefined) {
|
|
174
226
|
if (val === this._backgroundIntensity) return;
|
|
@@ -183,7 +235,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
183
235
|
}
|
|
184
236
|
private _backgroundIntensity?: number = undefined;
|
|
185
237
|
|
|
186
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* Gets or sets the rotation of the skybox background.
|
|
240
|
+
* Controls the orientation of the environment map.
|
|
241
|
+
*/
|
|
187
242
|
@serializable(Euler)
|
|
188
243
|
public set backgroundRotation(val: Euler | undefined) {
|
|
189
244
|
if (val === this._backgroundRotation) return;
|
|
@@ -198,7 +253,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
198
253
|
}
|
|
199
254
|
private _backgroundRotation?: Euler = undefined;
|
|
200
255
|
|
|
201
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* Gets or sets the intensity of the environment lighting.
|
|
258
|
+
* Controls how strongly the environment map affects scene lighting.
|
|
259
|
+
*/
|
|
202
260
|
@serializable()
|
|
203
261
|
public set environmentIntensity(val: number | undefined) {
|
|
204
262
|
this._environmentIntensity = val;
|
|
@@ -208,7 +266,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
208
266
|
}
|
|
209
267
|
private _environmentIntensity?: number = undefined;
|
|
210
268
|
|
|
211
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* Gets or sets the background color of the camera when {@link ClearFlags} is set to {@link ClearFlags.SolidColor}.
|
|
271
|
+
* The alpha component controls transparency.
|
|
272
|
+
*/
|
|
212
273
|
@serializable(RGBAColor)
|
|
213
274
|
public get backgroundColor(): RGBAColor | null {
|
|
214
275
|
return this._backgroundColor ?? null;
|
|
@@ -225,9 +286,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
225
286
|
this.applyClearFlagsIfIsActiveCamera();
|
|
226
287
|
}
|
|
227
288
|
|
|
228
|
-
/**
|
|
229
|
-
*
|
|
230
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Gets or sets the texture that the camera should render to instead of the screen.
|
|
291
|
+
* Useful for creating effects like mirrors, portals or custom post processing.
|
|
292
|
+
*/
|
|
231
293
|
@serializable(RenderTexture)
|
|
232
294
|
public set targetTexture(rt: RenderTexture | null) {
|
|
233
295
|
this._targetTexture = rt;
|
|
@@ -244,16 +306,17 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
244
306
|
private _skybox?: CameraSkybox;
|
|
245
307
|
|
|
246
308
|
/**
|
|
247
|
-
*
|
|
248
|
-
* @returns {PerspectiveCamera | OrthographicCamera}
|
|
249
|
-
* @deprecated
|
|
309
|
+
* Gets the three.js camera object. Creates one if it doesn't exist yet.
|
|
310
|
+
* @returns {PerspectiveCamera | OrthographicCamera} The three.js camera object
|
|
311
|
+
* @deprecated Use {@link threeCamera} instead
|
|
250
312
|
*/
|
|
251
313
|
public get cam(): PerspectiveCamera | OrthographicCamera {
|
|
252
314
|
return this.threeCamera;
|
|
253
315
|
}
|
|
316
|
+
|
|
254
317
|
/**
|
|
255
|
-
*
|
|
256
|
-
* @returns {PerspectiveCamera | OrthographicCamera}
|
|
318
|
+
* Gets the three.js camera object. Creates one if it doesn't exist yet.
|
|
319
|
+
* @returns {PerspectiveCamera | OrthographicCamera} The three.js camera object
|
|
257
320
|
*/
|
|
258
321
|
public get threeCamera(): PerspectiveCamera | OrthographicCamera {
|
|
259
322
|
if (this.activeAndEnabled)
|
|
@@ -263,6 +326,16 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
263
326
|
|
|
264
327
|
private static _origin: Vector3 = new Vector3();
|
|
265
328
|
private static _direction: Vector3 = new Vector3();
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Converts screen coordinates to a ray in world space.
|
|
332
|
+
* Useful for implementing picking or raycasting from screen to world.
|
|
333
|
+
*
|
|
334
|
+
* @param x The x screen coordinate
|
|
335
|
+
* @param y The y screen coordinate
|
|
336
|
+
* @param ray Optional ray object to reuse instead of creating a new one
|
|
337
|
+
* @returns {Ray} A ray originating from the camera position pointing through the screen point
|
|
338
|
+
*/
|
|
266
339
|
public screenPointToRay(x: number, y: number, ray?: Ray): Ray {
|
|
267
340
|
const cam = this.threeCamera;
|
|
268
341
|
const origin = Camera._origin;
|
|
@@ -285,9 +358,12 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
285
358
|
}
|
|
286
359
|
|
|
287
360
|
private _frustum?: Frustum;
|
|
361
|
+
|
|
288
362
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
363
|
+
* Gets the camera's view frustum for culling and visibility checks.
|
|
364
|
+
* Creates the frustum if it doesn't exist and returns it.
|
|
365
|
+
*
|
|
366
|
+
* @returns {Frustum} The camera's view frustum
|
|
291
367
|
*/
|
|
292
368
|
public getFrustum(): Frustum {
|
|
293
369
|
if (!this._frustum) {
|
|
@@ -296,13 +372,22 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
296
372
|
}
|
|
297
373
|
return this._frustum;
|
|
298
374
|
}
|
|
299
|
-
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Forces an update of the camera's frustum.
|
|
378
|
+
* This is automatically called every frame in onBeforeRender.
|
|
379
|
+
*/
|
|
300
380
|
public updateFrustum() {
|
|
301
381
|
if (!this._frustum) this._frustum = new Frustum();
|
|
302
382
|
this._frustum.setFromProjectionMatrix(this.getProjectionScreenMatrix(this._projScreenMatrix, true), this.context.renderer.coordinateSystem);
|
|
303
383
|
}
|
|
384
|
+
|
|
304
385
|
/**
|
|
305
|
-
*
|
|
386
|
+
* Gets this camera's projection-screen matrix.
|
|
387
|
+
*
|
|
388
|
+
* @param target Matrix4 object to store the result in
|
|
389
|
+
* @param forceUpdate Whether to force recalculation of the matrix
|
|
390
|
+
* @returns {Matrix4} The requested projection screen matrix
|
|
306
391
|
*/
|
|
307
392
|
public getProjectionScreenMatrix(target: Matrix4, forceUpdate?: boolean) {
|
|
308
393
|
if (forceUpdate) {
|
|
@@ -313,7 +398,6 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
313
398
|
}
|
|
314
399
|
private readonly _projScreenMatrix = new Matrix4();
|
|
315
400
|
|
|
316
|
-
|
|
317
401
|
/** @internal */
|
|
318
402
|
awake() {
|
|
319
403
|
if (debugscreenpointtoray) {
|
|
@@ -382,8 +466,9 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
382
466
|
}
|
|
383
467
|
|
|
384
468
|
/**
|
|
385
|
-
* Creates a
|
|
386
|
-
|
|
469
|
+
* Creates a three.js camera object if it doesn't exist yet and sets its properties.
|
|
470
|
+
* This is called internally when accessing the {@link threeCamera} property.
|
|
471
|
+
*/
|
|
387
472
|
buildCamera() {
|
|
388
473
|
if (this._cam) return;
|
|
389
474
|
|
|
@@ -428,13 +513,21 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
428
513
|
}
|
|
429
514
|
}
|
|
430
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Applies clear flags if this is the active main camera.
|
|
518
|
+
* @param opts Options for applying clear flags
|
|
519
|
+
*/
|
|
431
520
|
applyClearFlagsIfIsActiveCamera(opts?: { applySkybox: boolean }) {
|
|
432
521
|
if (this.context.mainCameraComponent === this) {
|
|
433
522
|
this.applyClearFlags(opts);
|
|
434
523
|
}
|
|
435
524
|
}
|
|
436
525
|
|
|
437
|
-
/**
|
|
526
|
+
/**
|
|
527
|
+
* Applies this camera's clear flags and related settings to the renderer.
|
|
528
|
+
* This controls how the background is rendered (skybox, solid color, transparent).
|
|
529
|
+
* @param opts Options for applying clear flags
|
|
530
|
+
*/
|
|
438
531
|
applyClearFlags(opts?: { applySkybox: boolean }) {
|
|
439
532
|
if (!this._cam) {
|
|
440
533
|
if (debug) console.log("Camera does not exist (apply clear flags)")
|
|
@@ -503,7 +596,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
503
596
|
}
|
|
504
597
|
|
|
505
598
|
/**
|
|
506
|
-
*
|
|
599
|
+
* Applies the skybox texture to the scene background.
|
|
507
600
|
*/
|
|
508
601
|
applySceneSkybox() {
|
|
509
602
|
if (!this._skybox)
|
|
@@ -511,9 +604,12 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
511
604
|
this._skybox.apply();
|
|
512
605
|
}
|
|
513
606
|
|
|
514
|
-
/**
|
|
515
|
-
*
|
|
516
|
-
|
|
607
|
+
/**
|
|
608
|
+
* Determines if the background should be transparent when in passthrough AR mode.
|
|
609
|
+
*
|
|
610
|
+
* @param context The current rendering context
|
|
611
|
+
* @returns {boolean} True when in XR on a pass through device where the background should be invisible
|
|
612
|
+
*/
|
|
517
613
|
static backgroundShouldBeTransparent(context: Context) {
|
|
518
614
|
const session = context.renderer.xr?.getSession();
|
|
519
615
|
if (!session) return false;
|
|
@@ -543,7 +639,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
543
639
|
}
|
|
544
640
|
}
|
|
545
641
|
|
|
546
|
-
|
|
642
|
+
/**
|
|
643
|
+
* Helper class for managing skybox textures for cameras.
|
|
644
|
+
* Handles retrieving and applying skybox textures to the scene.
|
|
645
|
+
*/
|
|
547
646
|
class CameraSkybox {
|
|
548
647
|
|
|
549
648
|
private _camera: Camera;
|
|
@@ -555,6 +654,10 @@ class CameraSkybox {
|
|
|
555
654
|
this._camera = camera;
|
|
556
655
|
}
|
|
557
656
|
|
|
657
|
+
/**
|
|
658
|
+
* Applies the skybox texture to the scene background.
|
|
659
|
+
* Retrieves the texture based on the camera's source ID.
|
|
660
|
+
*/
|
|
558
661
|
apply() {
|
|
559
662
|
this._skybox = this.context.lightmaps.tryGetSkybox(this._camera.sourceId) as Texture;
|
|
560
663
|
if (!this._skybox) {
|
|
@@ -572,13 +675,16 @@ class CameraSkybox {
|
|
|
572
675
|
}
|
|
573
676
|
}
|
|
574
677
|
|
|
575
|
-
|
|
678
|
+
/**
|
|
679
|
+
* Adds orbit controls to the camera if the freecam URL parameter is enabled.
|
|
680
|
+
*
|
|
681
|
+
* @param cam The camera to potentially add orbit controls to
|
|
682
|
+
*/
|
|
576
683
|
function handleFreeCam(cam: Camera) {
|
|
577
684
|
const isFreecam = getParam("freecam");
|
|
578
685
|
if (isFreecam) {
|
|
579
686
|
if (cam.context.mainCameraComponent === cam) {
|
|
580
687
|
GameObject.getOrAddComponent(cam.gameObject, OrbitControls);
|
|
581
688
|
}
|
|
582
|
-
|
|
583
689
|
}
|
|
584
690
|
}
|
|
@@ -13,6 +13,13 @@ import { OrbitControls } from "./OrbitControls.js";
|
|
|
13
13
|
|
|
14
14
|
const debug = getParam("debugmissingcamera");
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Handler for missing camera events. Creates a default fallback camera when no camera is found in the scene.
|
|
18
|
+
* Sets up camera properties based on the context and HTML element attributes.
|
|
19
|
+
*
|
|
20
|
+
* @param evt The context event containing scene and configuration information
|
|
21
|
+
* @returns The created camera component
|
|
22
|
+
*/
|
|
16
23
|
ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
|
|
17
24
|
if (debug) console.warn("Creating missing camera")
|
|
18
25
|
const scene = evt.context.scene;
|
|
@@ -57,6 +64,12 @@ ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
|
|
|
57
64
|
return cam;
|
|
58
65
|
});
|
|
59
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Handler for context creation events. Checks if camera controls should be added
|
|
69
|
+
* to the main camera when the context is created.
|
|
70
|
+
*
|
|
71
|
+
* @param evt The context creation event containing the context information
|
|
72
|
+
*/
|
|
60
73
|
ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
|
|
61
74
|
if (!evt.context.mainCamera) {
|
|
62
75
|
if (debug) console.log("Will not auto-fit because a default camera exists");
|
|
@@ -77,6 +90,13 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
|
|
|
77
90
|
}
|
|
78
91
|
})
|
|
79
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Creates default orbit camera controls for the specified camera.
|
|
95
|
+
* Configures auto-rotation and auto-fit settings based on HTML attributes.
|
|
96
|
+
*
|
|
97
|
+
* @param context The rendering context
|
|
98
|
+
* @param cam Optional camera component to attach controls to (uses main camera if not specified)
|
|
99
|
+
*/
|
|
80
100
|
function createDefaultCameraControls(context: IContext, cam?: ICamera) {
|
|
81
101
|
|
|
82
102
|
cam = cam ?? context.mainCameraComponent;
|