@luma.gl/engine 10.0.0-alpha.3 → 10.0.0-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/README.md +9 -0
- package/dist/animation/animation-clip.cjs +36 -0
- package/dist/animation/animation-interpolation.cjs +115 -0
- package/dist/animation/animation-mixer.cjs +302 -0
- package/dist/animation/animation-track.cjs +55 -0
- package/dist/animation/animator.cjs +75 -0
- package/dist/animation/deform-positions.cjs +69 -0
- package/dist/animation/deform-positions.d.ts +13 -0
- package/dist/animation/deform-positions.d.ts.map +1 -0
- package/dist/animation/deform-positions.js +49 -0
- package/dist/animation/deform-positions.js.map +1 -0
- package/dist/animation/key-frames.cjs +81 -0
- package/dist/animation/morph-targets.cjs +162 -0
- package/dist/animation/node-animation-binding.cjs +67 -0
- package/dist/animation/node-animation-binding.d.ts +9 -0
- package/dist/animation/node-animation-binding.d.ts.map +1 -0
- package/dist/animation/node-animation-binding.js +45 -0
- package/dist/animation/node-animation-binding.js.map +1 -0
- package/dist/animation/property-animation-binding.cjs +159 -0
- package/dist/animation/property-animation-binding.d.ts +29 -0
- package/dist/animation/property-animation-binding.d.ts.map +1 -0
- package/dist/animation/property-animation-binding.js +138 -0
- package/dist/animation/property-animation-binding.js.map +1 -0
- package/dist/animation/scenegraph-animator.cjs +122 -0
- package/dist/animation/scenegraph-animator.d.ts +37 -0
- package/dist/animation/scenegraph-animator.d.ts.map +1 -0
- package/dist/animation/scenegraph-animator.js +99 -0
- package/dist/animation/scenegraph-animator.js.map +1 -0
- package/dist/animation/skin.cjs +49 -0
- package/dist/animation/texture-transform.cjs +41 -0
- package/dist/animation/texture-transform.d.ts +8 -0
- package/dist/animation/texture-transform.d.ts.map +1 -0
- package/dist/animation/texture-transform.js +17 -0
- package/dist/animation/texture-transform.js.map +1 -0
- package/dist/animation/timeline.cjs +129 -0
- package/dist/animation-loop/animation-loop-template.cjs +33 -0
- package/dist/animation-loop/animation-loop.cjs +498 -0
- package/dist/animation-loop/animation-loop.d.ts +2 -1
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +9 -3
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.cjs +15 -0
- package/dist/animation-loop/make-animation-loop.cjs +104 -0
- package/dist/animation-loop/request-animation-frame.cjs +43 -0
- package/dist/application-utils/load-file.cjs +77 -0
- package/dist/application-utils/random.cjs +38 -0
- package/dist/audio/audio-controller.cjs +429 -0
- package/dist/audio/audio-controller.d.ts +146 -0
- package/dist/audio/audio-controller.d.ts.map +1 -0
- package/dist/audio/audio-controller.js +445 -0
- package/dist/audio/audio-controller.js.map +1 -0
- package/dist/audio/audio-environment.cjs +157 -0
- package/dist/audio/audio-environment.d.ts +49 -0
- package/dist/audio/audio-environment.d.ts.map +1 -0
- package/dist/audio/audio-environment.js +148 -0
- package/dist/audio/audio-environment.js.map +1 -0
- package/dist/audio/audio-graph.cjs +182 -0
- package/dist/audio/audio-graph.d.ts +58 -0
- package/dist/audio/audio-graph.d.ts.map +1 -0
- package/dist/audio/audio-graph.js +181 -0
- package/dist/audio/audio-graph.js.map +1 -0
- package/dist/compute/buffer-transform.cjs +146 -0
- package/dist/compute/buffer-transform.d.ts +15 -5
- package/dist/compute/buffer-transform.d.ts.map +1 -1
- package/dist/compute/buffer-transform.js +56 -12
- package/dist/compute/buffer-transform.js.map +1 -1
- package/dist/compute/computation.cjs +331 -0
- package/dist/compute/computation.d.ts +2 -4
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +3 -14
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.cjs +132 -0
- package/dist/compute/texture-transform.cjs +142 -0
- package/dist/compute/texture-transform.d.ts +11 -7
- package/dist/compute/texture-transform.d.ts.map +1 -1
- package/dist/compute/texture-transform.js +16 -6
- package/dist/compute/texture-transform.js.map +1 -1
- package/dist/controls/orbit-controls.cjs +283 -0
- package/dist/controls/orbit-controls.d.ts +2 -0
- package/dist/controls/orbit-controls.d.ts.map +1 -1
- package/dist/controls/orbit-controls.js +2 -1
- package/dist/controls/orbit-controls.js.map +1 -1
- package/dist/debug/copy-texture-to-image.cjs +84 -0
- package/dist/debug/debug-framebuffer.cjs +113 -0
- package/dist/debug/debug-shader-layout.cjs +45 -0
- package/dist/debug/pixel-data-utils.cjs +54 -0
- package/dist/dist.dev.js +11517 -6015
- package/dist/dist.min.js +39 -35
- package/dist/dynamic-buffer/dynamic-buffer.cjs +39 -0
- package/dist/dynamic-buffer/dynamic-buffer.d.ts +1 -170
- package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -1
- package/dist/dynamic-buffer/dynamic-buffer.js +2 -312
- package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.cjs +27 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts +1 -114
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +2 -584
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.cjs +31 -0
- package/dist/dynamic-texture/texture-binding-source.d.ts +1 -54
- package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.js +2 -51
- package/dist/dynamic-texture/texture-binding-source.js.map +1 -1
- package/dist/dynamic-texture/texture-data.cjs +53 -0
- package/dist/dynamic-texture/texture-data.d.ts +1 -145
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +2 -209
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/dynamic-texture/video-texture.cjs +269 -0
- package/dist/dynamic-texture/video-texture.d.ts +1 -1
- package/dist/dynamic-texture/video-texture.d.ts.map +1 -1
- package/dist/experimental/controls/comparison-splitter.cjs +231 -0
- package/dist/experimental/controls/comparison-splitter.d.ts +54 -0
- package/dist/experimental/controls/comparison-splitter.d.ts.map +1 -0
- package/dist/experimental/controls/comparison-splitter.js +215 -0
- package/dist/experimental/controls/comparison-splitter.js.map +1 -0
- package/dist/experimental/controls/flat-controller.cjs +301 -0
- package/dist/experimental/controls/flat-controller.d.ts +80 -0
- package/dist/experimental/controls/flat-controller.d.ts.map +1 -0
- package/dist/experimental/controls/flat-controller.js +295 -0
- package/dist/experimental/controls/flat-controller.js.map +1 -0
- package/dist/experimental/controls/index.cjs +35 -0
- package/dist/experimental/controls/index.cjs.map +6 -0
- package/dist/experimental/controls/index.d.ts +7 -0
- package/dist/experimental/controls/index.d.ts.map +1 -0
- package/dist/experimental/controls/index.js +7 -0
- package/dist/experimental/controls/index.js.map +1 -0
- package/dist/experimental/controls/orbit-controls.cjs +27 -0
- package/dist/experimental/controls/orbit-controls.d.ts +3 -0
- package/dist/experimental/controls/orbit-controls.d.ts.map +1 -0
- package/dist/experimental/controls/orbit-controls.js +5 -0
- package/dist/experimental/controls/orbit-controls.js.map +1 -0
- package/dist/experimental/materials/emissive-material.cjs +126 -0
- package/dist/experimental/materials/emissive-material.d.ts +38 -0
- package/dist/experimental/materials/emissive-material.d.ts.map +1 -0
- package/dist/experimental/materials/emissive-material.js +100 -0
- package/dist/experimental/materials/emissive-material.js.map +1 -0
- package/dist/experimental/materials/glass-material.cjs +570 -0
- package/dist/experimental/materials/glass-material.d.ts +107 -0
- package/dist/experimental/materials/glass-material.d.ts.map +1 -0
- package/dist/experimental/materials/glass-material.js +544 -0
- package/dist/experimental/materials/glass-material.js.map +1 -0
- package/dist/experimental/materials/glass-transmission.cjs +954 -0
- package/dist/experimental/materials/glass-transmission.d.ts +193 -0
- package/dist/experimental/materials/glass-transmission.d.ts.map +1 -0
- package/dist/experimental/materials/glass-transmission.js +928 -0
- package/dist/experimental/materials/glass-transmission.js.map +1 -0
- package/dist/experimental/materials/index.cjs +61 -0
- package/dist/experimental/materials/index.cjs.map +6 -0
- package/dist/experimental/materials/index.d.ts +14 -0
- package/dist/experimental/materials/index.d.ts.map +1 -0
- package/dist/experimental/materials/index.js +11 -0
- package/dist/experimental/materials/index.js.map +1 -0
- package/dist/experimental/materials/optical-caustics.cjs +201 -0
- package/dist/experimental/materials/optical-caustics.d.ts +69 -0
- package/dist/experimental/materials/optical-caustics.d.ts.map +1 -0
- package/dist/experimental/materials/optical-caustics.js +180 -0
- package/dist/experimental/materials/optical-caustics.js.map +1 -0
- package/dist/experimental/materials/optical-lighting.cjs +169 -0
- package/dist/experimental/materials/optical-lighting.d.ts +7 -0
- package/dist/experimental/materials/optical-lighting.d.ts.map +1 -0
- package/dist/experimental/materials/optical-lighting.js +144 -0
- package/dist/experimental/materials/optical-lighting.js.map +1 -0
- package/dist/experimental/materials/optical-point-lights.cjs +258 -0
- package/dist/experimental/materials/optical-point-lights.d.ts +68 -0
- package/dist/experimental/materials/optical-point-lights.d.ts.map +1 -0
- package/dist/experimental/materials/optical-point-lights.js +237 -0
- package/dist/experimental/materials/optical-point-lights.js.map +1 -0
- package/dist/experimental/materials/reflective-material.cjs +216 -0
- package/dist/experimental/materials/reflective-material.d.ts +46 -0
- package/dist/experimental/materials/reflective-material.d.ts.map +1 -0
- package/dist/experimental/materials/reflective-material.js +190 -0
- package/dist/experimental/materials/reflective-material.js.map +1 -0
- package/dist/experimental/textures/html-texture.cjs +221 -0
- package/dist/experimental/textures/html-texture.d.ts +85 -0
- package/dist/experimental/textures/html-texture.d.ts.map +1 -0
- package/dist/experimental/textures/html-texture.js +206 -0
- package/dist/experimental/textures/html-texture.js.map +1 -0
- package/dist/experimental/textures/index.cjs +33 -0
- package/dist/experimental/textures/index.cjs.map +6 -0
- package/dist/experimental/textures/index.d.ts +5 -0
- package/dist/experimental/textures/index.d.ts.map +1 -0
- package/dist/experimental/textures/index.js +7 -0
- package/dist/experimental/textures/index.js.map +1 -0
- package/dist/experimental/textures/packed-pixels.cjs +248 -0
- package/dist/experimental/textures/packed-pixels.d.ts +17 -0
- package/dist/experimental/textures/packed-pixels.d.ts.map +1 -0
- package/dist/experimental/textures/packed-pixels.js +237 -0
- package/dist/experimental/textures/packed-pixels.js.map +1 -0
- package/dist/experimental/textures/rgba-decoder.cjs +60 -0
- package/dist/experimental/textures/rgba-decoder.d.ts +29 -0
- package/dist/experimental/textures/rgba-decoder.d.ts.map +1 -0
- package/dist/experimental/textures/rgba-decoder.js +43 -0
- package/dist/experimental/textures/rgba-decoder.js.map +1 -0
- package/dist/experimental/webxr/index.cjs +38 -0
- package/dist/experimental/webxr/index.cjs.map +6 -0
- package/dist/experimental/webxr/index.d.ts +9 -0
- package/dist/experimental/webxr/index.d.ts.map +1 -0
- package/dist/experimental/webxr/index.js +8 -0
- package/dist/experimental/webxr/index.js.map +1 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.cjs +38 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.d.ts +9 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.js +17 -0
- package/dist/experimental/webxr/webxr-animation-frame-provider.js.map +1 -0
- package/dist/experimental/webxr/webxr-camera-texture.cjs +157 -0
- package/dist/experimental/webxr/webxr-camera-texture.d.ts +48 -0
- package/dist/experimental/webxr/webxr-camera-texture.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-camera-texture.js +144 -0
- package/dist/experimental/webxr/webxr-camera-texture.js.map +1 -0
- package/dist/experimental/webxr/webxr-input.cjs +93 -0
- package/dist/experimental/webxr/webxr-input.d.ts +24 -0
- package/dist/experimental/webxr/webxr-input.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-input.js +70 -0
- package/dist/experimental/webxr/webxr-input.js.map +1 -0
- package/dist/experimental/webxr/webxr-manager.cjs +356 -0
- package/dist/experimental/webxr/webxr-manager.d.ts +91 -0
- package/dist/experimental/webxr/webxr-manager.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-manager.js +354 -0
- package/dist/experimental/webxr/webxr-manager.js.map +1 -0
- package/dist/experimental/webxr/webxr-types.cjs +15 -0
- package/dist/experimental/webxr/webxr-types.d.ts +152 -0
- package/dist/experimental/webxr/webxr-types.d.ts.map +1 -0
- package/dist/experimental/webxr/webxr-types.js +5 -0
- package/dist/experimental/webxr/webxr-types.js.map +1 -0
- package/dist/geometry/edge-geometry.cjs +171 -0
- package/dist/geometry/edge-geometry.d.ts +3 -2
- package/dist/geometry/edge-geometry.d.ts.map +1 -1
- package/dist/geometry/edge-geometry.js.map +1 -1
- package/dist/geometry/geometry-primitives.cjs +189 -0
- package/dist/geometry/geometry-primitives.d.ts +60 -0
- package/dist/geometry/geometry-primitives.d.ts.map +1 -0
- package/dist/geometry/geometry-primitives.js +161 -0
- package/dist/geometry/geometry-primitives.js.map +1 -0
- package/dist/geometry/geometry-table.cjs +15 -0
- package/dist/geometry/geometry-utils.cjs +147 -0
- package/dist/geometry/geometry-utils.d.ts +7 -15
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +9 -55
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.cjs +90 -0
- package/dist/geometry/geometry.d.ts +9 -69
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +27 -93
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.cjs +130 -0
- package/dist/geometry/gpu-geometry.d.ts +4 -2
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +3 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/geometry/gpu-vector-geometry-adapter.cjs +88 -0
- package/dist/geometry/gpu-vector-geometry-adapter.d.ts +5 -0
- package/dist/geometry/gpu-vector-geometry-adapter.d.ts.map +1 -0
- package/dist/geometry/gpu-vector-geometry-adapter.js +73 -0
- package/dist/geometry/gpu-vector-geometry-adapter.js.map +1 -0
- package/dist/geometry/gpu-vector-geometry.cjs +40 -0
- package/dist/geometry/gpu-vector-geometry.d.ts +21 -0
- package/dist/geometry/gpu-vector-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-vector-geometry.js +19 -0
- package/dist/geometry/gpu-vector-geometry.js.map +1 -0
- package/dist/geometry/mesh-simplification.cjs +385 -0
- package/dist/geometry/ring-geometry.cjs +104 -0
- package/dist/geometry/ring-geometry.d.ts +17 -0
- package/dist/geometry/ring-geometry.d.ts.map +1 -0
- package/dist/geometry/ring-geometry.js +94 -0
- package/dist/geometry/ring-geometry.js.map +1 -0
- package/dist/geometry/stroke-geometry.cjs +171 -0
- package/dist/graph/models/index.cjs +66 -0
- package/dist/graph/models/index.cjs.map +6 -0
- package/dist/graph/models/index.d.ts +7 -0
- package/dist/graph/models/index.d.ts.map +1 -0
- package/dist/graph/models/index.js +10 -0
- package/dist/graph/models/index.js.map +1 -0
- package/dist/graph/models/path/path-attribute-model.cjs +421 -0
- package/dist/graph/models/path/path-attribute-model.d.ts +142 -0
- package/dist/graph/models/path/path-attribute-model.d.ts.map +1 -0
- package/dist/graph/models/path/path-attribute-model.js +409 -0
- package/dist/graph/models/path/path-attribute-model.js.map +1 -0
- package/dist/graph/models/path/path-storage-model.cjs +711 -0
- package/dist/graph/models/path/path-storage-model.d.ts +174 -0
- package/dist/graph/models/path/path-storage-model.d.ts.map +1 -0
- package/dist/graph/models/path/path-storage-model.js +720 -0
- package/dist/graph/models/path/path-storage-model.js.map +1 -0
- package/dist/graph/models/path/path-trips-storage-model.cjs +271 -0
- package/dist/graph/models/path/path-trips-storage-model.d.ts +58 -0
- package/dist/graph/models/path/path-trips-storage-model.d.ts.map +1 -0
- package/dist/graph/models/path/path-trips-storage-model.js +248 -0
- package/dist/graph/models/path/path-trips-storage-model.js.map +1 -0
- package/dist/graph/models/polygon/polygon-attribute-model.cjs +117 -0
- package/dist/graph/models/polygon/polygon-attribute-model.d.ts +53 -0
- package/dist/graph/models/polygon/polygon-attribute-model.d.ts.map +1 -0
- package/dist/graph/models/polygon/polygon-attribute-model.js +101 -0
- package/dist/graph/models/polygon/polygon-attribute-model.js.map +1 -0
- package/dist/graph/models/polygon/polygon-shaders.cjs +283 -0
- package/dist/graph/models/polygon/polygon-shaders.d.ts +77 -0
- package/dist/graph/models/polygon/polygon-shaders.d.ts.map +1 -0
- package/dist/graph/models/polygon/polygon-shaders.js +242 -0
- package/dist/graph/models/polygon/polygon-shaders.js.map +1 -0
- package/dist/graph/models/polygon/polygon-storage-model.cjs +111 -0
- package/dist/graph/models/polygon/polygon-storage-model.d.ts +53 -0
- package/dist/graph/models/polygon/polygon-storage-model.d.ts.map +1 -0
- package/dist/graph/models/polygon/polygon-storage-model.js +92 -0
- package/dist/graph/models/polygon/polygon-storage-model.js.map +1 -0
- package/dist/graph/physics/index.cjs +50 -0
- package/dist/graph/physics/index.cjs.map +6 -0
- package/dist/graph/physics/index.d.ts +12 -0
- package/dist/graph/physics/index.d.ts.map +1 -0
- package/dist/graph/physics/index.js +12 -0
- package/dist/graph/physics/index.js.map +1 -0
- package/dist/graph/physics/physics-scenegraph.cjs +92 -0
- package/dist/graph/physics/physics-scenegraph.d.ts +35 -0
- package/dist/graph/physics/physics-scenegraph.d.ts.map +1 -0
- package/dist/graph/physics/physics-scenegraph.js +80 -0
- package/dist/graph/physics/physics-scenegraph.js.map +1 -0
- package/dist/graph/physics/scenegraph-behaviors.cjs +164 -0
- package/dist/graph/physics/scenegraph-behaviors.d.ts +37 -0
- package/dist/graph/physics/scenegraph-behaviors.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-behaviors.js +145 -0
- package/dist/graph/physics/scenegraph-behaviors.js.map +1 -0
- package/dist/graph/physics/scenegraph-instance.cjs +246 -0
- package/dist/graph/physics/scenegraph-instance.d.ts +59 -0
- package/dist/graph/physics/scenegraph-instance.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-instance.js +241 -0
- package/dist/graph/physics/scenegraph-instance.js.map +1 -0
- package/dist/graph/physics/scenegraph-joints.cjs +51 -0
- package/dist/graph/physics/scenegraph-joints.d.ts +5 -0
- package/dist/graph/physics/scenegraph-joints.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-joints.js +31 -0
- package/dist/graph/physics/scenegraph-joints.js.map +1 -0
- package/dist/graph/physics/scenegraph-motion.cjs +177 -0
- package/dist/graph/physics/scenegraph-motion.d.ts +37 -0
- package/dist/graph/physics/scenegraph-motion.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-motion.js +168 -0
- package/dist/graph/physics/scenegraph-motion.js.map +1 -0
- package/dist/graph/physics/scenegraph-properties.cjs +170 -0
- package/dist/graph/physics/scenegraph-properties.d.ts +37 -0
- package/dist/graph/physics/scenegraph-properties.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-properties.js +186 -0
- package/dist/graph/physics/scenegraph-properties.js.map +1 -0
- package/dist/graph/physics/scenegraph-publication.cjs +112 -0
- package/dist/graph/physics/scenegraph-publication.d.ts +23 -0
- package/dist/graph/physics/scenegraph-publication.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-publication.js +99 -0
- package/dist/graph/physics/scenegraph-publication.js.map +1 -0
- package/dist/graph/physics/scenegraph-session.cjs +256 -0
- package/dist/graph/physics/scenegraph-session.d.ts +68 -0
- package/dist/graph/physics/scenegraph-session.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-session.js +249 -0
- package/dist/graph/physics/scenegraph-session.js.map +1 -0
- package/dist/graph/tables/gpu-table-geometry.cjs +84 -0
- package/dist/graph/tables/gpu-table-geometry.d.ts +32 -0
- package/dist/graph/tables/gpu-table-geometry.d.ts.map +1 -0
- package/dist/graph/tables/gpu-table-geometry.js +67 -0
- package/dist/graph/tables/gpu-table-geometry.js.map +1 -0
- package/dist/graph/tables/gpu-table-model.cjs +459 -0
- package/dist/graph/tables/gpu-table-model.d.ts +67 -0
- package/dist/graph/tables/gpu-table-model.d.ts.map +1 -0
- package/dist/graph/tables/gpu-table-model.js +457 -0
- package/dist/graph/tables/gpu-table-model.js.map +1 -0
- package/dist/graph/tables/gpu-table-transform.cjs +341 -0
- package/dist/graph/tables/gpu-table-transform.d.ts +61 -0
- package/dist/graph/tables/gpu-table-transform.d.ts.map +1 -0
- package/dist/graph/tables/gpu-table-transform.js +333 -0
- package/dist/graph/tables/gpu-table-transform.js.map +1 -0
- package/dist/graph/tables/index.cjs +33 -0
- package/dist/graph/tables/index.cjs.map +6 -0
- package/dist/graph/tables/index.d.ts +4 -0
- package/dist/graph/tables/index.d.ts.map +1 -0
- package/dist/graph/tables/index.js +7 -0
- package/dist/graph/tables/index.js.map +1 -0
- package/dist/index.cjs +303 -10629
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +46 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -10
- package/dist/index.js.map +1 -1
- package/dist/interactivity/interactivity.cjs +570 -0
- package/dist/interactivity/interactivity.d.ts +107 -0
- package/dist/interactivity/interactivity.d.ts.map +1 -0
- package/dist/interactivity/interactivity.js +575 -0
- package/dist/interactivity/interactivity.js.map +1 -0
- package/dist/interactivity/physics.cjs +15 -0
- package/dist/interactivity/physics.d.ts +12 -0
- package/dist/interactivity/physics.d.ts.map +1 -0
- package/dist/interactivity/physics.js +5 -0
- package/dist/interactivity/physics.js.map +1 -0
- package/dist/material/material-factory.cjs +99 -0
- package/dist/material/material-factory.d.ts +1 -1
- package/dist/material/material-factory.d.ts.map +1 -1
- package/dist/material/material.cjs +239 -0
- package/dist/material/material.d.ts +2 -2
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +2 -2
- package/dist/material/material.js.map +1 -1
- package/dist/model/gpu-vector-bindings.cjs +226 -0
- package/dist/model/gpu-vector-bindings.d.ts +36 -0
- package/dist/model/gpu-vector-bindings.d.ts.map +1 -0
- package/dist/model/gpu-vector-bindings.js +217 -0
- package/dist/model/gpu-vector-bindings.js.map +1 -0
- package/dist/model/gpu-vector-draw-batches.cjs +82 -0
- package/dist/model/gpu-vector-draw-batches.d.ts +5 -0
- package/dist/model/gpu-vector-draw-batches.d.ts.map +1 -0
- package/dist/model/gpu-vector-draw-batches.js +73 -0
- package/dist/model/gpu-vector-draw-batches.js.map +1 -0
- package/dist/model/gpu-vector-model-batches.cjs +94 -0
- package/dist/model/gpu-vector-model-batches.d.ts +41 -0
- package/dist/model/gpu-vector-model-batches.d.ts.map +1 -0
- package/dist/model/gpu-vector-model-batches.js +77 -0
- package/dist/model/gpu-vector-model-batches.js.map +1 -0
- package/dist/model/gpu-vector-model.cjs +1264 -0
- package/dist/model/gpu-vector-model.d.ts +352 -0
- package/dist/model/gpu-vector-model.d.ts.map +1 -0
- package/dist/model/gpu-vector-model.js +1375 -0
- package/dist/model/gpu-vector-model.js.map +1 -0
- package/dist/model/model.cjs +134 -0
- package/dist/model/model.d.ts +22 -306
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +68 -1092
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.cjs +44 -0
- package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +5 -2
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.cjs +167 -0
- package/dist/models/billboard-texture-model.d.ts +1 -1
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +1 -1
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/billboard-texture-module.cjs +61 -0
- package/dist/models/clip-space.cjs +103 -0
- package/dist/models/clip-space.d.ts +4 -1
- package/dist/models/clip-space.d.ts.map +1 -1
- package/dist/models/clip-space.js +16 -13
- package/dist/models/clip-space.js.map +1 -1
- package/dist/models/directional-light-model.cjs +45 -0
- package/dist/models/directional-light-model.js +1 -1
- package/dist/models/directional-light-model.js.map +1 -1
- package/dist/models/light-model-utils.cjs +426 -0
- package/dist/models/point-light-model.cjs +44 -0
- package/dist/models/point-light-model.js +1 -1
- package/dist/models/point-light-model.js.map +1 -1
- package/dist/models/spot-light-model.cjs +45 -0
- package/dist/models/spot-light-model.js +1 -1
- package/dist/models/spot-light-model.js.map +1 -1
- package/dist/modules/picking/color-picking.cjs +209 -0
- package/dist/modules/picking/color-picking.d.ts +1 -1
- package/dist/modules/picking/index-color-picking.cjs +230 -0
- package/dist/modules/picking/index-color-picking.d.ts +1 -1
- package/dist/modules/picking/index-picking.cjs +201 -0
- package/dist/modules/picking/index-picking.d.ts +1 -1
- package/dist/modules/picking/legacy-color-picking.cjs +28 -0
- package/dist/modules/picking/legacy-color-picking.d.ts +1 -1
- package/dist/modules/picking/legacy-picking-manager.cjs +92 -0
- package/dist/modules/picking/picking-manager.cjs +360 -0
- package/dist/modules/picking/picking-uniforms.cjs +140 -0
- package/dist/modules/picking/picking-uniforms.d.ts +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking.cjs +43 -0
- package/dist/modules/picking/picking.d.ts +1 -1
- package/dist/passes/get-fragment-shader.cjs +119 -0
- package/dist/passes/shader-pass-renderer.cjs +722 -0
- package/dist/passes/shader-pass-renderer.d.ts +2 -2
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +1 -1
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/passes/texture-transform-module.cjs +78 -0
- package/dist/scenegraph/controllers/area-light-controller.cjs +143 -0
- package/dist/scenegraph/controllers/area-light-controller.d.ts +31 -0
- package/dist/scenegraph/controllers/area-light-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/area-light-controller.js +130 -0
- package/dist/scenegraph/controllers/area-light-controller.js.map +1 -0
- package/dist/scenegraph/controllers/billboard-controller.cjs +156 -0
- package/dist/scenegraph/controllers/billboard-controller.d.ts +45 -0
- package/dist/scenegraph/controllers/billboard-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/billboard-controller.js +156 -0
- package/dist/scenegraph/controllers/billboard-controller.js.map +1 -0
- package/dist/scenegraph/controllers/joint-controller.cjs +71 -0
- package/dist/scenegraph/controllers/joint-controller.d.ts +30 -0
- package/dist/scenegraph/controllers/joint-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/joint-controller.js +53 -0
- package/dist/scenegraph/controllers/joint-controller.js.map +1 -0
- package/dist/scenegraph/controllers/material-variants.cjs +61 -0
- package/dist/scenegraph/controllers/material-variants.d.ts +42 -0
- package/dist/scenegraph/controllers/material-variants.d.ts.map +1 -0
- package/dist/scenegraph/controllers/material-variants.js +40 -0
- package/dist/scenegraph/controllers/material-variants.js.map +1 -0
- package/dist/scenegraph/controllers/morph-controller.cjs +61 -0
- package/dist/scenegraph/controllers/morph-controller.d.ts +19 -0
- package/dist/scenegraph/controllers/morph-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/morph-controller.js +41 -0
- package/dist/scenegraph/controllers/morph-controller.js.map +1 -0
- package/dist/scenegraph/controllers/skin-controller.cjs +111 -0
- package/dist/scenegraph/controllers/skin-controller.d.ts +36 -0
- package/dist/scenegraph/controllers/skin-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/skin-controller.js +90 -0
- package/dist/scenegraph/controllers/skin-controller.js.map +1 -0
- package/dist/scenegraph/group-node.cjs +129 -0
- package/dist/scenegraph/model-node.cjs +68 -0
- package/dist/scenegraph/physics-transforms.cjs +95 -0
- package/dist/scenegraph/physics-transforms.d.ts +13 -0
- package/dist/scenegraph/physics-transforms.d.ts.map +1 -0
- package/dist/scenegraph/physics-transforms.js +72 -0
- package/dist/scenegraph/physics-transforms.js.map +1 -0
- package/dist/scenegraph/published-transforms.cjs +37 -0
- package/dist/scenegraph/published-transforms.d.ts +17 -0
- package/dist/scenegraph/published-transforms.d.ts.map +1 -0
- package/dist/scenegraph/published-transforms.js +16 -0
- package/dist/scenegraph/published-transforms.js.map +1 -0
- package/dist/scenegraph/scenegraph-bounds.cjs +51 -0
- package/dist/scenegraph/scenegraph-node.cjs +182 -0
- package/dist/shader-inputs.cjs +231 -0
- package/dist/shader-inputs.d.ts +1 -1
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/utils/buffer-layout-helper.cjs +52 -0
- package/dist/utils/buffer-layout-order.cjs +37 -0
- package/dist/utils/deep-equal.cjs +65 -0
- package/dist/utils/get-platform-info.cjs +21 -0
- package/dist/utils/get-platform-info.d.ts +2 -0
- package/dist/utils/get-platform-info.d.ts.map +1 -0
- package/dist/utils/get-platform-info.js +5 -0
- package/dist/utils/get-platform-info.js.map +1 -0
- package/dist/utils/gpu-vector-batch-structure.cjs +45 -0
- package/dist/utils/gpu-vector-batch-structure.d.ts +12 -0
- package/dist/utils/gpu-vector-batch-structure.d.ts.map +1 -0
- package/dist/utils/gpu-vector-batch-structure.js +27 -0
- package/dist/utils/gpu-vector-batch-structure.js.map +1 -0
- package/dist/utils/shader-module-utils.cjs +148 -0
- package/dist/utils/uid.cjs +32 -0
- package/package.json +47 -8
- package/src/animation/deform-positions.ts +62 -0
- package/src/animation/node-animation-binding.ts +54 -0
- package/src/animation/property-animation-binding.ts +212 -0
- package/src/animation/scenegraph-animator.ts +117 -0
- package/src/animation/texture-transform.ts +59 -0
- package/src/animation-loop/animation-loop.ts +10 -3
- package/src/audio/audio-controller.ts +583 -0
- package/src/audio/audio-environment.ts +202 -0
- package/src/audio/audio-graph.ts +253 -0
- package/src/compute/buffer-transform.ts +71 -16
- package/src/compute/computation.ts +4 -19
- package/src/compute/texture-transform.ts +25 -12
- package/src/controls/orbit-controls.ts +4 -1
- package/src/dynamic-buffer/dynamic-buffer.ts +15 -449
- package/src/dynamic-texture/dynamic-texture.ts +5 -760
- package/src/dynamic-texture/texture-binding-source.ts +8 -90
- package/src/dynamic-texture/texture-data.ts +31 -340
- package/src/dynamic-texture/video-texture.ts +1 -1
- package/src/experimental/controls/comparison-splitter.ts +269 -0
- package/src/experimental/controls/flat-controller.ts +403 -0
- package/src/experimental/controls/index.ts +16 -0
- package/src/experimental/controls/orbit-controls.ts +6 -0
- package/src/experimental/materials/emissive-material.ts +120 -0
- package/src/experimental/materials/glass-material.ts +607 -0
- package/src/experimental/materials/glass-transmission.ts +1023 -0
- package/src/experimental/materials/index.ts +49 -0
- package/src/experimental/materials/optical-caustics.ts +234 -0
- package/src/experimental/materials/optical-lighting.ts +148 -0
- package/src/experimental/materials/optical-point-lights.ts +288 -0
- package/src/experimental/materials/reflective-material.ts +214 -0
- package/src/experimental/textures/html-texture.ts +285 -0
- package/src/experimental/textures/index.ts +8 -0
- package/src/experimental/textures/packed-pixels.ts +351 -0
- package/src/experimental/textures/rgba-decoder.ts +79 -0
- package/src/experimental/webxr/index.ts +21 -0
- package/src/experimental/webxr/webxr-animation-frame-provider.ts +22 -0
- package/src/experimental/webxr/webxr-camera-texture.ts +195 -0
- package/src/experimental/webxr/webxr-input.ts +117 -0
- package/src/experimental/webxr/webxr-manager.ts +524 -0
- package/src/experimental/webxr/webxr-types.ts +192 -0
- package/src/geometry/edge-geometry.ts +7 -3
- package/src/geometry/geometry-primitives.ts +226 -0
- package/src/geometry/geometry-utils.ts +16 -71
- package/src/geometry/geometry.ts +36 -163
- package/src/geometry/gpu-geometry.ts +9 -4
- package/src/geometry/gpu-vector-geometry-adapter.ts +78 -0
- package/src/geometry/gpu-vector-geometry.ts +33 -0
- package/src/geometry/ring-geometry.ts +117 -0
- package/src/graph/models/index.ts +45 -0
- package/src/graph/models/path/path-attribute-model.ts +563 -0
- package/src/graph/models/path/path-storage-model.ts +996 -0
- package/src/graph/models/path/path-trips-storage-model.ts +286 -0
- package/src/graph/models/polygon/polygon-attribute-model.ts +165 -0
- package/src/graph/models/polygon/polygon-shaders.ts +279 -0
- package/src/graph/models/polygon/polygon-storage-model.ts +146 -0
- package/src/graph/physics/index.ts +24 -0
- package/src/graph/physics/physics-scenegraph.ts +112 -0
- package/src/graph/physics/scenegraph-behaviors.ts +169 -0
- package/src/graph/physics/scenegraph-instance.ts +296 -0
- package/src/graph/physics/scenegraph-joints.ts +37 -0
- package/src/graph/physics/scenegraph-motion.ts +175 -0
- package/src/graph/physics/scenegraph-properties.ts +241 -0
- package/src/graph/physics/scenegraph-publication.ts +116 -0
- package/src/graph/physics/scenegraph-session.ts +317 -0
- package/src/graph/tables/gpu-table-geometry.ts +88 -0
- package/src/graph/tables/gpu-table-model.ts +661 -0
- package/src/graph/tables/gpu-table-transform.ts +497 -0
- package/src/graph/tables/index.ts +18 -0
- package/src/index.ts +144 -27
- package/src/interactivity/interactivity.ts +670 -0
- package/src/interactivity/physics.ts +19 -0
- package/src/material/material-factory.ts +1 -1
- package/src/material/material.ts +2 -2
- package/src/model/gpu-vector-bindings.ts +276 -0
- package/src/model/gpu-vector-draw-batches.ts +116 -0
- package/src/model/gpu-vector-model-batches.ts +142 -0
- package/src/model/gpu-vector-model.ts +1819 -0
- package/src/model/model.ts +91 -1444
- package/src/model/split-uniforms-and-bindings.ts +6 -3
- package/src/models/billboard-texture-model.ts +1 -1
- package/src/models/clip-space.ts +21 -14
- package/src/models/directional-light-model.ts +1 -1
- package/src/models/point-light-model.ts +1 -1
- package/src/models/spot-light-model.ts +1 -1
- package/src/modules/picking/legacy-picking-manager.ts +1 -1
- package/src/modules/picking/picking-uniforms.ts +1 -1
- package/src/passes/shader-pass-renderer.ts +2 -2
- package/src/scenegraph/controllers/area-light-controller.ts +152 -0
- package/src/scenegraph/controllers/billboard-controller.ts +204 -0
- package/src/scenegraph/controllers/joint-controller.ts +81 -0
- package/src/scenegraph/controllers/material-variants.ts +70 -0
- package/src/scenegraph/controllers/morph-controller.ts +61 -0
- package/src/scenegraph/controllers/skin-controller.ts +125 -0
- package/src/scenegraph/physics-transforms.ts +82 -0
- package/src/scenegraph/published-transforms.ts +18 -0
- package/src/shader-inputs.ts +1 -1
- package/src/utils/get-platform-info.ts +5 -0
- package/src/utils/gpu-vector-batch-structure.ts +36 -0
- package/dist/compute/kernel.d.ts +0 -54
- package/dist/compute/kernel.d.ts.map +0 -1
- package/dist/compute/kernel.js +0 -103
- package/dist/compute/kernel.js.map +0 -1
- package/dist/compute/render-kernel.d.ts +0 -65
- package/dist/compute/render-kernel.d.ts.map +0 -1
- package/dist/compute/render-kernel.js +0 -129
- package/dist/compute/render-kernel.js.map +0 -1
- package/dist/geometries/cone-geometry.d.ts +0 -12
- package/dist/geometries/cone-geometry.d.ts.map +0 -1
- package/dist/geometries/cone-geometry.js +0 -19
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.d.ts +0 -14
- package/dist/geometries/cube-geometry.d.ts.map +0 -1
- package/dist/geometries/cube-geometry.js +0 -222
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.d.ts +0 -11
- package/dist/geometries/cylinder-geometry.d.ts.map +0 -1
- package/dist/geometries/cylinder-geometry.js +0 -17
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +0 -11
- package/dist/geometries/ico-sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js +0 -158
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.d.ts +0 -20
- package/dist/geometries/plane-geometry.d.ts.map +0 -1
- package/dist/geometries/plane-geometry.js +0 -106
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.d.ts +0 -12
- package/dist/geometries/sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/sphere-geometry.js +0 -88
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +0 -23
- package/dist/geometries/truncated-cone-geometry.d.ts.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js +0 -112
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/src/compute/kernel.ts +0 -146
- package/src/compute/render-kernel.ts +0 -192
- package/src/geometries/cone-geometry.ts +0 -31
- package/src/geometries/cube-geometry.ts +0 -258
- package/src/geometries/cylinder-geometry.ts +0 -28
- package/src/geometries/ico-sphere-geometry.ts +0 -193
- package/src/geometries/plane-geometry.ts +0 -142
- package/src/geometries/sphere-geometry.ts +0 -113
- package/src/geometries/truncated-cone-geometry.ts +0 -145
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
GroupNode,
|
|
7
|
+
type ScenegraphNode,
|
|
8
|
+
type Interactivity,
|
|
9
|
+
type InteractivityPhysics
|
|
10
|
+
} from '../../index';
|
|
11
|
+
import type {GPURigidBodyWorld} from '@luma.gl/graph/gpu-physics';
|
|
12
|
+
|
|
13
|
+
export type ScenegraphPhysicsBehaviorProps = {
|
|
14
|
+
roots: readonly ScenegraphNode[];
|
|
15
|
+
/** Behavior-graph node identity table. Cross-references inside the scene remain objects. */
|
|
16
|
+
nodes: ReadonlyMap<number, ScenegraphNode>;
|
|
17
|
+
bodyNodes: ReadonlyMap<ScenegraphNode, number>;
|
|
18
|
+
colliderNodes: readonly ScenegraphNode[];
|
|
19
|
+
triggerNodes: readonly ScenegraphNode[];
|
|
20
|
+
querySelections?: readonly (readonly number[])[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Connect behavior operations to a GPU world without retaining an asset-format document. */
|
|
24
|
+
export class ScenegraphPhysicsBehaviors implements InteractivityPhysics {
|
|
25
|
+
private readonly bodyByNode = new Map<ScenegraphNode, number>();
|
|
26
|
+
private readonly nodeIndices: ReadonlyMap<ScenegraphNode, number>;
|
|
27
|
+
private readonly motionNodes = new Map<number, number>();
|
|
28
|
+
private active = true;
|
|
29
|
+
private readonly dispatches = new Set<Promise<void>>();
|
|
30
|
+
private queryTail: Promise<unknown> = Promise.resolve();
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
readonly world: GPURigidBodyWorld,
|
|
34
|
+
readonly props: ScenegraphPhysicsBehaviorProps
|
|
35
|
+
) {
|
|
36
|
+
this.nodeIndices = new Map(Array.from(props.nodes, ([index, node]) => [node, index]));
|
|
37
|
+
const visit = (node: ScenegraphNode, inherited?: number) => {
|
|
38
|
+
const body = props.bodyNodes.get(node) ?? inherited;
|
|
39
|
+
if (body !== undefined) this.bodyByNode.set(node, body);
|
|
40
|
+
if (node instanceof GroupNode) for (const child of node.children) visit(child, body);
|
|
41
|
+
};
|
|
42
|
+
for (const root of props.roots) visit(root);
|
|
43
|
+
for (const [node, body] of props.bodyNodes) {
|
|
44
|
+
if (world.getBodyMode(body) !== 'static')
|
|
45
|
+
this.motionNodes.set(body, this.nodeIndices.get(node) ?? -1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private body(nodeIndex: number): number | undefined {
|
|
50
|
+
if (!this.active) throw new Error('Disposed physics behavior binding');
|
|
51
|
+
if (!Number.isInteger(nodeIndex)) throw new Error('Invalid behavior node index');
|
|
52
|
+
const node = this.props.nodes.get(nodeIndex);
|
|
53
|
+
if (!node) throw new Error('Unknown behavior node');
|
|
54
|
+
return this.bodyByNode.get(node);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
applyImpulse(node: number, linear: readonly number[], angular: readonly number[]): void {
|
|
58
|
+
validateVector(linear);
|
|
59
|
+
validateVector(angular);
|
|
60
|
+
const body = this.body(node);
|
|
61
|
+
if (body === undefined) return;
|
|
62
|
+
this.world.applyImpulse(body, [linear[0], linear[1], linear[2]]);
|
|
63
|
+
this.world.applyAngularImpulse(body, [angular[0], angular[1], angular[2]]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
applyPointImpulse(node: number, impulse: readonly number[], position: readonly number[]): void {
|
|
67
|
+
validateVector(impulse);
|
|
68
|
+
validateVector(position);
|
|
69
|
+
const body = this.body(node);
|
|
70
|
+
if (body !== undefined)
|
|
71
|
+
this.world.applyImpulse(
|
|
72
|
+
body,
|
|
73
|
+
[impulse[0], impulse[1], impulse[2]],
|
|
74
|
+
[position[0], position[1], position[2]]
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
rayCast(start: readonly number[], end: readonly number[], filter: number) {
|
|
79
|
+
// Snapshot caller-owned inputs before waiting for the shared query transport.
|
|
80
|
+
const origin = [...start];
|
|
81
|
+
const destination = [...end];
|
|
82
|
+
const run = async () => {
|
|
83
|
+
if (!this.active) throw new Error('Disposed physics behavior binding');
|
|
84
|
+
validateVector(origin);
|
|
85
|
+
validateVector(destination);
|
|
86
|
+
if (
|
|
87
|
+
!Number.isInteger(filter) ||
|
|
88
|
+
filter < -1 ||
|
|
89
|
+
(filter >= 0 && !this.props.querySelections?.[filter])
|
|
90
|
+
)
|
|
91
|
+
throw new Error('Invalid query filter');
|
|
92
|
+
const direction: [number, number, number] = [
|
|
93
|
+
destination[0] - origin[0],
|
|
94
|
+
destination[1] - origin[1],
|
|
95
|
+
destination[2] - origin[2]
|
|
96
|
+
];
|
|
97
|
+
const length = Math.hypot(...direction);
|
|
98
|
+
if (!length) return null;
|
|
99
|
+
const result = await this.world.raycast({
|
|
100
|
+
origin: [origin[0], origin[1], origin[2]],
|
|
101
|
+
direction,
|
|
102
|
+
maximumDistance: length,
|
|
103
|
+
colliderIndices: filter === -1 ? undefined : this.props.querySelections![filter]
|
|
104
|
+
});
|
|
105
|
+
if (!this.active) throw new Error('Disposed physics behavior binding');
|
|
106
|
+
if (!result.complete || result.truncated) throw new Error('Incomplete behavior ray query');
|
|
107
|
+
const hit = result.hits[0];
|
|
108
|
+
if (!hit) return null;
|
|
109
|
+
const node = this.nodeIndices.get(this.props.colliderNodes[hit.collider]);
|
|
110
|
+
if (node === undefined) throw new Error('Missing collider node binding');
|
|
111
|
+
return {node, fraction: hit.distance / length, normal: hit.normal};
|
|
112
|
+
};
|
|
113
|
+
// The world owns one query transport. Serialize requests without dropping activations.
|
|
114
|
+
const result = this.queryTail.then(run, run);
|
|
115
|
+
this.queryTail = result.catch(() => {});
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Invalidate queued continuations and wait for the currently borrowed query transport. */
|
|
120
|
+
async destroy(): Promise<void> {
|
|
121
|
+
this.active = false;
|
|
122
|
+
await Promise.allSettled([this.queryTail, ...this.dispatches]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
isTriggerNode(node: number): boolean {
|
|
126
|
+
return (
|
|
127
|
+
Number.isInteger(node) &&
|
|
128
|
+
Boolean(
|
|
129
|
+
this.props.nodes.get(node) && this.props.triggerNodes.includes(this.props.nodes.get(node)!)
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
dispatchTriggers(behavior: Interactivity): Promise<void> {
|
|
135
|
+
const operation = this.dispatchTriggerBatch(behavior);
|
|
136
|
+
this.dispatches.add(operation);
|
|
137
|
+
void operation.finally(() => this.dispatches.delete(operation)).catch(() => {});
|
|
138
|
+
return operation;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private async dispatchTriggerBatch(behavior: Interactivity): Promise<void> {
|
|
142
|
+
if (!this.active) throw new Error('Disposed physics behavior binding');
|
|
143
|
+
if (!this.props.triggerNodes.length) {
|
|
144
|
+
await behavior.flushPhysics();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const batch = await this.world.readTriggerEvents();
|
|
148
|
+
if (!this.active) throw new Error('Disposed physics behavior binding');
|
|
149
|
+
if (batch.dropped || batch.saturated) throw new Error('Behavior trigger events lost');
|
|
150
|
+
for (const event of batch.events) {
|
|
151
|
+
const triggerNode = this.nodeIndices.get(this.props.triggerNodes[event.trigger]);
|
|
152
|
+
const colliderNode = this.nodeIndices.get(this.props.colliderNodes[event.collider]);
|
|
153
|
+
if (triggerNode === undefined || colliderNode === undefined)
|
|
154
|
+
throw new Error('Missing trigger node binding');
|
|
155
|
+
behavior.notifyPhysicsTrigger(
|
|
156
|
+
event.phase,
|
|
157
|
+
triggerNode,
|
|
158
|
+
colliderNode,
|
|
159
|
+
this.motionNodes.get(event.body) ?? -1
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
await behavior.flushPhysics();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function validateVector(vector: readonly number[]): void {
|
|
167
|
+
if (vector.length !== 3 || !vector.every(value => Number.isFinite(Math.fround(value))))
|
|
168
|
+
throw new Error('Expected finite three-component physics vector');
|
|
169
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Device, CommandEncoder} from '@luma.gl/core';
|
|
6
|
+
import {Vector3} from '@math.gl/core';
|
|
7
|
+
import type {ScenegraphNode} from '../../index';
|
|
8
|
+
import {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
|
|
9
|
+
import {
|
|
10
|
+
GPURigidBodyWorld,
|
|
11
|
+
type GPURigidBodyWorldProps,
|
|
12
|
+
type GPURigidBodyCapture
|
|
13
|
+
} from '@luma.gl/graph/gpu-physics';
|
|
14
|
+
import {rotateRigidBodyVector} from '@luma.gl/graph/gpu-physics';
|
|
15
|
+
|
|
16
|
+
export type ScenegraphPhysicsDefinition = {
|
|
17
|
+
world: GPURigidBodyWorldProps;
|
|
18
|
+
/** Stable scene object references; fixed synthetic bodies need not have a node. */
|
|
19
|
+
bodies: ReadonlyMap<ScenegraphNode, number>;
|
|
20
|
+
};
|
|
21
|
+
/** Implementation-version capture. Node identities remain caller-owned object references. */
|
|
22
|
+
export type ScenegraphPhysicsCapture = {
|
|
23
|
+
version: 1;
|
|
24
|
+
authored: ScenegraphPhysicsDefinition;
|
|
25
|
+
state: GPURigidBodyCapture;
|
|
26
|
+
};
|
|
27
|
+
type Execution = {
|
|
28
|
+
world: GPURigidBodyWorld;
|
|
29
|
+
graph: Awaited<ReturnType<GPUCommandGraph['compileAsync']>>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** Owns one independent simulation instance and transactional geometry/topology rebuilds. */
|
|
33
|
+
export class ScenegraphPhysicsInstance {
|
|
34
|
+
private pending: Promise<unknown> | undefined;
|
|
35
|
+
private destroying = false;
|
|
36
|
+
private destroyed = false;
|
|
37
|
+
/** Changes on reset/rebuild. Borrowed render buffers and event identities belong to one revision. */
|
|
38
|
+
revision = 0;
|
|
39
|
+
private constructor(
|
|
40
|
+
private readonly device: Device,
|
|
41
|
+
private definition: ScenegraphPhysicsDefinition,
|
|
42
|
+
private execution: Execution
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
static async create(
|
|
46
|
+
device: Device,
|
|
47
|
+
definition: ScenegraphPhysicsDefinition
|
|
48
|
+
): Promise<ScenegraphPhysicsInstance> {
|
|
49
|
+
validateDefinition(definition);
|
|
50
|
+
const saved = cloneDefinition(definition);
|
|
51
|
+
const instance = new ScenegraphPhysicsInstance(
|
|
52
|
+
device,
|
|
53
|
+
saved,
|
|
54
|
+
await compile(device, saved.world)
|
|
55
|
+
);
|
|
56
|
+
try {
|
|
57
|
+
await instance.publish();
|
|
58
|
+
return instance;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
await instance.destroy();
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
get world(): GPURigidBodyWorld {
|
|
65
|
+
return this.execution.world;
|
|
66
|
+
}
|
|
67
|
+
get graph(): Execution['graph'] {
|
|
68
|
+
return this.execution.graph;
|
|
69
|
+
}
|
|
70
|
+
get bodies(): ReadonlyMap<ScenegraphNode, number> {
|
|
71
|
+
return this.definition.bodies;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Track queries/readbacks so reset, rebuild and destruction cannot invalidate their buffers. */
|
|
75
|
+
async withWorld<T>(operation: (world: GPURigidBodyWorld) => Promise<T>): Promise<T> {
|
|
76
|
+
return this.exclusive(() => operation(this.world));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Explicit editing/debugging readback; never part of advance(). Includes authored reset state. */
|
|
80
|
+
async capture(): Promise<ScenegraphPhysicsCapture> {
|
|
81
|
+
return this.exclusive(async () => {
|
|
82
|
+
await this.finishSubmission();
|
|
83
|
+
return {
|
|
84
|
+
version: 1,
|
|
85
|
+
authored: cloneDefinition(this.definition),
|
|
86
|
+
state: await this.world.captureState()
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Atomically restore live state, commands, caches and events, retaining the captured reset state. */
|
|
92
|
+
async restore(
|
|
93
|
+
capture: ScenegraphPhysicsCapture,
|
|
94
|
+
prepare?: (world: GPURigidBodyWorld) => void
|
|
95
|
+
): Promise<void> {
|
|
96
|
+
if (capture.version !== 1) throw new Error('Unsupported scene physics capture');
|
|
97
|
+
validateDefinition(capture.authored);
|
|
98
|
+
const authored = cloneDefinition(capture.authored);
|
|
99
|
+
const state = structuredClone(capture.state);
|
|
100
|
+
if (state.props.bodies.length !== authored.world.bodies.length)
|
|
101
|
+
throw new Error('Invalid captured scene bindings');
|
|
102
|
+
return this.exclusive(async () => {
|
|
103
|
+
await this.finishSubmission();
|
|
104
|
+
const replacement = await compile(this.device, state.props);
|
|
105
|
+
try {
|
|
106
|
+
replacement.world.restoreState(state);
|
|
107
|
+
prepare?.(replacement.world);
|
|
108
|
+
replacement.world.publishPoses();
|
|
109
|
+
await this.finishSubmission();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
replacement.graph.destroy();
|
|
112
|
+
replacement.world.destroy();
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
const previous = this.execution;
|
|
116
|
+
this.execution = replacement;
|
|
117
|
+
this.definition = authored;
|
|
118
|
+
this.revision++;
|
|
119
|
+
previous.graph.destroy();
|
|
120
|
+
previous.world.destroy();
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Publish current poses and bounds without advancing simulation time. */
|
|
125
|
+
async publish(): Promise<void> {
|
|
126
|
+
return this.exclusive(async () => {
|
|
127
|
+
this.world.publishPoses();
|
|
128
|
+
await this.finishSubmission();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Advance one fixed step; state remains on GPU and only submission completion is awaited. */
|
|
133
|
+
async advance(
|
|
134
|
+
beforeStep?: (world: GPURigidBodyWorld) => void,
|
|
135
|
+
encode?: (graph: Execution['graph'], encoder: CommandEncoder) => void
|
|
136
|
+
): Promise<void> {
|
|
137
|
+
return this.exclusive(async () => {
|
|
138
|
+
beforeStep?.(this.world);
|
|
139
|
+
const encoder = this.device.createCommandEncoder();
|
|
140
|
+
if (encode) encode(this.graph, encoder);
|
|
141
|
+
else this.graph.encode(encoder, {parameters: undefined});
|
|
142
|
+
this.device.submit(encoder.finish());
|
|
143
|
+
await this.finishSubmission();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Restore this instance's authored state. Does not modify scene nodes or the camera. */
|
|
148
|
+
async reset(prepare?: (world: GPURigidBodyWorld) => void): Promise<void> {
|
|
149
|
+
return this.replace(this.definition, false, false, prepare);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Re-cook upstream first, then atomically install the resulting geometry and bindings.
|
|
153
|
+
* Preserves dynamic node poses and velocities by object identity. New/static/kinematic
|
|
154
|
+
* nodes use the new authored state. Contact caches and event histories start a new revision.
|
|
155
|
+
*/
|
|
156
|
+
async rebuild(
|
|
157
|
+
definition: ScenegraphPhysicsDefinition,
|
|
158
|
+
preserveState = true,
|
|
159
|
+
prepare?: (world: GPURigidBodyWorld) => void
|
|
160
|
+
): Promise<void> {
|
|
161
|
+
return this.replace(definition, preserveState, true, prepare);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async replace(
|
|
165
|
+
definition: ScenegraphPhysicsDefinition,
|
|
166
|
+
preserveState: boolean,
|
|
167
|
+
updateAuthored: boolean,
|
|
168
|
+
prepare?: (world: GPURigidBodyWorld) => void
|
|
169
|
+
): Promise<void> {
|
|
170
|
+
// Validate and snapshot caller-owned data before accepting an asynchronous operation.
|
|
171
|
+
validateDefinition(definition);
|
|
172
|
+
const authored = cloneDefinition(definition);
|
|
173
|
+
return this.exclusive(async () => {
|
|
174
|
+
await this.finishSubmission();
|
|
175
|
+
const props = structuredClone(authored.world);
|
|
176
|
+
if (preserveState) {
|
|
177
|
+
// Rebuilds are explicit editing operations, not a per-frame simulation bridge.
|
|
178
|
+
const states = await this.world.readState();
|
|
179
|
+
const bodies = [...props.bodies];
|
|
180
|
+
for (const [node, index] of authored.bodies) {
|
|
181
|
+
const previous = this.definition.bodies.get(node);
|
|
182
|
+
const body = bodies[index];
|
|
183
|
+
const mode = body.mode ?? ((body.mass ?? 1) === 0 ? 'static' : 'dynamic');
|
|
184
|
+
if (
|
|
185
|
+
previous === undefined ||
|
|
186
|
+
mode !== 'dynamic' ||
|
|
187
|
+
this.world.getBodyMode(previous) !== 'dynamic'
|
|
188
|
+
)
|
|
189
|
+
continue;
|
|
190
|
+
const state = states[previous];
|
|
191
|
+
const offset = rotateRigidBodyVector(
|
|
192
|
+
state.orientation,
|
|
193
|
+
this.world.getBodyParameters(previous).centerOfMass ?? [0, 0, 0]
|
|
194
|
+
);
|
|
195
|
+
bodies[index] = {
|
|
196
|
+
...body,
|
|
197
|
+
position: [
|
|
198
|
+
state.position[0] - offset[0],
|
|
199
|
+
state.position[1] - offset[1],
|
|
200
|
+
state.position[2] - offset[2]
|
|
201
|
+
],
|
|
202
|
+
orientation: state.orientation,
|
|
203
|
+
velocity: new Vector3(state.velocity)
|
|
204
|
+
.add(
|
|
205
|
+
new Vector3(state.angularVelocity).cross(
|
|
206
|
+
new Vector3(
|
|
207
|
+
rotateRigidBodyVector(state.orientation, body.centerOfMass ?? [0, 0, 0])
|
|
208
|
+
).subtract(offset)
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
.toArray() as [number, number, number],
|
|
212
|
+
angularVelocity: state.angularVelocity
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
props.bodies = bodies;
|
|
216
|
+
}
|
|
217
|
+
const replacement = await compile(this.device, props);
|
|
218
|
+
try {
|
|
219
|
+
prepare?.(replacement.world);
|
|
220
|
+
replacement.world.publishPoses();
|
|
221
|
+
await this.finishSubmission();
|
|
222
|
+
} catch (error) {
|
|
223
|
+
replacement.graph.destroy();
|
|
224
|
+
replacement.world.destroy();
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
const previous = this.execution;
|
|
228
|
+
this.execution = replacement;
|
|
229
|
+
if (updateAuthored) this.definition = authored;
|
|
230
|
+
this.revision++;
|
|
231
|
+
previous.graph.destroy();
|
|
232
|
+
previous.world.destroy();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private async exclusive<T>(operation: () => Promise<T>): Promise<T> {
|
|
237
|
+
if (this.pending || this.destroying || this.destroyed)
|
|
238
|
+
throw new Error('Physics instance is busy or destroyed');
|
|
239
|
+
// Claim the lifetime before invoking caller code, including synchronous re-entry.
|
|
240
|
+
const pending = Promise.resolve().then(operation);
|
|
241
|
+
this.pending = pending;
|
|
242
|
+
try {
|
|
243
|
+
return await pending;
|
|
244
|
+
} finally {
|
|
245
|
+
this.pending = undefined;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
private async finishSubmission(): Promise<void> {
|
|
249
|
+
const fence = this.device.createFence();
|
|
250
|
+
try {
|
|
251
|
+
await fence.signaled;
|
|
252
|
+
} finally {
|
|
253
|
+
fence.destroy();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** Wait for this instance's pending operation and submissions before releasing resources. */
|
|
257
|
+
async destroy(): Promise<void> {
|
|
258
|
+
if (this.destroyed) return;
|
|
259
|
+
this.destroying = true;
|
|
260
|
+
try {
|
|
261
|
+
await this.pending;
|
|
262
|
+
} catch {
|
|
263
|
+
/* A rejected edit still leaves an owned live execution. */
|
|
264
|
+
}
|
|
265
|
+
await this.finishSubmission();
|
|
266
|
+
if (this.destroyed) return;
|
|
267
|
+
this.destroyed = true;
|
|
268
|
+
this.execution.graph.destroy();
|
|
269
|
+
this.execution.world.destroy();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function cloneDefinition(definition: ScenegraphPhysicsDefinition): ScenegraphPhysicsDefinition {
|
|
274
|
+
return {world: structuredClone(definition.world), bodies: new Map(definition.bodies)};
|
|
275
|
+
}
|
|
276
|
+
function validateDefinition(definition: ScenegraphPhysicsDefinition): void {
|
|
277
|
+
const indices = [...definition.bodies.values()];
|
|
278
|
+
if (
|
|
279
|
+
new Set(indices).size !== indices.length ||
|
|
280
|
+
indices.some(
|
|
281
|
+
index => !Number.isInteger(index) || index < 0 || index >= definition.world.bodies.length
|
|
282
|
+
)
|
|
283
|
+
)
|
|
284
|
+
throw new Error('Invalid scene body bindings');
|
|
285
|
+
}
|
|
286
|
+
async function compile(device: Device, props: GPURigidBodyWorldProps): Promise<Execution> {
|
|
287
|
+
const world = new GPURigidBodyWorld(props);
|
|
288
|
+
try {
|
|
289
|
+
const definition = new GPUCommandGraph(device);
|
|
290
|
+
world.addToGraph(definition);
|
|
291
|
+
return {world, graph: await definition.compileAsync()};
|
|
292
|
+
} catch (error) {
|
|
293
|
+
world.destroy();
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ResolvedScenegraphJoint, ScenegraphNode} from '../../index';
|
|
6
|
+
import type {GPURigidBodyJoint} from '@luma.gl/graph/gpu-physics';
|
|
7
|
+
|
|
8
|
+
/** Compile shared scene attachments into backend rows; no glTF dependency or parsing. */
|
|
9
|
+
export function makeRigidBodyJointsFromScenegraph(
|
|
10
|
+
resolved: ResolvedScenegraphJoint,
|
|
11
|
+
bodyIndices: ReadonlyMap<ScenegraphNode, number>,
|
|
12
|
+
fixedWorldBody?: number
|
|
13
|
+
): GPURigidBodyJoint[] {
|
|
14
|
+
const bodyIndex = (body: ScenegraphNode | null) => {
|
|
15
|
+
const index = body ? bodyIndices.get(body) : fixedWorldBody;
|
|
16
|
+
if (index === undefined) throw new Error('Missing physics body for joint attachment');
|
|
17
|
+
return index;
|
|
18
|
+
};
|
|
19
|
+
const base = {
|
|
20
|
+
type: 'general' as const,
|
|
21
|
+
first: bodyIndex(resolved.first.body),
|
|
22
|
+
second: bodyIndex(resolved.second.body),
|
|
23
|
+
firstFrame: {position: resolved.first.position, orientation: resolved.first.orientation},
|
|
24
|
+
secondFrame: {position: resolved.second.position, orientation: resolved.second.orientation},
|
|
25
|
+
enabled: resolved.joint.enabled,
|
|
26
|
+
collideConnected: resolved.joint.collideConnected
|
|
27
|
+
};
|
|
28
|
+
const constraints: GPURigidBodyJoint[] = (resolved.joint.limits ?? []).map(limit => ({
|
|
29
|
+
...base,
|
|
30
|
+
...limit
|
|
31
|
+
}));
|
|
32
|
+
for (const {axis, angular, ...drive} of resolved.joint.drives ?? []) {
|
|
33
|
+
constraints.push({...base, axes: [axis], angular, drive});
|
|
34
|
+
}
|
|
35
|
+
// A joint without rows still governs connected collision filtering.
|
|
36
|
+
return constraints.length ? constraints : [{...base, axes: [0]}];
|
|
37
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Matrix4} from '@math.gl/core';
|
|
6
|
+
import {GroupNode, decomposePhysicsTransform, type ScenegraphNode} from '../../index';
|
|
7
|
+
import {scaleRigidBodyShape} from '@luma.gl/graph/gpu-physics';
|
|
8
|
+
import type {GPURigidBodyWorld} from '@luma.gl/graph/gpu-physics';
|
|
9
|
+
|
|
10
|
+
export type ScenegraphPhysicsColliderTarget = {
|
|
11
|
+
node: ScenegraphNode;
|
|
12
|
+
index: number;
|
|
13
|
+
body: ScenegraphNode;
|
|
14
|
+
/** Cooked collider frame relative to its scene node, before node scale. */
|
|
15
|
+
localMatrix?: readonly number[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Animation owns declared kinematic nodes; physics publishes their accepted poses for rendering. */
|
|
19
|
+
export class ScenegraphPhysicsMotion {
|
|
20
|
+
private readonly colliderScales = new Map<number, readonly number[]>();
|
|
21
|
+
private activeTargets?: Set<ScenegraphNode>;
|
|
22
|
+
private readonly colliderFrames = new Map<number, number[]>();
|
|
23
|
+
private readonly releasedModes = new Map<number, 'static' | 'dynamic' | 'kinematic'>();
|
|
24
|
+
readonly inverseBodyFrames = new Map<number, Matrix4>();
|
|
25
|
+
constructor(
|
|
26
|
+
readonly world: GPURigidBodyWorld,
|
|
27
|
+
readonly roots: readonly ScenegraphNode[],
|
|
28
|
+
readonly targets: ReadonlyMap<ScenegraphNode, number>,
|
|
29
|
+
readonly colliders: readonly ScenegraphPhysicsColliderTarget[] = []
|
|
30
|
+
) {
|
|
31
|
+
// Initial geometry already includes the authored scale. Record it before animation begins.
|
|
32
|
+
const matrices = this.collectWorldMatrices();
|
|
33
|
+
for (const collider of colliders) {
|
|
34
|
+
const matrix = matrices.get(collider.node);
|
|
35
|
+
if (!matrix) throw new Error('Detached collider animation target');
|
|
36
|
+
const local = new Matrix4(matrix);
|
|
37
|
+
if (collider.localMatrix) local.multiplyRight(collider.localMatrix);
|
|
38
|
+
this.colliderScales.set(collider.index, decomposePhysicsTransform(local).scale.map(Math.abs));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Resolve already-blended animation ownership. Animated ancestors own descendant body poses.
|
|
43
|
+
* Paused actions should remain in this set; stopped actions should be removed. On release,
|
|
44
|
+
* physics retains the last accepted pose and kinematic velocity rather than snapping to authoring.
|
|
45
|
+
*/
|
|
46
|
+
setAnimatedNodes(nodes: ReadonlySet<ScenegraphNode>): void {
|
|
47
|
+
const active = new Set<ScenegraphNode>();
|
|
48
|
+
const visit = (node: ScenegraphNode, inherited: boolean) => {
|
|
49
|
+
const animated = inherited || nodes.has(node);
|
|
50
|
+
if (animated && this.targets.has(node)) active.add(node);
|
|
51
|
+
if (node instanceof GroupNode) for (const child of node.children) visit(child, animated);
|
|
52
|
+
};
|
|
53
|
+
if (nodes.size) for (const root of this.roots) visit(root, false);
|
|
54
|
+
for (const [node, body] of this.targets) {
|
|
55
|
+
if (active.has(node)) {
|
|
56
|
+
if (!this.releasedModes.has(body) || this.world.getBodyMode(body) !== 'kinematic')
|
|
57
|
+
this.releasedModes.set(body, this.world.getBodyMode(body)!);
|
|
58
|
+
if (this.world.getBodyMode(body) !== 'kinematic')
|
|
59
|
+
this.world.setBodyParameters(body, {mode: 'kinematic'});
|
|
60
|
+
} else if (this.releasedModes.has(body)) {
|
|
61
|
+
this.world.setBodyParameters(body, {mode: this.releasedModes.get(body)!});
|
|
62
|
+
this.releasedModes.delete(body);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.activeTargets = active;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
captureOwnership(): {
|
|
69
|
+
active: ScenegraphNode[];
|
|
70
|
+
releasedModes: [number, 'static' | 'dynamic' | 'kinematic'][];
|
|
71
|
+
} {
|
|
72
|
+
return {active: [...(this.activeTargets ?? [])], releasedModes: [...this.releasedModes]};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
restoreOwnership(state: ReturnType<ScenegraphPhysicsMotion['captureOwnership']>): void {
|
|
76
|
+
if (
|
|
77
|
+
state.active.some(node => !this.targets.has(node)) ||
|
|
78
|
+
state.releasedModes.some(
|
|
79
|
+
([body, mode]) =>
|
|
80
|
+
![...this.targets.values()].includes(body) ||
|
|
81
|
+
!['static', 'dynamic', 'kinematic'].includes(mode)
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
throw new Error('Invalid animation ownership capture');
|
|
85
|
+
this.activeTargets = new Set(state.active);
|
|
86
|
+
this.releasedModes.clear();
|
|
87
|
+
for (const [body, mode] of state.releasedModes) this.releasedModes.set(body, mode);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private collectWorldMatrices(): Map<ScenegraphNode, Matrix4> {
|
|
91
|
+
const matrices = new Map<ScenegraphNode, Matrix4>();
|
|
92
|
+
const visit = (node: ScenegraphNode, parent: Matrix4) => {
|
|
93
|
+
if (matrices.has(node)) throw new Error('Physics motion scene must be a tree');
|
|
94
|
+
const matrix = new Matrix4(parent).multiplyRight(node.matrix);
|
|
95
|
+
matrices.set(node, matrix);
|
|
96
|
+
if (node instanceof GroupNode) for (const child of node.children) visit(child, matrix);
|
|
97
|
+
};
|
|
98
|
+
for (const root of this.roots) visit(root, new Matrix4());
|
|
99
|
+
return matrices;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Call after sampling animation, before submitting the corresponding fixed physics step. */
|
|
103
|
+
update(): void {
|
|
104
|
+
const currentMatrices = this.collectWorldMatrices();
|
|
105
|
+
const scaleChanges = this.colliders.flatMap(collider => {
|
|
106
|
+
const matrix = currentMatrices.get(collider.node);
|
|
107
|
+
if (!matrix) throw new Error('Detached collider animation target');
|
|
108
|
+
const local = new Matrix4(matrix);
|
|
109
|
+
if (collider.localMatrix) local.multiplyRight(collider.localMatrix);
|
|
110
|
+
const scale = decomposePhysicsTransform(local).scale.map(Math.abs);
|
|
111
|
+
const previous = this.colliderScales.get(collider.index)!;
|
|
112
|
+
if (scale.every((value, index) => Math.abs(value - previous[index]) < 1e-7)) return [];
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
collider: collider.index,
|
|
116
|
+
scale,
|
|
117
|
+
shapeScale: this.world
|
|
118
|
+
.getColliderShapeScale(collider.index)
|
|
119
|
+
.map((value, index) => (value * scale[index]) / previous[index]),
|
|
120
|
+
shape: scaleRigidBodyShape(
|
|
121
|
+
this.world.getColliderShape(collider.index),
|
|
122
|
+
scale.map((value, index) => value / previous[index])
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
});
|
|
127
|
+
if (scaleChanges.length) {
|
|
128
|
+
this.world.setColliderShapes(scaleChanges);
|
|
129
|
+
for (const change of scaleChanges) this.colliderScales.set(change.collider, change.scale);
|
|
130
|
+
}
|
|
131
|
+
this.inverseBodyFrames.clear();
|
|
132
|
+
for (const [node, body] of this.targets) {
|
|
133
|
+
if (this.activeTargets && !this.activeTargets.has(node)) continue;
|
|
134
|
+
if (this.activeTargets && this.world.getBodyMode(body) !== 'kinematic') {
|
|
135
|
+
this.releasedModes.set(body, this.world.getBodyMode(body)!);
|
|
136
|
+
this.world.setBodyParameters(body, {mode: 'kinematic'});
|
|
137
|
+
}
|
|
138
|
+
const matrix = currentMatrices.get(node);
|
|
139
|
+
if (!matrix) throw new Error('Detached physics motion target');
|
|
140
|
+
const transform = decomposePhysicsTransform(matrix);
|
|
141
|
+
this.world.setKinematicTarget(body, transform.position, transform.rotation);
|
|
142
|
+
this.inverseBodyFrames.set(
|
|
143
|
+
body,
|
|
144
|
+
new Matrix4()
|
|
145
|
+
.translate(transform.position)
|
|
146
|
+
.multiplyRight(new Matrix4().fromQuaternion(transform.rotation))
|
|
147
|
+
.invert()
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
for (const collider of this.colliders) {
|
|
151
|
+
const matrix = currentMatrices.get(collider.node);
|
|
152
|
+
const bodyMatrix = currentMatrices.get(collider.body);
|
|
153
|
+
if (!matrix || !bodyMatrix) throw new Error('Detached collider animation target');
|
|
154
|
+
const body = decomposePhysicsTransform(bodyMatrix);
|
|
155
|
+
const inverse = new Matrix4()
|
|
156
|
+
.translate(body.position)
|
|
157
|
+
.multiplyRight(new Matrix4().fromQuaternion(body.rotation))
|
|
158
|
+
.invert();
|
|
159
|
+
const colliderMatrix = inverse.multiplyRight(matrix);
|
|
160
|
+
if (collider.localMatrix) colliderMatrix.multiplyRight(collider.localMatrix);
|
|
161
|
+
const transform = decomposePhysicsTransform(colliderMatrix);
|
|
162
|
+
const frame = [...transform.position, ...transform.rotation];
|
|
163
|
+
const previousFrame = this.colliderFrames.get(collider.index);
|
|
164
|
+
if (
|
|
165
|
+
!previousFrame ||
|
|
166
|
+
frame.some((value, index) => Math.abs(value - previousFrame[index]) > 1e-7)
|
|
167
|
+
) {
|
|
168
|
+
this.world.setColliderTransform(collider.index, transform.position, transform.rotation);
|
|
169
|
+
this.colliderFrames.set(collider.index, frame);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (this.inverseBodyFrames.size !== (this.activeTargets?.size ?? this.targets.size))
|
|
173
|
+
throw new Error('Detached physics motion target');
|
|
174
|
+
}
|
|
175
|
+
}
|