@needle-tools/engine 5.1.0-canary.fbdfce3 → 5.1.0-experimental.03e8105
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 +86 -0
- package/SKILL.md +4 -1
- package/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-BFSj2Fz8.js → needle-engine.bundle-BNqUjnSQ.js} +19180 -18386
- package/dist/needle-engine.bundle-Bt8ULD7E.umd.cjs +1733 -0
- package/dist/needle-engine.bundle-DF6ovbwD.min.js +1733 -0
- package/dist/needle-engine.d.ts +1487 -356
- package/dist/needle-engine.js +544 -542
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/three.js +1 -0
- package/dist/three.min.js +21 -21
- package/dist/three.umd.cjs +16 -16
- package/lib/engine/api.d.ts +8 -1
- package/lib/engine/api.js +7 -1
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/codegen/register_types.js +10 -18
- package/lib/engine/codegen/register_types.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_camera.fit.js +16 -4
- package/lib/engine/engine_camera.fit.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_context.d.ts +21 -8
- package/lib/engine/engine_context.js +32 -16
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_context_eventbus.d.ts +47 -0
- package/lib/engine/engine_context_eventbus.js +47 -0
- package/lib/engine/engine_context_eventbus.js.map +1 -0
- package/lib/engine/engine_disposable.d.ts +172 -0
- package/lib/engine/engine_disposable.js +136 -0
- package/lib/engine/engine_disposable.js.map +1 -0
- package/lib/engine/engine_gameobject.d.ts +1 -10
- package/lib/engine/engine_gameobject.js +22 -120
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +7 -69
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_init.js +7 -7
- package/lib/engine/engine_init.js.map +1 -1
- package/lib/engine/engine_input.d.ts +24 -5
- package/lib/engine/engine_input.js +3 -2
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_instantiate_resolve.d.ts +42 -0
- package/lib/engine/engine_instantiate_resolve.js +372 -0
- package/lib/engine/engine_instantiate_resolve.js.map +1 -0
- package/lib/engine/engine_license.d.ts +7 -7
- package/lib/engine/engine_license.js +183 -57
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.js +7 -4
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +51 -37
- package/lib/engine/engine_networking.js +132 -82
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking.transport.websocket.d.ts +15 -0
- package/lib/engine/engine_networking.transport.websocket.js +38 -0
- package/lib/engine/engine_networking.transport.websocket.js.map +1 -0
- package/lib/engine/engine_networking_blob.js +4 -4
- package/lib/engine/engine_networking_blob.js.map +1 -1
- package/lib/engine/engine_networking_instantiate.js +2 -2
- package/lib/engine/engine_networking_instantiate.js.map +1 -1
- package/lib/engine/engine_networking_types.d.ts +39 -1
- package/lib/engine/engine_networking_types.js +7 -0
- package/lib/engine/engine_networking_types.js.map +1 -1
- package/lib/engine/engine_physics_rapier.d.ts +21 -3
- package/lib/engine/engine_physics_rapier.js +94 -25
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_scenedata.js +2 -2
- package/lib/engine/engine_scenedata.js.map +1 -1
- package/lib/engine/engine_serialization_builtin_serializer.js +28 -5
- package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
- package/lib/engine/engine_serialization_core.d.ts +1 -0
- package/lib/engine/engine_serialization_core.js +7 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_types.d.ts +29 -11
- package/lib/engine/engine_types.js +1 -1
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_util_decorator.js +7 -2
- package/lib/engine/engine_util_decorator.js.map +1 -1
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/engine_utils.js +19 -5
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/engine_utils_qrcode.js +2 -2
- package/lib/engine/engine_utils_qrcode.js.map +1 -1
- 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/needle menu/needle-menu-spatial.js +2 -2
- package/lib/engine/webcomponents/needle menu/needle-menu-spatial.js.map +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.js +6 -6
- package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +10 -4
- package/lib/engine/webcomponents/needle-engine.js +3 -3
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.loading.js +2 -2
- package/lib/engine/webcomponents/needle-engine.loading.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.d.ts +3 -2
- package/lib/engine/xr/NeedleXRSession.js +50 -14
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine/xr/TempXRContext.js +2 -2
- package/lib/engine/xr/TempXRContext.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/AnimationBuilder.d.ts +158 -0
- package/lib/engine-components/AnimationBuilder.js +305 -0
- package/lib/engine-components/AnimationBuilder.js.map +1 -0
- package/lib/engine-components/Animator.d.ts +6 -0
- package/lib/engine-components/Animator.js +23 -13
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.builder.d.ts +191 -0
- package/lib/engine-components/AnimatorController.builder.js +263 -0
- package/lib/engine-components/AnimatorController.builder.js.map +1 -0
- package/lib/engine-components/AnimatorController.d.ts +2 -119
- package/lib/engine-components/AnimatorController.js +33 -232
- 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/Collider.d.ts +18 -9
- package/lib/engine-components/Collider.js +61 -14
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +72 -9
- package/lib/engine-components/Component.js +114 -10
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/ContactShadows.d.ts +1 -0
- package/lib/engine-components/ContactShadows.js +14 -1
- package/lib/engine-components/ContactShadows.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +7 -0
- package/lib/engine-components/DragControls.js +19 -7
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/DropListener.js +3 -0
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/EventList.d.ts +31 -9
- package/lib/engine-components/EventList.js +37 -76
- package/lib/engine-components/EventList.js.map +1 -1
- package/lib/engine-components/Joints.d.ts +4 -2
- package/lib/engine-components/Joints.js +19 -3
- package/lib/engine-components/Joints.js.map +1 -1
- package/lib/engine-components/Light.js +9 -1
- 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.d.ts +0 -2
- package/lib/engine-components/OrbitControls.js +30 -12
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +12 -4
- package/lib/engine-components/RigidBody.js +18 -4
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.js +3 -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 +2 -1
- package/lib/engine-components/api.js +2 -1
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +7 -13
- package/lib/engine-components/codegen/components.js +7 -13
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/export/usdz/USDZExporter.js +4 -4
- package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
- package/lib/engine-components/timeline/PlayableDirector.d.ts +21 -11
- package/lib/engine-components/timeline/PlayableDirector.js +75 -67
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
- package/lib/engine-components/timeline/SignalAsset.d.ts +3 -1
- package/lib/engine-components/timeline/SignalAsset.js +1 -0
- package/lib/engine-components/timeline/SignalAsset.js.map +1 -1
- package/lib/engine-components/timeline/TimelineBuilder.d.ts +413 -0
- package/lib/engine-components/timeline/TimelineBuilder.js +506 -0
- package/lib/engine-components/timeline/TimelineBuilder.js.map +1 -0
- package/lib/engine-components/timeline/TimelineModels.d.ts +2 -1
- package/lib/engine-components/timeline/TimelineModels.js +3 -0
- package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
- package/lib/engine-components/timeline/TimelineTracks.d.ts +37 -6
- package/lib/engine-components/timeline/TimelineTracks.js +92 -26
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/timeline/index.d.ts +2 -1
- package/lib/engine-components/timeline/index.js +2 -0
- package/lib/engine-components/timeline/index.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.d.ts +0 -1
- package/lib/engine-components/web/CursorFollow.js +21 -13
- package/lib/engine-components/web/CursorFollow.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.js +4 -0
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/package.json +2 -83
- package/plugins/common/cloud.js +6 -1
- package/plugins/common/license.js +31 -10
- package/plugins/common/worker.js +9 -4
- package/plugins/vite/asap.js +17 -8
- package/plugins/vite/dependencies.js +29 -10
- package/plugins/vite/dependency-watcher.js +2 -2
- package/plugins/vite/editor-connection.js +3 -3
- package/plugins/vite/license.js +46 -7
- 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/reload.js +1 -1
- package/plugins/vite/server.js +2 -1
- package/src/engine/api.ts +11 -1
- package/src/engine/codegen/register_types.ts +10 -18
- package/src/engine/engine_audio.ts +184 -0
- package/src/engine/engine_camera.fit.ts +15 -4
- package/src/engine/engine_components.ts +1 -1
- package/src/engine/engine_context.ts +34 -18
- package/src/engine/engine_context_eventbus.ts +73 -0
- package/src/engine/engine_disposable.ts +214 -0
- package/src/engine/engine_gameobject.ts +54 -159
- package/src/engine/engine_gltf_builtin_components.ts +7 -76
- package/src/engine/engine_init.ts +7 -7
- package/src/engine/engine_input.ts +28 -7
- package/src/engine/engine_instantiate_resolve.ts +407 -0
- package/src/engine/engine_license.ts +197 -55
- package/src/engine/engine_mainloop_utils.ts +7 -4
- package/src/engine/engine_networking.transport.websocket.ts +45 -0
- package/src/engine/engine_networking.ts +161 -137
- package/src/engine/engine_networking_blob.ts +4 -4
- package/src/engine/engine_networking_instantiate.ts +2 -2
- package/src/engine/engine_networking_types.ts +41 -1
- package/src/engine/engine_physics_rapier.ts +102 -33
- package/src/engine/engine_scenedata.ts +3 -3
- package/src/engine/engine_serialization_builtin_serializer.ts +32 -9
- package/src/engine/engine_serialization_core.ts +9 -0
- package/src/engine/engine_types.ts +46 -27
- package/src/engine/engine_util_decorator.ts +7 -2
- package/src/engine/engine_utils.ts +16 -5
- package/src/engine/engine_utils_qrcode.ts +2 -2
- package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
- package/src/engine/webcomponents/needle menu/needle-menu-spatial.ts +2 -2
- package/src/engine/webcomponents/needle menu/needle-menu.ts +6 -6
- package/src/engine/webcomponents/needle-engine.loading.ts +6 -6
- package/src/engine/webcomponents/needle-engine.ts +12 -6
- package/src/engine/xr/NeedleXRSession.ts +48 -13
- package/src/engine/xr/TempXRContext.ts +2 -2
- package/src/engine/xr/events.ts +1 -1
- package/src/engine-components/Animation.ts +19 -16
- package/src/engine-components/AnimationBuilder.ts +472 -0
- package/src/engine-components/Animator.ts +24 -12
- package/src/engine-components/AnimatorController.builder.ts +387 -0
- package/src/engine-components/AnimatorController.ts +20 -291
- package/src/engine-components/AudioSource.ts +130 -79
- package/src/engine-components/Collider.ts +66 -18
- package/src/engine-components/Component.ts +118 -20
- package/src/engine-components/ContactShadows.ts +15 -1
- package/src/engine-components/DragControls.ts +18 -11
- package/src/engine-components/DropListener.ts +3 -0
- package/src/engine-components/EventList.ts +45 -83
- package/src/engine-components/Joints.ts +20 -4
- package/src/engine-components/Light.ts +10 -2
- package/src/engine-components/Networking.ts +1 -1
- package/src/engine-components/OrbitControls.ts +34 -14
- package/src/engine-components/RigidBody.ts +18 -4
- package/src/engine-components/SceneSwitcher.ts +3 -0
- package/src/engine-components/SeeThrough.ts +2 -2
- package/src/engine-components/api.ts +2 -1
- package/src/engine-components/codegen/components.ts +7 -13
- package/src/engine-components/export/usdz/USDZExporter.ts +4 -4
- package/src/engine-components/timeline/PlayableDirector.ts +83 -81
- package/src/engine-components/timeline/SignalAsset.ts +4 -1
- package/src/engine-components/timeline/TimelineBuilder.ts +824 -0
- package/src/engine-components/timeline/TimelineModels.ts +5 -1
- package/src/engine-components/timeline/TimelineTracks.ts +96 -27
- package/src/engine-components/timeline/index.ts +2 -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 -14
- package/src/engine-components/webxr/WebXRImageTracking.ts +2 -0
- package/dist/needle-engine.bundle-CmxIO5uH.min.js +0 -1732
- package/dist/needle-engine.bundle-tJIZukCz.umd.cjs +0 -1732
- package/lib/engine-components/AvatarLoader.d.ts +0 -80
- package/lib/engine-components/AvatarLoader.js +0 -232
- package/lib/engine-components/AvatarLoader.js.map +0 -1
- package/lib/engine-components/avatar/AvatarBlink_Simple.d.ts +0 -11
- package/lib/engine-components/avatar/AvatarBlink_Simple.js +0 -77
- package/lib/engine-components/avatar/AvatarBlink_Simple.js.map +0 -1
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.d.ts +0 -14
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js +0 -69
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js.map +0 -1
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.d.ts +0 -29
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js +0 -122
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +0 -1
- package/lib/engine-components/avatar/Avatar_MouthShapes.d.ts +0 -15
- package/lib/engine-components/avatar/Avatar_MouthShapes.js +0 -80
- package/lib/engine-components/avatar/Avatar_MouthShapes.js.map +0 -1
- package/lib/engine-components/avatar/Avatar_MustacheShake.d.ts +0 -9
- package/lib/engine-components/avatar/Avatar_MustacheShake.js +0 -30
- package/lib/engine-components/avatar/Avatar_MustacheShake.js.map +0 -1
- package/plugins/dts-generator/dts.codegen.js +0 -334
- package/plugins/dts-generator/dts.scan.js +0 -99
- package/plugins/dts-generator/dts.writer.js +0 -59
- package/plugins/dts-generator/glb.discovery.js +0 -279
- package/plugins/dts-generator/glb.extractor.js +0 -215
- package/plugins/dts-generator/glb.reader.js +0 -167
- package/plugins/dts-generator/index.js +0 -36
- package/plugins/dts-generator/manifest.types.js +0 -174
- package/plugins/gltf-packer.mjs +0 -1
- package/src/engine-components/AvatarLoader.ts +0 -264
- package/src/engine-components/avatar/AvatarBlink_Simple.ts +0 -70
- package/src/engine-components/avatar/AvatarEyeLook_Rotation.ts +0 -64
- package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +0 -140
- package/src/engine-components/avatar/Avatar_MouthShapes.ts +0 -84
- package/src/engine-components/avatar/Avatar_MustacheShake.ts +0 -32
- package/src/vite-env.d.ts +0 -16
|
@@ -4,7 +4,6 @@ import { PositionalAudioHelper } from 'three/examples/jsm/helpers/PositionalAudi
|
|
|
4
4
|
import { isDevEnvironment } from "../engine/debug/index.js";
|
|
5
5
|
import { Application, ApplicationEvents } from "../engine/engine_application.js";
|
|
6
6
|
import { findObjectOfType } from "../engine/engine_components.js";
|
|
7
|
-
import { Mathf } from "../engine/engine_math.js";
|
|
8
7
|
import { serializable } from "../engine/engine_serialization_decorator.js";
|
|
9
8
|
import { DeviceUtilities, getParam } from "../engine/engine_utils.js";
|
|
10
9
|
import { AudioListener } from "./AudioListener.js";
|
|
@@ -140,12 +139,23 @@ export class AudioSource extends Behaviour {
|
|
|
140
139
|
get isPlaying(): boolean { return this.sound?.isPlaying ?? false; }
|
|
141
140
|
|
|
142
141
|
/**
|
|
143
|
-
* The total duration of the
|
|
142
|
+
* The total duration of the currently loaded audio clip in seconds.
|
|
144
143
|
*
|
|
145
144
|
* @returns Duration in seconds or undefined if no clip is loaded
|
|
145
|
+
* @remarks For MediaStream clips, duration is not directly available and will return undefined. If the audio clip has not started loading or is still loading, duration may also be undefined until the audio buffer is ready.
|
|
146
146
|
*/
|
|
147
147
|
get duration() {
|
|
148
|
-
|
|
148
|
+
if (this.sound?.buffer?.duration) {
|
|
149
|
+
return this.sound.buffer.duration;
|
|
150
|
+
}
|
|
151
|
+
else if (this._audioElement?.duration) {
|
|
152
|
+
return this._audioElement.duration;
|
|
153
|
+
}
|
|
154
|
+
else if (this._loadedClip instanceof MediaStream) {
|
|
155
|
+
// MediaStream duration is not directly available; return undefined or estimate if possible
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
/**
|
|
@@ -200,7 +210,8 @@ export class AudioSource extends Behaviour {
|
|
|
200
210
|
/**
|
|
201
211
|
* Controls how the audio is positioned in space.
|
|
202
212
|
* Values range from 0 (2D, non-positional) to 1 (fully 3D positioned).
|
|
203
|
-
*
|
|
213
|
+
* Internally uses a dual-path audio graph to crossfade between a spatialized (PannerNode)
|
|
214
|
+
* and a non-spatialized (direct) signal path.
|
|
204
215
|
*/
|
|
205
216
|
@serializable()
|
|
206
217
|
get spatialBlend(): number {
|
|
@@ -292,12 +303,18 @@ export class AudioSource extends Behaviour {
|
|
|
292
303
|
// set this from audio context time, used to set clip offset when setting "time" property
|
|
293
304
|
// there is maybe a better way to set a audio clip current time?!
|
|
294
305
|
private _lastClipStartedLoading: string | MediaStream | null = null;
|
|
306
|
+
private _loadedClip: string | MediaStream | null = null;
|
|
295
307
|
private _audioElement: HTMLAudioElement | null = null;
|
|
296
308
|
|
|
309
|
+
// Spatial blend dual-path audio nodes
|
|
310
|
+
private _entryNode: GainNode | null = null;
|
|
311
|
+
private _spatialGain: GainNode | null = null;
|
|
312
|
+
private _bypassGain: GainNode | null = null;
|
|
313
|
+
|
|
297
314
|
/**
|
|
298
315
|
* Returns the underlying {@link PositionalAudio} object, creating it if necessary.
|
|
299
316
|
* The audio source needs a user interaction to be initialized due to browser autoplay policies.
|
|
300
|
-
*
|
|
317
|
+
*
|
|
301
318
|
* @returns The three.js PositionalAudio object or null if unavailable
|
|
302
319
|
*/
|
|
303
320
|
public get Sound(): PositionalAudio | null {
|
|
@@ -312,45 +329,12 @@ export class AudioSource extends Behaviour {
|
|
|
312
329
|
if (listener?.listener) {
|
|
313
330
|
this.sound = new PositionalAudio(listener.listener);
|
|
314
331
|
this.gameObject?.add(this.sound);
|
|
315
|
-
|
|
316
|
-
// this._listener = listener;
|
|
317
|
-
// this._originalSoundMatrixWorldFunction = this.sound.updateMatrixWorld;
|
|
318
|
-
// this.sound.updateMatrixWorld = this._onSoundMatrixWorld;
|
|
319
332
|
}
|
|
320
333
|
else if (debug) console.warn("No audio listener found in scene - can not play audio");
|
|
321
334
|
}
|
|
322
335
|
return this.sound;
|
|
323
336
|
}
|
|
324
337
|
|
|
325
|
-
// This is a hacky workaround to get the PositionalAudio behave like a 2D audio source
|
|
326
|
-
// private _listener: AudioListener | null = null;
|
|
327
|
-
// private _originalSoundMatrixWorldFunction: Function | null = null;
|
|
328
|
-
// private _onSoundMatrixWorld = (force: boolean) => {
|
|
329
|
-
// if (this._spatialBlend > .05) {
|
|
330
|
-
// if (this._originalSoundMatrixWorldFunction) {
|
|
331
|
-
// this._originalSoundMatrixWorldFunction.call(this.sound, force);
|
|
332
|
-
// }
|
|
333
|
-
// }
|
|
334
|
-
// else {
|
|
335
|
-
// // we use another object's matrix world function (but bound to the positional audio)
|
|
336
|
-
// // this is just a little trick to prevent calling the PositionalAudio's updateMatrixWorld function
|
|
337
|
-
// this.gameObject.updateMatrixWorld?.call(this.sound, force);
|
|
338
|
-
// if (this.sound && this._listener) {
|
|
339
|
-
// this.sound.gain.connect(this._listener.listener.getInput());
|
|
340
|
-
// // const pos = getTempVector().setFromMatrixPosition(this._listener.gameObject.matrixWorld);
|
|
341
|
-
// // const ctx = this.sound.context;
|
|
342
|
-
// // const delay = this._listener.listener.timeDelta;
|
|
343
|
-
// // const time = ctx.currentTime ;
|
|
344
|
-
// // this.sound.panner.positionX.setValueAtTime(pos.x, time);
|
|
345
|
-
// // this.sound.panner.positionY.setValueAtTime(pos.y, time);
|
|
346
|
-
// // this.sound.panner.positionZ.setValueAtTime(pos.z, time);
|
|
347
|
-
// // this.sound.panner.orientationX.setValueAtTime(0, time);
|
|
348
|
-
// // this.sound.panner.orientationY.setValueAtTime(0, time);
|
|
349
|
-
// // this.sound.panner.orientationZ.setValueAtTime(-1, time);
|
|
350
|
-
// }
|
|
351
|
-
// }
|
|
352
|
-
// }
|
|
353
|
-
|
|
354
338
|
/**
|
|
355
339
|
* Indicates whether the audio source is queued to play when possible.
|
|
356
340
|
* This may be true before user interaction has been registered.
|
|
@@ -376,8 +360,10 @@ export class AudioSource extends Behaviour {
|
|
|
376
360
|
if (this.playOnAwake) this.shouldPlay = true;
|
|
377
361
|
|
|
378
362
|
if (this.preload) {
|
|
379
|
-
if (typeof this.clip === "string") {
|
|
380
|
-
this.audioLoader.load(this.clip, this.createAudio, () => { },
|
|
363
|
+
if (typeof this.clip === "string" && this.clip.length > 0) {
|
|
364
|
+
this.audioLoader.load(this.clip, this.createAudio, () => { }, e => {
|
|
365
|
+
console.error(`[AudioSource] Error preloading audio clip "${this.clip}":`, e);
|
|
366
|
+
});
|
|
381
367
|
}
|
|
382
368
|
}
|
|
383
369
|
}
|
|
@@ -433,9 +419,9 @@ export class AudioSource extends Behaviour {
|
|
|
433
419
|
this.sound?.setVolume(this.volume);
|
|
434
420
|
}
|
|
435
421
|
|
|
436
|
-
private createAudio = (buffer?: AudioBuffer) => {
|
|
437
|
-
if(this.destroyed) {
|
|
438
|
-
if(debug) console.warn("AudioSource destroyed, not creating audio", this.name);
|
|
422
|
+
private createAudio = (buffer?: AudioBuffer) => {
|
|
423
|
+
if (this.destroyed) {
|
|
424
|
+
if (debug) console.warn("AudioSource destroyed, not creating audio", this.name);
|
|
439
425
|
return;
|
|
440
426
|
}
|
|
441
427
|
|
|
@@ -451,26 +437,17 @@ export class AudioSource extends Behaviour {
|
|
|
451
437
|
sound.stop();
|
|
452
438
|
|
|
453
439
|
if (buffer) sound.setBuffer(buffer);
|
|
440
|
+
this._loadedClip = this.clip;
|
|
454
441
|
sound.loop = this._loop;
|
|
455
442
|
if (this.context.application.muted) sound.setVolume(0);
|
|
456
443
|
else sound.setVolume(this.volume);
|
|
457
444
|
sound.autoplay = this.shouldPlay && AudioSource.userInteractionRegistered;
|
|
445
|
+
this.setupSpatialBlendNodes();
|
|
458
446
|
this.applySpatialDistanceSettings();
|
|
459
447
|
|
|
460
448
|
if (sound.isPlaying)
|
|
461
449
|
sound.stop();
|
|
462
450
|
|
|
463
|
-
// const panner = sound.panner;
|
|
464
|
-
// panner.coneOuterGain = 1;
|
|
465
|
-
// sound.setDirectionalCone(360, 360, 1);
|
|
466
|
-
// const src = sound.context.createBufferSource();
|
|
467
|
-
// src.buffer = sound.buffer;
|
|
468
|
-
// src.connect(sound.panner);
|
|
469
|
-
// src.start(this.audioContext?.currentTime);
|
|
470
|
-
// const gain = sound.context.createGain();
|
|
471
|
-
// gain.gain.value = 1 - this.spatialBlend;
|
|
472
|
-
// src.connect(gain);
|
|
473
|
-
|
|
474
451
|
// make sure we only play the sound if the user has interacted with the page
|
|
475
452
|
AudioSource.registerWaitForAllowAudio(this.__onAllowAudioCallback);
|
|
476
453
|
}
|
|
@@ -479,30 +456,97 @@ export class AudioSource extends Behaviour {
|
|
|
479
456
|
this.play();
|
|
480
457
|
}
|
|
481
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Sets up the dual-path audio graph for spatial blend crossfading.
|
|
461
|
+
* Creates two parallel signal paths from source to output:
|
|
462
|
+
* - 3D path: entry → panner → spatialGain → gain (spatialized)
|
|
463
|
+
* - 2D path: entry → bypassGain → gain (non-spatialized)
|
|
464
|
+
*/
|
|
465
|
+
private setupSpatialBlendNodes() {
|
|
466
|
+
const sound = this.sound;
|
|
467
|
+
if (!sound || this._entryNode) return;
|
|
468
|
+
|
|
469
|
+
const ctx = sound.context;
|
|
470
|
+
this._entryNode = ctx.createGain();
|
|
471
|
+
this._spatialGain = ctx.createGain();
|
|
472
|
+
this._bypassGain = ctx.createGain();
|
|
473
|
+
|
|
474
|
+
// Disconnect the default panner → gain connection set up by three.js
|
|
475
|
+
try { sound.panner.disconnect(sound.gain); } catch { /* not connected */ }
|
|
476
|
+
|
|
477
|
+
// 3D path: entry → panner → spatialGain → gain
|
|
478
|
+
this._entryNode.connect(sound.panner);
|
|
479
|
+
sound.panner.connect(this._spatialGain);
|
|
480
|
+
this._spatialGain.connect(sound.gain);
|
|
481
|
+
|
|
482
|
+
// 2D path: entry → bypassGain → gain
|
|
483
|
+
this._entryNode.connect(this._bypassGain);
|
|
484
|
+
this._bypassGain.connect(sound.gain);
|
|
485
|
+
|
|
486
|
+
// Override getOutput so three.js connects source → entryNode instead of panner
|
|
487
|
+
sound.getOutput = () => this._entryNode! as unknown as PannerNode;
|
|
488
|
+
|
|
489
|
+
// Wrap connect() to undo PositionalAudio's redundant panner → gain reconnection
|
|
490
|
+
const origConnect = sound.connect;
|
|
491
|
+
sound.connect = function () {
|
|
492
|
+
origConnect.call(sound);
|
|
493
|
+
try { sound.panner.disconnect(sound.gain); } catch { /* expected */ }
|
|
494
|
+
return sound;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// Wrap disconnect() to prevent error when panner → gain doesn't exist
|
|
498
|
+
const origDisconnect = sound.disconnect;
|
|
499
|
+
sound.disconnect = function () {
|
|
500
|
+
try { origDisconnect.call(sound); } catch { /* panner → gain already removed */ }
|
|
501
|
+
return sound;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
this.updateSpatialBlendGains();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Updates the spatial/bypass gain values based on the current spatialBlend. */
|
|
508
|
+
private updateSpatialBlendGains() {
|
|
509
|
+
if (!this._spatialGain || !this._bypassGain || !this.sound) return;
|
|
510
|
+
const t = this.sound.context.currentTime;
|
|
511
|
+
// Use setTargetAtTime for smooth transitions (avoids clicks/pops)
|
|
512
|
+
this._spatialGain.gain.setTargetAtTime(this._spatialBlend, t, 0.01);
|
|
513
|
+
this._bypassGain.gain.setTargetAtTime(1 - this._spatialBlend, t, 0.01);
|
|
514
|
+
}
|
|
515
|
+
|
|
482
516
|
private applySpatialDistanceSettings() {
|
|
483
517
|
const sound = this.sound;
|
|
484
518
|
if (!sound) return;
|
|
485
519
|
this._needUpdateSpatialDistanceSettings = false;
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
520
|
+
|
|
521
|
+
const ref = Math.max(0.0001, this._minDistance);
|
|
522
|
+
const max = Math.max(0.01, this._maxDistance);
|
|
523
|
+
if (debug) console.log(this.name, ref, max, this.spatialBlend);
|
|
524
|
+
sound.setRefDistance(ref);
|
|
525
|
+
sound.setMaxDistance(max);
|
|
492
526
|
|
|
493
527
|
// https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel
|
|
494
528
|
switch (this.rollOffMode) {
|
|
495
529
|
case AudioRolloffMode.Logarithmic:
|
|
496
|
-
|
|
530
|
+
// Unity's logarithmic rolloff matches Web Audio's 'inverse' model:
|
|
531
|
+
// gain = refDistance / (refDistance + rolloffFactor * (distance - refDistance))
|
|
532
|
+
// We compute rolloffFactor so gain reaches ~0.01 (-40dB) at maxDistance,
|
|
533
|
+
// matching Unity's behavior of effective silence at maxDistance.
|
|
534
|
+
sound.setDistanceModel('inverse');
|
|
535
|
+
sound.setRolloffFactor(99 * ref / Math.max(0.001, max - ref));
|
|
497
536
|
break;
|
|
498
537
|
case AudioRolloffMode.Linear:
|
|
538
|
+
// gain = 1 - rolloffFactor * (distance - refDistance) / (maxDistance - refDistance)
|
|
539
|
+
// With rolloffFactor=1 this reaches exactly 0 at maxDistance.
|
|
499
540
|
sound.setDistanceModel('linear');
|
|
541
|
+
sound.setRolloffFactor(1);
|
|
500
542
|
break;
|
|
501
543
|
case AudioRolloffMode.Custom:
|
|
502
544
|
console.warn("Custom rolloff for AudioSource is not supported: " + this.name);
|
|
503
545
|
break;
|
|
504
546
|
}
|
|
505
547
|
|
|
548
|
+
this.updateSpatialBlendGains();
|
|
549
|
+
|
|
506
550
|
if (this.spatialBlend > 0) {
|
|
507
551
|
if (debug && !this.helper) {
|
|
508
552
|
this.helper = new PositionalAudioHelper(sound, sound.getRefDistance());
|
|
@@ -519,7 +563,7 @@ export class AudioSource extends Behaviour {
|
|
|
519
563
|
if (typeof clip === "string") {
|
|
520
564
|
if (debug)
|
|
521
565
|
console.log(clip);
|
|
522
|
-
if (clip.endsWith(".mp3") || clip.endsWith(".wav")) {
|
|
566
|
+
if (clip.endsWith(".mp3") || clip.endsWith(".wav") || clip.endsWith(".ogg") || clip.endsWith(".flac") || clip.endsWith(".aac") || clip.endsWith(".webm")) {
|
|
523
567
|
if (!this.audioLoader)
|
|
524
568
|
this.audioLoader = new AudioLoader();
|
|
525
569
|
this.shouldPlay = true;
|
|
@@ -530,9 +574,12 @@ export class AudioSource extends Behaviour {
|
|
|
530
574
|
this._lastClipStartedLoading = clip;
|
|
531
575
|
if (debug)
|
|
532
576
|
console.log("load audio", clip);
|
|
533
|
-
const buffer = await this.audioLoader.loadAsync(clip).catch(
|
|
534
|
-
|
|
535
|
-
|
|
577
|
+
const buffer = await this.audioLoader.loadAsync(clip).catch(e => {
|
|
578
|
+
console.error(`[AudioSource] Error loading audio clip "${clip}":`, e);
|
|
579
|
+
return null;
|
|
580
|
+
});
|
|
581
|
+
if (this.destroyed) return;
|
|
582
|
+
if (this._lastClipStartedLoading === clip) this._lastClipStartedLoading = null;
|
|
536
583
|
if (buffer) this.createAudio(buffer);
|
|
537
584
|
}
|
|
538
585
|
else console.warn("Unsupported audio clip type", clip)
|
|
@@ -548,8 +595,9 @@ export class AudioSource extends Behaviour {
|
|
|
548
595
|
* If no argument is provided, plays the currently assigned clip.
|
|
549
596
|
*
|
|
550
597
|
* @param clip - Optional audio clip or {@link MediaStream} to play
|
|
598
|
+
* @returns A promise that resolves when playback starts successfully, or rejects on error
|
|
551
599
|
*/
|
|
552
|
-
play(clip: string | MediaStream | undefined = undefined) {
|
|
600
|
+
async play(clip: string | MediaStream | undefined = undefined): Promise<boolean> {
|
|
553
601
|
// use audio source's clip when no clip is passed in
|
|
554
602
|
if (!clip && this.clip)
|
|
555
603
|
clip = this.clip;
|
|
@@ -557,27 +605,27 @@ export class AudioSource extends Behaviour {
|
|
|
557
605
|
// We only support strings and media stream
|
|
558
606
|
// TODO: maybe we should return here if an invalid value is passed in
|
|
559
607
|
if (clip !== undefined && typeof clip !== "string" && !(clip instanceof MediaStream)) {
|
|
560
|
-
if (isDevEnvironment())
|
|
561
|
-
console.warn("Called play on AudioSource with unknown argument type:", clip + "\nUsing the assigned clip instead:", this.clip)
|
|
562
608
|
// e.g. when a AudioSource.Play is called from SpatialTrigger onEnter this event is called with the TriggerReceiver... to still make this work we *re-use* our already assigned clip. Because otherwise calling `play` would not play the clip...
|
|
563
609
|
clip = this.clip;
|
|
610
|
+
if (isDevEnvironment()) console.warn("[AudioSource] Called play on AudioSource with unknown argument type:", clip + "\nUsing the assigned clip instead:", this.clip)
|
|
564
611
|
}
|
|
565
612
|
|
|
566
|
-
//
|
|
567
|
-
let needsLoading = !this.sound || (clip && clip !== this.
|
|
613
|
+
// Load if the sound hasn't been created yet or if the clip changed since last load
|
|
614
|
+
let needsLoading = !this.sound || (clip && clip !== this._loadedClip);
|
|
568
615
|
if (typeof clip === "string" && !this.audioLoader) needsLoading = true;
|
|
569
616
|
if (clip instanceof MediaStream || typeof clip === "string")
|
|
570
617
|
this.clip = clip;
|
|
571
618
|
if (needsLoading) {
|
|
572
619
|
this.shouldPlay = true;
|
|
573
|
-
this.onNewClip(clip);
|
|
574
|
-
return;
|
|
620
|
+
return this.onNewClip(clip).then(() => true).catch(() => false);
|
|
575
621
|
}
|
|
576
622
|
|
|
577
623
|
this.shouldPlay = true;
|
|
578
624
|
this._hasEnded = false;
|
|
579
|
-
|
|
580
|
-
|
|
625
|
+
|
|
626
|
+
if (debug) console.log("[AudioSource] play", this.sound?.getVolume(), this.sound);
|
|
627
|
+
// If a different clip was passed in, needsLoading above would be true and onNewClip handles it.
|
|
628
|
+
// This guard prevents double-playing the same already-playing sound (which would throw in three.js).
|
|
581
629
|
if (this.sound && !this.sound.isPlaying) {
|
|
582
630
|
const muted = this.context.application.muted;
|
|
583
631
|
if (muted) this.sound.setVolume(0);
|
|
@@ -597,13 +645,17 @@ export class AudioSource extends Behaviour {
|
|
|
597
645
|
this.context.domElement.shadowRoot?.append(this._audioElement);
|
|
598
646
|
this._audioElement.srcObject = this.clip;
|
|
599
647
|
this._audioElement.autoplay = false;
|
|
648
|
+
return true;
|
|
600
649
|
|
|
601
650
|
}
|
|
602
651
|
else {
|
|
603
652
|
if (this._audioElement) this._audioElement.remove();
|
|
604
653
|
this.sound.play(muted ? .1 : 0);
|
|
654
|
+
return true;
|
|
605
655
|
}
|
|
606
656
|
}
|
|
657
|
+
|
|
658
|
+
return false;
|
|
607
659
|
}
|
|
608
660
|
|
|
609
661
|
/**
|
|
@@ -611,7 +663,7 @@ export class AudioSource extends Behaviour {
|
|
|
611
663
|
* Use play() to resume from the paused position.
|
|
612
664
|
*/
|
|
613
665
|
pause() {
|
|
614
|
-
if (debug) console.log("
|
|
666
|
+
if (debug) console.log("[AudioSource] pause", this);
|
|
615
667
|
this._hasEnded = true;
|
|
616
668
|
this.shouldPlay = false;
|
|
617
669
|
if (this.sound && this.sound.isPlaying && this.sound.source) {
|
|
@@ -626,13 +678,13 @@ export class AudioSource extends Behaviour {
|
|
|
626
678
|
* Unlike pause(), calling play() after stop() will start from the beginning.
|
|
627
679
|
*/
|
|
628
680
|
stop() {
|
|
629
|
-
if (debug) console.log("
|
|
681
|
+
if (debug) console.log("[AudioSource] stop", this);
|
|
630
682
|
this._hasEnded = true;
|
|
631
683
|
this.shouldPlay = false;
|
|
632
684
|
if (this.sound && this.sound.source) {
|
|
633
685
|
this._lastContextTime = this.sound?.context.currentTime;
|
|
634
686
|
if (debug)
|
|
635
|
-
console.log(this._lastContextTime)
|
|
687
|
+
console.log("[AudioSource] lastContextTime", this._lastContextTime);
|
|
636
688
|
this.sound.stop();
|
|
637
689
|
}
|
|
638
690
|
this._audioElement?.remove();
|
|
@@ -657,8 +709,7 @@ export class AudioSource extends Behaviour {
|
|
|
657
709
|
|
|
658
710
|
if (this.sound && !this.sound.isPlaying && this.shouldPlay && !this._hasEnded) {
|
|
659
711
|
this._hasEnded = true;
|
|
660
|
-
if (debug)
|
|
661
|
-
console.log("Audio clip ended", this.clip);
|
|
712
|
+
if (debug) console.log("[AudioSource] Audio clip ended", this.clip);
|
|
662
713
|
this.dispatchEvent(new CustomEvent("ended", { detail: this }));
|
|
663
714
|
}
|
|
664
715
|
|
|
@@ -72,12 +72,14 @@ export abstract class Collider extends Behaviour implements ICollider {
|
|
|
72
72
|
* When `true` the collider will not be used for collision detection but will still trigger events.
|
|
73
73
|
* Trigger colliders can trigger events when other colliders enter their space, without creating a physical response/collision.
|
|
74
74
|
*/
|
|
75
|
+
@validate()
|
|
75
76
|
@serializable()
|
|
76
77
|
isTrigger: boolean = false;
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
* The physics material that defines physical properties of the collider such as friction and bounciness.
|
|
80
81
|
*/
|
|
82
|
+
@validate()
|
|
81
83
|
@serializable()
|
|
82
84
|
sharedMaterial?: PhysicsMaterial;
|
|
83
85
|
|
|
@@ -85,15 +87,52 @@ export abstract class Collider extends Behaviour implements ICollider {
|
|
|
85
87
|
* The layers that this collider belongs to. Used for filtering collision detection.
|
|
86
88
|
* @default [0]
|
|
87
89
|
*/
|
|
90
|
+
@validate()
|
|
88
91
|
@serializable()
|
|
89
92
|
membership: number[] = [0];
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
95
|
* The layers that this collider will interact with. Used for filtering collision detection.
|
|
93
96
|
*/
|
|
97
|
+
@validate()
|
|
94
98
|
@serializable()
|
|
95
99
|
filter?: number[];
|
|
96
100
|
|
|
101
|
+
/**
|
|
102
|
+
* The density of the collider, used for automatic mass calculation when the attached {@link Rigidbody} has `autoMass` enabled.
|
|
103
|
+
* Rapier computes mass from density using the real-world formula: `mass = density × volume`.
|
|
104
|
+
* The volume is derived from the collider shape (sphere, box, capsule, or convex hull).
|
|
105
|
+
*
|
|
106
|
+
* Reference values (relative to water = 1.0):
|
|
107
|
+
* - Wood: 0.5–0.9
|
|
108
|
+
* - Water: 1.0 (engine default)
|
|
109
|
+
* - Rubber: 1.2
|
|
110
|
+
* - Steel: 7.8
|
|
111
|
+
*
|
|
112
|
+
* @default undefined — uses the physics engine default of 1.0
|
|
113
|
+
*/
|
|
114
|
+
@validate()
|
|
115
|
+
@serializable()
|
|
116
|
+
density?: number;
|
|
117
|
+
|
|
118
|
+
/** @internal */
|
|
119
|
+
protected _propertiesDirty: boolean = false;
|
|
120
|
+
|
|
121
|
+
/** @internal */
|
|
122
|
+
onValidate(_property?: string) {
|
|
123
|
+
if (this.activeAndEnabled) {
|
|
124
|
+
if (_property === "sharedMaterial") {
|
|
125
|
+
this.updatePhysicsMaterial();
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.updateProperties();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this._propertiesDirty = true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
97
136
|
/** @internal */
|
|
98
137
|
awake() {
|
|
99
138
|
super.awake();
|
|
@@ -197,6 +236,11 @@ export class SphereCollider extends Collider implements ISphereCollider {
|
|
|
197
236
|
if (!this.context.physics.engine?.setColliderEnabled(this, true)) {
|
|
198
237
|
this.context.physics.engine?.addSphereCollider(this);
|
|
199
238
|
}
|
|
239
|
+
else if (this._propertiesDirty) {
|
|
240
|
+
this.updateProperties();
|
|
241
|
+
this.updatePhysicsMaterial();
|
|
242
|
+
}
|
|
243
|
+
this._propertiesDirty = false;
|
|
200
244
|
watchWrite(this.gameObject.scale, this.updateProperties);
|
|
201
245
|
}
|
|
202
246
|
|
|
@@ -208,18 +252,12 @@ export class SphereCollider extends Collider implements ISphereCollider {
|
|
|
208
252
|
unwatchWrite(this.gameObject.scale, this.updateProperties);
|
|
209
253
|
}
|
|
210
254
|
|
|
211
|
-
/**
|
|
212
|
-
* Updates collider properties when validated in the editor or inspector.
|
|
213
|
-
*/
|
|
214
|
-
onValidate(): void {
|
|
215
|
-
this.updateProperties();
|
|
216
|
-
}
|
|
217
255
|
}
|
|
218
256
|
|
|
219
257
|
/**
|
|
220
|
-
* BoxCollider represents a box-shaped (cuboid) collision volume.
|
|
221
|
-
* Most common collider type, efficient for walls, floors, crates, and rectangular objects.
|
|
222
|
-
*
|
|
258
|
+
* BoxCollider represents a box-shaped (cuboid) collision volume.
|
|
259
|
+
* Most common collider type, efficient for walls, floors, crates, and rectangular objects.
|
|
260
|
+
*
|
|
223
261
|
* 
|
|
224
262
|
*
|
|
225
263
|
* @example Create a floor collider
|
|
@@ -284,6 +322,11 @@ export class BoxCollider extends Collider implements IBoxCollider {
|
|
|
284
322
|
if (!this.context.physics.engine?.setColliderEnabled(this, true)) {
|
|
285
323
|
this.context.physics.engine?.addBoxCollider(this, this.size);
|
|
286
324
|
}
|
|
325
|
+
else if (this._propertiesDirty) {
|
|
326
|
+
this.updateProperties();
|
|
327
|
+
this.updatePhysicsMaterial();
|
|
328
|
+
}
|
|
329
|
+
this._propertiesDirty = false;
|
|
287
330
|
watchWrite(this.gameObject.scale, this.updateProperties);
|
|
288
331
|
}
|
|
289
332
|
|
|
@@ -296,14 +339,6 @@ export class BoxCollider extends Collider implements IBoxCollider {
|
|
|
296
339
|
unwatchWrite(this.gameObject.scale, this.updateProperties);
|
|
297
340
|
}
|
|
298
341
|
|
|
299
|
-
/**
|
|
300
|
-
* Updates collider properties when validated in the editor or inspector.
|
|
301
|
-
* @internal
|
|
302
|
-
*/
|
|
303
|
-
onValidate(): void {
|
|
304
|
-
this.updateProperties();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
342
|
/**
|
|
308
343
|
* Automatically fits the collider to the geometry of the object.
|
|
309
344
|
* Sets the size and center based on the object's bounding box.
|
|
@@ -379,7 +414,15 @@ export class MeshCollider extends Collider {
|
|
|
379
414
|
super.onEnable();
|
|
380
415
|
if (!this.context.physics.engine) return;
|
|
381
416
|
// Re-enable existing collider instead of recreating it
|
|
382
|
-
if (this.context.physics.engine.setColliderEnabled(this, true))
|
|
417
|
+
if (this.context.physics.engine.setColliderEnabled(this, true)) {
|
|
418
|
+
if (this._propertiesDirty) {
|
|
419
|
+
this.updateProperties();
|
|
420
|
+
this.updatePhysicsMaterial();
|
|
421
|
+
}
|
|
422
|
+
this._propertiesDirty = false;
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
this._propertiesDirty = false;
|
|
383
426
|
|
|
384
427
|
if (!this.sharedMesh?.isMesh) {
|
|
385
428
|
// HACK using the renderer mesh
|
|
@@ -475,5 +518,10 @@ export class CapsuleCollider extends Collider {
|
|
|
475
518
|
if (!this.context.physics.engine?.setColliderEnabled(this, true)) {
|
|
476
519
|
this.context.physics.engine?.addCapsuleCollider(this, this.height, this.radius);
|
|
477
520
|
}
|
|
521
|
+
else if (this._propertiesDirty) {
|
|
522
|
+
this.updateProperties();
|
|
523
|
+
this.updatePhysicsMaterial();
|
|
524
|
+
}
|
|
525
|
+
this._propertiesDirty = false;
|
|
478
526
|
}
|
|
479
527
|
}
|