wallhammer-web 0.0.0-stage → 0.4.0
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 +88 -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,8 @@
|
|
|
1
|
+
export { Pose, Skeleton, boneMask } from './skeleton.ts';
|
|
2
|
+
export type { BoneMask, BoneMaskOptions, BoneSpec } from './skeleton.ts';
|
|
3
|
+
export { addPose, blendPose, nlerpInto, setBoneAxisAngle, setBoneEuler, setBoneRotation, solvePose, solvePoseBelow, subtractPose } from './pose-ops.ts';
|
|
4
|
+
export type { EulerOrder } from './pose-ops.ts';
|
|
5
|
+
export { MotionGraph, MotionGraphDef, compileMotionGraph, speedWeights } from './graph.ts';
|
|
6
|
+
export type { MotionCondition, MotionEase, MotionEventKind, MotionGraphDesc, MotionLayerDesc, MotionSource, MotionStateDesc, MotionTransitionDesc } from './graph.ts';
|
|
7
|
+
export { fitToGround, reachTwoBone } from './reach.ts';
|
|
8
|
+
export type { GroundFitOptions, TwoBoneChain } from './reach.ts';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Layer 2, motion: skeletons and poses as data, blend and additive operations, a motion graph of states, transitions,
|
|
2
|
+
// layers, parameters, triggers, marks and events over motions the game writes, and post steps (two-bone reach, ends
|
|
3
|
+
// kept on the ground). Imports nothing outside itself (it may use base): no GPU, no browser, no clock. The engine holds no
|
|
4
|
+
// motion: every pose comes from a `MotionSource` of the game.
|
|
5
|
+
export { Pose, Skeleton, boneMask } from './skeleton.js';
|
|
6
|
+
export { addPose, blendPose, nlerpInto, setBoneAxisAngle, setBoneEuler, setBoneRotation, solvePose, solvePoseBelow, subtractPose } from './pose-ops.js';
|
|
7
|
+
export { MotionGraph, MotionGraphDef, compileMotionGraph, speedWeights } from './graph.js';
|
|
8
|
+
export { fitToGround, reachTwoBone } from './reach.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BoneMask, Pose, Skeleton } from './skeleton.ts';
|
|
2
|
+
/** `out` = `a` blended toward `b` by `w` (0 = a, 1 = b), per bone times `mask` when given. */
|
|
3
|
+
export declare function blendPose(out: Pose, a: Pose, b: Pose, w: number, mask?: BoneMask | null): void;
|
|
4
|
+
/** `out` = `base` with the additive pose `add` applied by `w`, per bone times `mask` when given. */
|
|
5
|
+
export declare function addPose(out: Pose, base: Pose, add: Pose, w: number, mask?: BoneMask | null): void;
|
|
6
|
+
/** `out` = the additive pose that turns `ref` into `a` (ref⁻¹ · a per bone, offsets a − ref). */
|
|
7
|
+
export declare function subtractPose(out: Pose, a: Pose, ref: Pose): void;
|
|
8
|
+
/** Sets a bone's rotation to the quaternion (x, y, z, w), normalised. */
|
|
9
|
+
export declare function setBoneRotation(pose: Pose, bone: number, x: number, y: number, z: number, w: number): void;
|
|
10
|
+
/** Sets a bone's rotation to `rad` radians about the axis (ax, ay, az) (normalised; a zero axis gives identity). */
|
|
11
|
+
export declare function setBoneAxisAngle(pose: Pose, bone: number, ax: number, ay: number, az: number, rad: number): void;
|
|
12
|
+
/** Order of the three factors of `setBoneEuler`, left to right in the product (`'yxz'`: Ry · Rx · Rz). */
|
|
13
|
+
export type EulerOrder = 'xyz' | 'xzy' | 'yxz' | 'yzx' | 'zxy' | 'zyx';
|
|
14
|
+
/**
|
|
15
|
+
* Sets a bone's rotation from angles about its local x, y and z (radians, right-handed), multiplied in `order`
|
|
16
|
+
* from left to right: `'xyz'` (default) is Rx · Ry · Rz, so z is applied to a point first.
|
|
17
|
+
*/
|
|
18
|
+
export declare function setBoneEuler(pose: Pose, bone: number, rx: number, ry: number, rz: number, order?: EulerOrder): void;
|
|
19
|
+
/**
|
|
20
|
+
* World 3 × 4 matrix of every bone into `outWorld` (12 numbers per bone, column by column): a root bone is placed
|
|
21
|
+
* by `root` (a 3 × 4 matrix), every other one by its parent; local = translate(joint + offset) · rotate(rot).
|
|
22
|
+
*/
|
|
23
|
+
export declare function solvePose(skeleton: Skeleton, pose: Pose, root: ArrayLike<number>, outWorld: Float32Array | Float64Array): void;
|
|
24
|
+
/**
|
|
25
|
+
* Like `solvePose`, but only `bone` and the bones below it, from the parent matrices already in `outWorld`: after a
|
|
26
|
+
* change of the pose of that bone (a reach), the rest of the skeleton stays as it was solved.
|
|
27
|
+
*/
|
|
28
|
+
export declare function solvePoseBelow(skeleton: Skeleton, pose: Pose, root: ArrayLike<number>, outWorld: Float32Array | Float64Array, bone: number): void;
|
|
29
|
+
/** Normalised linear interpolation of two quaternions along the shortest arc into `o` at `q`. */
|
|
30
|
+
export declare function nlerpInto(o: Float32Array | Float64Array, q: number, ax: number, ay: number, az: number, aw: number, bx: number, by: number, bz: number, bw: number, t: number): void;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Operations on poses: override blend, additive layer, the difference of two poses, writing a bone's rotation from
|
|
2
|
+
// angles, and solving a pose into world matrices (3 × 4, 12 numbers per bone, the instance record layout of `base`).
|
|
3
|
+
// Everything writes into arrays it is given and allocates nothing; `out` may be the same pose as an input.
|
|
4
|
+
//
|
|
5
|
+
// Rotations blend by normalised linear interpolation along the shortest arc (the sign of one quaternion is flipped
|
|
6
|
+
// when the two lie more than half a turn apart). An additive pose is a change from the rest pose: its rotation is
|
|
7
|
+
// applied after the base rotation in the bone's own frame (base · add), its offset is added.
|
|
8
|
+
/** `out` = `a` blended toward `b` by `w` (0 = a, 1 = b), per bone times `mask` when given. */
|
|
9
|
+
export function blendPose(out, a, b, w, mask) {
|
|
10
|
+
const n = out.skeleton.count;
|
|
11
|
+
const ra = a.rot, rb = b.rot, ro = out.rot;
|
|
12
|
+
const oa = a.offset, ob = b.offset, oo = out.offset;
|
|
13
|
+
for (let i = 0; i < n; i++) {
|
|
14
|
+
const t = mask ? w * mask[i] : w;
|
|
15
|
+
const q = i * 4;
|
|
16
|
+
const p = i * 3;
|
|
17
|
+
if (t <= 0) {
|
|
18
|
+
if (out !== a) {
|
|
19
|
+
ro[q] = ra[q];
|
|
20
|
+
ro[q + 1] = ra[q + 1];
|
|
21
|
+
ro[q + 2] = ra[q + 2];
|
|
22
|
+
ro[q + 3] = ra[q + 3];
|
|
23
|
+
oo[p] = oa[p];
|
|
24
|
+
oo[p + 1] = oa[p + 1];
|
|
25
|
+
oo[p + 2] = oa[p + 2];
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (t >= 1) {
|
|
30
|
+
ro[q] = rb[q];
|
|
31
|
+
ro[q + 1] = rb[q + 1];
|
|
32
|
+
ro[q + 2] = rb[q + 2];
|
|
33
|
+
ro[q + 3] = rb[q + 3];
|
|
34
|
+
oo[p] = ob[p];
|
|
35
|
+
oo[p + 1] = ob[p + 1];
|
|
36
|
+
oo[p + 2] = ob[p + 2];
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
nlerpInto(ro, q, ra[q], ra[q + 1], ra[q + 2], ra[q + 3], rb[q], rb[q + 1], rb[q + 2], rb[q + 3], t);
|
|
40
|
+
oo[p] = oa[p] + (ob[p] - oa[p]) * t;
|
|
41
|
+
oo[p + 1] = oa[p + 1] + (ob[p + 1] - oa[p + 1]) * t;
|
|
42
|
+
oo[p + 2] = oa[p + 2] + (ob[p + 2] - oa[p + 2]) * t;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** `out` = `base` with the additive pose `add` applied by `w`, per bone times `mask` when given. */
|
|
46
|
+
export function addPose(out, base, add, w, mask) {
|
|
47
|
+
const n = out.skeleton.count;
|
|
48
|
+
const rb = base.rot, ra = add.rot, ro = out.rot;
|
|
49
|
+
const ob = base.offset, oa = add.offset, oo = out.offset;
|
|
50
|
+
for (let i = 0; i < n; i++) {
|
|
51
|
+
const t = mask ? w * mask[i] : w;
|
|
52
|
+
const q = i * 4;
|
|
53
|
+
const p = i * 3;
|
|
54
|
+
const bx = rb[q], by = rb[q + 1], bz = rb[q + 2], bw = rb[q + 3];
|
|
55
|
+
if (t === 0) {
|
|
56
|
+
ro[q] = bx;
|
|
57
|
+
ro[q + 1] = by;
|
|
58
|
+
ro[q + 2] = bz;
|
|
59
|
+
ro[q + 3] = bw;
|
|
60
|
+
oo[p] = ob[p];
|
|
61
|
+
oo[p + 1] = ob[p + 1];
|
|
62
|
+
oo[p + 2] = ob[p + 2];
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// The change scaled toward identity by t (nlerp from [0, 0, 0, 1]).
|
|
66
|
+
let x = ra[q], y = ra[q + 1], z = ra[q + 2], s = ra[q + 3];
|
|
67
|
+
if (t !== 1) {
|
|
68
|
+
if (s < 0) {
|
|
69
|
+
x = -x;
|
|
70
|
+
y = -y;
|
|
71
|
+
z = -z;
|
|
72
|
+
s = -s;
|
|
73
|
+
}
|
|
74
|
+
x *= t;
|
|
75
|
+
y *= t;
|
|
76
|
+
z *= t;
|
|
77
|
+
s = 1 - t + s * t;
|
|
78
|
+
const l = Math.sqrt(x * x + y * y + z * z + s * s) || 1;
|
|
79
|
+
x /= l;
|
|
80
|
+
y /= l;
|
|
81
|
+
z /= l;
|
|
82
|
+
s /= l;
|
|
83
|
+
}
|
|
84
|
+
ro[q] = bw * x + bx * s + by * z - bz * y;
|
|
85
|
+
ro[q + 1] = bw * y - bx * z + by * s + bz * x;
|
|
86
|
+
ro[q + 2] = bw * z + bx * y - by * x + bz * s;
|
|
87
|
+
ro[q + 3] = bw * s - bx * x - by * y - bz * z;
|
|
88
|
+
oo[p] = ob[p] + oa[p] * t;
|
|
89
|
+
oo[p + 1] = ob[p + 1] + oa[p + 1] * t;
|
|
90
|
+
oo[p + 2] = ob[p + 2] + oa[p + 2] * t;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** `out` = the additive pose that turns `ref` into `a` (ref⁻¹ · a per bone, offsets a − ref). */
|
|
94
|
+
export function subtractPose(out, a, ref) {
|
|
95
|
+
const n = out.skeleton.count;
|
|
96
|
+
const ra = a.rot, rr = ref.rot, ro = out.rot;
|
|
97
|
+
for (let i = 0; i < n; i++) {
|
|
98
|
+
const q = i * 4;
|
|
99
|
+
const cx = -rr[q], cy = -rr[q + 1], cz = -rr[q + 2], cw = rr[q + 3];
|
|
100
|
+
const x = ra[q], y = ra[q + 1], z = ra[q + 2], w = ra[q + 3];
|
|
101
|
+
ro[q] = cw * x + cx * w + cy * z - cz * y;
|
|
102
|
+
ro[q + 1] = cw * y - cx * z + cy * w + cz * x;
|
|
103
|
+
ro[q + 2] = cw * z + cx * y - cy * x + cz * w;
|
|
104
|
+
ro[q + 3] = cw * w - cx * x - cy * y - cz * z;
|
|
105
|
+
}
|
|
106
|
+
const oa = a.offset, or = ref.offset, oo = out.offset;
|
|
107
|
+
for (let k = 0; k < n * 3; k++)
|
|
108
|
+
oo[k] = oa[k] - or[k];
|
|
109
|
+
}
|
|
110
|
+
/** Sets a bone's rotation to the quaternion (x, y, z, w), normalised. */
|
|
111
|
+
export function setBoneRotation(pose, bone, x, y, z, w) {
|
|
112
|
+
const l = Math.sqrt(x * x + y * y + z * z + w * w) || 1;
|
|
113
|
+
const r = pose.rot;
|
|
114
|
+
const q = bone * 4;
|
|
115
|
+
r[q] = x / l;
|
|
116
|
+
r[q + 1] = y / l;
|
|
117
|
+
r[q + 2] = z / l;
|
|
118
|
+
r[q + 3] = w / l;
|
|
119
|
+
}
|
|
120
|
+
/** Sets a bone's rotation to `rad` radians about the axis (ax, ay, az) (normalised; a zero axis gives identity). */
|
|
121
|
+
export function setBoneAxisAngle(pose, bone, ax, ay, az, rad) {
|
|
122
|
+
const l = Math.sqrt(ax * ax + ay * ay + az * az);
|
|
123
|
+
const r = pose.rot;
|
|
124
|
+
const q = bone * 4;
|
|
125
|
+
if (l === 0) {
|
|
126
|
+
r[q] = 0;
|
|
127
|
+
r[q + 1] = 0;
|
|
128
|
+
r[q + 2] = 0;
|
|
129
|
+
r[q + 3] = 1;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const s = Math.sin(rad / 2) / l;
|
|
133
|
+
r[q] = ax * s;
|
|
134
|
+
r[q + 1] = ay * s;
|
|
135
|
+
r[q + 2] = az * s;
|
|
136
|
+
r[q + 3] = Math.cos(rad / 2);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sets a bone's rotation from angles about its local x, y and z (radians, right-handed), multiplied in `order`
|
|
140
|
+
* from left to right: `'xyz'` (default) is Rx · Ry · Rz, so z is applied to a point first.
|
|
141
|
+
*/
|
|
142
|
+
export function setBoneEuler(pose, bone, rx, ry, rz, order = 'xyz') {
|
|
143
|
+
const hx = rx / 2, hy = ry / 2, hz = rz / 2;
|
|
144
|
+
const sx = Math.sin(hx), cx = Math.cos(hx);
|
|
145
|
+
const sy = Math.sin(hy), cy = Math.cos(hy);
|
|
146
|
+
const sz = Math.sin(hz), cz = Math.cos(hz);
|
|
147
|
+
// Start with the first factor, multiply the next two on the right.
|
|
148
|
+
let x = 0, y = 0, z = 0, w = 1;
|
|
149
|
+
for (let k = 0; k < 3; k++) {
|
|
150
|
+
const axis = order.charCodeAt(k) - 120; // 0 x, 1 y, 2 z
|
|
151
|
+
const s = axis === 0 ? sx : axis === 1 ? sy : sz;
|
|
152
|
+
const c = axis === 0 ? cx : axis === 1 ? cy : cz;
|
|
153
|
+
const bx = axis === 0 ? s : 0, by = axis === 1 ? s : 0, bz = axis === 2 ? s : 0;
|
|
154
|
+
const nx = w * bx + x * c + y * bz - z * by;
|
|
155
|
+
const ny = w * by - x * bz + y * c + z * bx;
|
|
156
|
+
const nz = w * bz + x * by - y * bx + z * c;
|
|
157
|
+
const nw = w * c - x * bx - y * by - z * bz;
|
|
158
|
+
x = nx;
|
|
159
|
+
y = ny;
|
|
160
|
+
z = nz;
|
|
161
|
+
w = nw;
|
|
162
|
+
}
|
|
163
|
+
const r = pose.rot;
|
|
164
|
+
const q = bone * 4;
|
|
165
|
+
r[q] = x;
|
|
166
|
+
r[q + 1] = y;
|
|
167
|
+
r[q + 2] = z;
|
|
168
|
+
r[q + 3] = w;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* World 3 × 4 matrix of every bone into `outWorld` (12 numbers per bone, column by column): a root bone is placed
|
|
172
|
+
* by `root` (a 3 × 4 matrix), every other one by its parent; local = translate(joint + offset) · rotate(rot).
|
|
173
|
+
*/
|
|
174
|
+
export function solvePose(skeleton, pose, root, outWorld) {
|
|
175
|
+
solveRange(skeleton, pose, root, outWorld, -1);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Like `solvePose`, but only `bone` and the bones below it, from the parent matrices already in `outWorld`: after a
|
|
179
|
+
* change of the pose of that bone (a reach), the rest of the skeleton stays as it was solved.
|
|
180
|
+
*/
|
|
181
|
+
export function solvePoseBelow(skeleton, pose, root, outWorld, bone) {
|
|
182
|
+
solveRange(skeleton, pose, root, outWorld, bone);
|
|
183
|
+
}
|
|
184
|
+
function solveRange(skeleton, pose, root, out, from) {
|
|
185
|
+
const n = skeleton.count;
|
|
186
|
+
const par = skeleton.parent, jt = skeleton.joint, rot = pose.rot, off = pose.offset;
|
|
187
|
+
for (let b = from < 0 ? 0 : from; b < n; b++) {
|
|
188
|
+
if (from >= 0 && b !== from && !skeleton.isBelow(b, from))
|
|
189
|
+
continue;
|
|
190
|
+
const q = b * 4;
|
|
191
|
+
const x = rot[q], y = rot[q + 1], z = rot[q + 2], w = rot[q + 3];
|
|
192
|
+
// Local rotation columns.
|
|
193
|
+
const xx = x * x, yy = y * y, zz = z * z, xy = x * y, xz = x * z, yz = y * z, wx = w * x, wy = w * y, wz = w * z;
|
|
194
|
+
const l0 = 1 - 2 * (yy + zz), l1 = 2 * (xy + wz), l2 = 2 * (xz - wy);
|
|
195
|
+
const l3 = 2 * (xy - wz), l4 = 1 - 2 * (xx + zz), l5 = 2 * (yz + wx);
|
|
196
|
+
const l6 = 2 * (xz + wy), l7 = 2 * (yz - wx), l8 = 1 - 2 * (xx + yy);
|
|
197
|
+
const tx = jt[b * 3] + off[b * 3], ty = jt[b * 3 + 1] + off[b * 3 + 1], tz = jt[b * 3 + 2] + off[b * 3 + 2];
|
|
198
|
+
const p = par[b];
|
|
199
|
+
const P = p < 0 ? root : out;
|
|
200
|
+
const o = p < 0 ? 0 : p * 12;
|
|
201
|
+
const a0 = P[o], a1 = P[o + 1], a2 = P[o + 2], a3 = P[o + 3], a4 = P[o + 4], a5 = P[o + 5];
|
|
202
|
+
const a6 = P[o + 6], a7 = P[o + 7], a8 = P[o + 8], a9 = P[o + 9], a10 = P[o + 10], a11 = P[o + 11];
|
|
203
|
+
const d = b * 12;
|
|
204
|
+
out[d] = a0 * l0 + a3 * l1 + a6 * l2;
|
|
205
|
+
out[d + 1] = a1 * l0 + a4 * l1 + a7 * l2;
|
|
206
|
+
out[d + 2] = a2 * l0 + a5 * l1 + a8 * l2;
|
|
207
|
+
out[d + 3] = a0 * l3 + a3 * l4 + a6 * l5;
|
|
208
|
+
out[d + 4] = a1 * l3 + a4 * l4 + a7 * l5;
|
|
209
|
+
out[d + 5] = a2 * l3 + a5 * l4 + a8 * l5;
|
|
210
|
+
out[d + 6] = a0 * l6 + a3 * l7 + a6 * l8;
|
|
211
|
+
out[d + 7] = a1 * l6 + a4 * l7 + a7 * l8;
|
|
212
|
+
out[d + 8] = a2 * l6 + a5 * l7 + a8 * l8;
|
|
213
|
+
out[d + 9] = a0 * tx + a3 * ty + a6 * tz + a9;
|
|
214
|
+
out[d + 10] = a1 * tx + a4 * ty + a7 * tz + a10;
|
|
215
|
+
out[d + 11] = a2 * tx + a5 * ty + a8 * tz + a11;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** Normalised linear interpolation of two quaternions along the shortest arc into `o` at `q`. */
|
|
219
|
+
export function nlerpInto(o, q, ax, ay, az, aw, bx, by, bz, bw, t) {
|
|
220
|
+
if (ax * bx + ay * by + az * bz + aw * bw < 0) {
|
|
221
|
+
bx = -bx;
|
|
222
|
+
by = -by;
|
|
223
|
+
bz = -bz;
|
|
224
|
+
bw = -bw;
|
|
225
|
+
}
|
|
226
|
+
const x = ax + (bx - ax) * t, y = ay + (by - ay) * t, z = az + (bz - az) * t, w = aw + (bw - aw) * t;
|
|
227
|
+
const l = Math.sqrt(x * x + y * y + z * z + w * w) || 1;
|
|
228
|
+
o[q] = x / l;
|
|
229
|
+
o[q + 1] = y / l;
|
|
230
|
+
o[q + 2] = z / l;
|
|
231
|
+
o[q + 3] = w / l;
|
|
232
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Pose, Skeleton } from './skeleton.ts';
|
|
2
|
+
/** Three bones of a chain: `upper` holds `lower`, which holds `end` (the joint that should reach the target). */
|
|
3
|
+
export interface TwoBoneChain {
|
|
4
|
+
upper: number;
|
|
5
|
+
lower: number;
|
|
6
|
+
end: number;
|
|
7
|
+
/**
|
|
8
|
+
* Axis in the lower bone's frame that the middle joint bends about when the chain is straight (a positive turn
|
|
9
|
+
* about it is the way the joint bends). Default [1, 0, 0].
|
|
10
|
+
*/
|
|
11
|
+
bend?: readonly [number, number, number];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Turns the upper and lower bone of `chain` so that the end joint reaches `target` (world), as far as the chain's
|
|
15
|
+
* length allows, blended with the pose as it was by `weight` 0–1. `world` must hold the solved pose (`solvePose`)
|
|
16
|
+
* and is updated for the chain and everything below it. `pole` (world point, optional): the middle joint turns toward
|
|
17
|
+
* it. Returns the distance from the end joint to the target afterwards (0 when reached). Allocates nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function reachTwoBone(skeleton: Skeleton, pose: Pose, root: ArrayLike<number>, world: Float32Array | Float64Array, chain: TwoBoneChain, target: ArrayLike<number>, weight?: number, pole?: ArrayLike<number> | null): number;
|
|
20
|
+
/** What `fitToGround` needs besides the chains. */
|
|
21
|
+
export interface GroundFitOptions {
|
|
22
|
+
/** Ground height at a world point (x, z). */
|
|
23
|
+
heightAt(x: number, z: number): number;
|
|
24
|
+
/** Height of the plane the figure is posed on (where the chain ends stand in the unchanged pose). */
|
|
25
|
+
planeY: number;
|
|
26
|
+
/** Largest raise of a chain end, metres. Default 0.5. */
|
|
27
|
+
maxLift?: number;
|
|
28
|
+
/** Largest drop of a chain end, metres. Default 0.5. */
|
|
29
|
+
maxDrop?: number;
|
|
30
|
+
/**
|
|
31
|
+
* A bone lowered (along its parent's y) by the deepest drop, so that chains can reach down without stretching;
|
|
32
|
+
* −1 or unset: none.
|
|
33
|
+
*/
|
|
34
|
+
lower?: number;
|
|
35
|
+
/** Blend with the unchanged pose, 0–1. Default 1. */
|
|
36
|
+
weight?: number;
|
|
37
|
+
/** World points the middle joints turn toward, 3 numbers per chain (optional). */
|
|
38
|
+
poles?: ArrayLike<number> | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Keeps the ends of `chains` on the ground: every end is moved up or down by the ground height under it minus
|
|
42
|
+
* `planeY` (within the limits) and reached with `reachTwoBone`. `world` must hold the solved pose and is updated.
|
|
43
|
+
* At most 64 chains. Allocates nothing.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fitToGround(skeleton: Skeleton, pose: Pose, root: ArrayLike<number>, world: Float32Array | Float64Array, chains: readonly TwoBoneChain[], o: GroundFitOptions): void;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// Post steps over a solved pose, for the game to call when it wants them: a two-bone reach (the end of a chain of
|
|
2
|
+
// two bones put on a target by turning the two bones, analytic, no iteration) and its use for keeping chain ends on
|
|
3
|
+
// the ground (the height comes from a function of the game). Both change the pose and re-solve the bones below the
|
|
4
|
+
// chain, so the world matrices stay in step with the pose. Up is +y; a curved world is not covered.
|
|
5
|
+
//
|
|
6
|
+
// The reach follows the two-joint method of D. Holden ("Simple Two Joint IK", 2017): the angle at the middle joint
|
|
7
|
+
// gives the right distance, then the chain swings onto the target; an optional pole point turns the chain about the
|
|
8
|
+
// line to the target so that the middle joint points toward it.
|
|
9
|
+
import { solvePoseBelow } from './pose-ops.js';
|
|
10
|
+
const EPS = 1e-5;
|
|
11
|
+
// Scratch (module level: the post steps run one at a time).
|
|
12
|
+
const QA = new Float64Array(4);
|
|
13
|
+
const QB = new Float64Array(4);
|
|
14
|
+
const Q = new Float64Array(4);
|
|
15
|
+
const V = new Float64Array(3);
|
|
16
|
+
/**
|
|
17
|
+
* Turns the upper and lower bone of `chain` so that the end joint reaches `target` (world), as far as the chain's
|
|
18
|
+
* length allows, blended with the pose as it was by `weight` 0–1. `world` must hold the solved pose (`solvePose`)
|
|
19
|
+
* and is updated for the chain and everything below it. `pole` (world point, optional): the middle joint turns toward
|
|
20
|
+
* it. Returns the distance from the end joint to the target afterwards (0 when reached). Allocates nothing.
|
|
21
|
+
*/
|
|
22
|
+
export function reachTwoBone(skeleton, pose, root, world, chain, target, weight = 1, pole = null) {
|
|
23
|
+
const { upper, lower, end } = chain;
|
|
24
|
+
const tx = target[0], ty = target[1], tz = target[2];
|
|
25
|
+
if (weight <= 0)
|
|
26
|
+
return dist(world, end, tx, ty, tz);
|
|
27
|
+
const ua = upper * 12, ub = lower * 12, uc = end * 12;
|
|
28
|
+
const ax = world[ua + 9], ay = world[ua + 10], az = world[ua + 11];
|
|
29
|
+
const bx = world[ub + 9], by = world[ub + 10], bz = world[ub + 11];
|
|
30
|
+
const cx = world[uc + 9], cy = world[uc + 10], cz = world[uc + 11];
|
|
31
|
+
const lab = Math.hypot(bx - ax, by - ay, bz - az);
|
|
32
|
+
const lcb = Math.hypot(cx - bx, cy - by, cz - bz);
|
|
33
|
+
if (lab < EPS || lcb < EPS)
|
|
34
|
+
return dist(world, end, tx, ty, tz);
|
|
35
|
+
const lat = clamp(Math.hypot(tx - ax, ty - ay, tz - az), Math.abs(lab - lcb) + EPS, lab + lcb - EPS);
|
|
36
|
+
// Unit directions a→c, a→b, b→a, b→c, a→t.
|
|
37
|
+
let acx = cx - ax, acy = cy - ay, acz = cz - az;
|
|
38
|
+
const lac = Math.hypot(acx, acy, acz) || 1;
|
|
39
|
+
acx /= lac;
|
|
40
|
+
acy /= lac;
|
|
41
|
+
acz /= lac;
|
|
42
|
+
const abx = (bx - ax) / lab, aby = (by - ay) / lab, abz = (bz - az) / lab;
|
|
43
|
+
const bcx = (cx - bx) / lcb, bcy = (cy - by) / lcb, bcz = (cz - bz) / lcb;
|
|
44
|
+
let atx = tx - ax, aty = ty - ay, atz = tz - az;
|
|
45
|
+
const lt = Math.hypot(atx, aty, atz) || 1;
|
|
46
|
+
atx /= lt;
|
|
47
|
+
aty /= lt;
|
|
48
|
+
atz /= lt;
|
|
49
|
+
const acAb0 = Math.acos(clamp(acx * abx + acy * aby + acz * abz, -1, 1));
|
|
50
|
+
const baBc0 = Math.acos(clamp(-(abx * bcx + aby * bcy + abz * bcz), -1, 1));
|
|
51
|
+
const acAt0 = Math.acos(clamp(acx * atx + acy * aty + acz * atz, -1, 1));
|
|
52
|
+
const acAb1 = Math.acos(clamp((lcb * lcb - lab * lab - lat * lat) / (-2 * lab * lat), -1, 1));
|
|
53
|
+
const baBc1 = Math.acos(clamp((lat * lat - lab * lab - lcb * lcb) / (-2 * lab * lcb), -1, 1));
|
|
54
|
+
// The bend plane's normal: from the chain's own bend, or from the bend axis when it is straight.
|
|
55
|
+
let n0x = acy * abz - acz * aby, n0y = acz * abx - acx * abz, n0z = acx * aby - acy * abx;
|
|
56
|
+
let ln = Math.hypot(n0x, n0y, n0z);
|
|
57
|
+
if (ln < 1e-6) {
|
|
58
|
+
const k = chain.bend ?? DEFAULT_BEND;
|
|
59
|
+
// Lower bone's frame to world, negated: the geometric normal c×b of a joint bent the positive way.
|
|
60
|
+
n0x = -(world[ub] * k[0] + world[ub + 3] * k[1] + world[ub + 6] * k[2]);
|
|
61
|
+
n0y = -(world[ub + 1] * k[0] + world[ub + 4] * k[1] + world[ub + 7] * k[2]);
|
|
62
|
+
n0z = -(world[ub + 2] * k[0] + world[ub + 5] * k[1] + world[ub + 8] * k[2]);
|
|
63
|
+
ln = Math.hypot(n0x, n0y, n0z) || 1;
|
|
64
|
+
}
|
|
65
|
+
n0x /= ln;
|
|
66
|
+
n0y /= ln;
|
|
67
|
+
n0z /= ln;
|
|
68
|
+
let n1x = acy * atz - acz * aty, n1y = acz * atx - acx * atz, n1z = acx * aty - acy * atx;
|
|
69
|
+
const l1 = Math.hypot(n1x, n1y, n1z);
|
|
70
|
+
if (l1 > 1e-9) {
|
|
71
|
+
n1x /= l1;
|
|
72
|
+
n1y /= l1;
|
|
73
|
+
n1z /= l1;
|
|
74
|
+
}
|
|
75
|
+
// Keep the old rotations for the weight.
|
|
76
|
+
const rot = pose.rot;
|
|
77
|
+
const qa = upper * 4, qb = lower * 4;
|
|
78
|
+
for (let k = 0; k < 4; k++) {
|
|
79
|
+
QA[k] = rot[qa + k];
|
|
80
|
+
QB[k] = rot[qb + k];
|
|
81
|
+
}
|
|
82
|
+
// Upper: in world terms first the bend about n0 (with the lower bone's turn it keeps the direction a→c and sets
|
|
83
|
+
// its length), then the swing of a→c onto a→t. Both axes go into the frame of the bone as it was solved, so the
|
|
84
|
+
// local product is swing · bend (rot · r2 · r0 = R2 · R0 · global).
|
|
85
|
+
if (l1 > 1e-9)
|
|
86
|
+
rotateLocal(rot, qa, world, ua, n1x, n1y, n1z, acAt0);
|
|
87
|
+
rotateLocal(rot, qa, world, ua, n0x, n0y, n0z, acAb1 - acAb0);
|
|
88
|
+
rotateLocal(rot, qb, world, ub, n0x, n0y, n0z, baBc1 - baBc0);
|
|
89
|
+
solvePoseBelow(skeleton, pose, root, world, upper);
|
|
90
|
+
if (pole) {
|
|
91
|
+
// Turn the chain about the line a→end so that the middle joint lies toward the pole.
|
|
92
|
+
let ux = world[uc + 9] - ax, uy = world[uc + 10] - ay, uz = world[uc + 11] - az;
|
|
93
|
+
const lu = Math.hypot(ux, uy, uz);
|
|
94
|
+
if (lu > EPS) {
|
|
95
|
+
ux /= lu;
|
|
96
|
+
uy /= lu;
|
|
97
|
+
uz /= lu;
|
|
98
|
+
const px = pole[0] - ax, py = pole[1] - ay, pz = pole[2] - az;
|
|
99
|
+
const mx = world[ub + 9] - ax, my = world[ub + 10] - ay, mz = world[ub + 11] - az;
|
|
100
|
+
// Both projected on the plane across u.
|
|
101
|
+
const dp = px * ux + py * uy + pz * uz, dm = mx * ux + my * uy + mz * uz;
|
|
102
|
+
const ppx = px - ux * dp, ppy = py - uy * dp, ppz = pz - uz * dp;
|
|
103
|
+
const pmx = mx - ux * dm, pmy = my - uy * dm, pmz = mz - uz * dm;
|
|
104
|
+
if (Math.hypot(ppx, ppy, ppz) > EPS && Math.hypot(pmx, pmy, pmz) > EPS) {
|
|
105
|
+
const cs = pmx * ppx + pmy * ppy + pmz * ppz;
|
|
106
|
+
const sn = ux * (pmy * ppz - pmz * ppy) + uy * (pmz * ppx - pmx * ppz) + uz * (pmx * ppy - pmy * ppx);
|
|
107
|
+
rotateLocal(rot, qa, world, ua, ux, uy, uz, Math.atan2(sn, cs));
|
|
108
|
+
solvePoseBelow(skeleton, pose, root, world, upper);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (weight < 1) {
|
|
113
|
+
nlerp(rot, qa, QA, weight);
|
|
114
|
+
nlerp(rot, qb, QB, weight);
|
|
115
|
+
solvePoseBelow(skeleton, pose, root, world, upper);
|
|
116
|
+
}
|
|
117
|
+
return dist(world, end, tx, ty, tz);
|
|
118
|
+
}
|
|
119
|
+
const TARGET = new Float64Array(3);
|
|
120
|
+
const POLE = new Float64Array(3);
|
|
121
|
+
const DELTA = new Float64Array(64);
|
|
122
|
+
const ENDS = new Float64Array(64 * 3);
|
|
123
|
+
/**
|
|
124
|
+
* Keeps the ends of `chains` on the ground: every end is moved up or down by the ground height under it minus
|
|
125
|
+
* `planeY` (within the limits) and reached with `reachTwoBone`. `world` must hold the solved pose and is updated.
|
|
126
|
+
* At most 64 chains. Allocates nothing.
|
|
127
|
+
*/
|
|
128
|
+
export function fitToGround(skeleton, pose, root, world, chains, o) {
|
|
129
|
+
const n = Math.min(chains.length, 64);
|
|
130
|
+
const lift = o.maxLift ?? 0.5;
|
|
131
|
+
const drop = o.maxDrop ?? 0.5;
|
|
132
|
+
const w = o.weight ?? 1;
|
|
133
|
+
if (w <= 0 || n === 0)
|
|
134
|
+
return;
|
|
135
|
+
let deepest = 0;
|
|
136
|
+
for (let i = 0; i < n; i++) {
|
|
137
|
+
const u = chains[i].end * 12;
|
|
138
|
+
const x = world[u + 9], y = world[u + 10], z = world[u + 11];
|
|
139
|
+
ENDS[i * 3] = x;
|
|
140
|
+
ENDS[i * 3 + 1] = y;
|
|
141
|
+
ENDS[i * 3 + 2] = z;
|
|
142
|
+
const d = clamp(o.heightAt(x, z) - o.planeY, -drop, lift);
|
|
143
|
+
DELTA[i] = d;
|
|
144
|
+
if (d < deepest)
|
|
145
|
+
deepest = d;
|
|
146
|
+
}
|
|
147
|
+
const low = o.lower ?? -1;
|
|
148
|
+
if (low >= 0 && deepest < 0) {
|
|
149
|
+
pose.offset[low * 3 + 1] = pose.offset[low * 3 + 1] + deepest * w;
|
|
150
|
+
solvePoseBelow(skeleton, pose, root, world, low);
|
|
151
|
+
}
|
|
152
|
+
for (let i = 0; i < n; i++) {
|
|
153
|
+
TARGET[0] = ENDS[i * 3];
|
|
154
|
+
TARGET[1] = ENDS[i * 3 + 1] + DELTA[i];
|
|
155
|
+
TARGET[2] = ENDS[i * 3 + 2];
|
|
156
|
+
let pole = null;
|
|
157
|
+
if (o.poles) {
|
|
158
|
+
POLE[0] = o.poles[i * 3];
|
|
159
|
+
POLE[1] = o.poles[i * 3 + 1];
|
|
160
|
+
POLE[2] = o.poles[i * 3 + 2];
|
|
161
|
+
pole = POLE;
|
|
162
|
+
}
|
|
163
|
+
reachTwoBone(skeleton, pose, root, world, chains[i], TARGET, w, pole);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const DEFAULT_BEND = [1, 0, 0];
|
|
167
|
+
function clamp(v, a, b) {
|
|
168
|
+
return v < a ? a : v > b ? b : v;
|
|
169
|
+
}
|
|
170
|
+
function dist(world, bone, x, y, z) {
|
|
171
|
+
const u = bone * 12;
|
|
172
|
+
return Math.hypot(world[u + 9] - x, world[u + 10] - y, world[u + 11] - z);
|
|
173
|
+
}
|
|
174
|
+
/** Global rotation of a solved bone (its matrix columns normalised) into Q. */
|
|
175
|
+
function globalRot(world, u) {
|
|
176
|
+
const l0 = Math.hypot(world[u], world[u + 1], world[u + 2]) || 1;
|
|
177
|
+
const l1 = Math.hypot(world[u + 3], world[u + 4], world[u + 5]) || 1;
|
|
178
|
+
const l2 = Math.hypot(world[u + 6], world[u + 7], world[u + 8]) || 1;
|
|
179
|
+
const m00 = world[u] / l0, m10 = world[u + 1] / l0, m20 = world[u + 2] / l0;
|
|
180
|
+
const m01 = world[u + 3] / l1, m11 = world[u + 4] / l1, m21 = world[u + 5] / l1;
|
|
181
|
+
const m02 = world[u + 6] / l2, m12 = world[u + 7] / l2, m22 = world[u + 8] / l2;
|
|
182
|
+
const tr = m00 + m11 + m22;
|
|
183
|
+
let x, y, z, w;
|
|
184
|
+
if (tr > 0) {
|
|
185
|
+
const s = Math.sqrt(tr + 1) * 2;
|
|
186
|
+
w = s / 4;
|
|
187
|
+
x = (m21 - m12) / s;
|
|
188
|
+
y = (m02 - m20) / s;
|
|
189
|
+
z = (m10 - m01) / s;
|
|
190
|
+
}
|
|
191
|
+
else if (m00 > m11 && m00 > m22) {
|
|
192
|
+
const s = Math.sqrt(1 + m00 - m11 - m22) * 2;
|
|
193
|
+
w = (m21 - m12) / s;
|
|
194
|
+
x = s / 4;
|
|
195
|
+
y = (m01 + m10) / s;
|
|
196
|
+
z = (m02 + m20) / s;
|
|
197
|
+
}
|
|
198
|
+
else if (m11 > m22) {
|
|
199
|
+
const s = Math.sqrt(1 + m11 - m00 - m22) * 2;
|
|
200
|
+
w = (m02 - m20) / s;
|
|
201
|
+
x = (m01 + m10) / s;
|
|
202
|
+
y = s / 4;
|
|
203
|
+
z = (m12 + m21) / s;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const s = Math.sqrt(1 + m22 - m00 - m11) * 2;
|
|
207
|
+
w = (m10 - m01) / s;
|
|
208
|
+
x = (m02 + m20) / s;
|
|
209
|
+
y = (m12 + m21) / s;
|
|
210
|
+
z = s / 4;
|
|
211
|
+
}
|
|
212
|
+
Q[0] = x;
|
|
213
|
+
Q[1] = y;
|
|
214
|
+
Q[2] = z;
|
|
215
|
+
Q[3] = w;
|
|
216
|
+
}
|
|
217
|
+
/** World axis into a bone's frame (conjugate of its global rotation in Q) into V. */
|
|
218
|
+
function toLocal(nx, ny, nz) {
|
|
219
|
+
// v' = q* v q for unit q = (x, y, z, w): rotate by the conjugate.
|
|
220
|
+
const x = -Q[0], y = -Q[1], z = -Q[2], w = Q[3];
|
|
221
|
+
const ix = w * nx + y * nz - z * ny;
|
|
222
|
+
const iy = w * ny + z * nx - x * nz;
|
|
223
|
+
const iz = w * nz + x * ny - y * nx;
|
|
224
|
+
const iw = -x * nx - y * ny - z * nz;
|
|
225
|
+
V[0] = ix * w + iw * -x + iy * -z - iz * -y;
|
|
226
|
+
V[1] = iy * w + iw * -y + iz * -x - ix * -z;
|
|
227
|
+
V[2] = iz * w + iw * -z + ix * -y - iy * -x;
|
|
228
|
+
}
|
|
229
|
+
/** rot[q] = rot[q] · R(local axis of the world axis n, angle), with the bone's global rotation from `world`. */
|
|
230
|
+
function rotateLocal(rot, q, world, u, nx, ny, nz, angle) {
|
|
231
|
+
if (angle === 0)
|
|
232
|
+
return;
|
|
233
|
+
globalRot(world, u);
|
|
234
|
+
toLocal(nx, ny, nz);
|
|
235
|
+
mulAxisAngle(rot, q, V[0], V[1], V[2], angle);
|
|
236
|
+
}
|
|
237
|
+
function mulAxisAngle(rot, q, ax, ay, az, angle) {
|
|
238
|
+
const l = Math.hypot(ax, ay, az);
|
|
239
|
+
if (l < 1e-12)
|
|
240
|
+
return;
|
|
241
|
+
const s = Math.sin(angle / 2) / l, c = Math.cos(angle / 2);
|
|
242
|
+
const bx = ax * s, by = ay * s, bz = az * s;
|
|
243
|
+
const x = rot[q], y = rot[q + 1], z = rot[q + 2], w = rot[q + 3];
|
|
244
|
+
rot[q] = w * bx + x * c + y * bz - z * by;
|
|
245
|
+
rot[q + 1] = w * by - x * bz + y * c + z * bx;
|
|
246
|
+
rot[q + 2] = w * bz + x * by - y * bx + z * c;
|
|
247
|
+
rot[q + 3] = w * c - x * bx - y * by - z * bz;
|
|
248
|
+
}
|
|
249
|
+
function nlerp(rot, q, from, w) {
|
|
250
|
+
// rot[q] = from blended toward rot[q] by w.
|
|
251
|
+
let bx = rot[q], by = rot[q + 1], bz = rot[q + 2], bw = rot[q + 3];
|
|
252
|
+
if (from[0] * bx + from[1] * by + from[2] * bz + from[3] * bw < 0) {
|
|
253
|
+
bx = -bx;
|
|
254
|
+
by = -by;
|
|
255
|
+
bz = -bz;
|
|
256
|
+
bw = -bw;
|
|
257
|
+
}
|
|
258
|
+
const x = from[0] + (bx - from[0]) * w, y = from[1] + (by - from[1]) * w, z = from[2] + (bz - from[2]) * w, ww = from[3] + (bw - from[3]) * w;
|
|
259
|
+
const l = Math.hypot(x, y, z, ww) || 1;
|
|
260
|
+
rot[q] = x / l;
|
|
261
|
+
rot[q + 1] = y / l;
|
|
262
|
+
rot[q + 2] = z / l;
|
|
263
|
+
rot[q + 3] = ww / l;
|
|
264
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** One bone: its name, the index of its parent (−1 for a root) and its joint in the parent's frame. */
|
|
2
|
+
export interface BoneSpec {
|
|
3
|
+
name: string;
|
|
4
|
+
/** Index of the parent bone, earlier in the list; −1 for a root (placed by the `root` matrix of `solvePose`). */
|
|
5
|
+
parent: number;
|
|
6
|
+
/** Joint position in the parent's frame (for a root: in the frame of the `root` matrix). */
|
|
7
|
+
joint: readonly [number, number, number];
|
|
8
|
+
}
|
|
9
|
+
/** Bones in parent-before-child order, as typed arrays. Built once; shared by every figure of that build. */
|
|
10
|
+
export declare class Skeleton {
|
|
11
|
+
readonly count: number;
|
|
12
|
+
readonly names: readonly string[];
|
|
13
|
+
/** Parent of every bone, −1 for roots. */
|
|
14
|
+
readonly parent: Int16Array;
|
|
15
|
+
/** Joint of every bone in its parent's frame, 3 numbers per bone. */
|
|
16
|
+
readonly joint: Float32Array;
|
|
17
|
+
private readonly byName;
|
|
18
|
+
constructor(bones: readonly BoneSpec[]);
|
|
19
|
+
/** Index of a bone by name; throws when there is none. */
|
|
20
|
+
index(name: string): number;
|
|
21
|
+
/** Index of a bone by name, or −1. */
|
|
22
|
+
find(name: string): number;
|
|
23
|
+
/** True when `bone` is `ancestor` or lies below it. */
|
|
24
|
+
isBelow(bone: number, ancestor: number): boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Local pose: per bone a rotation (quaternion x, y, z, w) and an offset added to the joint. Plain typed arrays. */
|
|
27
|
+
export declare class Pose {
|
|
28
|
+
readonly skeleton: Skeleton;
|
|
29
|
+
/** 4 numbers per bone, [x, y, z, w]. */
|
|
30
|
+
readonly rot: Float32Array;
|
|
31
|
+
/** 3 numbers per bone, added to the bone's joint. */
|
|
32
|
+
readonly offset: Float32Array;
|
|
33
|
+
constructor(skeleton: Skeleton);
|
|
34
|
+
/** The rest pose: identity rotations, zero offsets. */
|
|
35
|
+
reset(): void;
|
|
36
|
+
copy(from: Pose): void;
|
|
37
|
+
}
|
|
38
|
+
/** Per-bone weights 0–1, built from bone names (with or without descendants). */
|
|
39
|
+
export type BoneMask = Float32Array;
|
|
40
|
+
export interface BoneMaskOptions {
|
|
41
|
+
/** Also the bones below each named bone. Default true. */
|
|
42
|
+
descendants?: boolean;
|
|
43
|
+
/** Weight given to the named bones. Default 1. */
|
|
44
|
+
weight?: number;
|
|
45
|
+
/** Start from this mask instead of zeros (it is copied, not changed). */
|
|
46
|
+
from?: BoneMask;
|
|
47
|
+
}
|
|
48
|
+
/** A mask with `weight` on the named bones (and by default everything below them), 0 elsewhere. For setup. */
|
|
49
|
+
export declare function boneMask(skeleton: Skeleton, names: readonly string[], o?: BoneMaskOptions): BoneMask;
|