@downdraft/engine 0.1.1 → 0.1.2-alpha.5
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/app/README.md +11 -0
- package/app/src/renderer/bootstrap.ts +295 -19
- package/app/src/renderer/game-module.ts +60 -12
- package/app/src/renderer/hooks.ts +9 -1
- package/app/src/renderer/hot-reload.ts +9 -9
- package/app/src/renderer/mcp-harness.ts +2 -2
- package/app/src/renderer/standard-automation-tools.ts +104 -3
- package/app/src/shared/feature-log.ts +2 -1
- package/app/src/shared/mcp-discovery.ts +8 -3
- package/app/src/shared/mcp-proxy.ts +2 -2
- package/asset-bake/README.md +22 -0
- package/core/README.md +25 -0
- package/core/src/animation/skeleton-animator.ts +23 -5
- package/core/src/assets/manager.ts +4 -4
- package/core/src/ecs/events.ts +1 -1
- package/core/src/ecs/schedule.ts +1 -1
- package/core/src/ecs/world.ts +1 -1
- package/core/src/index.ts +3 -4
- package/core/src/library/host.ts +27 -13
- package/core/src/library/library.ts +13 -5
- package/core/src/module/cross-thread.ts +6 -0
- package/core/src/module/diagnostics.ts +10 -6
- package/core/src/module/host.ts +65 -18
- package/core/src/module/index.ts +1 -0
- package/core/src/module/module.ts +11 -5
- package/core/src/module/renderer-module.ts +15 -0
- package/core/src/physics/safety.ts +1 -1
- package/core/src/platform/bun-preload.ts +7 -2
- package/core/src/platform/glob-polyfill.ts +17 -8
- package/core/src/platform/pkg-root.ts +27 -0
- package/core/src/platform/runtime.ts +29 -0
- package/core/src/plugin/discovery.ts +1 -1
- package/core/src/plugin/extension-loaders.ts +6 -4
- package/core/src/plugin/host.ts +13 -13
- package/core/src/plugin/loader-asset.ts +5 -5
- package/core/src/plugin/loader-quickjs.ts +1 -1
- package/core/src/plugin/loader-wasm.ts +3 -3
- package/core/src/plugin/loader-worker.ts +1 -1
- package/core/src/plugin/manifest.ts +8 -3
- package/core/src/plugin/workshop.ts +3 -3
- package/core/src/profiling/index.ts +1 -1
- package/core/src/profiling/profiling-sab.ts +19 -0
- package/core/src/profiling/warnings.ts +1 -1
- package/core/src/profiling/worker-prelude.ts +1 -1
- package/core/src/render/bindless/frame-bindings.ts +1 -1
- package/core/src/render/bindless/material-manager.ts +2 -2
- package/core/src/render/bindless/texture-registry.ts +2 -2
- package/core/src/render/device.ts +5 -5
- package/core/src/render/frame-graph.ts +2 -2
- package/core/src/render/game-renderer.ts +42 -18
- package/core/src/render/hot-reload.ts +3 -3
- package/core/src/render/renderer-module-host.ts +32 -12
- package/core/src/render/shader-validator.ts +7 -7
- package/core/src/render/surface.ts +1 -1
- package/core/src/sab/errors.ts +1 -1
- package/core/src/sab/sab-polyfill.ts +1 -1
- package/core/src/save/migration-registry.ts +4 -4
- package/core/src/save/schema.ts +1 -1
- package/core/src/scene/prefab.ts +1 -1
- package/core/src/scene/scene-manager.ts +2 -2
- package/core/src/scene/scene.ts +4 -4
- package/core/src/scene/streaming.ts +2 -2
- package/core/src/scripting/hot-reload.ts +2 -2
- package/core/src/sim/hot-reload-pipeline.ts +30 -6
- package/core/src/sim/sim-state-helper.ts +1 -1
- package/core/src/sim/transient-state-registry.ts +1 -1
- package/core/src/sim/worker-loop.ts +2 -2
- package/core/src/telemetry/gpu-profiler.ts +3 -3
- package/core/src/util/index.ts +1 -1
- package/core/src/util/logger.ts +36 -5
- package/core/src/version.ts +13 -0
- package/core/src/worker/base-worker-host.ts +87 -25
- package/core/src/worker/buffer-sync.ts +1 -1
- package/core/src/worker/crash-recovery.ts +2 -2
- package/core/src/worker/instrumented-worker-host.ts +3 -3
- package/core/src/worker/rpc.ts +62 -11
- package/core/src/worker/sim-worker-base.ts +3 -8
- package/core/src/worker/task-pool.ts +2 -2
- package/dist/.dd-manifest.json +4119 -0
- package/dist/app/src/index.js +9 -0
- package/dist/app/src/renderer/bootstrap.js +446 -0
- package/dist/app/src/renderer/downdraft-base.css +93 -0
- package/dist/app/src/renderer/feature-log.js +180 -0
- package/dist/app/src/renderer/game-module.js +562 -0
- package/dist/app/src/renderer/hooks.js +82 -0
- package/dist/app/src/renderer/hot-reload.js +158 -0
- package/dist/app/src/renderer/import-cache.js +77 -0
- package/dist/app/src/renderer/index.js +149 -0
- package/dist/app/src/renderer/mcp-harness.js +112 -0
- package/dist/app/src/renderer/save-store-factory.js +180 -0
- package/dist/app/src/renderer/sim-bridge.js +138 -0
- package/dist/app/src/renderer/standard-automation-tools.js +720 -0
- package/dist/app/src/shared/feature-log.js +54 -0
- package/dist/app/src/shared/gpu-info.js +74 -0
- package/dist/app/src/shared/import-cache-store.js +123 -0
- package/dist/app/src/shared/index.js +4 -0
- package/dist/app/src/shared/mcp-discovery.js +55 -0
- package/dist/app/src/shared/mcp-proxy.js +71 -0
- package/dist/app/src/shared/types.js +13 -0
- package/dist/asset-bake/src/bake-audio.js +103 -0
- package/dist/asset-bake/src/bake-gltf.js +141 -0
- package/dist/asset-bake/src/bake.js +63 -0
- package/dist/asset-bake/src/cache.js +147 -0
- package/dist/asset-bake/src/config.js +93 -0
- package/dist/asset-bake/src/index.js +25 -0
- package/dist/core/src/animation/animation-event.js +24 -0
- package/dist/core/src/animation/bone-mask.js +103 -0
- package/dist/core/src/animation/clip.js +210 -0
- package/dist/core/src/animation/index.js +13 -0
- package/dist/core/src/animation/mixamo.js +78 -0
- package/dist/core/src/animation/morph-target.js +37 -0
- package/dist/core/src/animation/player.js +621 -0
- package/dist/core/src/animation/retarget.js +101 -0
- package/dist/core/src/animation/skeleton-animator.js +1361 -0
- package/dist/core/src/animation/skeleton.js +166 -0
- package/dist/core/src/animation/state-machine.js +252 -0
- package/dist/core/src/assets/blob-store.js +14 -0
- package/dist/core/src/assets/cache.js +168 -0
- package/dist/core/src/assets/cubemap-converter.js +129 -0
- package/dist/core/src/assets/environment-manager.js +84 -0
- package/dist/core/src/assets/import-cache.js +36 -0
- package/dist/core/src/assets/import-settings.js +34 -0
- package/dist/core/src/assets/importer.js +78 -0
- package/dist/core/src/assets/index.js +29 -0
- package/dist/core/src/assets/irradiance-generator.js +179 -0
- package/dist/core/src/assets/loader-audio.js +70 -0
- package/dist/core/src/assets/loader-cubemap.js +141 -0
- package/dist/core/src/assets/loader-dds.js +185 -0
- package/dist/core/src/assets/loader-hdr.js +430 -0
- package/dist/core/src/assets/loader-mesh.js +47 -0
- package/dist/core/src/assets/loader-shader.js +61 -0
- package/dist/core/src/assets/loader-texture.js +264 -0
- package/dist/core/src/assets/lod.js +150 -0
- package/dist/core/src/assets/manager.js +401 -0
- package/dist/core/src/assets/manifest.js +57 -0
- package/dist/core/src/assets/material-bridge.js +160 -0
- package/dist/core/src/assets/model-importer.js +32 -0
- package/dist/core/src/assets/model-normalizer.js +213 -0
- package/dist/core/src/assets/model-to-gpu.js +44 -0
- package/dist/core/src/assets/model-to-mesh.js +171 -0
- package/dist/core/src/assets/prefilter-generator.js +220 -0
- package/dist/core/src/audio/engine.js +153 -0
- package/dist/core/src/audio/interface.js +8 -0
- package/dist/core/src/audio/listener.js +19 -0
- package/dist/core/src/audio/mixer.js +124 -0
- package/dist/core/src/audio/registry.js +43 -0
- package/dist/core/src/audio/sab.js +74 -0
- package/dist/core/src/audio/source.js +60 -0
- package/dist/core/src/change-detection/atomics.js +1 -0
- package/dist/core/src/change-detection/tracker.js +26 -0
- package/dist/core/src/debug-draw/lines.js +27 -0
- package/dist/core/src/debug-draw/points.js +9 -0
- package/dist/core/src/debug-draw/queue.js +77 -0
- package/dist/core/src/debug-draw/text.js +12 -0
- package/dist/core/src/ecs/archetype.js +271 -0
- package/dist/core/src/ecs/component.js +109 -0
- package/dist/core/src/ecs/entity.js +11 -0
- package/dist/core/src/ecs/events.js +73 -0
- package/dist/core/src/ecs/hierarchy.js +104 -0
- package/dist/core/src/ecs/hmr-swap-registry.js +15 -0
- package/dist/core/src/ecs/index.js +14 -0
- package/dist/core/src/ecs/query.js +110 -0
- package/dist/core/src/ecs/resource.js +3 -0
- package/dist/core/src/ecs/schedule.js +157 -0
- package/dist/core/src/ecs/system-params.js +45 -0
- package/dist/core/src/ecs/system.js +18 -0
- package/dist/core/src/ecs/world.js +292 -0
- package/dist/core/src/index.js +191 -0
- package/dist/core/src/input/context.js +69 -0
- package/dist/core/src/input/dom-handler.js +288 -0
- package/dist/core/src/input/local-player-manager.js +145 -0
- package/dist/core/src/input/mapping.js +36 -0
- package/dist/core/src/input/multi-sab-bridge.js +224 -0
- package/dist/core/src/input/multi-state.js +48 -0
- package/dist/core/src/input/sab-bridge.js +66 -0
- package/dist/core/src/input/state.js +108 -0
- package/dist/core/src/input/ui-router.js +76 -0
- package/dist/core/src/library/host.js +291 -0
- package/dist/core/src/library/index.js +1 -0
- package/dist/core/src/library/library.js +20 -0
- package/dist/core/src/material/compiler.js +73 -0
- package/dist/core/src/material/graph-bridge.js +119 -0
- package/dist/core/src/material/index.js +6 -0
- package/dist/core/src/material/library.js +414 -0
- package/dist/core/src/material/material.js +120 -0
- package/dist/core/src/material/variants.js +37 -0
- package/dist/core/src/math/mat4.js +198 -0
- package/dist/core/src/math/perlin-noise-2d.js +66 -0
- package/dist/core/src/math/perlin-noise-3d.js +76 -0
- package/dist/core/src/math/quat.js +29 -0
- package/dist/core/src/math/rng.js +25 -0
- package/dist/core/src/math/trig.js +42 -0
- package/dist/core/src/math/value-noise.js +49 -0
- package/dist/core/src/mesh/builder.js +137 -0
- package/dist/core/src/mesh/csg.js +250 -0
- package/dist/core/src/mesh/greased-line.js +102 -0
- package/dist/core/src/mesh/mesh.js +6 -0
- package/dist/core/src/mesh/parametric.js +392 -0
- package/dist/core/src/mesh/skinning.js +30 -0
- package/dist/core/src/mesh/vertex-layout.js +65 -0
- package/dist/core/src/module/cross-thread.js +126 -0
- package/dist/core/src/module/diagnostics.js +99 -0
- package/dist/core/src/module/host.js +449 -0
- package/dist/core/src/module/index.js +6 -0
- package/dist/core/src/module/module.js +1 -0
- package/dist/core/src/module/registry.js +83 -0
- package/dist/core/src/module/renderer-module.js +13 -0
- package/dist/core/src/module/ts-loader.js +20 -0
- package/dist/core/src/particles/compute-pass.js +329 -0
- package/dist/core/src/particles/emitter.js +113 -0
- package/dist/core/src/particles/index.js +7 -0
- package/dist/core/src/particles/particle-data.js +33 -0
- package/dist/core/src/particles/render-pass.js +338 -0
- package/dist/core/src/particles/simulator.js +224 -0
- package/dist/core/src/particles/system.js +157 -0
- package/dist/core/src/physics/body.js +25 -0
- package/dist/core/src/physics/ccd-heuristic.js +46 -0
- package/dist/core/src/physics/character.js +184 -0
- package/dist/core/src/physics/collider.js +36 -0
- package/dist/core/src/physics/collision-system.js +62 -0
- package/dist/core/src/physics/events.js +74 -0
- package/dist/core/src/physics/index.js +24 -0
- package/dist/core/src/physics/interface.js +14 -0
- package/dist/core/src/physics/interpolation-buffer.js +182 -0
- package/dist/core/src/physics/lifecycle.js +66 -0
- package/dist/core/src/physics/load-shedder.js +155 -0
- package/dist/core/src/physics/physics-accumulator.js +94 -0
- package/dist/core/src/physics/physics-system.js +142 -0
- package/dist/core/src/physics/ragdoll-presets.js +248 -0
- package/dist/core/src/physics/ragdoll-system.js +193 -0
- package/dist/core/src/physics/ragdoll.js +117 -0
- package/dist/core/src/physics/raycast.js +97 -0
- package/dist/core/src/physics/realm-manager.js +431 -0
- package/dist/core/src/physics/realm-worker-pool.js +181 -0
- package/dist/core/src/physics/realm-worker.js +91 -0
- package/dist/core/src/physics/realm.js +137 -0
- package/dist/core/src/physics/registry.js +43 -0
- package/dist/core/src/physics/safety.js +211 -0
- package/dist/core/src/physics/snapshot-manager.js +118 -0
- package/dist/core/src/physics/worker-protocol.js +1 -0
- package/dist/core/src/platform/bun-preload.js +175 -0
- package/dist/core/src/platform/css-stub.js +4 -0
- package/dist/core/src/platform/glob-polyfill.js +137 -0
- package/dist/core/src/platform/hidpi.js +52 -0
- package/dist/core/src/platform/pkg-root.js +27 -0
- package/dist/core/src/platform/render-surface.js +15 -0
- package/dist/core/src/platform/rpc.js +82 -0
- package/dist/core/src/platform/runtime.js +93 -0
- package/dist/core/src/plugin/context.js +144 -0
- package/dist/core/src/plugin/diagnostics.js +20 -0
- package/dist/core/src/plugin/discovery.js +124 -0
- package/dist/core/src/plugin/extension-loaders.js +111 -0
- package/dist/core/src/plugin/host.js +542 -0
- package/dist/core/src/plugin/index.js +19 -0
- package/dist/core/src/plugin/loader-asset.js +105 -0
- package/dist/core/src/plugin/loader-quickjs.js +67 -0
- package/dist/core/src/plugin/loader-wasm.js +385 -0
- package/dist/core/src/plugin/loader-worker.js +228 -0
- package/dist/core/src/plugin/manifest.js +424 -0
- package/dist/core/src/plugin/material-registry.js +44 -0
- package/dist/core/src/plugin/mcp-tools.js +147 -0
- package/dist/core/src/plugin/permissions.js +152 -0
- package/dist/core/src/plugin/quickjs-bridge.js +219 -0
- package/dist/core/src/plugin/registry.js +92 -0
- package/dist/core/src/plugin/sandbox-shim.js +79 -0
- package/dist/core/src/plugin/sandbox-worker.js +194 -0
- package/dist/core/src/plugin/wasm-abi.js +62 -0
- package/dist/core/src/plugin/wasm-worker.js +234 -0
- package/dist/core/src/plugin/workshop.js +131 -0
- package/dist/core/src/profiling/event-loop.js +164 -0
- package/dist/core/src/profiling/index.js +23 -0
- package/dist/core/src/profiling/iops/idb-patch.js +211 -0
- package/dist/core/src/profiling/iops/opfs-patch.js +206 -0
- package/dist/core/src/profiling/profiling-sab.js +632 -0
- package/dist/core/src/profiling/task-latency.js +118 -0
- package/dist/core/src/profiling/thread-metrics.js +103 -0
- package/dist/core/src/profiling/trace-event-writer.js +165 -0
- package/dist/core/src/profiling/warnings.js +304 -0
- package/dist/core/src/profiling/worker-prelude.js +281 -0
- package/dist/core/src/render/bind-group.js +33 -0
- package/dist/core/src/render/bindless/bindless-struct.js +39 -0
- package/dist/core/src/render/bindless/bindless.wgsl.js +163 -0
- package/dist/core/src/render/bindless/frame-bindings.js +142 -0
- package/dist/core/src/render/bindless/index.js +6 -0
- package/dist/core/src/render/bindless/material-manager.js +182 -0
- package/dist/core/src/render/bindless/texture-registry.js +498 -0
- package/dist/core/src/render/buffer.js +74 -0
- package/dist/core/src/render/camera-2d.js +151 -0
- package/dist/core/src/render/camera-controller.js +370 -0
- package/dist/core/src/render/camera.js +332 -0
- package/dist/core/src/render/canvas-resize-watcher.js +36 -0
- package/dist/core/src/render/compute-kernel.js +130 -0
- package/dist/core/src/render/constants.js +2 -0
- package/dist/core/src/render/device.js +91 -0
- package/dist/core/src/render/frame-graph.js +594 -0
- package/dist/core/src/render/frustum.js +152 -0
- package/dist/core/src/render/fullscreen-vs.js +24 -0
- package/dist/core/src/render/g-buffer.js +156 -0
- package/dist/core/src/render/game-renderer.js +1165 -0
- package/dist/core/src/render/gpu-driven/cull-pass.js +352 -0
- package/dist/core/src/render/gpu-driven/hzb.js +183 -0
- package/dist/core/src/render/gpu-driven/index.js +6 -0
- package/dist/core/src/render/gpu-driven/indirect-draw-pass.js +300 -0
- package/dist/core/src/render/gpu-driven/instance-buffer.js +150 -0
- package/dist/core/src/render/gpu-driven/mesh-table.js +130 -0
- package/dist/core/src/render/gpu-driven/passes/hzb-build-pass.js +39 -0
- package/dist/core/src/render/gpu-utils.js +72 -0
- package/dist/core/src/render/hdr.js +69 -0
- package/dist/core/src/render/hot-reload.js +236 -0
- package/dist/core/src/render/ibl-bind-group.js +232 -0
- package/dist/core/src/render/ibl.js +148 -0
- package/dist/core/src/render/index.js +86 -0
- package/dist/core/src/render/input-manager.js +224 -0
- package/dist/core/src/render/lighting/area-light.js +142 -0
- package/dist/core/src/render/lighting/cluster-grid.js +255 -0
- package/dist/core/src/render/lighting/cluster-types.js +87 -0
- package/dist/core/src/render/lighting/ies-parser.js +111 -0
- package/dist/core/src/render/lighting.js +300 -0
- package/dist/core/src/render/material-types/depth.wgsl +44 -0
- package/dist/core/src/render/material-types/line.wgsl +50 -0
- package/dist/core/src/render/material-types/matcap.wgsl +51 -0
- package/dist/core/src/render/material-types/normal.wgsl +41 -0
- package/dist/core/src/render/material-types/physical.wgsl +152 -0
- package/dist/core/src/render/material-types/sprite.wgsl +46 -0
- package/dist/core/src/render/material-types/sss.wgsl +79 -0
- package/dist/core/src/render/material-types/toon.wgsl +79 -0
- package/dist/core/src/render/passes/README.md +121 -0
- package/dist/core/src/render/passes/atmosphere.js +107 -0
- package/dist/core/src/render/passes/cluster-lighting-pass.js +441 -0
- package/dist/core/src/render/passes/csm.js +338 -0
- package/dist/core/src/render/passes/cubemap-capture.js +93 -0
- package/dist/core/src/render/passes/debug-viz.js +248 -0
- package/dist/core/src/render/passes/debug.js +500 -0
- package/dist/core/src/render/passes/decal-mesh.js +86 -0
- package/dist/core/src/render/passes/decal-pass.js +344 -0
- package/dist/core/src/render/passes/deferred-lighting.js +406 -0
- package/dist/core/src/render/passes/depth-prepass.js +148 -0
- package/dist/core/src/render/passes/dome-360.js +68 -0
- package/dist/core/src/render/passes/fluid-render.js +116 -0
- package/dist/core/src/render/passes/gi-types.js +78 -0
- package/dist/core/src/render/passes/graph-compute.js +251 -0
- package/dist/core/src/render/passes/greased-line-pass.js +218 -0
- package/dist/core/src/render/passes/morph-target.js +35 -0
- package/dist/core/src/render/passes/opaque.js +966 -0
- package/dist/core/src/render/passes/point-light-shadow.js +221 -0
- package/dist/core/src/render/passes/procedural-texture.js +142 -0
- package/dist/core/src/render/passes/reflection-probe.js +100 -0
- package/dist/core/src/render/passes/rsm-pass.js +228 -0
- package/dist/core/src/render/passes/sdf-text.js +114 -0
- package/dist/core/src/render/passes/shadow-map.js +121 -0
- package/dist/core/src/render/passes/shadow.js +191 -0
- package/dist/core/src/render/passes/skinning-vs.js +102 -0
- package/dist/core/src/render/passes/skinning.js +282 -0
- package/dist/core/src/render/passes/sky-dome.js +380 -0
- package/dist/core/src/render/passes/skybox.js +146 -0
- package/dist/core/src/render/passes/spot-light-shadow.js +223 -0
- package/dist/core/src/render/passes/terrain.js +303 -0
- package/dist/core/src/render/passes/transparent.js +323 -0
- package/dist/core/src/render/passes/underwater-fog.js +173 -0
- package/dist/core/src/render/passes/video-texture.js +58 -0
- package/dist/core/src/render/passes/volumetric-pass.js +278 -0
- package/dist/core/src/render/passes/volumetric-types.js +96 -0
- package/dist/core/src/render/passes/water.js +697 -0
- package/dist/core/src/render/pbr.js +257 -0
- package/dist/core/src/render/pipeline.js +49 -0
- package/dist/core/src/render/render-pass.js +13 -0
- package/dist/core/src/render/renderer-input-bus.js +176 -0
- package/dist/core/src/render/renderer-module-host.js +539 -0
- package/dist/core/src/render/resource-tracker.js +59 -0
- package/dist/core/src/render/sab-canvas-overlay.js +83 -0
- package/dist/core/src/render/shader-validator.js +172 -0
- package/dist/core/src/render/shaders/debug/debug-line.wgsl +27 -0
- package/dist/core/src/render/shaders/debug/debug-point.wgsl +30 -0
- package/dist/core/src/render/shaders/debug/debug-text.wgsl +42 -0
- package/dist/core/src/render/shaders/debug-viz/aabb.wgsl +20 -0
- package/dist/core/src/render/shaders/debug-viz/depth.wgsl +29 -0
- package/dist/core/src/render/shaders/debug-viz/lod.wgsl +38 -0
- package/dist/core/src/render/shaders/debug-viz/normals.wgsl +30 -0
- package/dist/core/src/render/shaders/debug-viz/overdraw.wgsl +21 -0
- package/dist/core/src/render/shaders/debug-viz/tangents.wgsl +29 -0
- package/dist/core/src/render/shaders/debug-viz/wireframe.wgsl +33 -0
- package/dist/core/src/render/shaders/shadow-chunks.js +133 -0
- package/dist/core/src/render/skybox.js +123 -0
- package/dist/core/src/render/splitscreen.js +60 -0
- package/dist/core/src/render/surface.js +63 -0
- package/dist/core/src/render/tonemap.js +171 -0
- package/dist/core/src/render/tracked-render-pass.js +115 -0
- package/dist/core/src/render/viewport.js +81 -0
- package/dist/core/src/render/wgsl-hmr.js +66 -0
- package/dist/core/src/sab/core-input-channel.js +22 -0
- package/dist/core/src/sab/define.js +127 -0
- package/dist/core/src/sab/errors.js +60 -0
- package/dist/core/src/sab/game-input.js +299 -0
- package/dist/core/src/sab/gamepad-devices.js +205 -0
- package/dist/core/src/sab/grid-buffer.js +91 -0
- package/dist/core/src/sab/input.js +38 -0
- package/dist/core/src/sab/layout.js +160 -0
- package/dist/core/src/sab/multi-input-channel.js +39 -0
- package/dist/core/src/sab/record-buffer.js +130 -0
- package/dist/core/src/sab/sab-polyfill.js +47 -0
- package/dist/core/src/sab/sim-channel.js +397 -0
- package/dist/core/src/sab/slot-buffer.js +140 -0
- package/dist/core/src/sab/types.js +1 -0
- package/dist/core/src/safety/bounds.js +71 -0
- package/dist/core/src/safety/json.js +70 -0
- package/dist/core/src/safety/path.js +151 -0
- package/dist/core/src/save/binary-format.js +95 -0
- package/dist/core/src/save/game-save-system.js +101 -0
- package/dist/core/src/save/grid-save-system.js +102 -0
- package/dist/core/src/save/migrate.js +35 -0
- package/dist/core/src/save/migration-registry.js +66 -0
- package/dist/core/src/save/persist-types.js +4 -0
- package/dist/core/src/save/schema.js +36 -0
- package/dist/core/src/save/serializer.js +139 -0
- package/dist/core/src/scene/builder.js +31 -0
- package/dist/core/src/scene/camera.js +118 -0
- package/dist/core/src/scene/checkpoint.js +84 -0
- package/dist/core/src/scene/game-loop.js +155 -0
- package/dist/core/src/scene/index.js +14 -0
- package/dist/core/src/scene/layer.js +7 -0
- package/dist/core/src/scene/prefab.js +97 -0
- package/dist/core/src/scene/scene-manager.js +141 -0
- package/dist/core/src/scene/scene.js +147 -0
- package/dist/core/src/scene/sky.js +179 -0
- package/dist/core/src/scene/spatial-grid.js +140 -0
- package/dist/core/src/scene/streaming.js +247 -0
- package/dist/core/src/scene/vegetation.js +107 -0
- package/dist/core/src/scene/world.js +66 -0
- package/dist/core/src/scripting/binding.js +85 -0
- package/dist/core/src/scripting/hot-reload.js +123 -0
- package/dist/core/src/scripting/script.js +68 -0
- package/dist/core/src/sim/hot-reload-pipeline.js +65 -0
- package/dist/core/src/sim/sim-state-helper.js +40 -0
- package/dist/core/src/sim/transient-state-registry.js +63 -0
- package/dist/core/src/sim/types.js +4 -0
- package/dist/core/src/sim/worker-loop.js +168 -0
- package/dist/core/src/stores/game-store.js +81 -0
- package/dist/core/src/stores/hot-reload-store.js +19 -0
- package/dist/core/src/telemetry/collector.js +303 -0
- package/dist/core/src/telemetry/gc-controller.js +365 -0
- package/dist/core/src/telemetry/gc-profiler.js +82 -0
- package/dist/core/src/telemetry/gc-tracker.js +63 -0
- package/dist/core/src/telemetry/gpu-profiler.js +554 -0
- package/dist/core/src/telemetry/gpu-resource-tracker.js +234 -0
- package/dist/core/src/telemetry/gpu-timer-pool.js +223 -0
- package/dist/core/src/telemetry/gpu-timer.js +117 -0
- package/dist/core/src/telemetry/gpu-timestamp-gate.js +22 -0
- package/dist/core/src/telemetry/reporter.js +56 -0
- package/dist/core/src/types/engine-types.js +21 -0
- package/dist/core/src/ui-font-scale.js +111 -0
- package/dist/core/src/util/broad-phase-grid.js +77 -0
- package/dist/core/src/util/feature-log.js +176 -0
- package/dist/core/src/util/index.js +4 -0
- package/dist/core/src/util/logger.js +596 -0
- package/dist/core/src/version.js +11 -0
- package/dist/core/src/webgpu-destroy-augmentation.d.ts +25 -0
- package/dist/core/src/worker/base-worker-host.js +212 -0
- package/dist/core/src/worker/buffer-sync.js +454 -0
- package/dist/core/src/worker/crash-recovery.js +153 -0
- package/dist/core/src/worker/entity-sim-worker-host.js +128 -0
- package/dist/core/src/worker/instrumented-worker-host.js +139 -0
- package/dist/core/src/worker/rpc.js +244 -0
- package/dist/core/src/worker/sim-worker-base.js +558 -0
- package/dist/core/src/worker/sim-worker-host.js +271 -0
- package/dist/core/src/worker/task-pool.js +205 -0
- package/dist/core/src/worker/task-worker.js +77 -0
- package/dist/libraries/asset-browser/src/index.js +10 -0
- package/dist/libraries/asset-browser/src/software-thumbnails.js +940 -0
- package/dist/libraries/audio-kira/src/backend.js +405 -0
- package/dist/libraries/audio-kira/src/index.js +4 -0
- package/dist/libraries/audio-kira/src/library.js +54 -0
- package/dist/libraries/blitz-ui/src/index.js +13 -0
- package/dist/libraries/blitz-ui/src/native-module.js +162 -0
- package/dist/libraries/blitz-ui/src/native-osr-ffi.js +409 -0
- package/dist/libraries/blitz-ui/src/router.js +82 -0
- package/dist/libraries/blitz-ui/src/shaders/ui-blit.wgsl.js +32 -0
- package/dist/libraries/blitz-ui/src/ui-blit-pass.js +108 -0
- package/dist/libraries/character/src/character-animator.js +323 -0
- package/dist/libraries/character/src/customization.js +464 -0
- package/dist/libraries/character/src/index.js +19 -0
- package/dist/libraries/character/src/inspectable.js +77 -0
- package/dist/libraries/character/src/loader.js +336 -0
- package/dist/libraries/character/src/locomotion.js +84 -0
- package/dist/libraries/character/src/preview.js +280 -0
- package/dist/libraries/devtools/src/backend.js +449 -0
- package/dist/libraries/devtools/src/cdp-bridge.js +293 -0
- package/dist/libraries/devtools/src/collectors.js +318 -0
- package/dist/libraries/devtools/src/index.js +31 -0
- package/dist/libraries/devtools/src/native-providers.js +749 -0
- package/dist/libraries/devtools/src/snapshot.js +35 -0
- package/dist/libraries/devtools/src/verify.js +139 -0
- package/dist/libraries/devtools/src/web/browser.js +94 -0
- package/dist/libraries/devtools/src/web/host.js +183 -0
- package/dist/libraries/devtools/src/web/mirror.js +26 -0
- package/dist/libraries/devtools/src/web/server.js +187 -0
- package/dist/libraries/entities/src/index.js +3 -0
- package/dist/libraries/entities/src/library.js +46 -0
- package/dist/libraries/entities/src/model-renderer.js +1307 -0
- package/dist/libraries/entities/src/shaders/model.wgsl +375 -0
- package/dist/libraries/gamepad/src/feed-input.js +54 -0
- package/dist/libraries/gamepad/src/filters.js +44 -0
- package/dist/libraries/gamepad/src/glyphs.js +83 -0
- package/dist/libraries/gamepad/src/hub.js +164 -0
- package/dist/libraries/gamepad/src/index.js +10 -0
- package/dist/libraries/gamepad/src/library.js +56 -0
- package/dist/libraries/gamepad/src/source-sab.js +62 -0
- package/dist/libraries/gamepad/src/sysfs-enrich.js +125 -0
- package/dist/libraries/gaussian-splats/src/gpu-sort.js +506 -0
- package/dist/libraries/gaussian-splats/src/index.js +8 -0
- package/dist/libraries/gaussian-splats/src/library.js +44 -0
- package/dist/libraries/gaussian-splats/src/parser.js +297 -0
- package/dist/libraries/gaussian-splats/src/renderer.js +368 -0
- package/dist/libraries/gaussian-splats/src/sh-eval.js +196 -0
- package/dist/libraries/gaussian-splats/src/sorter.js +76 -0
- package/dist/libraries/gaussian-splats/src/tile-raster.js +424 -0
- package/dist/libraries/gpu-kernels/src/index.js +8 -0
- package/dist/libraries/gpu-kernels/src/kernel.js +591 -0
- package/dist/libraries/gpu-kernels/src/transpile.js +896 -0
- package/dist/libraries/html-ui-kit/src/behaviors.js +231 -0
- package/dist/libraries/html-ui-kit/src/components.js +219 -0
- package/dist/libraries/html-ui-kit/src/index.js +17 -0
- package/dist/libraries/html-ui-kit/src/nav/nav-controller.js +215 -0
- package/dist/libraries/html-ui-kit/src/nav/nav-input.js +138 -0
- package/dist/libraries/html-ui-kit/src/nav/osk.js +135 -0
- package/dist/libraries/html-ui-kit/src/nav/router.js +152 -0
- package/dist/libraries/html-ui-kit/src/nav/vcursor.js +177 -0
- package/dist/libraries/html-ui-kit/src/ten-foot.js +138 -0
- package/dist/libraries/html-ui-kit/src/theme.js +235 -0
- package/dist/libraries/inspectable/src/index.js +6 -0
- package/dist/libraries/inspectable/src/inspectable.js +205 -0
- package/dist/libraries/lighting/src/index.js +4 -0
- package/dist/libraries/lighting/src/library.js +48 -0
- package/dist/libraries/lighting/src/light-system.js +395 -0
- package/dist/libraries/lighting/src/lighting-system.js +57 -0
- package/dist/libraries/lighting/src/shaders/light-debug.wgsl +30 -0
- package/dist/libraries/marching-cubes/src/chunked-field.js +130 -0
- package/dist/libraries/marching-cubes/src/deformation.js +41 -0
- package/dist/libraries/marching-cubes/src/generator.js +356 -0
- package/dist/libraries/marching-cubes/src/index.js +13 -0
- package/dist/libraries/marching-cubes/src/library.js +54 -0
- package/dist/libraries/marching-cubes/src/lod.js +95 -0
- package/dist/libraries/marching-cubes/src/marching-tetrahedra.js +261 -0
- package/dist/libraries/marching-cubes/src/sab.js +40 -0
- package/dist/libraries/marching-cubes/src/streaming-config.js +28 -0
- package/dist/libraries/marching-cubes/src/streaming-manager.js +490 -0
- package/dist/libraries/marching-cubes/src/tables.js +314 -0
- package/dist/libraries/marching-cubes/src/types.js +1 -0
- package/dist/libraries/models/src/bake-node-transforms.js +146 -0
- package/dist/libraries/models/src/bind-unskinned-meshes.js +145 -0
- package/dist/libraries/models/src/codecs/basisu-codec.js +134 -0
- package/dist/libraries/models/src/codecs/draco-codec.js +236 -0
- package/dist/libraries/models/src/codecs/draco3dgltf.d.ts +40 -0
- package/dist/libraries/models/src/codecs/index.js +5 -0
- package/dist/libraries/models/src/codecs/meshopt-codec.js +59 -0
- package/dist/libraries/models/src/codecs/registry.js +111 -0
- package/dist/libraries/models/src/dae.js +665 -0
- package/dist/libraries/models/src/default-part-selection.js +58 -0
- package/dist/libraries/models/src/dxf.js +235 -0
- package/dist/libraries/models/src/fbx/index.js +438 -0
- package/dist/libraries/models/src/fbx/interpreter/animation.js +369 -0
- package/dist/libraries/models/src/fbx/interpreter/blend-shapes.js +283 -0
- package/dist/libraries/models/src/fbx/interpreter/connections.js +158 -0
- package/dist/libraries/models/src/fbx/interpreter/diagnostics.js +48 -0
- package/dist/libraries/models/src/fbx/interpreter/geometry.js +430 -0
- package/dist/libraries/models/src/fbx/interpreter/global-settings.js +77 -0
- package/dist/libraries/models/src/fbx/interpreter/materials.js +231 -0
- package/dist/libraries/models/src/fbx/interpreter/nodes.js +168 -0
- package/dist/libraries/models/src/fbx/interpreter/skeleton.js +454 -0
- package/dist/libraries/models/src/fbx/parsers/binary-parser.js +217 -0
- package/dist/libraries/models/src/fbx/types.js +88 -0
- package/dist/libraries/models/src/gltf-extensions.js +121 -0
- package/dist/libraries/models/src/gltf.js +724 -0
- package/dist/libraries/models/src/index.js +46 -0
- package/dist/libraries/models/src/library.js +44 -0
- package/dist/libraries/models/src/loader.js +218 -0
- package/dist/libraries/models/src/material-adapter.js +82 -0
- package/dist/libraries/models/src/mini-xml.js +145 -0
- package/dist/libraries/models/src/normalize.js +168 -0
- package/dist/libraries/models/src/obj.js +247 -0
- package/dist/libraries/models/src/off.js +94 -0
- package/dist/libraries/models/src/ply.js +329 -0
- package/dist/libraries/models/src/pose-sampler.js +183 -0
- package/dist/libraries/models/src/sidecar/blender-extras.js +32 -0
- package/dist/libraries/models/src/sidecar/ddmeta.js +98 -0
- package/dist/libraries/models/src/sidecar/godot-import.js +76 -0
- package/dist/libraries/models/src/sidecar/resolver.js +112 -0
- package/dist/libraries/models/src/sidecar/types.js +8 -0
- package/dist/libraries/models/src/sidecar/unity-meta.js +46 -0
- package/dist/libraries/models/src/skeleton-synthesis.js +122 -0
- package/dist/libraries/models/src/stl.js +129 -0
- package/dist/libraries/models/src/threeds.js +312 -0
- package/dist/libraries/models/src/threemf.js +203 -0
- package/dist/libraries/models/src/types.js +33 -0
- package/dist/libraries/models/src/vtk.js +242 -0
- package/dist/libraries/navmesh/src/crowd-system.js +207 -0
- package/dist/libraries/navmesh/src/debug-viz.js +52 -0
- package/dist/libraries/navmesh/src/index.js +7 -0
- package/dist/libraries/navmesh/src/library.js +47 -0
- package/dist/libraries/navmesh/src/navmesh-generator.js +364 -0
- package/dist/libraries/navmesh/src/navmesh.js +141 -0
- package/dist/libraries/navmesh/src/pathfinder.js +221 -0
- package/dist/libraries/navmesh/src/types.js +1 -0
- package/dist/libraries/networking/src/authority.js +107 -0
- package/dist/libraries/networking/src/connection.js +107 -0
- package/dist/libraries/networking/src/discovery.js +314 -0
- package/dist/libraries/networking/src/enhanced-replication.js +282 -0
- package/dist/libraries/networking/src/epic-adapter.js +101 -0
- package/dist/libraries/networking/src/index.js +16 -0
- package/dist/libraries/networking/src/library.js +45 -0
- package/dist/libraries/networking/src/lobby.js +84 -0
- package/dist/libraries/networking/src/platform-adapter.js +92 -0
- package/dist/libraries/networking/src/rcs-adapter.js +100 -0
- package/dist/libraries/networking/src/remote-input.js +162 -0
- package/dist/libraries/networking/src/replication.js +273 -0
- package/dist/libraries/networking/src/rpc.js +172 -0
- package/dist/libraries/networking/src/session.js +129 -0
- package/dist/libraries/networking/src/transport.js +156 -0
- package/dist/libraries/networking/src/webrtc.js +266 -0
- package/dist/libraries/pathfinding-2d/src/astar-grid.js +255 -0
- package/dist/libraries/pathfinding-2d/src/index.js +9 -0
- package/dist/libraries/persistence/src/autosave-manager.js +94 -0
- package/dist/libraries/persistence/src/binary-record-store.js +205 -0
- package/dist/libraries/persistence/src/browser.js +16 -0
- package/dist/libraries/persistence/src/file-save-store.js +507 -0
- package/dist/libraries/persistence/src/hash-utils.js +54 -0
- package/dist/libraries/persistence/src/index.js +17 -0
- package/dist/libraries/persistence/src/library.js +51 -0
- package/dist/libraries/persistence/src/mock-opfs.js +114 -0
- package/dist/libraries/persistence/src/node-fs-directory-handle.js +168 -0
- package/dist/libraries/persistence/src/opfs-save-store.js +584 -0
- package/dist/libraries/persistence/src/save-worker-proxy.js +96 -0
- package/dist/libraries/persistence/src/save-worker.js +76 -0
- package/dist/libraries/persistence/src/xxh3-ts.d.ts +10 -0
- package/dist/libraries/physics-native/src/backend.js +960 -0
- package/dist/libraries/physics-native/src/broadphase.js +79 -0
- package/dist/libraries/physics-native/src/index.js +6 -0
- package/dist/libraries/physics-native/src/library.js +57 -0
- package/dist/libraries/physics-native/src/narrowphase-shapes.js +348 -0
- package/dist/libraries/physics-native/src/narrowphase.js +60 -0
- package/dist/libraries/physics-native/src/solver.js +105 -0
- package/dist/libraries/physics-native/src/types.js +4 -0
- package/dist/libraries/physics-rapier/src/api.js +352 -0
- package/dist/libraries/physics-rapier/src/auto-backend.js +54 -0
- package/dist/libraries/physics-rapier/src/backend.js +1066 -0
- package/dist/libraries/physics-rapier/src/bulk-ops.js +46 -0
- package/dist/libraries/physics-rapier/src/ffi-backend.js +17 -0
- package/dist/libraries/physics-rapier/src/ffi-lib.js +605 -0
- package/dist/libraries/physics-rapier/src/index.js +9 -0
- package/dist/libraries/physics-rapier/src/library.js +71 -0
- package/dist/libraries/physics-rapier/src/rapier-backend.js +1102 -0
- package/dist/libraries/physics-rapier/src/realm-worker-script.js +233 -0
- package/dist/libraries/postfx/src/index.js +14 -0
- package/dist/libraries/postfx/src/library.js +207 -0
- package/dist/libraries/postfx/src/post-process-stack.js +1641 -0
- package/dist/libraries/postfx/src/shaders/post-process/afterimage.wgsl +14 -0
- package/dist/libraries/postfx/src/shaders/post-process/ascii.wgsl +24 -0
- package/dist/libraries/postfx/src/shaders/post-process/blit.wgsl +12 -0
- package/dist/libraries/postfx/src/shaders/post-process/bloom-blur.wgsl +21 -0
- package/dist/libraries/postfx/src/shaders/post-process/bloom-bright.wgsl +15 -0
- package/dist/libraries/postfx/src/shaders/post-process/bloom-composite.wgsl +14 -0
- package/dist/libraries/postfx/src/shaders/post-process/bloom-downsample.wgsl +60 -0
- package/dist/libraries/postfx/src/shaders/post-process/bloom-soft.wgsl +46 -0
- package/dist/libraries/postfx/src/shaders/post-process/bloom-upsample.wgsl +51 -0
- package/dist/libraries/postfx/src/shaders/post-process/channel-mixer.wgsl +36 -0
- package/dist/libraries/postfx/src/shaders/post-process/chromatic-aberration.wgsl +37 -0
- package/dist/libraries/postfx/src/shaders/post-process/dithering.wgsl +64 -0
- package/dist/libraries/postfx/src/shaders/post-process/dof.wgsl +131 -0
- package/dist/libraries/postfx/src/shaders/post-process/edges.wgsl +45 -0
- package/dist/libraries/postfx/src/shaders/post-process/fullscreen-vs.wgsl +15 -0
- package/dist/libraries/postfx/src/shaders/post-process/fxaa.wgsl +102 -0
- package/dist/libraries/postfx/src/shaders/post-process/gaussian-blur.wgsl +37 -0
- package/dist/libraries/postfx/src/shaders/post-process/glow-blur.wgsl +33 -0
- package/dist/libraries/postfx/src/shaders/post-process/glow-composite.wgsl +25 -0
- package/dist/libraries/postfx/src/shaders/post-process/grain.wgsl +37 -0
- package/dist/libraries/postfx/src/shaders/post-process/halftone.wgsl +80 -0
- package/dist/libraries/postfx/src/shaders/post-process/highlight-blur.wgsl +33 -0
- package/dist/libraries/postfx/src/shaders/post-process/highlight-composite.wgsl +32 -0
- package/dist/libraries/postfx/src/shaders/post-process/lens-distortion.wgsl +43 -0
- package/dist/libraries/postfx/src/shaders/post-process/lens-flare.wgsl +68 -0
- package/dist/libraries/postfx/src/shaders/post-process/lut.wgsl +30 -0
- package/dist/libraries/postfx/src/shaders/post-process/motion-blur.wgsl +55 -0
- package/dist/libraries/postfx/src/shaders/post-process/occluder-chunk.wgsl +28 -0
- package/dist/libraries/postfx/src/shaders/post-process/outline.wgsl +51 -0
- package/dist/libraries/postfx/src/shaders/post-process/pixelation.wgsl +47 -0
- package/dist/libraries/postfx/src/shaders/post-process/sharpen.wgsl +32 -0
- package/dist/libraries/postfx/src/shaders/post-process/sobel.wgsl +26 -0
- package/dist/libraries/postfx/src/shaders/post-process/split-tone.wgsl +36 -0
- package/dist/libraries/postfx/src/shaders/post-process/ssao-blur.wgsl +38 -0
- package/dist/libraries/postfx/src/shaders/post-process/ssao-composite.wgsl +25 -0
- package/dist/libraries/postfx/src/shaders/post-process/ssao.wgsl +147 -0
- package/dist/libraries/postfx/src/shaders/post-process/ssr.wgsl +155 -0
- package/dist/libraries/postfx/src/shaders/post-process/taa.wgsl +98 -0
- package/dist/libraries/postfx/src/shaders/post-process/tonemap.wgsl +40 -0
- package/dist/libraries/postfx/src/shaders/post-process/watercolor.wgsl +82 -0
- package/dist/libraries/postfx/src/shaders/post-process/white-balance.wgsl +41 -0
- package/dist/libraries/recast/src/backend.js +124 -0
- package/dist/libraries/recast/src/crowd-system.js +310 -0
- package/dist/libraries/recast/src/index.js +4 -0
- package/dist/libraries/recast/src/library.js +59 -0
- package/dist/libraries/recast/src/types.js +4 -0
- package/dist/libraries/sand/src/cell.js +32 -0
- package/dist/libraries/sand/src/fields.js +27 -0
- package/dist/libraries/sand/src/fluid-grid.js +267 -0
- package/dist/libraries/sand/src/grid-dims.js +47 -0
- package/dist/libraries/sand/src/grid-sim-buffer.js +184 -0
- package/dist/libraries/sand/src/index.js +20 -0
- package/dist/libraries/sand/src/library.js +67 -0
- package/dist/libraries/sand/src/materials.js +437 -0
- package/dist/libraries/sand/src/palette.js +87 -0
- package/dist/libraries/sand/src/particles.js +163 -0
- package/dist/libraries/sand/src/render/sand-grid-pass.js +377 -0
- package/dist/libraries/sand/src/rng.js +44 -0
- package/dist/libraries/sand/src/rules/builtin-rules.js +125 -0
- package/dist/libraries/sand/src/rules/rule-compiler.js +164 -0
- package/dist/libraries/sand/src/rules/rule-engine.js +210 -0
- package/dist/libraries/sand/src/rules/rule-types.js +27 -0
- package/dist/libraries/sand/src/sand-step-pool.js +458 -0
- package/dist/libraries/sand/src/sand-step-worker.js +101 -0
- package/dist/libraries/sand/src/sand-world.js +3382 -0
- package/dist/libraries/stickman/src/index.js +7 -0
- package/dist/libraries/stickman/src/library.js +44 -0
- package/dist/libraries/stickman/src/proportions.js +40 -0
- package/dist/libraries/stickman/src/shader.js +113 -0
- package/dist/libraries/stickman/src/skeleton.js +163 -0
- package/dist/libraries/stickman/src/stickman-pass.js +210 -0
- package/dist/libraries/stickman/src/thick-line.js +120 -0
- package/dist/libraries/surface-nets/src/chunked-field.js +5 -0
- package/dist/libraries/surface-nets/src/deformation.js +29 -0
- package/dist/libraries/surface-nets/src/index.js +15 -0
- package/dist/libraries/surface-nets/src/library.js +41 -0
- package/dist/libraries/surface-nets/src/lod.js +6 -0
- package/dist/libraries/surface-nets/src/sab.js +4 -0
- package/dist/libraries/surface-nets/src/streaming-config.js +4 -0
- package/dist/libraries/surface-nets/src/streaming-manager.js +9 -0
- package/dist/libraries/surface-nets/src/surface-nets.js +361 -0
- package/dist/libraries/surface-nets/src/types.js +1 -0
- package/dist/libraries/water/src/buoyancy.js +80 -0
- package/dist/libraries/water/src/index.js +12 -0
- package/dist/libraries/water/src/library.js +65 -0
- package/dist/libraries/water/src/shore-damping.js +70 -0
- package/dist/libraries/water/src/water-buffer.js +78 -0
- package/dist/libraries/water/src/water-chunks.js +5 -0
- package/dist/libraries/water/src/water-physics.js +315 -0
- package/dist/libraries/water/src/water-renderer.js +736 -0
- package/dist/libraries/water/src/water-sab.js +138 -0
- package/dist/libraries/water/src/wave-sources.js +45 -0
- package/dist/libraries/weather/src/index.js +5 -0
- package/dist/libraries/weather/src/library.js +48 -0
- package/dist/libraries/weather/src/types.js +29 -0
- package/dist/libraries/weather/src/weather-blend.js +108 -0
- package/dist/libraries/weather/src/weather-system.js +275 -0
- package/dist/libraries/weatherfx/src/cloud-provider.js +5 -0
- package/dist/libraries/weatherfx/src/cloud-system.js +294 -0
- package/dist/libraries/weatherfx/src/index.js +4 -0
- package/dist/libraries/weatherfx/src/library.js +41 -0
- package/dist/libraries/weatherfx/src/particle-system.js +350 -0
- package/dist/libraries/weatherfx/src/shaders/cloud.wgsl +111 -0
- package/dist/libraries/weatherfx/src/shaders/particle-compute.wgsl +187 -0
- package/dist/libraries/weatherfx/src/shaders/particle-render.wgsl +95 -0
- package/dist/mcp/src/client.js +669 -0
- package/dist/mcp/src/engine-context.js +99 -0
- package/dist/mcp/src/http-transport.js +423 -0
- package/dist/mcp/src/index.js +5 -0
- package/dist/mcp/src/prompts/add-entity.js +39 -0
- package/dist/mcp/src/prompts/create-scene.js +41 -0
- package/dist/mcp/src/prompts/debug-frame.js +36 -0
- package/dist/mcp/src/prompts/index.js +10 -0
- package/dist/mcp/src/resources/asset-list.js +28 -0
- package/dist/mcp/src/resources/checkpoint-list.js +29 -0
- package/dist/mcp/src/resources/entity-state.js +45 -0
- package/dist/mcp/src/resources/gpu-info.js +90 -0
- package/dist/mcp/src/resources/index.js +51 -0
- package/dist/mcp/src/resources/performance.js +33 -0
- package/dist/mcp/src/resources/scene-tree.js +37 -0
- package/dist/mcp/src/server.js +307 -0
- package/dist/mcp/src/tools/animation.js +102 -0
- package/dist/mcp/src/tools/asset.js +146 -0
- package/dist/mcp/src/tools/audio.js +80 -0
- package/dist/mcp/src/tools/build.js +128 -0
- package/dist/mcp/src/tools/camera.js +157 -0
- package/dist/mcp/src/tools/checkpoint.js +90 -0
- package/dist/mcp/src/tools/component.js +176 -0
- package/dist/mcp/src/tools/debug.js +273 -0
- package/dist/mcp/src/tools/entity.js +309 -0
- package/dist/mcp/src/tools/inspect.js +192 -0
- package/dist/mcp/src/tools/lighting.js +239 -0
- package/dist/mcp/src/tools/material.js +225 -0
- package/dist/mcp/src/tools/mesh.js +210 -0
- package/dist/mcp/src/tools/physics.js +251 -0
- package/dist/mcp/src/tools/scene.js +139 -0
- package/dist/mcp/src/tools/script.js +114 -0
- package/dist/mcp/src/types.js +9 -0
- package/dist/mcp/src/undo-redo.js +64 -0
- package/dist/modules/camera-controls/src/index.js +116 -0
- package/dist/modules/controller-ui/src/index.js +149 -0
- package/dist/modules/devtools/src/api.js +317 -0
- package/dist/modules/devtools/src/asset-utils.js +102 -0
- package/dist/modules/devtools/src/bind-debug-store.js +34 -0
- package/dist/modules/devtools/src/blitz/host.js +391 -0
- package/dist/modules/devtools/src/blitz/module.js +65 -0
- package/dist/modules/devtools/src/blitz/panels/console.js +217 -0
- package/dist/modules/devtools/src/blitz/panels/elements.js +79 -0
- package/dist/modules/devtools/src/blitz/panels/gpu.js +61 -0
- package/dist/modules/devtools/src/blitz/panels/performance.js +113 -0
- package/dist/modules/devtools/src/blitz/panels/snapshot.js +141 -0
- package/dist/modules/devtools/src/blitz/panels/types.js +55 -0
- package/dist/modules/devtools/src/blitz/theme.js +167 -0
- package/dist/modules/devtools/src/data-bridge.js +247 -0
- package/dist/modules/devtools/src/debug-overlay.js +181 -0
- package/dist/modules/devtools/src/debug-raycast.js +296 -0
- package/dist/modules/devtools/src/debug-store.js +28 -0
- package/dist/modules/devtools/src/debug-view-descriptors.js +24 -0
- package/dist/modules/devtools/src/doctor-panel.js +163 -0
- package/dist/modules/devtools/src/gizmo-module.js +95 -0
- package/dist/modules/devtools/src/graph-model.js +387 -0
- package/dist/modules/devtools/src/grid-renderer.js +145 -0
- package/dist/modules/devtools/src/height-ruler-renderer.js +189 -0
- package/dist/modules/devtools/src/index.js +46 -0
- package/dist/modules/devtools/src/init.js +204 -0
- package/dist/modules/devtools/src/label-overlay.js +129 -0
- package/dist/modules/devtools/src/material-stats-panel.js +171 -0
- package/dist/modules/devtools/src/profiling-bridge.js +288 -0
- package/dist/modules/devtools/src/profiling-hooks.js +63 -0
- package/dist/modules/devtools/src/renderer-adapter.js +61 -0
- package/dist/modules/devtools/src/scene-inspector.js +571 -0
- package/dist/modules/devtools/src/scene-store.js +212 -0
- package/dist/modules/devtools/src/scene-sync.js +92 -0
- package/dist/modules/devtools/src/shaders/transform-gizmo.wgsl +38 -0
- package/dist/modules/devtools/src/sim-stats-panel.js +250 -0
- package/dist/modules/devtools/src/sim-stats-provider.js +73 -0
- package/dist/modules/devtools/src/skeleton-renderer.js +326 -0
- package/dist/modules/devtools/src/transform-gizmo.js +677 -0
- package/dist/modules/devtools/src/types.js +5 -0
- package/dist/modules/devtools/src/worker-expose.js +59 -0
- package/dist/modules/devtools/src/worker-sync.js +115 -0
- package/dist/modules/editor/src/commands/component.js +151 -0
- package/dist/modules/editor/src/commands/entity.js +253 -0
- package/dist/modules/editor/src/commands/hierarchy.js +79 -0
- package/dist/modules/editor/src/commands/index.js +57 -0
- package/dist/modules/editor/src/commands/prefab.js +149 -0
- package/dist/modules/editor/src/commands/registry.js +246 -0
- package/dist/modules/editor/src/commands/scene-io.js +206 -0
- package/dist/modules/editor/src/commands/selection.js +71 -0
- package/dist/modules/editor/src/commands/transform.js +88 -0
- package/dist/modules/editor/src/ddscene.js +189 -0
- package/dist/modules/editor/src/document.js +96 -0
- package/dist/modules/editor/src/editor-context.js +115 -0
- package/dist/modules/editor/src/index.js +11 -0
- package/dist/modules/editor/src/mcp.js +91 -0
- package/dist/modules/editor/src/module.js +115 -0
- package/dist/modules/editor/src/selection.js +60 -0
- package/dist/modules/editor/src/shell.js +397 -0
- package/dist/modules/editor/src/viewport.js +186 -0
- package/dist/modules/html-ui/src/composite.js +116 -0
- package/dist/modules/html-ui/src/create-html-ui.js +137 -0
- package/dist/modules/html-ui/src/doc-backend.js +518 -0
- package/dist/modules/html-ui/src/host.js +819 -0
- package/dist/modules/html-ui/src/index.js +5 -0
- package/dist/modules/html-ui/src/jsx-dev-runtime.js +9 -0
- package/dist/modules/html-ui/src/jsx-runtime.js +121 -0
- package/dist/modules/html-ui/src/protocol.js +6 -0
- package/dist/modules/html-ui/src/ui-worker.js +10 -0
- package/dist/modules/mcp/src/index.js +62 -0
- package/dist/modules/movement-2d/src/grid-character.js +345 -0
- package/dist/modules/movement-2d/src/index.js +27 -0
- package/dist/modules/movement-3d/src/character-motor.js +166 -0
- package/dist/modules/movement-3d/src/index.js +27 -0
- package/dist/modules/native-osr/src/index.js +12 -0
- package/dist/modules/native-osr/src/input-router.js +335 -0
- package/dist/modules/native-osr/src/native-osr-manager.js +210 -0
- package/dist/modules/native-osr/src/native-texture-source.js +66 -0
- package/dist/modules/native-osr/src/types.js +8 -0
- package/dist/modules/native-osr/src/world-space-ui-pass.js +313 -0
- package/dist/modules/sailing/src/index.js +39 -0
- package/dist/modules/terrain/src/index.js +44 -0
- package/dist/modules/vitals/src/index.js +25 -0
- package/dist/modules/vitals/src/vitals.js +195 -0
- package/dist/modules/xr/src/camera-rig.js +119 -0
- package/dist/modules/xr/src/debug.js +45 -0
- package/dist/modules/xr/src/frame-loop.js +139 -0
- package/dist/modules/xr/src/index.js +10 -0
- package/dist/modules/xr/src/input.js +164 -0
- package/dist/modules/xr/src/layer.js +100 -0
- package/dist/modules/xr/src/session.js +133 -0
- package/dist/modules/xr/src/sim-module.js +21 -0
- package/dist/modules/xr/src/types.js +4 -0
- package/dist/modules/xr/src/webxr.d.ts +182 -0
- package/dist/modules/xr/src/xr-module.js +134 -0
- package/dist/shader-graph/src/chunks.js +340 -0
- package/dist/shader-graph/src/compiler.js +639 -0
- package/dist/shader-graph/src/compute-compiler.js +384 -0
- package/dist/shader-graph/src/compute-graph.js +55 -0
- package/dist/shader-graph/src/compute-profiles.js +39 -0
- package/dist/shader-graph/src/graph.js +38 -0
- package/dist/shader-graph/src/index.js +15 -0
- package/dist/shader-graph/src/profiles.js +305 -0
- package/dist/shader-graph/src/validator.js +42 -0
- package/dist/shader-graph/src/wgsl-binding-validator.js +110 -0
- package/dist/shader-graph/src/wgsl-struct-validator.js +222 -0
- package/dist/shader-graph/src/wgsl-struct.js +251 -0
- package/dist/test/src/index.js +1 -0
- package/dist/test/src/vision-test.js +228 -0
- package/libraries/asset-browser/src/software-thumbnails.ts +2 -2
- package/libraries/audio-kira/src/backend.ts +2 -1
- package/libraries/blitz-ui/native/src/shell.rs +35 -1
- package/libraries/blitz-ui/native-osr/Cargo.toml +8 -0
- package/libraries/blitz-ui/native-osr/src/lib.rs +213 -22
- package/libraries/blitz-ui/native-osr/src/mutate.rs +109 -14
- package/libraries/blitz-ui/src/native-osr-ffi.ts +71 -8
- package/libraries/blitz-ui/src/router.ts +3 -1
- package/libraries/blitz-ui/src/ui-blit-pass.ts +1 -1
- package/libraries/character/src/character-animator.ts +1 -1
- package/libraries/character/src/customization.ts +513 -0
- package/libraries/character/src/index.ts +6 -0
- package/libraries/character/src/inspectable.ts +111 -0
- package/libraries/character/src/loader.ts +38 -13
- package/libraries/character/src/locomotion.ts +13 -1
- package/libraries/character/src/preview.ts +94 -24
- package/libraries/devtools/README.md +16 -18
- package/libraries/devtools/src/backend.ts +505 -0
- package/libraries/devtools/src/cdp-bridge.ts +8 -8
- package/libraries/devtools/src/collectors.ts +41 -37
- package/libraries/devtools/src/index.ts +32 -14
- package/libraries/devtools/src/native-providers.ts +20 -12
- package/libraries/devtools/src/snapshot.ts +77 -0
- package/libraries/devtools/src/web/host.ts +11 -12
- package/libraries/devtools/src/web/mirror.ts +14 -405
- package/libraries/devtools/src/web/server.ts +4 -3
- package/libraries/entities/src/model-renderer.ts +96 -23
- package/libraries/gamepad/src/library.ts +2 -1
- package/libraries/inspectable/src/index.ts +11 -0
- package/libraries/inspectable/src/inspectable.ts +277 -0
- package/libraries/marching-cubes/src/streaming-manager.ts +4 -4
- package/libraries/models/src/bind-unskinned-meshes.ts +131 -0
- package/libraries/models/src/index.ts +1 -0
- package/libraries/models/src/types.ts +22 -0
- package/libraries/persistence/src/autosave-manager.ts +1 -1
- package/libraries/persistence/src/binary-record-store.ts +1 -1
- package/libraries/persistence/src/file-save-store.ts +4 -4
- package/libraries/persistence/src/library.ts +1 -1
- package/libraries/persistence/src/opfs-save-store.ts +5 -5
- package/libraries/persistence/src/save-worker.ts +13 -14
- package/libraries/physics-rapier/src/ffi-lib.ts +2 -1
- package/libraries/postfx/src/post-process-stack.ts +1 -1
- package/libraries/sand/src/sand-step-pool.ts +5 -0
- package/libraries/water/src/water-renderer.ts +1 -1
- package/libraries/weatherfx/src/cloud-system.ts +3 -3
- package/mcp/README.md +20 -0
- package/mcp/src/client.ts +75 -22
- package/mcp/src/undo-redo.ts +2 -2
- package/modules/devtools/src/blitz/host.ts +430 -0
- package/modules/devtools/src/blitz/module.ts +101 -0
- package/modules/devtools/src/blitz/panels/console.ts +223 -0
- package/modules/devtools/src/blitz/panels/elements.ts +92 -0
- package/modules/devtools/src/blitz/panels/gpu.ts +70 -0
- package/modules/devtools/src/blitz/panels/performance.ts +120 -0
- package/modules/devtools/src/blitz/panels/snapshot.ts +152 -0
- package/modules/devtools/src/blitz/panels/types.ts +120 -0
- package/modules/devtools/src/blitz/theme.ts +168 -0
- package/modules/devtools/src/data-bridge.ts +1 -1
- package/modules/devtools/src/index.ts +6 -0
- package/modules/devtools/src/profiling-bridge.ts +17 -13
- package/modules/devtools/src/profiling-hooks.ts +22 -13
- package/modules/devtools/src/scene-inspector.ts +1 -1
- package/modules/devtools/src/worker-sync.ts +9 -1
- package/modules/editor/src/commands/registry.ts +2 -2
- package/modules/editor/src/module.ts +1 -1
- package/modules/html-ui/src/composite.ts +1 -1
- package/modules/html-ui/src/create-html-ui.ts +21 -9
- package/modules/html-ui/src/doc-backend.ts +189 -10
- package/modules/html-ui/src/host.ts +354 -40
- package/modules/html-ui/src/index.ts +1 -1
- package/modules/html-ui/src/jsx-runtime.ts +1 -1
- package/modules/html-ui/src/protocol.ts +53 -6
- package/modules/mcp/README.md +6 -0
- package/modules/mcp/src/index.ts +70 -3
- package/modules/movement-3d/src/character-motor.ts +83 -10
- package/package.json +838 -165
- package/shader-graph/README.md +25 -0
- package/test/README.md +16 -0
- package/libraries/blitz-ui/native-osr-spike.ts +0 -70
- package/libraries/devtools/native/Cargo.toml +0 -12
- package/libraries/devtools/native/src/lib.rs +0 -1646
- package/libraries/devtools/native/src/panels/console.rs +0 -338
- package/libraries/devtools/native/src/panels/dom_tree.rs +0 -47
- package/libraries/devtools/native/src/panels/generic.rs +0 -317
- package/libraries/devtools/native/src/panels/gpu.rs +0 -107
- package/libraries/devtools/native/src/panels/input.rs +0 -88
- package/libraries/devtools/native/src/panels/mod.rs +0 -154
- package/libraries/devtools/native/src/panels/perf_metrics.rs +0 -91
- package/libraries/devtools/native/src/panels/perf_recorder.rs +0 -158
- package/libraries/devtools/native/src/panels/scene.rs +0 -72
- package/libraries/devtools/native/src/state.rs +0 -394
- package/libraries/devtools/src/egui-ffi.ts +0 -804
- package/libraries/devtools/src/egui-renderer.ts +0 -407
- package/libraries/devtools/src/host.ts +0 -363
- package/libraries/devtools/src/mirror.ts +0 -794
- package/libraries/models/test-fixtures/fbx/LICENSE-notice.txt +0 -24
- package/libraries/models/test-fixtures/fbx/README.md +0 -46
- package/libraries/models/test-fixtures/fbx/m01_cube_phong.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m02_geo_ngons.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m03_normals.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m04_material_properties.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m05_external_diffuse.png +0 -0
- package/libraries/models/test-fixtures/fbx/m05_textures.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m06_uv_transform.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m07_multimaterial.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m08_transforms.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m09_skinning.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m10_morph.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m11_node_anim.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m12_skeletal_anim.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m13_morph_anim.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m14_multiclip.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m15_camera_lights.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m16_axis_yup.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m16_axis_zup.fbx +0 -0
- package/libraries/models/test-fixtures/fbx/m16_units_254.fbx +0 -0
- package/libraries/physics-native/src/ffi-spike-worker.ts +0 -71
- package/libraries/physics-rapier/bench/ffi-bench.ts +0 -79
- package/libraries/physics-rapier/bench/wasm-baseline.ts +0 -90
|
@@ -0,0 +1,1066 @@
|
|
|
1
|
+
import { loadPhysicsLib } from "./rapier-backend.js";
|
|
2
|
+
export class RapierPhysicsBackend {
|
|
3
|
+
name = "rapier";
|
|
4
|
+
version = "0.2.0";
|
|
5
|
+
lib = null;
|
|
6
|
+
libFactory;
|
|
7
|
+
realms = new Map();
|
|
8
|
+
realmIds = [];
|
|
9
|
+
nextRealmId = 1;
|
|
10
|
+
nextColliderId = 1;
|
|
11
|
+
destroyed = false;
|
|
12
|
+
/**
|
|
13
|
+
* Step options — set by UniversalPhysicsAPI from PhysicsModuleConfig.
|
|
14
|
+
* Games that don't read contacts/intersections set extractContacts=false
|
|
15
|
+
* to skip the expensive WASM↔JS callback traversal in step().
|
|
16
|
+
* Games that read transforms via the Raw API set readBackTransformsOnStep=false
|
|
17
|
+
* to skip redundant high-level transform readback.
|
|
18
|
+
*/
|
|
19
|
+
extractContacts = true;
|
|
20
|
+
readBackTransformsOnStep = true;
|
|
21
|
+
/**
|
|
22
|
+
* @param libFactory — override the PhysicsLib source. Defaults to the WASM
|
|
23
|
+
* Rapier bundle; the native runtime passes `loadFfiPhysicsLib` from
|
|
24
|
+
* `./ffi-lib` to drive the Rust cdylib instead.
|
|
25
|
+
*/
|
|
26
|
+
constructor(libFactory) {
|
|
27
|
+
this.libFactory = libFactory;
|
|
28
|
+
}
|
|
29
|
+
async init() {
|
|
30
|
+
if (this.lib)
|
|
31
|
+
return;
|
|
32
|
+
this.lib = await (this.libFactory ? this.libFactory() : loadPhysicsLib());
|
|
33
|
+
}
|
|
34
|
+
ensureLib() {
|
|
35
|
+
if (!this.lib) {
|
|
36
|
+
throw new Error("RapierPhysicsBackend not initialized. Call init() first.");
|
|
37
|
+
}
|
|
38
|
+
return this.lib;
|
|
39
|
+
}
|
|
40
|
+
createRealm(config) {
|
|
41
|
+
const id = config.id ?? this.nextRealmId++;
|
|
42
|
+
const realm = {
|
|
43
|
+
id,
|
|
44
|
+
config,
|
|
45
|
+
bodies: new Map(),
|
|
46
|
+
nextBodyId: 1,
|
|
47
|
+
contacts: [],
|
|
48
|
+
intersections: [],
|
|
49
|
+
nextControllerId: 1,
|
|
50
|
+
nextJointId: 1,
|
|
51
|
+
readbackIds: new Uint32Array(0),
|
|
52
|
+
readbackStates: new Float32Array(0),
|
|
53
|
+
};
|
|
54
|
+
this.realms.set(id, realm);
|
|
55
|
+
this.realmIds.push(id);
|
|
56
|
+
if (this.lib) {
|
|
57
|
+
this.lib.createRealm(id, config.gravity);
|
|
58
|
+
}
|
|
59
|
+
return id;
|
|
60
|
+
}
|
|
61
|
+
destroyRealm(realmId) {
|
|
62
|
+
const realm = this.realms.get(realmId);
|
|
63
|
+
if (!realm)
|
|
64
|
+
return;
|
|
65
|
+
if (this.lib) {
|
|
66
|
+
this.lib.destroyRealm(realmId);
|
|
67
|
+
}
|
|
68
|
+
realm.bodies.clear();
|
|
69
|
+
this.realms.delete(realmId);
|
|
70
|
+
this.realmIds = this.realmIds.filter((id) => id !== realmId);
|
|
71
|
+
}
|
|
72
|
+
getRealmIds() {
|
|
73
|
+
return [...this.realmIds];
|
|
74
|
+
}
|
|
75
|
+
createBody(realmId, desc, entity) {
|
|
76
|
+
const realm = this.realms.get(realmId);
|
|
77
|
+
if (!realm)
|
|
78
|
+
throw new Error(`Realm ${realmId} not found`);
|
|
79
|
+
const bodyId = realm.nextBodyId++;
|
|
80
|
+
const body = { id: bodyId, realmId, entity };
|
|
81
|
+
const state = {
|
|
82
|
+
body,
|
|
83
|
+
desc,
|
|
84
|
+
colliders: new Map(),
|
|
85
|
+
position: [...desc.position],
|
|
86
|
+
rotation: [...desc.rotation],
|
|
87
|
+
linearVelocity: [...(desc.linearVelocity ?? [0, 0, 0])],
|
|
88
|
+
angularVelocity: [...(desc.angularVelocity ?? [0, 0, 0])],
|
|
89
|
+
sleeping: desc.sleeping ?? false,
|
|
90
|
+
};
|
|
91
|
+
realm.bodies.set(bodyId, state);
|
|
92
|
+
if (this.lib) {
|
|
93
|
+
this.lib.createBody(realmId, bodyId, desc, entity);
|
|
94
|
+
}
|
|
95
|
+
return body;
|
|
96
|
+
}
|
|
97
|
+
destroyBody(body) {
|
|
98
|
+
const realm = this.realms.get(body.realmId);
|
|
99
|
+
if (!realm)
|
|
100
|
+
return;
|
|
101
|
+
if (this.lib) {
|
|
102
|
+
this.lib.destroyBody(body.realmId, body.id);
|
|
103
|
+
}
|
|
104
|
+
realm.bodies.delete(body.id);
|
|
105
|
+
}
|
|
106
|
+
setBodyType(body, type) {
|
|
107
|
+
const state = this.getBodyState(body);
|
|
108
|
+
if (!state)
|
|
109
|
+
return;
|
|
110
|
+
state.desc.type = type;
|
|
111
|
+
if (this.lib) {
|
|
112
|
+
this.lib.setBodyType(body.realmId, body.id, type);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
addCollider(body, desc) {
|
|
116
|
+
const state = this.getBodyState(body);
|
|
117
|
+
if (!state)
|
|
118
|
+
return -1;
|
|
119
|
+
// Collider ids are allocated from a backend-global counter — the
|
|
120
|
+
// realm-scoped lib APIs (colliderMaps, FFI collider_map) key by
|
|
121
|
+
// colliderId alone, so per-body counters would collide across bodies
|
|
122
|
+
// and silently swap/remove the wrong collider.
|
|
123
|
+
const id = this.nextColliderId++;
|
|
124
|
+
state.colliders.set(id, desc);
|
|
125
|
+
if (this.lib) {
|
|
126
|
+
this.lib.addCollider(body.realmId, body.id, id, desc);
|
|
127
|
+
}
|
|
128
|
+
return id;
|
|
129
|
+
}
|
|
130
|
+
removeCollider(body, colliderId) {
|
|
131
|
+
const state = this.getBodyState(body);
|
|
132
|
+
if (!state)
|
|
133
|
+
return;
|
|
134
|
+
state.colliders.delete(colliderId);
|
|
135
|
+
if (this.lib) {
|
|
136
|
+
this.lib.removeCollider(body.realmId, body.id, colliderId);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
testConvexHull(vertices) {
|
|
140
|
+
if (!this.lib?.testConvexHull)
|
|
141
|
+
return false;
|
|
142
|
+
return this.lib.testConvexHull(vertices);
|
|
143
|
+
}
|
|
144
|
+
getColliderShapeType(body, colliderId) {
|
|
145
|
+
if (!this.lib?.getColliderShapeType)
|
|
146
|
+
return -1;
|
|
147
|
+
return this.lib.getColliderShapeType(body.realmId, colliderId);
|
|
148
|
+
}
|
|
149
|
+
getColliderCount(body) {
|
|
150
|
+
if (!this.lib?.getColliderCount)
|
|
151
|
+
return -1;
|
|
152
|
+
return this.lib.getColliderCount(body.realmId, body.id);
|
|
153
|
+
}
|
|
154
|
+
setColliderPosition(realmId, colliderId, pos) {
|
|
155
|
+
if (this.lib && this.lib.setColliderPosition) {
|
|
156
|
+
this.lib.setColliderPosition(realmId, colliderId, pos);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
getColliderPosition(realmId, colliderId) {
|
|
160
|
+
if (this.lib && this.lib.getColliderPosition) {
|
|
161
|
+
return this.lib.getColliderPosition(realmId, colliderId);
|
|
162
|
+
}
|
|
163
|
+
return [0, 0, 0];
|
|
164
|
+
}
|
|
165
|
+
applyForce(body, force) {
|
|
166
|
+
const state = this.getBodyState(body);
|
|
167
|
+
if (!state || state.desc.type !== "dynamic")
|
|
168
|
+
return;
|
|
169
|
+
if (this.lib) {
|
|
170
|
+
this.lib.applyForce(body.realmId, body.id, force);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
applyImpulse(body, impulse) {
|
|
174
|
+
const state = this.getBodyState(body);
|
|
175
|
+
if (!state || state.desc.type !== "dynamic")
|
|
176
|
+
return;
|
|
177
|
+
state.linearVelocity[0] += impulse[0] / (state.desc.mass ?? 1);
|
|
178
|
+
state.linearVelocity[1] += impulse[1] / (state.desc.mass ?? 1);
|
|
179
|
+
state.linearVelocity[2] += impulse[2] / (state.desc.mass ?? 1);
|
|
180
|
+
if (this.lib) {
|
|
181
|
+
this.lib.applyImpulse(body.realmId, body.id, impulse);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
applyTorque(body, torque) {
|
|
185
|
+
const state = this.getBodyState(body);
|
|
186
|
+
if (!state || state.desc.type !== "dynamic")
|
|
187
|
+
return;
|
|
188
|
+
if (this.lib) {
|
|
189
|
+
this.lib.applyTorque(body.realmId, body.id, torque);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
applyTorqueImpulse(body, impulse) {
|
|
193
|
+
const state = this.getBodyState(body);
|
|
194
|
+
if (!state || state.desc.type !== "dynamic")
|
|
195
|
+
return;
|
|
196
|
+
state.angularVelocity[0] += impulse[0];
|
|
197
|
+
state.angularVelocity[1] += impulse[1];
|
|
198
|
+
state.angularVelocity[2] += impulse[2];
|
|
199
|
+
if (this.lib) {
|
|
200
|
+
this.lib.applyTorqueImpulse(body.realmId, body.id, impulse);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
applyImpulseAtPoint(body, impulse, point) {
|
|
204
|
+
const state = this.getBodyState(body);
|
|
205
|
+
if (!state || state.desc.type !== "dynamic")
|
|
206
|
+
return;
|
|
207
|
+
state.linearVelocity[0] += impulse[0] / (state.desc.mass ?? 1);
|
|
208
|
+
state.linearVelocity[1] += impulse[1] / (state.desc.mass ?? 1);
|
|
209
|
+
state.linearVelocity[2] += impulse[2] / (state.desc.mass ?? 1);
|
|
210
|
+
if (this.lib) {
|
|
211
|
+
this.lib.applyImpulseAtPoint(body.realmId, body.id, impulse, point);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
setLinearVelocity(body, vel) {
|
|
215
|
+
const state = this.getBodyState(body);
|
|
216
|
+
if (!state)
|
|
217
|
+
return;
|
|
218
|
+
state.linearVelocity = [...vel];
|
|
219
|
+
if (this.lib) {
|
|
220
|
+
this.lib.setLinearVelocity(body.realmId, body.id, vel);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
getLinearVelocity(body) {
|
|
224
|
+
const state = this.getBodyState(body);
|
|
225
|
+
return state ? [...state.linearVelocity] : [0, 0, 0];
|
|
226
|
+
}
|
|
227
|
+
setAngularVelocity(body, vel) {
|
|
228
|
+
const state = this.getBodyState(body);
|
|
229
|
+
if (!state)
|
|
230
|
+
return;
|
|
231
|
+
state.angularVelocity = [...vel];
|
|
232
|
+
if (this.lib) {
|
|
233
|
+
this.lib.setAngularVelocity(body.realmId, body.id, vel);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
getAngularVelocity(body) {
|
|
237
|
+
const state = this.getBodyState(body);
|
|
238
|
+
return state ? [...state.angularVelocity] : [0, 0, 0];
|
|
239
|
+
}
|
|
240
|
+
setPosition(body, pos) {
|
|
241
|
+
const state = this.getBodyState(body);
|
|
242
|
+
if (!state)
|
|
243
|
+
return;
|
|
244
|
+
state.position = [...pos];
|
|
245
|
+
if (this.lib) {
|
|
246
|
+
this.lib.setPosition(body.realmId, body.id, pos);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
getPosition(body) {
|
|
250
|
+
const state = this.getBodyState(body);
|
|
251
|
+
return state ? [...state.position] : [0, 0, 0];
|
|
252
|
+
}
|
|
253
|
+
setRotation(body, rot) {
|
|
254
|
+
const state = this.getBodyState(body);
|
|
255
|
+
if (!state)
|
|
256
|
+
return;
|
|
257
|
+
state.rotation = [...rot];
|
|
258
|
+
if (this.lib) {
|
|
259
|
+
this.lib.setRotation(body.realmId, body.id, rot);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
getRotation(body) {
|
|
263
|
+
const state = this.getBodyState(body);
|
|
264
|
+
return state ? [...state.rotation] : [0, 0, 0, 1];
|
|
265
|
+
}
|
|
266
|
+
wakeUp(body) {
|
|
267
|
+
const state = this.getBodyState(body);
|
|
268
|
+
if (!state)
|
|
269
|
+
return;
|
|
270
|
+
state.sleeping = false;
|
|
271
|
+
if (this.lib) {
|
|
272
|
+
this.lib.wakeUp(body.realmId, body.id);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
isSleeping(body) {
|
|
276
|
+
const state = this.getBodyState(body);
|
|
277
|
+
return state ? state.sleeping : false;
|
|
278
|
+
}
|
|
279
|
+
// --- Raw fast paths ---
|
|
280
|
+
setTranslationRaw(body, x, y, z, wakeUp) {
|
|
281
|
+
const state = this.getBodyState(body);
|
|
282
|
+
if (state) {
|
|
283
|
+
state.position[0] = x;
|
|
284
|
+
state.position[1] = y;
|
|
285
|
+
state.position[2] = z;
|
|
286
|
+
}
|
|
287
|
+
if (this.lib && this.lib.setTranslationRaw) {
|
|
288
|
+
this.lib.setTranslationRaw(body.realmId, body.id, x, y, z, wakeUp);
|
|
289
|
+
}
|
|
290
|
+
else if (this.lib) {
|
|
291
|
+
this.lib.setPosition(body.realmId, body.id, [x, y, z]);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
setRotationRaw(body, x, y, z, w, wakeUp) {
|
|
295
|
+
const state = this.getBodyState(body);
|
|
296
|
+
if (state) {
|
|
297
|
+
state.rotation[0] = x;
|
|
298
|
+
state.rotation[1] = y;
|
|
299
|
+
state.rotation[2] = z;
|
|
300
|
+
state.rotation[3] = w;
|
|
301
|
+
}
|
|
302
|
+
if (this.lib && this.lib.setRotationRaw) {
|
|
303
|
+
this.lib.setRotationRaw(body.realmId, body.id, x, y, z, w, wakeUp);
|
|
304
|
+
}
|
|
305
|
+
else if (this.lib) {
|
|
306
|
+
this.lib.setRotation(body.realmId, body.id, [x, y, z, w]);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
getTranslationRaw(body, out) {
|
|
310
|
+
if (this.lib && this.lib.getTranslationRaw) {
|
|
311
|
+
this.lib.getTranslationRaw(body.realmId, body.id, out);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
const state = this.getBodyState(body);
|
|
315
|
+
if (state) {
|
|
316
|
+
out[0] = state.position[0];
|
|
317
|
+
out[1] = state.position[1];
|
|
318
|
+
out[2] = state.position[2];
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
out[0] = 0;
|
|
322
|
+
out[1] = 0;
|
|
323
|
+
out[2] = 0;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
getRotationRaw(body, out) {
|
|
328
|
+
if (this.lib && this.lib.getRotationRaw) {
|
|
329
|
+
this.lib.getRotationRaw(body.realmId, body.id, out);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
const state = this.getBodyState(body);
|
|
333
|
+
if (state) {
|
|
334
|
+
out[0] = state.rotation[0];
|
|
335
|
+
out[1] = state.rotation[1];
|
|
336
|
+
out[2] = state.rotation[2];
|
|
337
|
+
out[3] = state.rotation[3];
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
out[0] = 0;
|
|
341
|
+
out[1] = 0;
|
|
342
|
+
out[2] = 0;
|
|
343
|
+
out[3] = 1;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
getLinearVelocityRaw(body, out) {
|
|
348
|
+
if (this.lib && this.lib.getLinearVelocityRaw) {
|
|
349
|
+
this.lib.getLinearVelocityRaw(body.realmId, body.id, out);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
const state = this.getBodyState(body);
|
|
353
|
+
if (state) {
|
|
354
|
+
out[0] = state.linearVelocity[0];
|
|
355
|
+
out[1] = state.linearVelocity[1];
|
|
356
|
+
out[2] = state.linearVelocity[2];
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
out[0] = 0;
|
|
360
|
+
out[1] = 0;
|
|
361
|
+
out[2] = 0;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
setLinearVelocityRaw(body, x, y, z, wakeUp) {
|
|
366
|
+
const state = this.getBodyState(body);
|
|
367
|
+
if (state) {
|
|
368
|
+
state.linearVelocity[0] = x;
|
|
369
|
+
state.linearVelocity[1] = y;
|
|
370
|
+
state.linearVelocity[2] = z;
|
|
371
|
+
}
|
|
372
|
+
if (this.lib && this.lib.setLinearVelocityRaw) {
|
|
373
|
+
this.lib.setLinearVelocityRaw(body.realmId, body.id, x, y, z, wakeUp);
|
|
374
|
+
}
|
|
375
|
+
else if (this.lib) {
|
|
376
|
+
this.lib.setLinearVelocity(body.realmId, body.id, [x, y, z]);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
setAngularVelocityRaw(body, x, y, z, wakeUp) {
|
|
380
|
+
const state = this.getBodyState(body);
|
|
381
|
+
if (state) {
|
|
382
|
+
state.angularVelocity[0] = x;
|
|
383
|
+
state.angularVelocity[1] = y;
|
|
384
|
+
state.angularVelocity[2] = z;
|
|
385
|
+
}
|
|
386
|
+
if (this.lib && this.lib.setAngularVelocityRaw) {
|
|
387
|
+
this.lib.setAngularVelocityRaw(body.realmId, body.id, x, y, z, wakeUp);
|
|
388
|
+
}
|
|
389
|
+
else if (this.lib) {
|
|
390
|
+
this.lib.setAngularVelocity(body.realmId, body.id, [x, y, z]);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
isSleepingRaw(body) {
|
|
394
|
+
if (this.lib && this.lib.isSleepingRaw) {
|
|
395
|
+
return this.lib.isSleepingRaw(body.realmId, body.id);
|
|
396
|
+
}
|
|
397
|
+
const state = this.getBodyState(body);
|
|
398
|
+
return state ? state.sleeping : false;
|
|
399
|
+
}
|
|
400
|
+
readAwakeBodyStates(realmId, idsOut, out, maxCount) {
|
|
401
|
+
if (this.lib?.readAwakeBodyStates) {
|
|
402
|
+
return this.lib.readAwakeBodyStates(realmId, idsOut, out, maxCount);
|
|
403
|
+
}
|
|
404
|
+
const realm = this.realms.get(realmId);
|
|
405
|
+
if (!realm)
|
|
406
|
+
return 0;
|
|
407
|
+
let n = 0;
|
|
408
|
+
for (const [bodyId, b] of realm.bodies.entries()) {
|
|
409
|
+
if (n >= maxCount)
|
|
410
|
+
break;
|
|
411
|
+
if (b.sleeping || b.desc.type !== "dynamic")
|
|
412
|
+
continue;
|
|
413
|
+
const o = n * 10;
|
|
414
|
+
out[o] = b.position[0];
|
|
415
|
+
out[o + 1] = b.position[1];
|
|
416
|
+
out[o + 2] = b.position[2];
|
|
417
|
+
out[o + 3] = b.rotation[0];
|
|
418
|
+
out[o + 4] = b.rotation[1];
|
|
419
|
+
out[o + 5] = b.rotation[2];
|
|
420
|
+
out[o + 6] = b.rotation[3];
|
|
421
|
+
out[o + 7] = b.linearVelocity[0];
|
|
422
|
+
out[o + 8] = b.linearVelocity[1];
|
|
423
|
+
out[o + 9] = b.linearVelocity[2];
|
|
424
|
+
idsOut[n] = bodyId;
|
|
425
|
+
n++;
|
|
426
|
+
}
|
|
427
|
+
return n;
|
|
428
|
+
}
|
|
429
|
+
swapColliderShapeRaw(realmId, colliderId, vertices, indices) {
|
|
430
|
+
if (this.lib && this.lib.swapColliderShapeRaw) {
|
|
431
|
+
return this.lib.swapColliderShapeRaw(realmId, colliderId, vertices, indices);
|
|
432
|
+
}
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
reserveMemory(bytes) {
|
|
436
|
+
if (this.lib && this.lib.reserveMemory) {
|
|
437
|
+
this.lib.reserveMemory(bytes);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
setIntegrationDt(realmId, dt) {
|
|
441
|
+
if (this.lib && this.lib.setIntegrationDt) {
|
|
442
|
+
this.lib.setIntegrationDt(realmId, dt);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
setSleepThresholds(realmId, linearThreshold, angularThreshold) {
|
|
446
|
+
if (this.lib) {
|
|
447
|
+
this.lib.setSleepThresholds(realmId, linearThreshold, angularThreshold);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
setSolverIterations(realmId, iterations) {
|
|
451
|
+
if (this.lib) {
|
|
452
|
+
this.lib.setSolverIterations(realmId, iterations);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
setMinIslandSize(realmId, size) {
|
|
456
|
+
if (this.lib && this.lib.setMinIslandSize) {
|
|
457
|
+
this.lib.setMinIslandSize(realmId, size);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
setCCDEnabled(body, enabled) {
|
|
461
|
+
if (this.lib) {
|
|
462
|
+
this.lib.setCCDEnabled(body.realmId, body.id, enabled);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
raycast(realmId, origin, direction, maxDistance, filter) {
|
|
466
|
+
if (this.lib) {
|
|
467
|
+
return this.lib.raycast(realmId, origin, direction, maxDistance, filter);
|
|
468
|
+
}
|
|
469
|
+
const realm = this.realms.get(realmId);
|
|
470
|
+
if (!realm)
|
|
471
|
+
return null;
|
|
472
|
+
let closest = null;
|
|
473
|
+
let closestDist = maxDistance;
|
|
474
|
+
for (const [, b] of realm.bodies.entries()) {
|
|
475
|
+
if (filter?.excludeEntity && b.body.entity.index === filter.excludeEntity.index)
|
|
476
|
+
continue;
|
|
477
|
+
for (const collider of b.colliders.values()) {
|
|
478
|
+
const hit = raycastCollider(origin, direction, maxDistance, b.position, collider.shape);
|
|
479
|
+
if (hit && hit.distance < closestDist) {
|
|
480
|
+
closestDist = hit.distance;
|
|
481
|
+
closest = {
|
|
482
|
+
entity: b.body.entity,
|
|
483
|
+
point: hit.point,
|
|
484
|
+
normal: hit.normal,
|
|
485
|
+
distance: hit.distance,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return closest;
|
|
491
|
+
}
|
|
492
|
+
raycastMulti(realmId, origin, direction, maxDistance, filter) {
|
|
493
|
+
const results = [];
|
|
494
|
+
if (this.lib) {
|
|
495
|
+
return this.lib.raycastMulti(realmId, origin, direction, maxDistance, filter);
|
|
496
|
+
}
|
|
497
|
+
const realm = this.realms.get(realmId);
|
|
498
|
+
if (!realm)
|
|
499
|
+
return [];
|
|
500
|
+
for (const [, b] of realm.bodies.entries()) {
|
|
501
|
+
if (filter?.excludeEntity && b.body.entity.index === filter.excludeEntity.index)
|
|
502
|
+
continue;
|
|
503
|
+
for (const collider of b.colliders.values()) {
|
|
504
|
+
const hit = raycastCollider(origin, direction, maxDistance, b.position, collider.shape);
|
|
505
|
+
if (hit) {
|
|
506
|
+
results.push({
|
|
507
|
+
entity: b.body.entity,
|
|
508
|
+
point: hit.point,
|
|
509
|
+
normal: hit.normal,
|
|
510
|
+
distance: hit.distance,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return results.sort((a, b) => a.distance - b.distance);
|
|
516
|
+
}
|
|
517
|
+
shapeCast(realmId, shape, origin, rotation, direction, maxDistance, filter) {
|
|
518
|
+
if (this.lib) {
|
|
519
|
+
return this.lib.shapeCast(realmId, shape, origin, rotation, direction, maxDistance, filter);
|
|
520
|
+
}
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
step(realmId, dt) {
|
|
524
|
+
const realm = this.realms.get(realmId);
|
|
525
|
+
if (!realm)
|
|
526
|
+
return;
|
|
527
|
+
if (this.lib) {
|
|
528
|
+
if (this.readBackTransformsOnStep && this.lib.readAwakeBodyStates && realm.bodies.size > 0) {
|
|
529
|
+
// Batched readback: one lib call for the whole awake set instead of a
|
|
530
|
+
// per-body getBodyTransform round trip. Sleeping bodies don't move, so
|
|
531
|
+
// the JS cache keeps last-synced values for them.
|
|
532
|
+
const cap = realm.bodies.size;
|
|
533
|
+
if (realm.readbackIds.length < cap) {
|
|
534
|
+
realm.readbackIds = new Uint32Array(cap);
|
|
535
|
+
realm.readbackStates = new Float32Array(cap * 10);
|
|
536
|
+
}
|
|
537
|
+
const n = this.lib.stepAndReadAwake
|
|
538
|
+
? this.lib.stepAndReadAwake(realmId, dt, realm.readbackIds, realm.readbackStates, cap)
|
|
539
|
+
: (this.lib.step(realmId, dt),
|
|
540
|
+
this.lib.readAwakeBodyStates(realmId, realm.readbackIds, realm.readbackStates, cap));
|
|
541
|
+
for (let i = 0; i < n; i++) {
|
|
542
|
+
const b = realm.bodies.get(realm.readbackIds[i]);
|
|
543
|
+
if (!b)
|
|
544
|
+
continue;
|
|
545
|
+
const o = i * 10;
|
|
546
|
+
b.position[0] = realm.readbackStates[o];
|
|
547
|
+
b.position[1] = realm.readbackStates[o + 1];
|
|
548
|
+
b.position[2] = realm.readbackStates[o + 2];
|
|
549
|
+
b.rotation[0] = realm.readbackStates[o + 3];
|
|
550
|
+
b.rotation[1] = realm.readbackStates[o + 4];
|
|
551
|
+
b.rotation[2] = realm.readbackStates[o + 5];
|
|
552
|
+
b.rotation[3] = realm.readbackStates[o + 6];
|
|
553
|
+
b.linearVelocity[0] = realm.readbackStates[o + 7];
|
|
554
|
+
b.linearVelocity[1] = realm.readbackStates[o + 8];
|
|
555
|
+
b.linearVelocity[2] = realm.readbackStates[o + 9];
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
this.lib.step(realmId, dt);
|
|
560
|
+
if (this.readBackTransformsOnStep)
|
|
561
|
+
this.readBackTransforms(realm);
|
|
562
|
+
}
|
|
563
|
+
if (this.extractContacts) {
|
|
564
|
+
realm.contacts = this.lib.getContacts(realmId);
|
|
565
|
+
realm.intersections = this.lib.getIntersections(realmId);
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
realm.contacts.length = 0;
|
|
569
|
+
realm.intersections.length = 0;
|
|
570
|
+
}
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
this.stepFallback(realm, dt);
|
|
574
|
+
}
|
|
575
|
+
stepAll(dt) {
|
|
576
|
+
this.realmIds.forEach((realmId) => {
|
|
577
|
+
this.step(realmId, dt);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
getContacts(realmId) {
|
|
581
|
+
const realm = this.realms.get(realmId);
|
|
582
|
+
return realm ? realm.contacts : [];
|
|
583
|
+
}
|
|
584
|
+
getIntersections(realmId) {
|
|
585
|
+
const realm = this.realms.get(realmId);
|
|
586
|
+
return realm ? realm.intersections : [];
|
|
587
|
+
}
|
|
588
|
+
getIslands(realmId) {
|
|
589
|
+
if (this.lib) {
|
|
590
|
+
return this.lib.getIslands(realmId);
|
|
591
|
+
}
|
|
592
|
+
// Fallback: each body is its own island
|
|
593
|
+
const realm = this.realms.get(realmId);
|
|
594
|
+
if (!realm)
|
|
595
|
+
return [];
|
|
596
|
+
const islands = [];
|
|
597
|
+
for (const [bodyId, b] of realm.bodies.entries()) {
|
|
598
|
+
const speed = Math.sqrt(b.linearVelocity[0] ** 2 + b.linearVelocity[1] ** 2 + b.linearVelocity[2] ** 2);
|
|
599
|
+
islands.push({ bodyIds: [bodyId], maxImportance: 0, avgVelocity: speed });
|
|
600
|
+
}
|
|
601
|
+
return islands;
|
|
602
|
+
}
|
|
603
|
+
createCharacterController(realmId, desc, entity) {
|
|
604
|
+
const realm = this.realms.get(realmId);
|
|
605
|
+
if (!realm)
|
|
606
|
+
throw new Error(`Realm ${realmId} not found`);
|
|
607
|
+
const controllerId = realm.nextControllerId++;
|
|
608
|
+
const handle = { realmId, controllerId, entity };
|
|
609
|
+
if (this.lib) {
|
|
610
|
+
this.lib.createCharacterController(realmId, desc, handle);
|
|
611
|
+
}
|
|
612
|
+
return handle;
|
|
613
|
+
}
|
|
614
|
+
destroyCharacterController(handle) {
|
|
615
|
+
if (this.lib) {
|
|
616
|
+
this.lib.destroyCharacterController(handle.realmId, handle.controllerId);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
characterMove(handle, desiredMovement, dt) {
|
|
620
|
+
if (this.lib) {
|
|
621
|
+
return this.lib.characterMove(handle.realmId, handle.controllerId, desiredMovement, dt);
|
|
622
|
+
}
|
|
623
|
+
return this.characterMoveFallback(handle, desiredMovement, dt);
|
|
624
|
+
}
|
|
625
|
+
setCharacterColliderPosition(handle, pos) {
|
|
626
|
+
if (this.lib && this.lib.setCharacterColliderPosition) {
|
|
627
|
+
this.lib.setCharacterColliderPosition(handle.realmId, handle.controllerId, pos);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
createJoint(realmId, parentBody, childBody, desc) {
|
|
631
|
+
const realm = this.realms.get(realmId);
|
|
632
|
+
if (!realm)
|
|
633
|
+
throw new Error(`Realm ${realmId} not found`);
|
|
634
|
+
const jointId = realm.nextJointId++;
|
|
635
|
+
if (this.lib) {
|
|
636
|
+
this.lib.createJoint(realmId, parentBody.id, childBody.id, jointId, desc);
|
|
637
|
+
}
|
|
638
|
+
return jointId;
|
|
639
|
+
}
|
|
640
|
+
destroyJoint(realmId, jointId) {
|
|
641
|
+
if (this.lib) {
|
|
642
|
+
this.lib.destroyJoint(realmId, jointId);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
syncTransforms(realmId, transformBuffer, entityCount) {
|
|
646
|
+
const realm = this.realms.get(realmId);
|
|
647
|
+
if (!realm)
|
|
648
|
+
return;
|
|
649
|
+
for (const [, b] of realm.bodies.entries()) {
|
|
650
|
+
const idx = b.body.entity.index;
|
|
651
|
+
if (idx < entityCount) {
|
|
652
|
+
const offset = idx * 8;
|
|
653
|
+
b.position[0] = transformBuffer[offset];
|
|
654
|
+
b.position[1] = transformBuffer[offset + 1];
|
|
655
|
+
b.position[2] = transformBuffer[offset + 2];
|
|
656
|
+
b.rotation[0] = transformBuffer[offset + 3];
|
|
657
|
+
b.rotation[1] = transformBuffer[offset + 4];
|
|
658
|
+
b.rotation[2] = transformBuffer[offset + 5];
|
|
659
|
+
b.rotation[3] = transformBuffer[offset + 6];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
readTransforms(realmId, transformBuffer, entityCount) {
|
|
664
|
+
const realm = this.realms.get(realmId);
|
|
665
|
+
if (!realm)
|
|
666
|
+
return;
|
|
667
|
+
for (const [, b] of realm.bodies.entries()) {
|
|
668
|
+
const idx = b.body.entity.index;
|
|
669
|
+
if (idx < entityCount) {
|
|
670
|
+
const offset = idx * 8;
|
|
671
|
+
transformBuffer[offset] = b.position[0];
|
|
672
|
+
transformBuffer[offset + 1] = b.position[1];
|
|
673
|
+
transformBuffer[offset + 2] = b.position[2];
|
|
674
|
+
transformBuffer[offset + 3] = b.rotation[0];
|
|
675
|
+
transformBuffer[offset + 4] = b.rotation[1];
|
|
676
|
+
transformBuffer[offset + 5] = b.rotation[2];
|
|
677
|
+
transformBuffer[offset + 6] = b.rotation[3];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
serializeRealm(realmId) {
|
|
682
|
+
if (this.lib) {
|
|
683
|
+
return this.lib.serializeRealm(realmId);
|
|
684
|
+
}
|
|
685
|
+
return new Uint8Array(0);
|
|
686
|
+
}
|
|
687
|
+
deserializeRealm(realmId, data) {
|
|
688
|
+
if (this.lib) {
|
|
689
|
+
this.lib.deserializeRealm(realmId, data);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
destroy() {
|
|
693
|
+
if (this.destroyed)
|
|
694
|
+
return;
|
|
695
|
+
this.destroyed = true;
|
|
696
|
+
if (this.lib) {
|
|
697
|
+
// Only destroy this backend's realms — do NOT call this.lib.destroy(),
|
|
698
|
+
// which would clear the shared lib's closure maps for ALL backends
|
|
699
|
+
// (the lib is a process-wide singleton via cachedLib).
|
|
700
|
+
for (let _i26137 = 0, _it26137 = this.realmIds, _n26137 = _it26137.length; _i26137 < _n26137; _i26137++) {
|
|
701
|
+
const realmId = _it26137[_i26137];
|
|
702
|
+
this.lib.destroyRealm(realmId);
|
|
703
|
+
}
|
|
704
|
+
;
|
|
705
|
+
}
|
|
706
|
+
this.realms.clear();
|
|
707
|
+
this.realmIds = [];
|
|
708
|
+
}
|
|
709
|
+
getBodyState(body) {
|
|
710
|
+
const realm = this.realms.get(body.realmId);
|
|
711
|
+
return realm?.bodies.get(body.id);
|
|
712
|
+
}
|
|
713
|
+
characterMoveFallback(handle, desiredMovement, dt) {
|
|
714
|
+
const realm = this.realms.get(handle.realmId);
|
|
715
|
+
if (!realm) {
|
|
716
|
+
return { grounded: false, groundNormal: [0, 1, 0], groundEntity: null, slid: false, stepped: false, effectiveMovement: [0, 0, 0], collisions: [] };
|
|
717
|
+
}
|
|
718
|
+
// Find the body associated with this character controller's entity
|
|
719
|
+
let body = null;
|
|
720
|
+
for (const b of realm.bodies.values()) {
|
|
721
|
+
if (b.body.entity.index === handle.entity.index) {
|
|
722
|
+
body = b;
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (!body) {
|
|
727
|
+
return { grounded: false, groundNormal: [0, 1, 0], groundEntity: null, slid: false, stepped: false, effectiveMovement: [0, 0, 0], collisions: [] };
|
|
728
|
+
}
|
|
729
|
+
const desired = [...desiredMovement];
|
|
730
|
+
let effective = [...desired];
|
|
731
|
+
let slid = false;
|
|
732
|
+
let stepped = false;
|
|
733
|
+
const groundRay = this.raycast(handle.realmId, body.position, [0, -1, 0], 1.2);
|
|
734
|
+
const grounded = groundRay !== null && groundRay.distance <= 1.0;
|
|
735
|
+
const groundNormal = groundRay ? groundRay.normal : [0, 1, 0];
|
|
736
|
+
const groundEntity = groundRay ? groundRay.entity : null;
|
|
737
|
+
if (grounded) {
|
|
738
|
+
const slopeDot = groundNormal[1];
|
|
739
|
+
const maxSlopeCos = Math.cos(Math.PI / 3);
|
|
740
|
+
if (slopeDot < maxSlopeCos) {
|
|
741
|
+
const slideDir = [
|
|
742
|
+
groundNormal[0] * (1 - slopeDot),
|
|
743
|
+
groundNormal[1] * (1 - slopeDot) - 1,
|
|
744
|
+
groundNormal[2] * (1 - slopeDot),
|
|
745
|
+
];
|
|
746
|
+
const slideLen = Math.sqrt(slideDir[0] ** 2 + slideDir[1] ** 2 + slideDir[2] ** 2);
|
|
747
|
+
if (slideLen > 1e-6) {
|
|
748
|
+
effective[0] = slideDir[0] / slideLen * Math.abs(desired[1]) * 0.5;
|
|
749
|
+
effective[1] = slideDir[1] / slideLen * Math.abs(desired[1]) * 0.5;
|
|
750
|
+
effective[2] = slideDir[2] / slideLen * Math.abs(desired[1]) * 0.5;
|
|
751
|
+
slid = true;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
const wallRay = this.raycast(handle.realmId, body.position, [desired[0], 0, desired[2]], 0.6);
|
|
756
|
+
if (wallRay && wallRay.distance < 0.5) {
|
|
757
|
+
const wallNormal = wallRay.normal;
|
|
758
|
+
const dot = effective[0] * wallNormal[0] + effective[2] * wallNormal[2];
|
|
759
|
+
if (dot < 0) {
|
|
760
|
+
effective[0] -= dot * wallNormal[0];
|
|
761
|
+
effective[2] -= dot * wallNormal[2];
|
|
762
|
+
slid = true;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
body.position[0] += effective[0] * dt;
|
|
766
|
+
body.position[1] += effective[1] * dt;
|
|
767
|
+
body.position[2] += effective[2] * dt;
|
|
768
|
+
return { grounded, groundNormal, groundEntity, slid, stepped, effectiveMovement: effective, collisions: [] };
|
|
769
|
+
}
|
|
770
|
+
readBackTransforms(realm) {
|
|
771
|
+
if (!this.lib)
|
|
772
|
+
return;
|
|
773
|
+
for (const [bodyId, b] of realm.bodies.entries()) {
|
|
774
|
+
const transform = this.lib.getBodyTransform(realm.id, bodyId);
|
|
775
|
+
if (transform) {
|
|
776
|
+
b.position = transform.position;
|
|
777
|
+
b.rotation = transform.rotation;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
stepFallback(realm, dt) {
|
|
782
|
+
const gravity = realm.config.gravity;
|
|
783
|
+
for (const [, b] of realm.bodies.entries()) {
|
|
784
|
+
if (b.desc.type !== "dynamic" || b.sleeping)
|
|
785
|
+
continue;
|
|
786
|
+
b.linearVelocity[0] += gravity[0] * (b.desc.gravityScale ?? 1) * dt;
|
|
787
|
+
b.linearVelocity[1] += gravity[1] * (b.desc.gravityScale ?? 1) * dt;
|
|
788
|
+
b.linearVelocity[2] += gravity[2] * (b.desc.gravityScale ?? 1) * dt;
|
|
789
|
+
const damping = b.desc.linearDamping ?? 0;
|
|
790
|
+
const dampFactor = Math.max(0, 1 - damping * dt);
|
|
791
|
+
b.linearVelocity[0] *= dampFactor;
|
|
792
|
+
b.linearVelocity[1] *= dampFactor;
|
|
793
|
+
b.linearVelocity[2] *= dampFactor;
|
|
794
|
+
const angDamping = b.desc.angularDamping ?? 0;
|
|
795
|
+
const angDampFactor = Math.max(0, 1 - angDamping * dt);
|
|
796
|
+
b.angularVelocity[0] *= angDampFactor;
|
|
797
|
+
b.angularVelocity[1] *= angDampFactor;
|
|
798
|
+
b.angularVelocity[2] *= angDampFactor;
|
|
799
|
+
b.position[0] += b.linearVelocity[0] * dt;
|
|
800
|
+
b.position[1] += b.linearVelocity[1] * dt;
|
|
801
|
+
b.position[2] += b.linearVelocity[2] * dt;
|
|
802
|
+
integrateRotation(b.rotation, b.angularVelocity, dt);
|
|
803
|
+
}
|
|
804
|
+
realm.contacts = this.detectContacts(realm);
|
|
805
|
+
realm.intersections = this.detectIntersections(realm);
|
|
806
|
+
}
|
|
807
|
+
detectContacts(realm) {
|
|
808
|
+
const contacts = [];
|
|
809
|
+
const bodies = [...realm.bodies.values()];
|
|
810
|
+
for (let i = 0; i < bodies.length; i++) {
|
|
811
|
+
for (let j = i + 1; j < bodies.length; j++) {
|
|
812
|
+
const a = bodies[i];
|
|
813
|
+
const b = bodies[j];
|
|
814
|
+
for (const colA of a.colliders.values()) {
|
|
815
|
+
if (colA.sensor)
|
|
816
|
+
continue;
|
|
817
|
+
for (const colB of b.colliders.values()) {
|
|
818
|
+
if (colB.sensor)
|
|
819
|
+
continue;
|
|
820
|
+
const contact = checkColliderCollision(a.position, colA.shape, b.position, colB.shape);
|
|
821
|
+
if (contact) {
|
|
822
|
+
contacts.push({
|
|
823
|
+
entityA: a.body.entity,
|
|
824
|
+
entityB: b.body.entity,
|
|
825
|
+
normal: contact.normal,
|
|
826
|
+
points: [contact.point],
|
|
827
|
+
penetrationDepth: contact.penetration,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
return contacts;
|
|
835
|
+
}
|
|
836
|
+
detectIntersections(realm) {
|
|
837
|
+
const intersections = [];
|
|
838
|
+
const bodies = [...realm.bodies.values()];
|
|
839
|
+
for (let i = 0; i < bodies.length; i++) {
|
|
840
|
+
for (let j = i + 1; j < bodies.length; j++) {
|
|
841
|
+
const a = bodies[i];
|
|
842
|
+
const b = bodies[j];
|
|
843
|
+
for (const colA of a.colliders.values()) {
|
|
844
|
+
for (const colB of b.colliders.values()) {
|
|
845
|
+
// Only report pairs where at least one collider is a sensor
|
|
846
|
+
if (!colA.sensor && !colB.sensor)
|
|
847
|
+
continue;
|
|
848
|
+
const contact = checkColliderCollision(a.position, colA.shape, b.position, colB.shape);
|
|
849
|
+
if (contact) {
|
|
850
|
+
intersections.push({
|
|
851
|
+
entityA: a.body.entity,
|
|
852
|
+
entityB: b.body.entity,
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return intersections;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function integrateRotation(rot, angularVel, dt) {
|
|
863
|
+
const ax = angularVel[0] * dt * 0.5;
|
|
864
|
+
const ay = angularVel[1] * dt * 0.5;
|
|
865
|
+
const az = angularVel[2] * dt * 0.5;
|
|
866
|
+
const dq = [ax, ay, az, 1];
|
|
867
|
+
const len = Math.sqrt(dq[0] ** 2 + dq[1] ** 2 + dq[2] ** 2 + dq[3] ** 2);
|
|
868
|
+
if (len > 1e-9) {
|
|
869
|
+
dq[0] /= len;
|
|
870
|
+
dq[1] /= len;
|
|
871
|
+
dq[2] /= len;
|
|
872
|
+
dq[3] /= len;
|
|
873
|
+
}
|
|
874
|
+
const result = multiplyQuat(rot, dq);
|
|
875
|
+
rot[0] = result[0];
|
|
876
|
+
rot[1] = result[1];
|
|
877
|
+
rot[2] = result[2];
|
|
878
|
+
rot[3] = result[3];
|
|
879
|
+
}
|
|
880
|
+
function multiplyQuat(a, b) {
|
|
881
|
+
return [
|
|
882
|
+
a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],
|
|
883
|
+
a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0],
|
|
884
|
+
a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3],
|
|
885
|
+
a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],
|
|
886
|
+
];
|
|
887
|
+
}
|
|
888
|
+
function raycastCollider(origin, direction, maxDistance, bodyPos, shape) {
|
|
889
|
+
if (shape.type === "sphere") {
|
|
890
|
+
return raycastSphere(origin, direction, maxDistance, bodyPos, shape.radius);
|
|
891
|
+
}
|
|
892
|
+
if (shape.type === "box") {
|
|
893
|
+
return raycastBox(origin, direction, maxDistance, bodyPos, shape.halfExtents);
|
|
894
|
+
}
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
function raycastSphere(origin, dir, maxDist, center, radius) {
|
|
898
|
+
const ox = origin[0] - center[0];
|
|
899
|
+
const oy = origin[1] - center[1];
|
|
900
|
+
const oz = origin[2] - center[2];
|
|
901
|
+
const b = ox * dir[0] + oy * dir[1] + oz * dir[2];
|
|
902
|
+
const c = ox * ox + oy * oy + oz * oz - radius * radius;
|
|
903
|
+
const disc = b * b - c;
|
|
904
|
+
if (disc < 0)
|
|
905
|
+
return null;
|
|
906
|
+
const t = -b - Math.sqrt(disc);
|
|
907
|
+
if (t < 0 || t > maxDist)
|
|
908
|
+
return null;
|
|
909
|
+
const point = [
|
|
910
|
+
origin[0] + dir[0] * t,
|
|
911
|
+
origin[1] + dir[1] * t,
|
|
912
|
+
origin[2] + dir[2] * t,
|
|
913
|
+
];
|
|
914
|
+
const normal = [
|
|
915
|
+
(point[0] - center[0]) / radius,
|
|
916
|
+
(point[1] - center[1]) / radius,
|
|
917
|
+
(point[2] - center[2]) / radius,
|
|
918
|
+
];
|
|
919
|
+
return { point, normal, distance: t };
|
|
920
|
+
}
|
|
921
|
+
function raycastBox(origin, dir, maxDist, center, halfExtents) {
|
|
922
|
+
let tmin = 0;
|
|
923
|
+
let tmax = maxDist;
|
|
924
|
+
for (let i = 0; i < 3; i++) {
|
|
925
|
+
const o = origin[i] - center[i];
|
|
926
|
+
const d = dir[i];
|
|
927
|
+
const half = halfExtents[i];
|
|
928
|
+
if (Math.abs(d) < 1e-9) {
|
|
929
|
+
if (Math.abs(o) > half)
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
let t1 = (-half - o) / d;
|
|
934
|
+
let t2 = (half - o) / d;
|
|
935
|
+
if (t1 > t2) {
|
|
936
|
+
const tmp = t1;
|
|
937
|
+
t1 = t2;
|
|
938
|
+
t2 = tmp;
|
|
939
|
+
}
|
|
940
|
+
tmin = Math.max(tmin, t1);
|
|
941
|
+
tmax = Math.min(tmax, t2);
|
|
942
|
+
if (tmin > tmax)
|
|
943
|
+
return null;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
const t = tmin;
|
|
947
|
+
const point = [
|
|
948
|
+
origin[0] + dir[0] * t,
|
|
949
|
+
origin[1] + dir[1] * t,
|
|
950
|
+
origin[2] + dir[2] * t,
|
|
951
|
+
];
|
|
952
|
+
const rel = [
|
|
953
|
+
point[0] - center[0],
|
|
954
|
+
point[1] - center[1],
|
|
955
|
+
point[2] - center[2],
|
|
956
|
+
];
|
|
957
|
+
const nx = rel[0] / halfExtents[0];
|
|
958
|
+
const ny = rel[1] / halfExtents[1];
|
|
959
|
+
const nz = rel[2] / halfExtents[2];
|
|
960
|
+
const ax = Math.abs(nx);
|
|
961
|
+
const ay = Math.abs(ny);
|
|
962
|
+
const az = Math.abs(nz);
|
|
963
|
+
let normal;
|
|
964
|
+
if (ax >= ay && ax >= az)
|
|
965
|
+
normal = [Math.sign(nx), 0, 0];
|
|
966
|
+
else if (ay >= ax && ay >= az)
|
|
967
|
+
normal = [0, Math.sign(ny), 0];
|
|
968
|
+
else
|
|
969
|
+
normal = [0, 0, Math.sign(nz)];
|
|
970
|
+
return { point, normal, distance: t };
|
|
971
|
+
}
|
|
972
|
+
function checkColliderCollision(posA, shapeA, posB, shapeB) {
|
|
973
|
+
if (shapeA.type === "sphere" && shapeB.type === "sphere") {
|
|
974
|
+
return sphereSphere(posA, shapeA.radius, posB, shapeB.radius);
|
|
975
|
+
}
|
|
976
|
+
if (shapeA.type === "box" && shapeB.type === "box") {
|
|
977
|
+
return aabbAabb(posA, shapeA.halfExtents, posB, shapeB.halfExtents);
|
|
978
|
+
}
|
|
979
|
+
if (shapeA.type === "sphere" && shapeB.type === "box") {
|
|
980
|
+
return sphereAabb(posA, shapeA.radius, posB, shapeB.halfExtents);
|
|
981
|
+
}
|
|
982
|
+
if (shapeA.type === "box" && shapeB.type === "sphere") {
|
|
983
|
+
const result = sphereAabb(posB, shapeB.radius, posA, shapeA.halfExtents);
|
|
984
|
+
if (result) {
|
|
985
|
+
result.normal = [-result.normal[0], -result.normal[1], -result.normal[2]];
|
|
986
|
+
}
|
|
987
|
+
return result;
|
|
988
|
+
}
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
function sphereSphere(posA, rA, posB, rB) {
|
|
992
|
+
const dx = posB[0] - posA[0];
|
|
993
|
+
const dy = posB[1] - posA[1];
|
|
994
|
+
const dz = posB[2] - posA[2];
|
|
995
|
+
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
996
|
+
const sumR = rA + rB;
|
|
997
|
+
if (dist >= sumR)
|
|
998
|
+
return null;
|
|
999
|
+
const penetration = sumR - dist;
|
|
1000
|
+
const normal = dist > 1e-9
|
|
1001
|
+
? [dx / dist, dy / dist, dz / dist]
|
|
1002
|
+
: [0, 1, 0];
|
|
1003
|
+
const point = [
|
|
1004
|
+
posA[0] + normal[0] * rA,
|
|
1005
|
+
posA[1] + normal[1] * rA,
|
|
1006
|
+
posA[2] + normal[2] * rA,
|
|
1007
|
+
];
|
|
1008
|
+
return { normal, point, penetration };
|
|
1009
|
+
}
|
|
1010
|
+
function aabbAabb(posA, halfA, posB, halfB) {
|
|
1011
|
+
const dx = posB[0] - posA[0];
|
|
1012
|
+
const px = halfA[0] + halfB[0] - Math.abs(dx);
|
|
1013
|
+
if (px <= 0)
|
|
1014
|
+
return null;
|
|
1015
|
+
const dy = posB[1] - posA[1];
|
|
1016
|
+
const py = halfA[1] + halfB[1] - Math.abs(dy);
|
|
1017
|
+
if (py <= 0)
|
|
1018
|
+
return null;
|
|
1019
|
+
const dz = posB[2] - posA[2];
|
|
1020
|
+
const pz = halfA[2] + halfB[2] - Math.abs(dz);
|
|
1021
|
+
if (pz <= 0)
|
|
1022
|
+
return null;
|
|
1023
|
+
if (px < py && px < pz) {
|
|
1024
|
+
const nx = dx < 0 ? -1 : 1;
|
|
1025
|
+
return {
|
|
1026
|
+
normal: [nx, 0, 0],
|
|
1027
|
+
point: [posA[0] + nx * halfA[0], posA[1], posA[2]],
|
|
1028
|
+
penetration: px,
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
else if (py < pz) {
|
|
1032
|
+
const ny = dy < 0 ? -1 : 1;
|
|
1033
|
+
return {
|
|
1034
|
+
normal: [0, ny, 0],
|
|
1035
|
+
point: [posA[0], posA[1] + ny * halfA[1], posA[2]],
|
|
1036
|
+
penetration: py,
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
const nz = dz < 0 ? -1 : 1;
|
|
1041
|
+
return {
|
|
1042
|
+
normal: [0, 0, nz],
|
|
1043
|
+
point: [posA[0], posA[1], posA[2] + nz * halfA[2]],
|
|
1044
|
+
penetration: pz,
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function sphereAabb(spherePos, radius, boxPos, halfExtents) {
|
|
1049
|
+
const closest = [
|
|
1050
|
+
Math.max(boxPos[0] - halfExtents[0], Math.min(spherePos[0], boxPos[0] + halfExtents[0])),
|
|
1051
|
+
Math.max(boxPos[1] - halfExtents[1], Math.min(spherePos[1], boxPos[1] + halfExtents[1])),
|
|
1052
|
+
Math.max(boxPos[2] - halfExtents[2], Math.min(spherePos[2], boxPos[2] + halfExtents[2])),
|
|
1053
|
+
];
|
|
1054
|
+
const dx = spherePos[0] - closest[0];
|
|
1055
|
+
const dy = spherePos[1] - closest[1];
|
|
1056
|
+
const dz = spherePos[2] - closest[2];
|
|
1057
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
1058
|
+
if (distSq >= radius * radius)
|
|
1059
|
+
return null;
|
|
1060
|
+
const dist = Math.sqrt(distSq);
|
|
1061
|
+
const penetration = radius - dist;
|
|
1062
|
+
const normal = dist > 1e-9
|
|
1063
|
+
? [dx / dist, dy / dist, dz / dist]
|
|
1064
|
+
: [0, 1, 0];
|
|
1065
|
+
return { normal, point: closest, penetration };
|
|
1066
|
+
}
|