@needle-tools/engine 5.1.0-alpha.1 → 5.1.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/.needle/generated/needle-bindings.gen.d.ts +5 -0
- package/CHANGELOG.md +52 -0
- package/components.needle.json +1 -1
- package/dist/{gltf-progressive-DJBMx-zB.umd.cjs → gltf-progressive-BmblPzFj.umd.cjs} +4 -4
- package/dist/{gltf-progressive-BryRjllq.min.js → gltf-progressive-CN_mbb66.min.js} +2 -2
- package/dist/{gltf-progressive-Cl167Vjx.js → gltf-progressive-DUlhxdv4.js} +5 -2
- package/dist/needle-engine.bundle-C-ixARur.umd.cjs +1733 -0
- package/dist/needle-engine.bundle-CHmXdnE1.min.js +1733 -0
- package/dist/{needle-engine.bundle-BGyKqxBH.js → needle-engine.bundle-DF01sSGQ.js} +10841 -10434
- package/dist/needle-engine.d.ts +244 -54
- package/dist/needle-engine.js +541 -536
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-B_9sKVU7.min.js → postprocessing-B571qGWR.min.js} +34 -34
- package/dist/{postprocessing-WDc9WwI3.js → postprocessing-CfrLAbLX.js} +0 -1
- package/dist/{postprocessing-B2wb6pzI.umd.cjs → postprocessing-CiGkAeM9.umd.cjs} +17 -17
- package/dist/{vendor-CAcsI0eU.js → vendor-BFrMaK9q.js} +8983 -9136
- package/dist/vendor-CJmyOrCq.min.js +1116 -0
- package/dist/vendor-DkMW3WY4.umd.cjs +1116 -0
- package/lib/engine/api.d.ts +14 -0
- package/lib/engine/api.js +4 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/debug/debug_environment.js +1 -1
- package/lib/engine/debug/debug_environment.js.map +1 -1
- package/lib/engine/debug/debug_spatial_console.d.ts +2 -0
- package/lib/engine/debug/debug_spatial_console.js +10 -7
- package/lib/engine/debug/debug_spatial_console.js.map +1 -1
- package/lib/engine/engine_addressables.d.ts +2 -0
- package/lib/engine/engine_addressables.js +6 -3
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_application.js +8 -6
- package/lib/engine/engine_application.js.map +1 -1
- package/lib/engine/engine_audio.d.ts +68 -0
- package/lib/engine/engine_audio.js +172 -0
- package/lib/engine/engine_audio.js.map +1 -1
- package/lib/engine/engine_components.js +1 -1
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_constants.js +6 -0
- package/lib/engine/engine_constants.js.map +1 -1
- package/lib/engine/engine_context.d.ts +33 -7
- package/lib/engine/engine_context.js +40 -2
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_context_registry.js +1 -1
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine/engine_gameobject.js +2 -2
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_init.js +16 -1
- package/lib/engine/engine_init.js.map +1 -1
- package/lib/engine/engine_input.d.ts +3 -2
- package/lib/engine/engine_input.js +3 -2
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_license.d.ts +2 -0
- package/lib/engine/engine_license.js +25 -15
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_lifecycle_functions_internal.js +5 -0
- package/lib/engine/engine_lifecycle_functions_internal.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.js +5 -2
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_networking_blob.d.ts +1 -1
- package/lib/engine/engine_networking_blob.js +5 -11
- package/lib/engine/engine_networking_blob.js.map +1 -1
- package/lib/engine/engine_physics_rapier.js +0 -1
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_pmrem.js +2 -2
- package/lib/engine/engine_pmrem.js.map +1 -1
- package/lib/engine/engine_scenedata.d.ts +32 -0
- package/lib/engine/engine_scenedata.js +138 -0
- package/lib/engine/engine_scenedata.js.map +1 -0
- package/lib/engine/engine_serialization_builtin_serializer.d.ts +10 -16
- package/lib/engine/engine_serialization_builtin_serializer.js +55 -41
- package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
- package/lib/engine/engine_ssr.d.ts +18 -0
- package/lib/engine/engine_ssr.js +40 -0
- package/lib/engine/engine_ssr.js.map +1 -0
- package/lib/engine/engine_three_utils.d.ts +14 -7
- package/lib/engine/engine_three_utils.js +14 -7
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_types.d.ts +2 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_utils.js +2 -0
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/engine_utils_hash.d.ts +9 -0
- package/lib/engine/engine_utils_hash.js +112 -0
- package/lib/engine/engine_utils_hash.js.map +1 -0
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js.map +1 -1
- package/lib/engine/webcomponents/jsx.d.ts +51 -0
- package/lib/engine/webcomponents/logo-element.d.ts +2 -1
- package/lib/engine/webcomponents/logo-element.js +2 -1
- package/lib/engine/webcomponents/logo-element.js.map +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +4 -4
- package/lib/engine/webcomponents/needle menu/needle-menu.js +2 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
- package/lib/engine/webcomponents/needle-button.d.ts +2 -1
- package/lib/engine/webcomponents/needle-button.js +2 -1
- package/lib/engine/webcomponents/needle-button.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +11 -4
- package/lib/engine/webcomponents/needle-engine.js +2 -1
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.d.ts +3 -2
- package/lib/engine/xr/NeedleXRSession.js +51 -15
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine/xr/events.d.ts +1 -1
- package/lib/engine/xr/events.js.map +1 -1
- package/lib/engine-components/Animation.js +17 -16
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +2 -0
- package/lib/engine-components/AnimatorController.js +4 -1
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +19 -3
- package/lib/engine-components/AudioSource.js +121 -68
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +7 -0
- package/lib/engine-components/DragControls.js +19 -0
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/Light.d.ts +6 -8
- package/lib/engine-components/Light.js +40 -27
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +1 -1
- package/lib/engine-components/Networking.js +1 -1
- package/lib/engine-components/OrbitControls.js +16 -11
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +2 -0
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/RigidBody.js +3 -3
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.js +2 -0
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/SeeThrough.js +2 -2
- package/lib/engine-components/SeeThrough.js.map +1 -1
- package/lib/engine-components/api.d.ts +1 -1
- package/lib/engine-components/api.js +1 -1
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +1 -2
- package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +5 -6
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/VolumeParameter.d.ts +2 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js +4 -1
- package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -1
- package/lib/engine-components/ui/Canvas.d.ts +1 -1
- package/lib/engine-components/ui/Canvas.js +2 -8
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/Text.d.ts +1 -0
- package/lib/engine-components/ui/Text.js +10 -7
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/web/CursorFollow.js +21 -12
- package/lib/engine-components/web/CursorFollow.js.map +1 -1
- package/lib/engine-components/web/ScrollFollow.d.ts +0 -1
- package/lib/engine-components/web/ScrollFollow.js +3 -2
- package/lib/engine-components/web/ScrollFollow.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.js +4 -0
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/needle-engine.d.ts +2 -0
- package/lib/needle-engine.js +2 -0
- package/lib/needle-engine.js.map +1 -1
- package/package.json +6 -4
- package/plugins/dts-generator/dts.codegen.js +334 -0
- package/plugins/dts-generator/dts.scan.js +99 -0
- package/plugins/dts-generator/dts.writer.js +59 -0
- package/plugins/dts-generator/glb.discovery.js +279 -0
- package/plugins/dts-generator/glb.extractor.js +215 -0
- package/plugins/dts-generator/glb.reader.js +167 -0
- package/plugins/dts-generator/index.js +36 -0
- package/plugins/dts-generator/manifest.types.js +174 -0
- package/plugins/types/index.d.ts +2 -1
- package/plugins/types/needle-bindings.d.ts +30 -0
- package/plugins/types/userconfig.d.ts +21 -2
- package/plugins/vite/asap.js +18 -9
- package/plugins/vite/dependencies.js +29 -0
- package/plugins/vite/dependency-watcher.d.ts +2 -2
- package/plugins/vite/dependency-watcher.js +3 -4
- package/plugins/vite/drop.d.ts +2 -2
- package/plugins/vite/drop.js +3 -4
- package/plugins/vite/dts-generator.d.ts +7 -0
- package/plugins/vite/dts-generator.js +191 -0
- package/plugins/vite/index.d.ts +10 -3
- package/plugins/vite/index.js +27 -10
- package/plugins/vite/local-files-core.js +3 -3
- package/plugins/vite/local-files-utils.d.ts +3 -1
- package/plugins/vite/local-files-utils.js +29 -5
- package/plugins/vite/logging.js +2 -2
- package/plugins/vite/meta.js +4 -2
- package/plugins/vite/poster.d.ts +2 -2
- package/plugins/vite/poster.js +3 -5
- package/plugins/vite/reload.d.ts +2 -2
- package/plugins/vite/reload.js +23 -22
- package/src/engine/api.ts +18 -1
- package/src/engine/debug/debug_environment.ts +1 -1
- package/src/engine/debug/debug_spatial_console.ts +10 -7
- package/src/engine/engine_addressables.ts +6 -3
- package/src/engine/engine_application.ts +8 -6
- package/src/engine/engine_audio.ts +184 -0
- package/src/engine/engine_components.ts +1 -1
- package/src/engine/engine_constants.ts +11 -6
- package/src/engine/engine_context.ts +50 -7
- package/src/engine/engine_context_registry.ts +1 -1
- package/src/engine/engine_gameobject.ts +2 -2
- package/src/engine/engine_init.ts +15 -1
- package/src/engine/engine_input.ts +3 -2
- package/src/engine/engine_license.ts +23 -19
- package/src/engine/engine_lifecycle_functions_internal.ts +7 -0
- package/src/engine/engine_mainloop_utils.ts +5 -2
- package/src/engine/engine_networking_blob.ts +5 -11
- package/src/engine/engine_physics_rapier.ts +0 -3
- package/src/engine/engine_pmrem.ts +3 -3
- package/src/engine/engine_scenedata.ts +136 -0
- package/src/engine/engine_serialization_builtin_serializer.ts +63 -46
- package/src/engine/engine_ssr.ts +48 -0
- package/src/engine/engine_three_utils.ts +15 -7
- package/src/engine/engine_types.ts +2 -0
- package/src/engine/engine_utils.ts +1 -0
- package/src/engine/engine_utils_hash.ts +65 -0
- package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
- package/src/engine/webcomponents/jsx.d.ts +51 -0
- package/src/engine/webcomponents/logo-element.ts +3 -1
- package/src/engine/webcomponents/needle menu/needle-menu.ts +4 -2
- package/src/engine/webcomponents/needle-button.ts +3 -1
- package/src/engine/webcomponents/needle-engine.ts +12 -4
- package/src/engine/xr/NeedleXRSession.ts +49 -14
- package/src/engine/xr/events.ts +1 -1
- package/src/engine-components/Animation.ts +19 -16
- package/src/engine-components/AnimatorController.ts +4 -1
- package/src/engine-components/AudioSource.ts +130 -79
- package/src/engine-components/DragControls.ts +18 -2
- package/src/engine-components/Light.ts +40 -26
- package/src/engine-components/Networking.ts +1 -1
- package/src/engine-components/OrbitControls.ts +18 -9
- package/src/engine-components/ReflectionProbe.ts +2 -0
- package/src/engine-components/RigidBody.ts +3 -3
- package/src/engine-components/SceneSwitcher.ts +1 -0
- package/src/engine-components/SeeThrough.ts +2 -2
- package/src/engine-components/api.ts +1 -1
- package/src/engine-components/postprocessing/Effects/BloomEffect.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +1 -2
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +4 -8
- package/src/engine-components/postprocessing/VolumeParameter.ts +4 -1
- package/src/engine-components/ui/Canvas.ts +2 -8
- package/src/engine-components/ui/Text.ts +12 -8
- package/src/engine-components/web/CursorFollow.ts +21 -13
- package/src/engine-components/web/ScrollFollow.ts +2 -2
- package/src/engine-components/webxr/WebXRImageTracking.ts +2 -0
- package/src/needle-engine.ts +3 -0
- package/src/vite-env.d.ts +16 -0
- package/dist/needle-engine.bundle-CiYtOO2O.min.js +0 -1732
- package/dist/needle-engine.bundle-DzVx9Z8D.umd.cjs +0 -1732
- package/dist/vendor-CEM38hLE.umd.cjs +0 -1116
- package/dist/vendor-HRlxIBga.min.js +0 -1116
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { isDevEnvironment } from "../debug/index.js";
|
|
2
|
+
import { HTMLElementBase } from "../engine_ssr.js";
|
|
2
3
|
import { ButtonsFactory } from "./buttons.js";
|
|
3
4
|
import { iconFontUrl, loadFont } from "./fonts.js";
|
|
4
5
|
import { WebXRButtonFactory } from "./WebXRButtons.js";
|
|
5
6
|
|
|
7
|
+
// NOTE: keep JSX attributes in sync with ./jsx.d.ts
|
|
6
8
|
declare global {
|
|
7
9
|
interface HTMLElementTagNameMap {
|
|
8
10
|
"needle-button": NeedleButtonElement;
|
|
@@ -65,7 +67,7 @@ const isDev = isDevEnvironment();
|
|
|
65
67
|
* @see {@link NeedleEngineWebComponent} for the main <needle-engine> element
|
|
66
68
|
* @see {@link NeedleMenu} for the built-in menu component that can display similar buttons
|
|
67
69
|
*/
|
|
68
|
-
export class NeedleButtonElement extends
|
|
70
|
+
export class NeedleButtonElement extends HTMLElementBase {
|
|
69
71
|
|
|
70
72
|
static observedAttributes = ["ar", "vr", "quicklook", "qrcode"];
|
|
71
73
|
|
|
@@ -5,6 +5,7 @@ import { hasCommercialLicense } from "../engine_license.js";
|
|
|
5
5
|
import { onStart } from "../engine_lifecycle_api.js";
|
|
6
6
|
import { setDracoDecoderPath, setDracoDecoderType, setKtx2TranscoderPath } from "../engine_loaders.gltf.js";
|
|
7
7
|
import { Context, ContextCreateArgs } from "../engine_setup.js";
|
|
8
|
+
import { HTMLElementBase } from "../engine_ssr.js";
|
|
8
9
|
import { nameToThreeTonemapping } from "../engine_tonemapping.js";
|
|
9
10
|
import { type INeedleEngineComponent, type LoadedModel } from "../engine_types.js";
|
|
10
11
|
import type { addAttributeChangeCallback } from "../engine_utils.js";
|
|
@@ -16,6 +17,7 @@ import { arContainerClassName, AROverlayHandler } from "./needle-engine.ar-overl
|
|
|
16
17
|
import type { registerObservableAttribute } from "./needle-engine.extras.js";
|
|
17
18
|
import { calculateProgress01, EngineLoadingView, type ILoadingViewHandler } from "./needle-engine.loading.js";
|
|
18
19
|
|
|
20
|
+
// NOTE: keep JSX attributes in sync with ./jsx.d.ts
|
|
19
21
|
declare global {
|
|
20
22
|
interface HTMLElementTagNameMap {
|
|
21
23
|
"needle-engine": NeedleEngineWebComponent;
|
|
@@ -40,11 +42,17 @@ export interface NeedleEngineAttributes {
|
|
|
40
42
|
'hash': string;
|
|
41
43
|
/** Set to automatically add OrbitControls to the loaded scene. */
|
|
42
44
|
'camera-controls': string;
|
|
43
|
-
/** Override the default
|
|
45
|
+
/** Override the default Draco decoder/decompressor path. Can be a URL or a local path to a directory containing the Draco decoder files.
|
|
46
|
+
* @default "https://www.gstatic.com/draco/versioned/decoders/1.5.7/"
|
|
47
|
+
* @example <needle-engine dracoDecoderPath="./decoders/draco/"></needle-engine>
|
|
48
|
+
*/
|
|
44
49
|
'dracoDecoderPath': string;
|
|
45
|
-
/** Override the default
|
|
50
|
+
/** Override the default Draco decoder type. */
|
|
46
51
|
'dracoDecoderType': 'wasm' | 'js';
|
|
47
|
-
/** Override the default KTX2 transcoder/decoder path.
|
|
52
|
+
/** Override the default KTX2 transcoder/decoder path. Can be a URL or a local path to a directory containing the KTX2 transcoder files.
|
|
53
|
+
* @default "https://cdn.needle.tools/static/three/0.179.1/basis2/"
|
|
54
|
+
* @example <needle-engine ktx2DecoderPath="./decoders/ktx2/"></needle-engine>
|
|
55
|
+
*/
|
|
48
56
|
'ktx2DecoderPath': string;
|
|
49
57
|
/** Prevent context from being disposed when element is removed from DOM. */
|
|
50
58
|
'keep-alive': 'true' | 'false';
|
|
@@ -153,7 +161,7 @@ const observedAttributes = [
|
|
|
153
161
|
* @see {@link NeedleButtonElement} for adding AR/VR/Quicklook buttons via <needle-button>
|
|
154
162
|
* @see {@link NeedleMenu} for the built-in menu configuration component
|
|
155
163
|
*/
|
|
156
|
-
export class NeedleEngineWebComponent extends
|
|
164
|
+
export class NeedleEngineWebComponent extends HTMLElementBase implements INeedleEngineComponent {
|
|
157
165
|
|
|
158
166
|
static get observedAttributes() {
|
|
159
167
|
return observedAttributes;
|
|
@@ -207,7 +207,7 @@ function waitForContextLoadingFinished(): Promise<void> {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
|
|
210
|
-
if (DeviceUtilities.isDesktop() && isDevEnvironment()) {
|
|
210
|
+
if (typeof window !== "undefined" && DeviceUtilities.isDesktop() && isDevEnvironment()) {
|
|
211
211
|
window.addEventListener("keydown", (evt) => {
|
|
212
212
|
if (evt.key === "x" || evt.key === "Escape") {
|
|
213
213
|
if (NeedleXRSession.active) {
|
|
@@ -840,15 +840,16 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
840
840
|
get viewerPose(): XRViewerPose | undefined { return this._viewerPose; }
|
|
841
841
|
|
|
842
842
|
|
|
843
|
-
/** @returns `true` if any image is currently being tracked */
|
|
844
|
-
/** returns true if images are currently being tracked */
|
|
843
|
+
/** @returns `true` if any image is currently being tracked or emulated */
|
|
845
844
|
get isTrackingImages() {
|
|
846
845
|
if (this.frame && "getImageTrackingResults" in this.frame && typeof this.frame.getImageTrackingResults === "function") {
|
|
847
846
|
try {
|
|
848
847
|
const trackingResult = this.frame.getImageTrackingResults();
|
|
849
848
|
for (const result of trackingResult) {
|
|
850
849
|
const state = result.trackingState;
|
|
851
|
-
if (state === "tracked")
|
|
850
|
+
if (state === "tracked" || state === "emulated") {
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
852
853
|
}
|
|
853
854
|
}
|
|
854
855
|
catch {
|
|
@@ -1053,6 +1054,8 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1053
1054
|
private readonly _xr_update_scripts: INeedleXRSessionEventReceiver[] = [];
|
|
1054
1055
|
/** scripts that are in the scene but inactive (e.g. disabled parent gameObject) */
|
|
1055
1056
|
private readonly _inactive_scripts: INeedleXRSessionEventReceiver[] = [];
|
|
1057
|
+
/** tracks scripts that have received onEnterXR — prevents spurious onLeaveXR calls */
|
|
1058
|
+
private readonly _scripts_in_xr = new Set<INeedleXRSessionEventReceiver>();
|
|
1056
1059
|
private readonly _controllerAdded: ControllerChangedEvt[];
|
|
1057
1060
|
private readonly _controllerRemoved: ControllerChangedEvt[];
|
|
1058
1061
|
private readonly _originalCameraWorldPosition?: Vector3 | null;
|
|
@@ -1163,7 +1166,18 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1163
1166
|
// we set the session on the webxr manager at the end because we want to receive inputsource events first
|
|
1164
1167
|
// e.g. in case there's a bug in the threejs codebase
|
|
1165
1168
|
this.context.xr = this;
|
|
1166
|
-
this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)
|
|
1169
|
+
this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)
|
|
1170
|
+
.catch(err => {
|
|
1171
|
+
// Workaround for WebXR emulators on localhost: the polyfilled XRSession fails the
|
|
1172
|
+
// native XRWebGLBinding constructor's instanceof check. Retry with layers disabled.
|
|
1173
|
+
// See https://github.com/meta-quest/immersive-web-emulator/issues/80
|
|
1174
|
+
if (isDevEnvironment() && err instanceof TypeError && typeof XRWebGLBinding !== "undefined") {
|
|
1175
|
+
console.error(`XRWebGLBinding failed (${err.message}).\nSee https://github.com/meta-quest/immersive-web-emulator/issues/80`);
|
|
1176
|
+
}
|
|
1177
|
+
else {
|
|
1178
|
+
console.error("renderer.xr.setSession failed:", err);
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1167
1181
|
// disable three.js renderer controller autoUpdate (added in ac67b31e3548386f8a93e23a4176554c92bbd0d9)
|
|
1168
1182
|
if ("controllerAutoUpdate" in this.context.renderer.xr) {
|
|
1169
1183
|
console.debug("Disabling three.js controllerAutoUpdate");
|
|
@@ -1331,8 +1345,10 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1331
1345
|
// even if they might already be destroyed e.g. by the WebXR component (it destroys the default controller scripts)
|
|
1332
1346
|
// they should still receive this callback to be properly cleaned up
|
|
1333
1347
|
for (const listener of this._xr_scripts) {
|
|
1348
|
+
this._scripts_in_xr.delete(listener);
|
|
1334
1349
|
listener?.onLeaveXR?.({ xr: this });
|
|
1335
1350
|
}
|
|
1351
|
+
this._scripts_in_xr.clear();
|
|
1336
1352
|
|
|
1337
1353
|
this.sync?.onExitXR(this);
|
|
1338
1354
|
|
|
@@ -1399,10 +1415,17 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1399
1415
|
}
|
|
1400
1416
|
|
|
1401
1417
|
// make sure the camera is parented to the active rig
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1418
|
+
// Note: applyCustomForward() inserts _cameraRenderParent between rig and camera,
|
|
1419
|
+
// so the hierarchy is: rig → _cameraRenderParent → camera. We check the effective parent.
|
|
1420
|
+
if (this.rig) {
|
|
1421
|
+
const cameraObject = this._mainCamera?.gameObject ?? this.context.mainCamera;
|
|
1422
|
+
if (cameraObject) {
|
|
1423
|
+
const effectiveParent = cameraObject.parent === this._cameraRenderParent
|
|
1424
|
+
? this._cameraRenderParent.parent
|
|
1425
|
+
: cameraObject.parent;
|
|
1426
|
+
if (effectiveParent !== this.rig.gameObject) {
|
|
1427
|
+
this.rig.gameObject.add(cameraObject);
|
|
1428
|
+
}
|
|
1406
1429
|
}
|
|
1407
1430
|
}
|
|
1408
1431
|
|
|
@@ -1534,8 +1557,12 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1534
1557
|
}
|
|
1535
1558
|
|
|
1536
1559
|
//performance.mark('NeedleXRSession update scripts start');
|
|
1537
|
-
//
|
|
1538
|
-
|
|
1560
|
+
// check all XR scripts for destroyed or inactive state
|
|
1561
|
+
// this must cover _xr_scripts (not just _xr_update_scripts) so that scripts
|
|
1562
|
+
// without onUpdateXR are also detected as inactive when removed from the scene
|
|
1563
|
+
// iterate backwards since markInactive/removeScript modifies the array
|
|
1564
|
+
for (let i = this._xr_scripts.length - 1; i >= 0; i--) {
|
|
1565
|
+
const script = this._xr_scripts[i];
|
|
1539
1566
|
if (script.destroyed === true) {
|
|
1540
1567
|
this._script_to_remove.push(script);
|
|
1541
1568
|
continue;
|
|
@@ -1544,6 +1571,10 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1544
1571
|
this.markInactive(script);
|
|
1545
1572
|
continue;
|
|
1546
1573
|
}
|
|
1574
|
+
}
|
|
1575
|
+
// invoke update on scripts that have onUpdateXR
|
|
1576
|
+
for (const script of this._xr_update_scripts) {
|
|
1577
|
+
if (script.destroyed || script.activeAndEnabled === false) continue;
|
|
1547
1578
|
if (script.onUpdateXR) script.onUpdateXR(args);
|
|
1548
1579
|
}
|
|
1549
1580
|
//performance.mark('NeedleXRSession update scripts end');
|
|
@@ -1666,9 +1697,11 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1666
1697
|
const script = this._inactive_scripts[i];
|
|
1667
1698
|
if (script.activeAndEnabled) {
|
|
1668
1699
|
this._inactive_scripts.splice(i, 1);
|
|
1669
|
-
|
|
1670
|
-
this.
|
|
1671
|
-
|
|
1700
|
+
// addScript returns false if already re-added (e.g. via new_scripts_xr processing)
|
|
1701
|
+
if (this.addScript(script)) {
|
|
1702
|
+
this.invokeCallback_EnterXR(script);
|
|
1703
|
+
for (const ctrl of this.controllers) this.invokeCallback_ControllerAdded(script, ctrl);
|
|
1704
|
+
}
|
|
1672
1705
|
}
|
|
1673
1706
|
}
|
|
1674
1707
|
}
|
|
@@ -1689,6 +1722,7 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1689
1722
|
}
|
|
1690
1723
|
|
|
1691
1724
|
private invokeCallback_EnterXR(script: INeedleXRSessionEventReceiver) {
|
|
1725
|
+
this._scripts_in_xr.add(script);
|
|
1692
1726
|
if (script.onEnterXR) {
|
|
1693
1727
|
script.onEnterXR({ xr: this });
|
|
1694
1728
|
}
|
|
@@ -1704,6 +1738,7 @@ export class NeedleXRSession implements INeedleXRSession {
|
|
|
1704
1738
|
}
|
|
1705
1739
|
}
|
|
1706
1740
|
private invokeCallback_LeaveXR(script: INeedleXRSessionEventReceiver) {
|
|
1741
|
+
if (!this._scripts_in_xr.delete(script)) return;
|
|
1707
1742
|
if (script.onLeaveXR && !script.destroyed) {
|
|
1708
1743
|
script.onLeaveXR({ xr: this });
|
|
1709
1744
|
}
|
package/src/engine/xr/events.ts
CHANGED
|
@@ -447,25 +447,13 @@ export class Animation extends Behaviour implements IAnimationComponent {
|
|
|
447
447
|
|
|
448
448
|
private internalOnPlay(action: AnimationAction, options: PlayOptions): Promise<AnimationAction> {
|
|
449
449
|
var existing = this.actions.find(a => a === action);
|
|
450
|
-
if (existing === action && existing.isRunning() && existing.time < existing.getClip().duration) {
|
|
451
|
-
const handle = this.tryFindHandle(action);
|
|
452
|
-
if (existing.paused) {
|
|
453
|
-
existing.paused = false;
|
|
454
|
-
}
|
|
455
|
-
if (handle) return handle.waitForFinish();
|
|
456
|
-
}
|
|
457
450
|
|
|
458
|
-
//
|
|
459
|
-
|
|
460
|
-
if (options.clampWhenFinished === undefined) options.clampWhenFinished = this.clampWhenFinished;
|
|
461
|
-
if (options.minMaxOffsetNormalized === undefined && this.randomStartTime) options.minMaxOffsetNormalized = this.minMaxOffsetNormalized;
|
|
462
|
-
if (options.minMaxSpeed === undefined) options.minMaxSpeed = this.minMaxSpeed;
|
|
463
|
-
|
|
464
|
-
// Reset currently running animations
|
|
451
|
+
// Stop other animations before the early-return check so exclusive always applies,
|
|
452
|
+
// even when the target animation is already running.
|
|
465
453
|
const stopOther = options?.exclusive ?? true;
|
|
466
454
|
if (stopOther) {
|
|
467
455
|
for (const act of this.actions) {
|
|
468
|
-
if (act
|
|
456
|
+
if (act !== action) {
|
|
469
457
|
if (options.fadeDuration) {
|
|
470
458
|
act.fadeOut(options.fadeDuration);
|
|
471
459
|
}
|
|
@@ -475,6 +463,20 @@ export class Animation extends Behaviour implements IAnimationComponent {
|
|
|
475
463
|
}
|
|
476
464
|
}
|
|
477
465
|
}
|
|
466
|
+
|
|
467
|
+
if (existing === action && existing.isRunning() && existing.time < existing.getClip().duration) {
|
|
468
|
+
const handle = this.tryFindHandle(action);
|
|
469
|
+
if (existing.paused) {
|
|
470
|
+
existing.paused = false;
|
|
471
|
+
}
|
|
472
|
+
if (handle) return handle.waitForFinish();
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Assign defaults
|
|
476
|
+
if (options.loop === undefined) options.loop = this.loop;
|
|
477
|
+
if (options.clampWhenFinished === undefined) options.clampWhenFinished = this.clampWhenFinished;
|
|
478
|
+
if (options.minMaxOffsetNormalized === undefined && this.randomStartTime) options.minMaxOffsetNormalized = this.minMaxOffsetNormalized;
|
|
479
|
+
if (options.minMaxSpeed === undefined) options.minMaxSpeed = this.minMaxSpeed;
|
|
478
480
|
if (options?.fadeDuration) {
|
|
479
481
|
action.fadeIn(options.fadeDuration);
|
|
480
482
|
}
|
|
@@ -515,10 +517,11 @@ export class Animation extends Behaviour implements IAnimationComponent {
|
|
|
515
517
|
|
|
516
518
|
action.paused = false;
|
|
517
519
|
action.play();
|
|
520
|
+
if (debug) console.log("[Animation] Now Playing", action.getClip().name, action)
|
|
521
|
+
|
|
518
522
|
|
|
519
523
|
window.requestAnimationFrame(() => AnimationUtils.testIfRootCanAnimate(action));
|
|
520
524
|
|
|
521
|
-
if (debug) console.log("PLAY", action.getClip().name, action)
|
|
522
525
|
const handle = new AnimationHandle(action, this.mixer!, options, _ => {
|
|
523
526
|
this._handles.splice(this._handles.indexOf(handle), 1);
|
|
524
527
|
});
|
|
@@ -1586,4 +1586,7 @@ class AnimatorControllerSerializator extends TypeSerializer {
|
|
|
1586
1586
|
return undefined;
|
|
1587
1587
|
}
|
|
1588
1588
|
}
|
|
1589
|
-
|
|
1589
|
+
/** @internal */
|
|
1590
|
+
export function initAnimatorControllerSerializer() {
|
|
1591
|
+
new AnimatorControllerSerializator(AnimatorController);
|
|
1592
|
+
}
|