@needle-tools/engine 2.65.2-pre → 2.67.0-pre
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 +43 -0
- package/dist/needle-engine.js +34490 -26304
- package/dist/needle-engine.umd.cjs +748 -303
- package/lib/engine/api.d.ts +4 -0
- package/lib/engine/api.js +10 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/codegen/register_types.js +23 -7
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/debug/debug_overlay.js +11 -2
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_addressables.js +4 -4
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_assetdatabase.d.ts +17 -51
- package/lib/engine/engine_assetdatabase.js +252 -126
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_components.js +13 -1
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_components_internal.d.ts +8 -0
- package/lib/engine/engine_components_internal.js +29 -0
- package/lib/engine/engine_components_internal.js.map +1 -0
- package/lib/engine/engine_constants.d.ts +1 -0
- package/lib/engine/engine_constants.js +1 -0
- package/lib/engine/engine_constants.js.map +1 -1
- package/lib/engine/engine_context_registry.d.ts +2 -0
- package/lib/engine/engine_context_registry.js +6 -0
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine/engine_editor-sync.d.ts +9 -0
- package/lib/engine/engine_editor-sync.js +8 -0
- package/lib/engine/engine_editor-sync.js.map +1 -0
- package/lib/engine/engine_element.d.ts +1 -0
- package/lib/engine/engine_element.js +4 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.d.ts +3 -2
- package/lib/engine/engine_element_loading.js +19 -15
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.js +21 -23
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gizmos.js +3 -1
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
- package/lib/engine/engine_gltf_builtin_components.js +23 -6
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +3 -1
- package/lib/engine/engine_networking.js +10 -8
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_auto.d.ts +1 -0
- package/lib/engine/engine_networking_auto.js +42 -9
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_patcher.d.ts +8 -0
- package/lib/engine/engine_patcher.js +98 -0
- package/lib/engine/engine_patcher.js.map +1 -0
- package/lib/engine/engine_physics.d.ts +34 -2
- package/lib/engine/engine_physics.js +110 -11
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_scenetools.js +0 -1
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +4 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +1 -1
- package/lib/engine/engine_setup.js +12 -5
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_texture.d.ts +6 -1
- package/lib/engine/engine_texture.js +39 -1
- package/lib/engine/engine_texture.js.map +1 -1
- package/lib/engine/engine_types.d.ts +4 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_utils.js +3 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
- package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
- package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.js +9 -0
- package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +4 -1
- package/lib/engine/extensions/extensions.js +16 -0
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine/extensions/usage_tracker.d.ts +12 -0
- package/lib/engine/extensions/usage_tracker.js +59 -0
- package/lib/engine/extensions/usage_tracker.js.map +1 -0
- package/lib/engine-components/Animator.js +0 -1
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +4 -0
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioSource.js +2 -1
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +6 -0
- package/lib/engine-components/Camera.js +70 -31
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CharacterController.d.ts +1 -0
- package/lib/engine-components/CharacterController.js +14 -9
- package/lib/engine-components/CharacterController.js.map +1 -1
- package/lib/engine-components/Collider.js +14 -1
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +52 -0
- package/lib/engine-components/Component.js +55 -14
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Networking.js +19 -0
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +2 -0
- package/lib/engine-components/OrbitControls.js +9 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +5 -1
- package/lib/engine-components/ParticleSystem.js +52 -7
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ParticleSystemModules.d.ts +2 -0
- package/lib/engine-components/ParticleSystemModules.js +26 -0
- package/lib/engine-components/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/ParticleSystemSubEmitter.js +5 -2
- package/lib/engine-components/ParticleSystemSubEmitter.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +18 -6
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -1
- package/lib/engine-components/Renderer.js +33 -11
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/ScreenCapture.js +3 -3
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/Skybox.js +2 -0
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/SmoothFollow.js +1 -2
- package/lib/engine-components/SmoothFollow.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.js +3 -3
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedCamera.js +1 -1
- package/lib/engine-components/SyncedCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.js +2 -2
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TestRunner.js +1 -1
- package/lib/engine-components/TestRunner.js.map +1 -1
- package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
- package/lib/engine-components/WebARCameraBackground.js +185 -0
- package/lib/engine-components/WebARCameraBackground.js.map +1 -0
- package/lib/engine-components/WebARSessionRoot.js +3 -2
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +4 -0
- package/lib/engine-components/WebXR.js +11 -8
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.js +1 -0
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.js +2 -2
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.js +2 -2
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +14 -6
- package/lib/engine-components/codegen/components.js +14 -6
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/js-extensions/Object3D.js +4 -1
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
- package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
- package/lib/engine-components/postprocessing/Volume.js +176 -0
- package/lib/engine-components/postprocessing/Volume.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
- package/lib/engine-components/timeline/TimelineTracks.js +14 -15
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/ui/Text.js +28 -170
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
- package/lib/engine-components-experimental/networking/PlayerSync.js +62 -8
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/lib/include/three/ARButton.d.ts +1 -1
- package/lib/include/three/ARButton.js +11 -19
- package/lib/include/three/ARButton.js.map +1 -1
- package/lib/include/three/VRButton.js +1 -4
- package/lib/include/three/VRButton.js.map +1 -1
- package/package.json +3 -2
- package/plugins/vite/drop-client.js +77 -0
- package/plugins/vite/drop.js +81 -0
- package/plugins/vite/editor-connection.js +121 -0
- package/plugins/vite/index.js +9 -4
- package/plugins/vite/meta.js +3 -0
- package/plugins/vite/poster-client.js +6 -4
- package/src/engine/api.ts +30 -1
- package/src/engine/codegen/register_types.js +25 -9
- package/src/engine/debug/debug_overlay.ts +11 -2
- package/src/engine/engine_addressables.ts +4 -4
- package/src/engine/engine_assetdatabase.ts +291 -184
- package/src/engine/engine_components.ts +20 -1
- package/src/engine/engine_components_internal.ts +30 -0
- package/src/engine/engine_constants.ts +4 -1
- package/src/engine/engine_context_registry.ts +7 -0
- package/src/engine/engine_editor-sync.ts +21 -0
- package/src/engine/engine_element.ts +8 -1
- package/src/engine/engine_element_loading.ts +19 -15
- package/src/engine/engine_gameobject.ts +579 -583
- package/src/engine/engine_gizmos.ts +3 -2
- package/src/engine/engine_gltf_builtin_components.ts +30 -15
- package/src/engine/engine_networking.ts +10 -8
- package/src/engine/engine_networking_auto.ts +48 -11
- package/src/engine/engine_patcher.ts +113 -0
- package/src/engine/engine_physics.ts +128 -12
- package/src/engine/engine_scenetools.ts +0 -1
- package/src/engine/engine_serialization_core.ts +6 -0
- package/src/engine/engine_setup.ts +15 -5
- package/src/engine/engine_texture.ts +54 -5
- package/src/engine/engine_types.ts +6 -1
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
- package/src/engine/extensions/NEEDLE_render_objects.ts +10 -1
- package/src/engine/extensions/extensions.ts +22 -1
- package/src/engine/extensions/usage_tracker.ts +91 -0
- package/src/engine-components/Animator.ts +0 -1
- package/src/engine-components/AnimatorController.ts +2 -0
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Camera.ts +77 -37
- package/src/engine-components/CharacterController.ts +12 -9
- package/src/engine-components/Collider.ts +16 -2
- package/src/engine-components/Component.ts +74 -30
- package/src/engine-components/Networking.ts +9 -1
- package/src/engine-components/OrbitControls.ts +11 -2
- package/src/engine-components/ParticleSystem.ts +54 -10
- package/src/engine-components/ParticleSystemModules.ts +28 -1
- package/src/engine-components/ParticleSystemSubEmitter.ts +5 -3
- package/src/engine-components/ReflectionProbe.ts +17 -7
- package/src/engine-components/Renderer.ts +36 -16
- package/src/engine-components/ScreenCapture.ts +3 -3
- package/src/engine-components/Skybox.ts +2 -0
- package/src/engine-components/SmoothFollow.ts +4 -4
- package/src/engine-components/SpectatorCamera.ts +3 -3
- package/src/engine-components/SyncedCamera.ts +1 -1
- package/src/engine-components/SyncedTransform.ts +2 -2
- package/src/engine-components/TestRunner.ts +1 -1
- package/src/engine-components/WebARCameraBackground.ts +215 -0
- package/src/engine-components/WebARSessionRoot.ts +3 -2
- package/src/engine-components/WebXR.ts +12 -8
- package/src/engine-components/WebXRAvatar.ts +1 -1
- package/src/engine-components/WebXRGrabRendering.ts +2 -2
- package/src/engine-components/WebXRSync.ts +2 -2
- package/src/engine-components/codegen/components.ts +14 -6
- package/src/engine-components/js-extensions/Object3D.ts +6 -1
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
- package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
- package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
- package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
- package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
- package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
- package/src/engine-components/postprocessing/Volume.ts +194 -0
- package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
- package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
- package/src/engine-components/timeline/TimelineTracks.ts +16 -17
- package/src/engine-components/ui/Text.ts +37 -174
- package/src/engine-components-experimental/networking/PlayerSync.ts +69 -8
- package/src/include/three/ARButton.js +13 -24
- package/src/include/three/VRButton.js +1 -7
- package/lib/engine-components/Volume.d.ts +0 -34
- package/lib/engine-components/Volume.js +0 -140
- package/lib/engine-components/Volume.js.map +0 -1
- package/src/engine-components/Volume.ts +0 -141
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { serializable } from "../../engine/engine_serialization";
|
|
2
|
+
import { Effect, Pass } from "postprocessing";
|
|
3
|
+
import { VolumeParameter } from "./VolumeParameter";
|
|
4
|
+
import { Component } from "../Component";
|
|
5
|
+
import { ISerializable, SerializationContext } from "../../engine/engine_serialization_core";
|
|
6
|
+
import { EditorModification, IEditorModification } from "../../engine/engine_editor-sync";
|
|
7
|
+
|
|
8
|
+
export declare type EffectProviderResult = Effect | Pass | Array<Effect | Pass>;
|
|
9
|
+
|
|
10
|
+
export interface IEffectProvider {
|
|
11
|
+
apply(): void | undefined | EffectProviderResult;
|
|
12
|
+
unapply(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export abstract class PostProcessingEffect extends Component implements IEffectProvider, ISerializable, IEditorModification {
|
|
16
|
+
|
|
17
|
+
abstract get typeName(): string;
|
|
18
|
+
|
|
19
|
+
onEnable(): void {
|
|
20
|
+
// Dont override the serialized value by enabling (we could also just disable this component / map enabled to active)
|
|
21
|
+
if (this.__internalDidAwakeAndStart)
|
|
22
|
+
this.active = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onDisable(): void {
|
|
26
|
+
this.active = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@serializable()
|
|
30
|
+
active: boolean = true;
|
|
31
|
+
|
|
32
|
+
/** override to initialize bindings on parameters */
|
|
33
|
+
init() {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** previously created effect (if any) */
|
|
38
|
+
private _result: void | undefined | EffectProviderResult;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/** Apply post settings. Make sure to call super.apply() if you also create an effect */
|
|
42
|
+
apply(): void | undefined | EffectProviderResult {
|
|
43
|
+
if (!this._result) {
|
|
44
|
+
this._result = this.onCreateEffect?.call(this);
|
|
45
|
+
if (this._result) {
|
|
46
|
+
this.initParameters();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return this._result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Reset previously set values (e.g. when adjusting settings on the renderer like Tonemapping) */
|
|
53
|
+
unapply(): void { }
|
|
54
|
+
|
|
55
|
+
/** implement to create a effect once to be cached in the base class. Make sure super.apply() is called if you also override apply */
|
|
56
|
+
onCreateEffect?(): EffectProviderResult | undefined
|
|
57
|
+
|
|
58
|
+
dispose() {
|
|
59
|
+
if (this._result) {
|
|
60
|
+
if (Array.isArray(this._result)) {
|
|
61
|
+
this._result.forEach(r => r.dispose());
|
|
62
|
+
} else {
|
|
63
|
+
this._result.dispose();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this._result = undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private initParameters() {
|
|
70
|
+
// Automatically call init on all VolumeParameter properties
|
|
71
|
+
// This will enforce the valueProcessor and onValueChanged to be called
|
|
72
|
+
const keys = Object.keys(this);
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
const value = this[key];
|
|
75
|
+
if (value instanceof VolumeParameter) {
|
|
76
|
+
value.__init();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
onAfterDeserialize(data: any, _context: SerializationContext): void {
|
|
82
|
+
// When using additional effects and parameters exported from the editor are not in the volume parameter format
|
|
83
|
+
if (typeof data === "object") {
|
|
84
|
+
const types = this["$serializedTypes"];
|
|
85
|
+
if (types) {
|
|
86
|
+
for (const fieldName in Object.keys(types)) {
|
|
87
|
+
const type = types[fieldName];
|
|
88
|
+
if (type === VolumeParameter) {
|
|
89
|
+
const value = data[fieldName];
|
|
90
|
+
if (value !== undefined) {
|
|
91
|
+
this[fieldName].value = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
onEditorModification(modification: EditorModification): void | boolean | undefined {
|
|
101
|
+
// Handle a property modification if the property is a VolumeParameter and the modification is just a plain value
|
|
102
|
+
const key = modification.propertyName;
|
|
103
|
+
if (this[key] instanceof VolumeParameter) {
|
|
104
|
+
const value = modification.value;
|
|
105
|
+
this[key].value = value;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { HalfFloatType, sRGBEncoding, WebGLRenderTarget } from "three";
|
|
2
|
+
import { Context } from "../../engine/engine_setup";
|
|
3
|
+
import { getParam } from "../../engine/engine_utils";
|
|
4
|
+
import { Effect, EffectComposer, EffectPass, Pass, RenderPass } from "postprocessing";
|
|
5
|
+
import { showBalloonWarning } from "../../engine/debug/debug";
|
|
6
|
+
import { Camera } from "../Camera";
|
|
7
|
+
import { PostProcessingEffect } from "./PostProcessingEffect";
|
|
8
|
+
|
|
9
|
+
const debug = getParam("debugpost");
|
|
10
|
+
|
|
11
|
+
const activeKey = Symbol("postprocessing-handler");
|
|
12
|
+
|
|
13
|
+
export class PostProcessingHandler {
|
|
14
|
+
|
|
15
|
+
private _composer: EffectComposer | null = null;
|
|
16
|
+
private _lastVolumeComponents?: PostProcessingEffect[];
|
|
17
|
+
private _effects: Array<Effect | Pass> = [];
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
apply(context: Context, components: PostProcessingEffect[]) {
|
|
21
|
+
this.onApply(context, components);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
unapply(context: Context) {
|
|
25
|
+
if (this._lastVolumeComponents) {
|
|
26
|
+
for (const component of this._lastVolumeComponents) {
|
|
27
|
+
component.unapply();
|
|
28
|
+
}
|
|
29
|
+
this._lastVolumeComponents.length = 0;
|
|
30
|
+
}
|
|
31
|
+
const active = context[activeKey] as PostProcessingHandler | null;
|
|
32
|
+
if (active === this) {
|
|
33
|
+
delete context[activeKey];
|
|
34
|
+
}
|
|
35
|
+
if (context.composer === this._composer)
|
|
36
|
+
context.composer = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
dispose(context: Context) {
|
|
40
|
+
this.unapply(context);
|
|
41
|
+
|
|
42
|
+
for (const effect of this._effects) {
|
|
43
|
+
effect.dispose();
|
|
44
|
+
}
|
|
45
|
+
this._effects.length = 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
private onApply(context: Context, components: PostProcessingEffect[]) {
|
|
50
|
+
|
|
51
|
+
if (!components) return;
|
|
52
|
+
|
|
53
|
+
context[activeKey] = this;
|
|
54
|
+
|
|
55
|
+
if (debug) console.log("refreshing volume profile", components);
|
|
56
|
+
|
|
57
|
+
this._lastVolumeComponents = [...components];
|
|
58
|
+
|
|
59
|
+
// store all effects in an array to apply them all in one pass
|
|
60
|
+
// const effects: Array<Effect | Pass> = [];
|
|
61
|
+
this._effects.length = 0;
|
|
62
|
+
|
|
63
|
+
for (const component of components) {
|
|
64
|
+
//@ts-ignore
|
|
65
|
+
component.context = context;
|
|
66
|
+
if (component.apply) {
|
|
67
|
+
if (component.active) {
|
|
68
|
+
if (!context.mainCameraComponent) {
|
|
69
|
+
console.error("No camera in scene found or available yet - can not create postprocessing effects");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// apply or collect effects
|
|
73
|
+
const res = component.apply();
|
|
74
|
+
if (res === undefined || res === null) continue;
|
|
75
|
+
if (Array.isArray(res)) {
|
|
76
|
+
this._effects.push(...res);
|
|
77
|
+
}
|
|
78
|
+
else this._effects.push(res);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (component.active)
|
|
83
|
+
showBalloonWarning("Volume component is not a VolumeComponent: " + component["__type"]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.applyEffects(context);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
/** Build composer passes */
|
|
93
|
+
private applyEffects(context: Context) {
|
|
94
|
+
|
|
95
|
+
const effectsOrPasses = this._effects;
|
|
96
|
+
const camera = context.mainCameraComponent as Camera;
|
|
97
|
+
const renderer = context.renderer;
|
|
98
|
+
|
|
99
|
+
if (effectsOrPasses.length <= 0) return;
|
|
100
|
+
|
|
101
|
+
const cam = camera.cam;
|
|
102
|
+
|
|
103
|
+
// create composer and set active on context
|
|
104
|
+
if (!this._composer) {
|
|
105
|
+
// const hdrRenderTarget = new WebGLRenderTarget(window.innerWidth, window.innerHeight, { type: HalfFloatType });
|
|
106
|
+
this._composer = new EffectComposer(renderer, {
|
|
107
|
+
frameBufferType: HalfFloatType,
|
|
108
|
+
// multisampling: 2,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
context.composer = this._composer;
|
|
112
|
+
const composer = context.composer;
|
|
113
|
+
composer.setMainCamera(cam);
|
|
114
|
+
composer.setRenderer(renderer);
|
|
115
|
+
for (const prev of composer.passes)
|
|
116
|
+
prev.dispose();
|
|
117
|
+
composer.removeAllPasses();
|
|
118
|
+
composer.addPass(new RenderPass(context.scene, cam));
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if (debug)
|
|
122
|
+
console.log("Set effects or passes", camera, effectsOrPasses, composer);
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
const effects: Array<Effect> = [];
|
|
126
|
+
|
|
127
|
+
for (const ef of effectsOrPasses) {
|
|
128
|
+
if (ef instanceof Effect)
|
|
129
|
+
effects.push(ef as Effect);
|
|
130
|
+
else if (ef instanceof Pass) {
|
|
131
|
+
const pass = new EffectPass(cam, ...effects);
|
|
132
|
+
pass.name = effects.map(e => e.constructor.name).join(", ");
|
|
133
|
+
pass.enabled = true;
|
|
134
|
+
composer.addPass(pass);
|
|
135
|
+
effects.length = 0;
|
|
136
|
+
composer.addPass(ef as Pass);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// create and apply uber pass
|
|
141
|
+
if (effects.length > 0) {
|
|
142
|
+
const pass = new EffectPass(cam, ...effects);
|
|
143
|
+
pass.enabled = true;
|
|
144
|
+
composer.addPass(pass);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Behaviour, GameObject } from "../Component";
|
|
2
|
+
import { serializeable } from "../../engine/engine_serialization_decorator";
|
|
3
|
+
import { getParam } from "../../engine/engine_utils";
|
|
4
|
+
import { VolumeProfile } from "./VolumeProfile";
|
|
5
|
+
import { EditorModification, IEditorModification as IEditorModificationReceiver } from "../../engine/engine_editor-sync";
|
|
6
|
+
import { PostProcessingHandler } from "./PostProcessingHandler";
|
|
7
|
+
import { PostProcessingEffect } from "./PostProcessingEffect";
|
|
8
|
+
import { VolumeParameter } from "./VolumeParameter";
|
|
9
|
+
import { getEditorModificationCache } from "../../engine/engine_editor-sync";
|
|
10
|
+
import { isDevEnvironment } from "../../engine/debug";
|
|
11
|
+
// import { CustomPostProcessingEffect } from "./CustomPostProcessingEffect";
|
|
12
|
+
|
|
13
|
+
const debug = getParam("debugpost");
|
|
14
|
+
|
|
15
|
+
export class Volume extends Behaviour implements IEditorModificationReceiver {
|
|
16
|
+
|
|
17
|
+
@serializeable(VolumeProfile)
|
|
18
|
+
sharedProfile?: VolumeProfile;
|
|
19
|
+
|
|
20
|
+
private _postprocessing: PostProcessingHandler = new PostProcessingHandler();
|
|
21
|
+
private _effects: PostProcessingEffect[] = [];
|
|
22
|
+
|
|
23
|
+
awake() {
|
|
24
|
+
// ensure the profile is initialized
|
|
25
|
+
this.sharedProfile?.init();
|
|
26
|
+
|
|
27
|
+
if (debug) {
|
|
28
|
+
console.log(this);
|
|
29
|
+
console.log("Press P to toggle post processing");
|
|
30
|
+
window.addEventListener("keydown", (e) => {
|
|
31
|
+
if (e.key === "p") {
|
|
32
|
+
console.log("Toggle volume: " + this.name, !this.enabled);
|
|
33
|
+
this.enabled = !this.enabled;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
start() {
|
|
40
|
+
this.apply();
|
|
41
|
+
this.tryApplyCache();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onEnable() {
|
|
45
|
+
// We need to wait for the camera to be ready
|
|
46
|
+
if (this.__internalDidAwakeAndStart)
|
|
47
|
+
this.apply();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
onDisable() {
|
|
51
|
+
this._postprocessing?.unapply(this.context);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onBeforeRender(): void {
|
|
55
|
+
if (!this.context.isInXR && this.context.composer && this.context.mainCamera) {
|
|
56
|
+
this.context.composer.setRenderer(this.context.renderer);
|
|
57
|
+
this.context.composer.setMainScene(this.context.scene);
|
|
58
|
+
this.context.composer.setMainCamera(this.context.mainCamera);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onDestroy(): void {
|
|
63
|
+
this._postprocessing?.dispose(this.context);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private _lastApplyTime?: number;
|
|
67
|
+
private _rapidApplyCount = 0;
|
|
68
|
+
|
|
69
|
+
private apply() {
|
|
70
|
+
if (debug) console.log("Apply PostProcessing", this);
|
|
71
|
+
|
|
72
|
+
if (isDevEnvironment()) {
|
|
73
|
+
if (this._lastApplyTime !== undefined && Date.now() - this._lastApplyTime < 100) {
|
|
74
|
+
this._rapidApplyCount++;
|
|
75
|
+
if (this._rapidApplyCount === 5)
|
|
76
|
+
console.warn("Detected rapid post processing modifications - this might be a bug", this);
|
|
77
|
+
}
|
|
78
|
+
this._lastApplyTime = Date.now();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
this.unapply();
|
|
83
|
+
|
|
84
|
+
this._effects.length = 0;
|
|
85
|
+
// get from profile
|
|
86
|
+
if (this.sharedProfile?.components) {
|
|
87
|
+
this._effects.push(...this.sharedProfile.components);
|
|
88
|
+
}
|
|
89
|
+
// get additional effects
|
|
90
|
+
const additionalComponents = this.gameObject.getComponentsInChildren(PostProcessingEffect);
|
|
91
|
+
if (debug && additionalComponents?.length)
|
|
92
|
+
console.log("Additional", additionalComponents);
|
|
93
|
+
if (additionalComponents) {
|
|
94
|
+
for (const comp of additionalComponents) {
|
|
95
|
+
if (comp.active) this._effects.push(comp);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (this._effects.length > 0) {
|
|
99
|
+
this._postprocessing.apply(this.context, this._effects);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private unapply() {
|
|
104
|
+
this._postprocessing.unapply(this.context);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
private tryApplyCache() {
|
|
109
|
+
const cache = getEditorModificationCache();
|
|
110
|
+
if (cache) {
|
|
111
|
+
for (const entry of cache.values()) this.onEditorModification(entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/** called from needle editor sync package if its active */
|
|
117
|
+
onEditorModification(modification: EditorModification): void | boolean | undefined {
|
|
118
|
+
|
|
119
|
+
if (modification.propertyName.startsWith("postprocessing.")) {
|
|
120
|
+
if (!this._effects?.length) return;
|
|
121
|
+
const path = modification.propertyName.split(".");
|
|
122
|
+
if (path.length === 3 || path.length === 4) {
|
|
123
|
+
const componentName = path[1];
|
|
124
|
+
const propertyName = path[2];
|
|
125
|
+
for (const comp of this._effects) {
|
|
126
|
+
if (comp.typeName?.toLowerCase() === componentName.toLowerCase()) {
|
|
127
|
+
|
|
128
|
+
if (propertyName === "active") {
|
|
129
|
+
comp.active = modification.value;
|
|
130
|
+
this.scheduleRecreate();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// cache the volume parameters
|
|
135
|
+
if (!effectVolumeProperties.has(componentName)) {
|
|
136
|
+
const volumeParameterKeys = new Array<string>();
|
|
137
|
+
effectVolumeProperties.set(componentName, volumeParameterKeys);
|
|
138
|
+
const keys = Object.keys(comp);
|
|
139
|
+
for (const key of keys) {
|
|
140
|
+
const prop = comp[key];
|
|
141
|
+
if (prop instanceof VolumeParameter) {
|
|
142
|
+
volumeParameterKeys.push(key);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (effectVolumeProperties.has(componentName)) {
|
|
148
|
+
const paramName = propertyName.toLowerCase();
|
|
149
|
+
const volumeParameterKeys = effectVolumeProperties.get(componentName)!;
|
|
150
|
+
for (const key of volumeParameterKeys) {
|
|
151
|
+
if (key.toLowerCase() === paramName) {
|
|
152
|
+
const prop = comp[key] as VolumeParameter;
|
|
153
|
+
if (prop instanceof VolumeParameter) {
|
|
154
|
+
const isActiveStateChange = path.length === 4 && path[3] === "active";
|
|
155
|
+
if (isActiveStateChange) {
|
|
156
|
+
prop.overrideState = modification.value;
|
|
157
|
+
this.scheduleRecreate();
|
|
158
|
+
}
|
|
159
|
+
else if (prop && prop.value !== undefined) {
|
|
160
|
+
prop.value = modification.value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
console.warn("Unknown modification", propertyName);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private _recreateId: number = -1;
|
|
180
|
+
private scheduleRecreate() {
|
|
181
|
+
// When the editor modifications come in with changed active effects we want/need to re-create the effects
|
|
182
|
+
// We defer it slightly because multiple active changes could be made and we dont want to recreate the full effect stack multiple times
|
|
183
|
+
const id = ++this._recreateId;
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
if (id !== this._recreateId) return;
|
|
186
|
+
this.onDisable();
|
|
187
|
+
this.onEnable();
|
|
188
|
+
}, 200);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** cached VolumeParameter keys per object */
|
|
194
|
+
const effectVolumeProperties: Map<string, string[]> = new Map<string, string[]>();
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { serializable } from "../../engine/engine_serialization";
|
|
2
|
+
|
|
3
|
+
export declare type VolumeParameterChangedEvent = (newValue: any, oldValue: any, parameter: VolumeParameter) => void;
|
|
4
|
+
export declare type VolumeParameterValueProcessor = (value: any) => any;
|
|
5
|
+
|
|
6
|
+
export class VolumeParameter {
|
|
7
|
+
|
|
8
|
+
@serializable()
|
|
9
|
+
get overrideState(): boolean {
|
|
10
|
+
return this._active;
|
|
11
|
+
}
|
|
12
|
+
set overrideState(val: boolean) {
|
|
13
|
+
if (this._active === val) return;
|
|
14
|
+
this._active = val;
|
|
15
|
+
const value = val ? this._lastActiveSetValue : this._defaultValue;
|
|
16
|
+
this.processValue(value, true);
|
|
17
|
+
}
|
|
18
|
+
private _active: boolean = false;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@serializable()
|
|
23
|
+
get value() {
|
|
24
|
+
return this._value;
|
|
25
|
+
}
|
|
26
|
+
set value(val: any) {
|
|
27
|
+
this.processValue(val, false);
|
|
28
|
+
}
|
|
29
|
+
private _value: any;
|
|
30
|
+
private _lastActiveSetValue?: any;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
set defaultValue(val: any) {
|
|
34
|
+
this._defaultValue = val;
|
|
35
|
+
}
|
|
36
|
+
private _defaultValue: any = undefined;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/** enforce the value to be set and onValueChanged to be called if assigned */
|
|
40
|
+
__init() {
|
|
41
|
+
this.processValue(this._lastActiveSetValue, true);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** called to modify a changing value before it is saved */
|
|
45
|
+
valueProcessor: VolumeParameterValueProcessor | undefined;
|
|
46
|
+
/** called when a value has changed (with the final value) */
|
|
47
|
+
onValueChanged: VolumeParameterChangedEvent | undefined;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
private processValue(val: any, forceUpdate: boolean): any {
|
|
51
|
+
if (val === null || val === undefined) return;
|
|
52
|
+
|
|
53
|
+
if (!forceUpdate && this.testIfValueChanged(val) === false)
|
|
54
|
+
return;
|
|
55
|
+
|
|
56
|
+
const oldValue = this._value;
|
|
57
|
+
|
|
58
|
+
if (!this._active && this._defaultValue !== undefined) {
|
|
59
|
+
// when setting the default value we dont process them (default values are explicitly set from the effect that declares them
|
|
60
|
+
// with the value that is expected to received when the parameter is disabled)
|
|
61
|
+
this._value = this._defaultValue;
|
|
62
|
+
val = this._defaultValue;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this._lastActiveSetValue = val;
|
|
66
|
+
if (this._active && this.valueProcessor)
|
|
67
|
+
val = this.valueProcessor(val);
|
|
68
|
+
this._value = val;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.onValueChanged) {
|
|
72
|
+
this.onValueChanged(val, oldValue, this);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private testIfValueChanged(newValue: any): boolean {
|
|
77
|
+
|
|
78
|
+
if (this._lastActiveSetValue === newValue)
|
|
79
|
+
return false;
|
|
80
|
+
|
|
81
|
+
// TODO: may need checks for colors or vectors (check by xyz,rgb because they might come in as anonymous objects via editor modifications)
|
|
82
|
+
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { serializeable } from "../../engine/engine_serialization_decorator";
|
|
2
|
+
import { getParam } from "../../engine/engine_utils";
|
|
3
|
+
import { PostProcessingEffect } from "./PostProcessingEffect";
|
|
4
|
+
|
|
5
|
+
const debug = getParam("debugpost");
|
|
6
|
+
|
|
7
|
+
const customEffects: { [name: string]: typeof PostProcessingEffect } = {};
|
|
8
|
+
export function registerCustomEffectType(name: string, effect: typeof PostProcessingEffect) {
|
|
9
|
+
customEffects[name] = effect;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// resolve the types:
|
|
13
|
+
function resolveComponentType(data: { __type: string }) {
|
|
14
|
+
if (data.__type in customEffects)
|
|
15
|
+
return customEffects[data.__type];
|
|
16
|
+
// if ("mode" in data) return ToneMapping;
|
|
17
|
+
// if ("postExposure" in data) return ColorAdjustments;
|
|
18
|
+
// switch (data.__type) {
|
|
19
|
+
// // case "Bloom": return Bloom;
|
|
20
|
+
// // case "DepthOfField": return DepthOfField;
|
|
21
|
+
// // case "Vignette": return Vignette
|
|
22
|
+
// // case "ColorAdjustments": return ColorAdjustments;
|
|
23
|
+
// // case "Tonemapping": return ToneMapping;
|
|
24
|
+
// }
|
|
25
|
+
if (debug && data.__type)
|
|
26
|
+
console.warn("Unknown postprocessing type", data.__type, data)
|
|
27
|
+
return PostProcessingEffect;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class VolumeProfile {
|
|
31
|
+
|
|
32
|
+
@serializeable([d => resolveComponentType(d), PostProcessingEffect])
|
|
33
|
+
components?: PostProcessingEffect[];
|
|
34
|
+
|
|
35
|
+
/** call init on all components */
|
|
36
|
+
init() {
|
|
37
|
+
this.components?.forEach(c => c.init());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
@@ -658,25 +658,24 @@ export class AudioTrackHandler extends TrackHandler {
|
|
|
658
658
|
|
|
659
659
|
private handleAudioLoading(model: Models.ClipModel, audio: THREE.Audio): Promise<AudioBuffer | null> | null {
|
|
660
660
|
if (!this._audioLoader) {
|
|
661
|
-
const path = this.getAudioFilePath(model.asset.clip);
|
|
662
661
|
this._audioLoader = new THREE.AudioLoader();
|
|
663
|
-
// TODO: maybe we should cache the loaders / buffers here by path
|
|
664
|
-
if (debug) console.warn("LOAD audio track", path, this.director.sourceId);
|
|
665
|
-
const loadingPromise = new Promise<AudioBuffer | null>((resolve, _reject) => {
|
|
666
|
-
this._audioLoader!.load(path,
|
|
667
|
-
buffer => {
|
|
668
|
-
audio.setBuffer(buffer);
|
|
669
|
-
resolve(buffer);
|
|
670
|
-
},
|
|
671
|
-
undefined,
|
|
672
|
-
err => {
|
|
673
|
-
console.error("Error loading audio", err);
|
|
674
|
-
resolve(null);
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
|
-
return loadingPromise;
|
|
678
662
|
}
|
|
679
|
-
|
|
663
|
+
// TODO: maybe we should cache the loaders / buffers here by path
|
|
664
|
+
const path = this.getAudioFilePath(model.asset.clip);
|
|
665
|
+
if (debug) console.warn("LOAD audio track", path, this.director.sourceId);
|
|
666
|
+
const loadingPromise = new Promise<AudioBuffer | null>((resolve, _reject) => {
|
|
667
|
+
this._audioLoader!.load(path,
|
|
668
|
+
buffer => {
|
|
669
|
+
audio.setBuffer(buffer);
|
|
670
|
+
resolve(buffer);
|
|
671
|
+
},
|
|
672
|
+
undefined,
|
|
673
|
+
err => {
|
|
674
|
+
console.error("Error loading audio", err);
|
|
675
|
+
resolve(null);
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
return loadingPromise;
|
|
680
679
|
}
|
|
681
680
|
}
|
|
682
681
|
|