wallhammer-web 0.0.0-stage → 0.4.1
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/LICENSE +21 -0
- package/README.md +92 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Destruction
|
|
2
|
+
|
|
3
|
+
Destruction has three parts in three places:
|
|
4
|
+
|
|
5
|
+
| Part | Where | What |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| Data types | `wallhammer-web/base` (`destructible.ts`) | `StructureDesc`, `StructureState`, `DAMAGE`, `PART_FLAG`, `PART_ROLE`, damage entries. |
|
|
8
|
+
| The model | `wallhammer-web/sim/destruction` | Pure functions: what an event breaks, what loses support, where rubble lies, the hashable state. |
|
|
9
|
+
| The look | `wallhammer-web/gen-arch` and `wallhammer-web/render` | Damaged meshes, rubble meshes, falling pieces (`fallPieces`) drawn by `TransientLayer`. |
|
|
10
|
+
|
|
11
|
+
The model runs in Node. It has no clock and no GPU.
|
|
12
|
+
|
|
13
|
+
## Descriptions
|
|
14
|
+
|
|
15
|
+
A `StructureDesc` describes one structure as convex parts and bonds. All lengths are integer **centimetres**.
|
|
16
|
+
|
|
17
|
+
- `parts` (sorted by `key`): `role` (`PART_ROLE`: foundation, bearing, span, attached, fixture), `material` (index into `materials`), `mass` in kg, `piece` (a vertical prism over a convex polygon: `xz` corners counter-clockwise, `y0`, `y1`), `flags` (`PART_FLAG.anchor`, `indestructible`, `inner`), `maxSpan`.
|
|
18
|
+
- `bonds` (sorted by `a`, then `b`): `bearing` true when `b` rests on `a`; false for a lateral tie. Centre and area of the shared face.
|
|
19
|
+
- `materials`: `crack`, `breach`, `gone` energy thresholds and `density`.
|
|
20
|
+
- `keepOut`: events never change the structure.
|
|
21
|
+
|
|
22
|
+
Part keys must come from the input (a rule id and the part's path in the recipe), never from emission order. `gen-arch` builds descriptions with `buildBuildingMesh(..., { describe: true })` and stable keys (`PART_RULE`, `bayKey`, `slabKey`, …).
|
|
23
|
+
|
|
24
|
+
You can also write a description by hand. [Recipes](recipes.md#add-a-destructible-structure) shows a two-part structure.
|
|
25
|
+
|
|
26
|
+
## Events and results
|
|
27
|
+
|
|
28
|
+
<!-- check: wrap -->
|
|
29
|
+
```ts
|
|
30
|
+
import type { StructureDesc, StructureState } from 'wallhammer-web/base';
|
|
31
|
+
import { applyEventToAll, compileStructure, destructionEvent, encodeStates, stateHash } from 'wallhammer-web/sim/destruction';
|
|
32
|
+
declare const descs: StructureDesc[];
|
|
33
|
+
|
|
34
|
+
const compiled = descs.map((d) => compileStructure(d)); // cached per description
|
|
35
|
+
let states = new Map<number, StructureState>();
|
|
36
|
+
const ev = destructionEvent({ position: [12, 4, 30], radius: 3, energy: 900, seed: 77, tick: 1 });
|
|
37
|
+
const res = applyEventToAll(compiled, states, ev);
|
|
38
|
+
states = res.states;
|
|
39
|
+
// res.changes: parts that changed rung; res.rubble: new rubble footprints; res.timeline: when each change lets go
|
|
40
|
+
const saved = encodeStates(states.values()); // URL-safe text
|
|
41
|
+
const hash = stateHash([...states.values()]);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`destructionEvent` converts metres to integer centimetres. `applyEvent` works on one structure:
|
|
45
|
+
|
|
46
|
+
1. Hit test: parts whose piece lies within the radius, in key order.
|
|
47
|
+
2. Damage: energy × (r² − d²) / r² against the part's thresholds, each jittered ±20 % by the event seed. A part hit again moves at least one rung.
|
|
48
|
+
3. Support: connectivity from the anchors. A part with no supported path falls (gone).
|
|
49
|
+
4. Rubble: each newly gone part gets a footprint.
|
|
50
|
+
5. Budget: a structure with more than `maxEntries` (default 600) damaged parts becomes a ruin.
|
|
51
|
+
6. Timeline: per change, ticks after the event (`TIMELINE_TICK_S` = 0.05 s) at which the part lets go.
|
|
52
|
+
|
|
53
|
+
The state is committed at once. The timeline is presentation only: a state saved mid-collapse loads as the final state.
|
|
54
|
+
|
|
55
|
+
Other helpers: `intactState`, `isIntact`, `decodeStates`, `sortedEntries`, `solveSupport`, `rubbleFootprints`, `partRubble`, `ruinRubble`, `raycastParts` (pick a part with a ray).
|
|
56
|
+
|
|
57
|
+
## Feeding events from the simulation
|
|
58
|
+
|
|
59
|
+
The module header says that feeding events from the simulation queue is "a later step". Nothing in the engine does it. The two users do it differently:
|
|
60
|
+
|
|
61
|
+
- The destruction example (`examples/destruction`) calls `applyEventToAll` directly from input handlers.
|
|
62
|
+
- The campus app registers simulation commands for hit, set and reset and calls the pure functions from those handlers. That gives replay and seeking for free.
|
|
63
|
+
|
|
64
|
+
If you add destruction to a project, copy the campus pattern: one command per event, the state as simulation state.
|
|
65
|
+
|
|
66
|
+
## State in streamed cells
|
|
67
|
+
|
|
68
|
+
In a streamed world a cell is built again whenever it comes back, so damage cannot live in the cell. `CellStates` keeps it apart: the changed structure states of the whole world, keyed by the home cell of each structure (the one cell that owns it; the content decides at which level) and the structure's id.
|
|
69
|
+
|
|
70
|
+
- `commit(home, states)` replaces the states of a home cell. Intact states are dropped, a ruin keeps no entries. `of(home)` reads them back.
|
|
71
|
+
- `text(under?)` is the canonical URL-safe text of the store, or of the home cells at or under one cell. Hand it to the generator of a cell as its edits (see [Edits and refresh](streaming.md#edits-and-refresh)), so the cell is built with the damage. `decodeCellStates(text)` reads it back; malformed, repeated or refused cells are skipped and reported in `errors`.
|
|
72
|
+
- `hash()` is a 64-bit hash of the store. Text and hash depend only on the content, never on the order of the commits or of a map.
|
|
73
|
+
- Ceiling: `units` (1 per changed structure plus its part entries, 1 per ruin) stays at most `maxUnits` (default `DEFAULT_MAX_UNITS` = 20,000). Over it, the structure with the most entries becomes a ruin (ties: the earlier cell, then the lower id); `commit` returns which ones in `ruined`. A commit that would leave more changed structures than `maxUnits` is refused (`accepted: false`) and changes nothing. The rule reads only the store, never what is loaded or where a viewer is, so the same events give the same store. The text is at most `CELL_STATES_CHARS_PER_UNIT` (40) characters per unit.
|
|
74
|
+
|
|
75
|
+
<!-- check: wrap -->
|
|
76
|
+
```ts
|
|
77
|
+
import type { CellId } from 'wallhammer-web/gen-core';
|
|
78
|
+
import type { DestructionEvent, StructureDesc } from 'wallhammer-web/base';
|
|
79
|
+
import { CellStates, applyEventToAll, decodeCellStates } from 'wallhammer-web/sim/destruction';
|
|
80
|
+
|
|
81
|
+
declare const home: CellId;
|
|
82
|
+
declare const structures: StructureDesc[]; // the structures this home cell owns, from the generator
|
|
83
|
+
declare const ev: DestructionEvent;
|
|
84
|
+
const store = new CellStates({ maxUnits: 2000 });
|
|
85
|
+
const r = applyEventToAll(structures, store.of(home), ev);
|
|
86
|
+
const { accepted, ruined } = store.commit(home, r.states); // then refresh the cells that draw `home` and `ruined`
|
|
87
|
+
const saved = store.text(); // survives a reload, e.g. in the URL
|
|
88
|
+
const { store: loaded, errors } = decodeCellStates(saved, { maxUnits: 2000 });
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The endless example (`dmg=1`) wires it: structures in home cells of level 9, drawn by the cells of levels 7–9 over them, hits by click, the state in the URL. Its golden recipe ("endless example damage") checks that the cells come back as the same bytes after leaving and after a reload.
|
|
92
|
+
|
|
93
|
+
## Drawing damage
|
|
94
|
+
|
|
95
|
+
- `buildBuildingMesh(specs, props, groundAt, dims, { states })` draws structures in a damage state: cracked parts through the damage shader, breached walls as holes with reveals, gone parts as cut faces, a ruin as stubs.
|
|
96
|
+
- `structureMaterial(dims, { damage: true })` is the damage program. Intact structures can keep the plain material.
|
|
97
|
+
- `buildRubbleMesh(footprints, rubbleColours(specs), groundAt, arrival?)` draws rubble. `arrival` lets heaps grow in when pieces land.
|
|
98
|
+
- `fallPieces({ desc, state, before, changes, event, at, groundAt, budget })` cuts the gone parts out of the structure as it stood before the event. Each piece gets a closed-form track. Draw the batch with `fallingMaterial` in a `TransientLayer` (`maxPieces` default 320). Over budget, pieces turn into dust.
|
|
99
|
+
- `retimeFall(out, dt)` moves a prepared batch `dt` seconds later on the clock: tracks in the vertices, puffs, rubble arrivals, start and end. Use it when the batch is made some time before it is shown.
|
|
100
|
+
|
|
101
|
+
`examples/destruction/src/main.ts` wires all of this.
|
|
102
|
+
|
|
103
|
+
### How the pieces look and move
|
|
104
|
+
|
|
105
|
+
- Solid pieces (masonry, floors, partitions) get a closed shell just inside their outline. Faces narrower than 0.8 m (a broken edge, the thickness of a slab or a wall) show the dark broken core (damage 3). Broad faces show what the part had inside, in the interior shading (`KIND.interior`): a slab has its floor on top and its ceiling below, a partition and the back of a wall have room paint. The room hash comes from the part key, so all pieces of one slab match.
|
|
106
|
+
- Patterns stay on a moving piece. `BUILDING_VS` passes the rest position and rest normal (`v_pat`, `v_patN`); `fallingMaterial` sets them from the vertex before its track moves it. The damage pattern, the roof noise and the door heights read them. For a static mesh they equal the world position, so intact structures draw the same as before.
|
|
107
|
+
- Fallen roof reads as roof. Rubble of a roof span is a dust mound in the wall colour with three to five roof sections on it: a core slab with the roof covering on top (`KIND.roofPitched`, courses along its tilt). Floor spans get concrete sections in the trim colour.
|
|
108
|
+
- Tracks stay out of standing parts, without collision state. A piece that lost its support leans away from the structure's centre (0.35–1.05 m/s) and lets go within 0.14 s of its timeline time. Before a track is kept, its landing spot and the middle of its flight are tested against standing parts (grid lookup, point in footprint). When one lies inside, the horizontal velocity is tried at 0.6, 0.3, −0.4 and 0 of its value. The landing height follows the spot: the highest standing top under it, else the ground. Every landing still makes a dust puff.
|
|
109
|
+
|
|
110
|
+
### Keeping a hit cheap
|
|
111
|
+
|
|
112
|
+
A hit on the largest campus structure (`tools/bench/bench.mjs hit` against the app's page) used to block the main thread for 140–170 ms in one task: describe the structure, apply the event, draw the before mesh by parts, cut the pieces, regenerate the damaged mesh. The campus now splits it:
|
|
113
|
+
|
|
114
|
+
- Descriptions are made in idle time after the buildings are set, largest footprint first, a few per idle slot (`requestIdleCallback`, at most ~8 ms of work per slot unless one structure takes longer). A hit before that finishes describes on the spot.
|
|
115
|
+
- `buildBuildingMesh` keeps the footprint index of a spec array (`WeakMap`, checked against every ring), and the cut roof cells of a spec (checked against its box, grid and roof triangles).
|
|
116
|
+
- The hit commits the state at once (`destroy()` returns the new state), then queues the rest, one job per task: the before mesh by parts (reused from the last drawn mesh when its state hash matches), `fallPieces`, the new damaged mesh. A last task moves the prepared falls to the current clock time with `retimeFall`, uploads everything and shows it. The picture changes about 0.1 s after the hit.
|
|
117
|
+
- `__wh.destructionSettled()` resolves when the picture is shown; `collapseAt` flushes the queue first.
|
|
118
|
+
|
|
119
|
+
## Known weaknesses
|
|
120
|
+
|
|
121
|
+
Measured on 2026-11-13 with headless Chrome on the development machine:
|
|
122
|
+
|
|
123
|
+
- A hit on the largest campus structure: `destroy()` 8–9 ms when the description is ready, longest task after it 30–34 ms (`fallPieces`), picture shown after 110–120 ms. A hit within about a second of loading describes the structure on the spot: 32–43 ms in the bench (with the profiler on). No task of 50 ms or more in either case.
|
|
124
|
+
- Pieces can still pass through each other: there is no piece-to-piece test, only the lean away from the centre and the stagger. A large roof section can sweep through wall pieces as it tilts.
|
|
125
|
+
- A piece is tested against standing parts at two points of its flight only. A fast piece can clip a corner between them.
|
|
126
|
+
- Campus screenshots at the usual zooms show the pieces small; most of the look was judged on the destruction example (`examples/destruction`).
|
|
127
|
+
- Interiors are generic: the same division on every storey, empty rooms, dark by day.
|
package/docs/frames.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# Bodies on rails and nested frames
|
|
2
|
+
|
|
3
|
+
This page covers scenes that are far larger than a flat map: several bodies that move round each other, each with a surface you can stand on. Three parts work together. All of them are plain math, run in Node, and change nothing in a scene that does not use them.
|
|
4
|
+
|
|
5
|
+
| Part | Entry | What it is |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| Reproducible trigonometry | `wallhammer-web/base` | `detSinCosTurns` and relatives: the same bits on every machine. |
|
|
8
|
+
| Nested frames | `wallhammer-web/base` | `FrameSet`: positions in 64 bits, conversion between frames, 32-bit numbers relative to the eye for the GPU. |
|
|
9
|
+
| Orbits and spin from time | `wallhammer-web/core` | `prepareOrbit`, `orbitPosition`, `spinRotation`, and `BodySystem`, which places a whole system in a `FrameSet`. |
|
|
10
|
+
|
|
11
|
+
Axes are those of the rest of the engine: one unit is one metre, y is up. On a surface patch x points east and z south, as on a flat map.
|
|
12
|
+
|
|
13
|
+
## Scale
|
|
14
|
+
|
|
15
|
+
The engine is built and tested for a reduced scale, not for real astronomical sizes:
|
|
16
|
+
|
|
17
|
+
| Quantity | Range |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| Radius of a body | 50 km to 300 km |
|
|
20
|
+
| Distance between bodies | tens of thousands of km; tested up to 100,000 km from the centre |
|
|
21
|
+
| Day and year | free; periods are given directly, not derived from masses, so a day can last minutes |
|
|
22
|
+
|
|
23
|
+
Travel between bodies is short enough to need no special mode, and time can be sped up. Nothing in the code enforces these ranges. Positions are 64-bit, so at 100,000 km from the centre one step of a coordinate is 0.00001 mm.
|
|
24
|
+
|
|
25
|
+
## Reproducible trigonometry
|
|
26
|
+
|
|
27
|
+
`Math.sin` and its relatives may differ in the last bit between machines, and between Node and a browser. Anything whose result must agree everywhere uses the `det` functions instead. They are built only from `+ − × ÷` and `Math.sqrt` in a fixed order.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { detAtan2, detSinCos, detSinCosTurns } from 'wallhammer-web/base';
|
|
31
|
+
|
|
32
|
+
const [s, c] = detSinCosTurns(0.125); // 45°, the angle in turns
|
|
33
|
+
const [s2, c2] = detSinCos(Math.PI / 4); // the same in radians
|
|
34
|
+
const angle = detAtan2(s, c); // radians, −π … π
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Keep an angle that grows with time in turns (`phase + t / period`). The whole turns are dropped without rounding, so the angle stays precise after any number of turns. `detSinCos` takes radians and keeps an absolute error near 1e-16 up to about a million radians; a result close to zero then has fewer correct digits than one in turns, and beyond that range the accuracy drops further.
|
|
38
|
+
|
|
39
|
+
The functions are accurate to about one unit in the last place. They are not the correctly rounded values and they are not bit-equal to `Math.sin`; they are equal to themselves everywhere.
|
|
40
|
+
|
|
41
|
+
## Orbits and spin from time
|
|
42
|
+
|
|
43
|
+
An orbit is a Kepler ellipse round the origin of the parent. `prepareOrbit` checks the elements and works out the constant part. `orbitPosition` and `orbitVelocity` are then pure functions of time: no state is kept, so stepping through time and jumping to a moment give the same bits.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { orbitPosition, orbitVelocity, prepareOrbit, prepareSpin, spinRotation } from 'wallhammer-web/core';
|
|
47
|
+
|
|
48
|
+
const orbit = prepareOrbit({
|
|
49
|
+
semiMajorAxis: 40_000_000, // metres
|
|
50
|
+
periodS: 5400, // one round; negative goes the other way
|
|
51
|
+
eccentricity: 0.2, // 0 … ORBIT_MAX_ECCENTRICITY (0.9)
|
|
52
|
+
inclinationDeg: 12,
|
|
53
|
+
ascendingNodeDeg: 75,
|
|
54
|
+
periapsisDeg: 200,
|
|
55
|
+
phase: 0.3, // turns of mean anomaly at time 0
|
|
56
|
+
});
|
|
57
|
+
const p = orbitPosition(orbit, 1234.5); // metres, in the parent frame
|
|
58
|
+
const v = orbitVelocity(orbit, 1234.5); // m/s
|
|
59
|
+
|
|
60
|
+
const spin = prepareSpin({ periodS: 600, tiltDeg: 23.5, tiltLongitudeDeg: 40 });
|
|
61
|
+
const q = spinRotation(spin, 1234.5); // a unit quaternion [x, y, z, w]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The reference plane is the xz plane. Longitudes are measured in it from +x toward −z (anticlockwise seen from +y). Kepler's equation is solved with exactly `ORBIT_SOLVER_STEPS` Newton steps, never "until it converges", so the result does not depend on a tolerance. `solveKepler` is exported for code that needs the anomaly itself.
|
|
65
|
+
|
|
66
|
+
## A system of bodies
|
|
67
|
+
|
|
68
|
+
`BodySystem` takes a list of bodies and owns a `FrameSet`. Each body gets two frames:
|
|
69
|
+
|
|
70
|
+
- `carriedFrame`: the origin is the centre of the body, the axes stay parallel to the system. Bodies that go round this one hang under it, so they do not turn with it.
|
|
71
|
+
- `turningFrame`: the same origin, turned by the spin. +y is the axis of the body. Everything that stands on the body hangs under it.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { BodySystem } from 'wallhammer-web/core';
|
|
75
|
+
|
|
76
|
+
const system = new BodySystem([
|
|
77
|
+
{ name: 'light', radius: 300_000 },
|
|
78
|
+
{ name: 'home', radius: 100_000, orbit: { semiMajorAxis: 20_000_000, periodS: 5400 }, spin: { periodS: 600, tiltDeg: 23.5 } },
|
|
79
|
+
{ name: 'companion', parent: 'home', radius: 50_000, orbit: { semiMajorAxis: 1_200_000, periodS: 900, inclinationDeg: 12 } },
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const HZ = 20;
|
|
83
|
+
system.setTick(36_000, HZ); // the state 30 minutes in, however the clock got there
|
|
84
|
+
const home = system.body('home');
|
|
85
|
+
const centre = system.frames.pose(home.carriedFrame).origin; // 64-bit, in the frame of the system
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A parent must come before its children in the list. A body without an orbit stays at the centre of its parent.
|
|
89
|
+
|
|
90
|
+
**Keep time as a whole number of ticks.** `setTime(t)` depends on `t` alone, but a `t` that was summed from fractional steps is itself different from a `t` computed in one go. `setTick(tick, hz)` divides once. The golden test steps a system 40,000 ticks and compares it bit for bit with a system that jumps.
|
|
91
|
+
|
|
92
|
+
`fingerprint()` returns a 32-bit digest of every frame. Print it in the browser and in Node for the same tick to check that both agree.
|
|
93
|
+
|
|
94
|
+
The golden scenarios have one digest of their own for the same purpose. It must print the same text in Node and in the console of a page served by the dev server (here the page of `examples/minimal-3d`; the path starts with the example's name):
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
docker compose exec -T dev sh -c 'cd /app && node --input-type=module -e "import(\"/app/tools/golden/engine/frames-scenario.ts\").then((m) => console.log(m.framesDigest()))"'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
(await import('/minimal-3d/@fs/app/tools/golden/engine/frames-scenario.ts')).framesDigest();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Day, night and seasons
|
|
105
|
+
|
|
106
|
+
They need no code of their own. They follow from the spin and the tilt:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { directionFromDeg } from 'wallhammer-web/base';
|
|
110
|
+
import { BodySystem } from 'wallhammer-web/core';
|
|
111
|
+
|
|
112
|
+
declare const system: BodySystem;
|
|
113
|
+
const home = system.body('home');
|
|
114
|
+
const light = system.body('light').carriedFrame;
|
|
115
|
+
|
|
116
|
+
// Direction toward the light, in the turning frame of the body.
|
|
117
|
+
const { direction } = system.frames.directionTo(light, home.turningFrame);
|
|
118
|
+
const up = directionFromDeg(50, 14); // a place: latitude 50°, longitude 14°
|
|
119
|
+
const isDay = direction[0] * up[0] + direction[1] * up[1] + direction[2] * up[2] > 0;
|
|
120
|
+
|
|
121
|
+
// The place that has the light overhead. Its latitude is the season: it swings between
|
|
122
|
+
// plus and minus the tilt over one round. Its longitude is where it is noon.
|
|
123
|
+
const under = system.subPoint(home.index, light);
|
|
124
|
+
const hour = ((((14 - under.longitudeDeg) / 360 + 0.5) % 1) + 1) % 1 * 24; // local solar time at longitude 14°
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
To light a scene drawn in a surface patch, ask for the direction in the frame of that patch: `system.frames.directionTo(light, patch).direction` is a unit vector with y up, ready for `Renderer.lightDirection`.
|
|
128
|
+
|
|
129
|
+
## Nested frames
|
|
130
|
+
|
|
131
|
+
A frame is an origin and a rotation in its parent. `FrameSet` stores them as 64-bit numbers and converts between any two frames under the same top frame. A conversion climbs to the lowest frame the two share and descends again, so the large numbers of the upper levels never enter a conversion between neighbours.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { directionFromDeg, relativeMatrix, relativePoints, tangentPose } from 'wallhammer-web/base';
|
|
135
|
+
import { BodySystem } from 'wallhammer-web/core';
|
|
136
|
+
|
|
137
|
+
declare const system: BodySystem;
|
|
138
|
+
const frames = system.frames;
|
|
139
|
+
const home = system.body('home');
|
|
140
|
+
|
|
141
|
+
// A patch of the surface: origin on the sphere, x east, y up, z south.
|
|
142
|
+
const patch = frames.add('patch', home.turningFrame, tangentPose(directionFromDeg(50, 14), home.radius));
|
|
143
|
+
const neighbour = frames.add('neighbour', home.turningFrame, tangentPose(directionFromDeg(50.5, 14), home.radius));
|
|
144
|
+
|
|
145
|
+
// The image is drawn in the frame the camera is in; the eye is a 64-bit point of that frame.
|
|
146
|
+
const drawIn = patch;
|
|
147
|
+
const eye: [number, number, number] = [812.5, 1.7, -1340];
|
|
148
|
+
|
|
149
|
+
// Model matrix of another frame for the GPU: 32-bit, relative to the eye.
|
|
150
|
+
const model = relativeMatrix(frames.relativePose(neighbour, drawIn), eye);
|
|
151
|
+
|
|
152
|
+
// Or many 64-bit points at once (x, y, z triples local to `neighbour`).
|
|
153
|
+
const centres = new Float64Array([0, 0, 0, 512, 3, -128]);
|
|
154
|
+
const forGpu = relativePoints(centres, frames.relativePose(neighbour, drawIn), eye);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Rules that keep the image steady:
|
|
158
|
+
|
|
159
|
+
- Keep every position in the frame where it is small: a thing on the ground in its patch, a body in the frame of its parent.
|
|
160
|
+
- Never send an absolute position to the GPU. Send `relativeMatrix` or `relativePoints`; both subtract the eye in 64 bits and round once.
|
|
161
|
+
- The eye passed here and the origin the view matrix is built round must be the same point (`Renderer.worldOrigin` for a renderer that draws relative to a moving origin).
|
|
162
|
+
|
|
163
|
+
The golden test puts an object on a turning body 100,000 km from the centre. The position the GPU gets is within 0.001 mm of the truth in every drawing frame. Absolute 32-bit coordinates are off by four metres there.
|
|
164
|
+
|
|
165
|
+
`convertPoint`, `convertDirection` and `convertRotation` convert a single value. `directionTo(target, frame, at)` gives the unit direction and the distance from a point to the origin of another frame.
|
|
166
|
+
|
|
167
|
+
### Moving frames and reparenting
|
|
168
|
+
|
|
169
|
+
A frame may carry its motion: the velocity of its origin and its angular velocity (`setMotion`). `BodySystem.setTime` sets both for every body frame. `convertState` converts a point together with its velocity and accounts for the motion of the frames on the way: a thing that stands on a turning body moves when seen from outside.
|
|
170
|
+
|
|
171
|
+
`reparent(id, parent)` hands a frame to another parent without moving it. Its pose, velocity and angular velocity are rewritten. Use it when something travels from one body to another:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { BodySystem } from 'wallhammer-web/core';
|
|
175
|
+
|
|
176
|
+
declare const system: BodySystem;
|
|
177
|
+
const frames = system.frames;
|
|
178
|
+
const craft = frames.add('craft', system.root, { origin: [0, 0, 30_000_000] });
|
|
179
|
+
|
|
180
|
+
// Index of the body the craft is kept by; −1 while it is in the frame of the whole system.
|
|
181
|
+
let attached = -1;
|
|
182
|
+
|
|
183
|
+
// On a simulation step, never between steps. The point [0, 0, 0] of the craft's own frame is the craft.
|
|
184
|
+
const enter = system.dominantBody([0, 0, 0], craft); // the body whose reach holds the craft, or −1
|
|
185
|
+
const keep = system.dominantBody([0, 0, 0], craft, 1.1); // the same with every reach 10 % larger
|
|
186
|
+
// Stay with the current body while its enlarged reach still wins; otherwise go where the plain reaches say.
|
|
187
|
+
// A body is entered at its reach and left only 10 % beyond, so the answer does not flip on the boundary.
|
|
188
|
+
const next = keep === attached ? attached : enter;
|
|
189
|
+
if (next !== attached) {
|
|
190
|
+
frames.reparent(craft, next >= 0 ? system.bodies[next]!.carriedFrame : system.root);
|
|
191
|
+
attached = next;
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
`dominantBody` picks the most deeply nested body whose reach (`BodyDef.influence`, by default `BODY_INFLUENCE_RADII` radii) holds the point. A frame that follows a camera can be reparented the same way; convert the camera's own position and orientation with `convertPoint` and `convertRotation` before the frame they were given in changes.
|
|
196
|
+
|
|
197
|
+
## Checks
|
|
198
|
+
|
|
199
|
+
Three golden recipes cover this page (`tools/golden/engine/frames-scenario.ts`): a fixed table of the `det` functions, a system stepped against a system that jumps, and the far surface object with reparenting. See [Tools](tools.md#golden-hashes).
|