@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
|
@@ -49,18 +49,25 @@ export class WebARSessionRoot extends Behaviour {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
private static _hasPlaced: boolean = false;
|
|
53
|
+
/**
|
|
54
|
+
* @returns true if the scene has been placed in AR by the user or automatic placement
|
|
55
|
+
*/
|
|
56
|
+
static get hasPlaced(): boolean {
|
|
57
|
+
return this._hasPlaced;
|
|
58
|
+
}
|
|
59
|
+
|
|
52
60
|
|
|
53
|
-
/** The scale of
|
|
54
|
-
*
|
|
61
|
+
/** The scale of the user in AR.
|
|
62
|
+
* **NOTE**: a large value makes the scene appear smaller
|
|
55
63
|
* @default 1
|
|
56
64
|
*/
|
|
57
65
|
get arScale(): number {
|
|
58
66
|
return this._arScale;
|
|
59
67
|
}
|
|
60
68
|
set arScale(val: number) {
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
this.onScaleChanged();
|
|
69
|
+
this._arScale = Math.max(0.000001, val);
|
|
70
|
+
this.onSetScale();
|
|
64
71
|
}
|
|
65
72
|
private _arScale: number = 1;
|
|
66
73
|
|
|
@@ -134,6 +141,7 @@ export class WebARSessionRoot extends Behaviour {
|
|
|
134
141
|
if (debug) console.log("ENTER WEBXR: SessionRoot start...");
|
|
135
142
|
|
|
136
143
|
this._anchor = null;
|
|
144
|
+
WebARSessionRoot._hasPlaced = false;
|
|
137
145
|
|
|
138
146
|
// if (_args.xr.session.enabledFeatures?.includes("image-tracking")) {
|
|
139
147
|
// console.warn("Image tracking is enabled - will not place scene");
|
|
@@ -193,6 +201,7 @@ export class WebARSessionRoot extends Behaviour {
|
|
|
193
201
|
this.onRevertSceneChanges();
|
|
194
202
|
// this._anchor?.delete();
|
|
195
203
|
this._anchor = null;
|
|
204
|
+
WebARSessionRoot._hasPlaced = false;
|
|
196
205
|
this._rigPlacementMatrix = undefined;
|
|
197
206
|
}
|
|
198
207
|
onUpdateXR(args: NeedleXREventArgs): void {
|
|
@@ -405,6 +414,7 @@ export class WebARSessionRoot extends Behaviour {
|
|
|
405
414
|
reticle.quaternion.copy(reticle["lastQuat"]);
|
|
406
415
|
|
|
407
416
|
this.onApplyPose(reticle);
|
|
417
|
+
WebARSessionRoot._hasPlaced = true;
|
|
408
418
|
|
|
409
419
|
if (this.useXRAnchor) {
|
|
410
420
|
this.onCreateAnchor(NeedleXRSession.active!, hit);
|
|
@@ -417,8 +427,16 @@ export class WebARSessionRoot extends Behaviour {
|
|
|
417
427
|
}
|
|
418
428
|
}
|
|
419
429
|
|
|
420
|
-
private
|
|
421
|
-
|
|
430
|
+
private onSetScale() {
|
|
431
|
+
if (!WebARSessionRoot._hasPlaced) return;
|
|
432
|
+
const rig = NeedleXRSession.active?.rig?.gameObject;
|
|
433
|
+
if (rig) {
|
|
434
|
+
const currentScale = NeedleXRSession.active?.rigScale || 1;
|
|
435
|
+
const newScale = (1 / this._arScale) * currentScale;
|
|
436
|
+
const scaleMatrix = new Matrix4().makeScale(newScale, newScale, newScale).invert();
|
|
437
|
+
rig.matrix.premultiply(scaleMatrix);
|
|
438
|
+
rig.matrix.decompose(rig.position, rig.quaternion, rig.scale);
|
|
439
|
+
}
|
|
422
440
|
}
|
|
423
441
|
|
|
424
442
|
private onRevertSceneChanges() {
|
|
@@ -516,7 +534,7 @@ export class WebARSessionRoot extends Behaviour {
|
|
|
516
534
|
console.warn("No rig object to place");
|
|
517
535
|
return;
|
|
518
536
|
}
|
|
519
|
-
const rigScale = NeedleXRSession.active?.rigScale || 1;
|
|
537
|
+
// const rigScale = NeedleXRSession.active?.rigScale || 1;
|
|
520
538
|
|
|
521
539
|
// save the previous rig parent
|
|
522
540
|
const previousParent = rigObject.parent || this.context.scene;
|
|
@@ -578,6 +596,10 @@ class WebXRSessionRootUserInput {
|
|
|
578
596
|
private _scale: number = 1;
|
|
579
597
|
private _hasChanged: boolean = false;
|
|
580
598
|
|
|
599
|
+
get scale() {
|
|
600
|
+
return this._scale;
|
|
601
|
+
}
|
|
602
|
+
|
|
581
603
|
// readonly translate: Vector3 = new Vector3();
|
|
582
604
|
// readonly rotation: Quaternion = new Quaternion();
|
|
583
605
|
// readonly scale: Vector3 = new Vector3(1, 1, 1);
|
|
@@ -594,6 +616,7 @@ class WebXRSessionRootUserInput {
|
|
|
594
616
|
reset() {
|
|
595
617
|
this._scale = 1;
|
|
596
618
|
this.offset.identity();
|
|
619
|
+
this._hasChanged = true;
|
|
597
620
|
}
|
|
598
621
|
get hasChanged() { return this._hasChanged; }
|
|
599
622
|
|
|
@@ -31,74 +31,127 @@ const debugQuicklook = getParam("debugusdz");
|
|
|
31
31
|
export class WebXR extends Behaviour {
|
|
32
32
|
|
|
33
33
|
// UI
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* When enabled, a button will be automatically added to {@link NeedleMenu} that allows users to enter VR mode.
|
|
36
|
+
*/
|
|
35
37
|
@serializable()
|
|
36
38
|
createVRButton: boolean = true;
|
|
37
|
-
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* When enabled, a button will be automatically added to {@link NeedleMenu} that allows users to enter AR mode.
|
|
42
|
+
*/
|
|
38
43
|
@serializable()
|
|
39
44
|
createARButton: boolean = true;
|
|
40
|
-
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* When enabled, a button to send the experience to an Oculus Quest will be shown if the current device does not support VR.
|
|
48
|
+
* This helps direct users to compatible devices for optimal VR experiences.
|
|
49
|
+
*/
|
|
41
50
|
@serializable()
|
|
42
51
|
createSendToQuestButton: boolean = true;
|
|
43
|
-
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* When enabled, a QR code will be generated and displayed on desktop devices to allow easy opening of the experience on mobile devices.
|
|
55
|
+
*/
|
|
44
56
|
@serializable()
|
|
45
57
|
createQRCode: boolean = true;
|
|
46
58
|
|
|
47
59
|
// VR Settings
|
|
48
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* When enabled, default movement controls will be automatically added to the scene when entering VR.
|
|
62
|
+
* This includes teleportation and smooth locomotion options for VR controllers.
|
|
63
|
+
*/
|
|
49
64
|
@serializable()
|
|
50
65
|
useDefaultControls: boolean = true;
|
|
51
|
-
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* When enabled, 3D models representing the user's VR controllers will be automatically created and rendered in the scene.
|
|
69
|
+
*/
|
|
52
70
|
@serializable()
|
|
53
71
|
showControllerModels: boolean = true;
|
|
54
|
-
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* When enabled, 3D models representing the user's hands will be automatically created and rendered when hand tracking is available.
|
|
75
|
+
*/
|
|
55
76
|
@serializable()
|
|
56
77
|
showHandModels: boolean = true;
|
|
57
78
|
|
|
58
79
|
// AR Settings
|
|
59
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* When enabled, a reticle will be displayed to help place the scene in AR. The user must tap on a detected surface to position the scene.
|
|
82
|
+
*/
|
|
60
83
|
@serializable()
|
|
61
84
|
usePlacementReticle: boolean = true;
|
|
62
|
-
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Optional custom 3D object to use as the AR placement reticle instead of the default one.
|
|
88
|
+
*/
|
|
63
89
|
@serializable(AssetReference)
|
|
64
90
|
customARPlacementReticle?: AssetReference;
|
|
65
|
-
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* When enabled, users can adjust the position, rotation, and scale of the AR scene with one or two fingers after initial placement.
|
|
94
|
+
*/
|
|
66
95
|
@serializable()
|
|
67
96
|
usePlacementAdjustment: boolean = true;
|
|
68
|
-
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Determines the scale of the user relative to the scene in AR. Larger values make the 3D content appear smaller.
|
|
100
|
+
* Only applies when `usePlacementReticle` is enabled.
|
|
101
|
+
*/
|
|
69
102
|
@serializable()
|
|
70
103
|
arScale: number = 1;
|
|
71
|
-
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* When enabled, an XRAnchor will be created for the AR scene and its position will be regularly updated to match the anchor.
|
|
107
|
+
* This can help with spatial persistence in AR experiences.
|
|
108
|
+
* @experimental
|
|
109
|
+
*/
|
|
72
110
|
@serializable()
|
|
73
111
|
useXRAnchor: boolean = false;
|
|
112
|
+
|
|
74
113
|
/**
|
|
75
|
-
* When enabled the scene will be placed
|
|
114
|
+
* When enabled, the scene will be automatically placed as soon as a suitable surface is detected in AR,
|
|
115
|
+
* without requiring the user to tap to confirm placement.
|
|
76
116
|
*/
|
|
77
117
|
@serializable()
|
|
78
|
-
autoPlace: boolean =
|
|
79
|
-
|
|
118
|
+
autoPlace: boolean = false;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* When enabled, the AR session root center will be automatically adjusted to place the center of the scene.
|
|
122
|
+
* This helps ensure the scene is properly aligned with detected surfaces.
|
|
123
|
+
*/
|
|
80
124
|
@serializable()
|
|
81
125
|
autoCenter: boolean = false;
|
|
82
126
|
|
|
83
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* When enabled, a USDZExporter component will be automatically added to the scene if none is found.
|
|
129
|
+
* This allows iOS and visionOS devices to view 3D content using Apple's AR QuickLook.
|
|
130
|
+
*/
|
|
84
131
|
@serializable()
|
|
85
132
|
useQuicklookExport: boolean = false;
|
|
86
133
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
134
|
+
/**
|
|
135
|
+
* When enabled, the 'depth-sensing' WebXR feature will be requested to provide real-time depth occlusion.
|
|
136
|
+
* Currently only supported on Oculus Quest devices.
|
|
137
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/XRDepthInformation
|
|
138
|
+
* @experimental
|
|
90
139
|
*/
|
|
91
140
|
@serializable()
|
|
92
141
|
useDepthSensing: boolean = false;
|
|
93
142
|
|
|
94
143
|
/**
|
|
95
|
-
* When enabled
|
|
144
|
+
* When enabled, a {@link SpatialGrabRaycaster} will be added or enabled in the scene,
|
|
145
|
+
* allowing users to interact with objects at a distance in VR/AR.
|
|
96
146
|
* @default true
|
|
97
147
|
*/
|
|
98
148
|
@serializable()
|
|
99
149
|
useSpatialGrab: boolean = true;
|
|
100
150
|
|
|
101
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Specifies the avatar representation that will be created when entering a WebXR session.
|
|
153
|
+
* Can be a reference to a 3D model or a boolean to use the default avatar.
|
|
154
|
+
*/
|
|
102
155
|
@serializable(AssetReference)
|
|
103
156
|
defaultAvatar?: AssetReference | boolean;
|
|
104
157
|
|
|
@@ -111,10 +164,19 @@ export class WebXR extends Behaviour {
|
|
|
111
164
|
|
|
112
165
|
static activeWebXRComponent: WebXR | null = null;
|
|
113
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Initializes the WebXR component by obtaining the XR sync object for this context.
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
114
171
|
awake() {
|
|
115
172
|
NeedleXRSession.getXRSync(this.context);
|
|
116
173
|
}
|
|
117
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Sets up the WebXR component when it's enabled. Checks for HTTPS connection,
|
|
177
|
+
* sets up USDZ export if enabled, creates UI buttons, and configures avatar settings.
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
118
180
|
onEnable(): void {
|
|
119
181
|
// check if we're on a secure connection:
|
|
120
182
|
if (window.location.protocol !== "https:") {
|
|
@@ -153,11 +215,21 @@ export class WebXR extends Behaviour {
|
|
|
153
215
|
}
|
|
154
216
|
}
|
|
155
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Cleans up resources when the component is disabled.
|
|
220
|
+
* Destroys the USDZ exporter if one was created and removes UI buttons.
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
156
223
|
onDisable(): void {
|
|
157
224
|
this._usdzExporter?.destroy();
|
|
158
225
|
this.removeButtons();
|
|
159
226
|
}
|
|
160
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Checks if WebXR is supported and offers an appropriate session.
|
|
230
|
+
* This is used to show the WebXR session joining prompt in browsers that support it.
|
|
231
|
+
* @returns A Promise that resolves to true if a session was offered, false otherwise
|
|
232
|
+
*/
|
|
161
233
|
private async handleOfferSession() {
|
|
162
234
|
if (this.createVRButton) {
|
|
163
235
|
const hasVRSupport = await NeedleXRSession.isVRSupported();
|
|
@@ -182,16 +254,32 @@ export class WebXR extends Behaviour {
|
|
|
182
254
|
get sessionMode(): XRSessionMode | null {
|
|
183
255
|
return NeedleXRSession.activeMode ?? null;;
|
|
184
256
|
}
|
|
257
|
+
/** While AR: this will return the currently active WebARSessionRoot component.
|
|
258
|
+
* You can also query this component in your scene with `findObjectOfType(WebARSessionRoot)`
|
|
259
|
+
*/
|
|
260
|
+
get arSessionRoot() {
|
|
261
|
+
return this._activeWebARSessionRoot;
|
|
262
|
+
}
|
|
185
263
|
|
|
186
|
-
/** Call to start an WebVR session
|
|
264
|
+
/** Call to start an WebVR session.
|
|
265
|
+
*
|
|
266
|
+
* This is a shorthand for `NeedleXRSession.start("immersive-vr", init, this.context)`
|
|
267
|
+
*/
|
|
187
268
|
async enterVR(init?: XRSessionInit): Promise<NeedleXRSession | null> {
|
|
188
269
|
return NeedleXRSession.start("immersive-vr", init, this.context);
|
|
189
270
|
}
|
|
190
|
-
/** Call to start an WebAR session
|
|
271
|
+
/** Call to start an WebAR session
|
|
272
|
+
*
|
|
273
|
+
* This is a shorthand for `NeedleXRSession.start("immersive-ar", init, this.context)`
|
|
274
|
+
*/
|
|
191
275
|
async enterAR(init?: XRSessionInit): Promise<NeedleXRSession | null> {
|
|
192
276
|
return NeedleXRSession.start("immersive-ar", init, this.context);
|
|
193
277
|
}
|
|
194
|
-
|
|
278
|
+
|
|
279
|
+
/** Call to end a WebXR (AR or VR) session.
|
|
280
|
+
*
|
|
281
|
+
* This is a shorthand for `NeedleXRSession.stop()`
|
|
282
|
+
*/
|
|
195
283
|
exitXR() {
|
|
196
284
|
NeedleXRSession.stop();
|
|
197
285
|
}
|
|
@@ -199,11 +287,18 @@ export class WebXR extends Behaviour {
|
|
|
199
287
|
private _exitXRMenuButton?: HTMLElement;
|
|
200
288
|
private _previousXRState: number = 0;
|
|
201
289
|
private _spatialGrabRaycaster?: SpatialGrabRaycaster;
|
|
290
|
+
private _activeWebARSessionRoot: WebARSessionRoot | null = null;
|
|
202
291
|
|
|
203
292
|
private get isActiveWebXR() {
|
|
204
293
|
return !WebXR.activeWebXRComponent || WebXR.activeWebXRComponent === this;
|
|
205
294
|
}
|
|
206
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Called before entering a WebXR session. Sets up optional features like depth sensing, if needed.
|
|
298
|
+
* @param _mode The XR session mode being requested (immersive-ar or immersive-vr)
|
|
299
|
+
* @param args The XRSessionInit object that will be passed to the WebXR API
|
|
300
|
+
* @internal
|
|
301
|
+
*/
|
|
207
302
|
onBeforeXR(_mode: XRSessionMode, args: XRSessionInit): void {
|
|
208
303
|
if (!this.isActiveWebXR) {
|
|
209
304
|
console.warn(`WebXR: another WebXR component is already active (${WebXR.activeWebXRComponent?.name}). This is ignored: ${this.name}`);
|
|
@@ -217,6 +312,12 @@ export class WebXR extends Behaviour {
|
|
|
217
312
|
}
|
|
218
313
|
}
|
|
219
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Called when a WebXR session begins. Sets up the scene for XR by configuring controllers,
|
|
317
|
+
* AR placement, and other features based on component settings.
|
|
318
|
+
* @param args Event arguments containing information about the started XR session
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
220
321
|
async onEnterXR(args: NeedleXREventArgs) {
|
|
221
322
|
if (!this.isActiveWebXR) return;
|
|
222
323
|
|
|
@@ -244,6 +345,7 @@ export class WebXR extends Behaviour {
|
|
|
244
345
|
}
|
|
245
346
|
}
|
|
246
347
|
|
|
348
|
+
this._activeWebARSessionRoot = sessionroot;
|
|
247
349
|
if (sessionroot) {
|
|
248
350
|
// sessionroot.enabled = this.usePlacementReticle; // < not sure if we want to disable the session root when placement reticle if OFF...
|
|
249
351
|
sessionroot.customReticle = this.customARPlacementReticle;
|
|
@@ -288,6 +390,12 @@ export class WebXR extends Behaviour {
|
|
|
288
390
|
}
|
|
289
391
|
}
|
|
290
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Called every frame during an active WebXR session.
|
|
395
|
+
* Updates components that depend on the current XR state.
|
|
396
|
+
* @param _args Event arguments containing information about the current XR session frame
|
|
397
|
+
* @internal
|
|
398
|
+
*/
|
|
291
399
|
onUpdateXR(_args: NeedleXREventArgs): void {
|
|
292
400
|
if (!this.isActiveWebXR) return;
|
|
293
401
|
if (this._spatialGrabRaycaster) {
|
|
@@ -295,6 +403,12 @@ export class WebXR extends Behaviour {
|
|
|
295
403
|
}
|
|
296
404
|
}
|
|
297
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Called when a WebXR session ends. Restores pre-session state,
|
|
408
|
+
* removes temporary components, and cleans up resources.
|
|
409
|
+
* @param _ Event arguments containing information about the ended XR session
|
|
410
|
+
* @internal
|
|
411
|
+
*/
|
|
298
412
|
onLeaveXR(_: NeedleXREventArgs): void {
|
|
299
413
|
this._exitXRMenuButton?.remove();
|
|
300
414
|
|
|
@@ -310,6 +424,8 @@ export class WebXR extends Behaviour {
|
|
|
310
424
|
}
|
|
311
425
|
this._createdComponentsInSession.length = 0;
|
|
312
426
|
|
|
427
|
+
this._activeWebARSessionRoot = null;
|
|
428
|
+
|
|
313
429
|
this.handleOfferSession();
|
|
314
430
|
|
|
315
431
|
delayForFrames(1).then(() => WebXR.activeWebXRComponent = null);
|
|
@@ -339,8 +455,10 @@ export class WebXR extends Behaviour {
|
|
|
339
455
|
return models;
|
|
340
456
|
}
|
|
341
457
|
|
|
342
|
-
|
|
343
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Creates and instantiates the user's avatar representation in the WebXR session.
|
|
460
|
+
* @param xr The active session
|
|
461
|
+
*/
|
|
344
462
|
protected async createLocalAvatar(xr: NeedleXRSession) {
|
|
345
463
|
if (this._playerSync && xr.running && typeof this.defaultAvatar != "boolean") {
|
|
346
464
|
this._playerSync.asset = this.defaultAvatar;
|
|
@@ -348,6 +466,11 @@ export class WebXR extends Behaviour {
|
|
|
348
466
|
}
|
|
349
467
|
}
|
|
350
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Event handler called when a player avatar is spawned.
|
|
471
|
+
* Ensures the avatar has the necessary Avatar component.
|
|
472
|
+
* @param instance The spawned avatar 3D object
|
|
473
|
+
*/
|
|
351
474
|
private onAvatarSpawned = (instance: Object3D) => {
|
|
352
475
|
// spawned webxr avatars must have a avatar component
|
|
353
476
|
if (debug) console.log("WebXR.onAvatarSpawned", instance);
|
|
@@ -360,13 +483,16 @@ export class WebXR extends Behaviour {
|
|
|
360
483
|
|
|
361
484
|
// HTML UI
|
|
362
485
|
|
|
363
|
-
/** @deprecated use
|
|
486
|
+
/** @deprecated use {@link getButtonsFactory} or directly access {@link WebXRButtonFactory.getOrCreate} */
|
|
364
487
|
getButtonsContainer(): WebXRButtonFactory {
|
|
365
488
|
return this.getButtonsFactory();
|
|
366
489
|
}
|
|
367
490
|
|
|
368
|
-
/**
|
|
369
|
-
*
|
|
491
|
+
/**
|
|
492
|
+
* Returns the WebXR button factory, creating one if it doesn't exist.
|
|
493
|
+
* Use this to access and modify WebXR UI buttons.
|
|
494
|
+
* @returns The WebXRButtonFactory instance
|
|
495
|
+
*/
|
|
370
496
|
getButtonsFactory(): WebXRButtonFactory {
|
|
371
497
|
if (!this._buttonFactory) {
|
|
372
498
|
this._buttonFactory = WebXRButtonFactory.getOrCreate();
|
|
@@ -374,8 +500,15 @@ export class WebXR extends Behaviour {
|
|
|
374
500
|
return this._buttonFactory;
|
|
375
501
|
}
|
|
376
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Reference to the WebXR button factory used by this component.
|
|
505
|
+
*/
|
|
377
506
|
private _buttonFactory?: WebXRButtonFactory;
|
|
378
507
|
|
|
508
|
+
/**
|
|
509
|
+
* Creates and sets up UI elements for WebXR interaction based on component settings
|
|
510
|
+
* and device capabilities. Handles creating AR, VR, QuickLook buttons and utility buttons like QR codes.
|
|
511
|
+
*/
|
|
379
512
|
private handleCreatingHTML() {
|
|
380
513
|
const xrButtonsPriority = 50;
|
|
381
514
|
|
|
@@ -423,14 +556,25 @@ export class WebXR extends Behaviour {
|
|
|
423
556
|
}
|
|
424
557
|
}
|
|
425
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Storage for UI buttons created by this component.
|
|
561
|
+
*/
|
|
426
562
|
private readonly _buttons: HTMLElement[] = [];
|
|
427
563
|
|
|
564
|
+
/**
|
|
565
|
+
* Adds a button to the UI with the specified priority.
|
|
566
|
+
* @param button The HTML element to add
|
|
567
|
+
* @param priority The button's priority value (lower numbers appear first)
|
|
568
|
+
*/
|
|
428
569
|
private addButton(button: HTMLElement, priority: number) {
|
|
429
570
|
this._buttons.push(button);
|
|
430
571
|
button.setAttribute("priority", priority.toString());
|
|
431
572
|
this.context.menu.appendChild(button);
|
|
432
573
|
}
|
|
433
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Removes all buttons created by this component from the UI.
|
|
577
|
+
*/
|
|
434
578
|
private removeButtons() {
|
|
435
579
|
for (const button of this._buttons) {
|
|
436
580
|
button.remove();
|