A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): a selected spring-bone chain and its colliders are drawn in the viewport, Details groups and counts them, and Preview FX simulates the chain
yhh9c04245e838c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8c5f4c8b2..ef6db7ee0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -35,6 +35,7 @@ published separately; it ships inside the editor.- **Contact shadows and screen-space bounce light.** Contact Shadows and Screen Space GI effects add small sharp shadows at contacts and one bounce of colour between surfaces, and the weather softens the sun's shadows. `contactShadows` marches a short ray toward the scene's sun in the depth buffer; `ssgi` gathers eight rays a pixel over the G-buffer's normals at half size into a float target and averages the neighbours on the same surface before laying the light, times the receiver's colour, over the picture. The Weather component raises the sun's `sourceAngle` and lowers its `shadowStrength` as the sky clouds over.- **Terrain and Foliage.** A Terrain component makes ground from a heightmap or noise, paints it with grass, dirt, snow and rock layers and draws it in chunks that coarsen with distance; a Foliage component scatters grass or a mesh over it, swaying in the wind and thinning out with distance.- **Separate material maps packed on import.** Importing an FBX with separate metalness, roughness and occlusion images now packs them into the one map the Model shader samples, instead of dropping them. Occlusion goes in red, roughness in green and metal in blue, each from its image's red channel (a glossiness map is inverted); a channel with no image stays at full so the material's own value speaks. Only PNG and DDS can be read.+- **Spring-bone authoring.** Spring bones can be authored in the editor: Details groups a chain's fields into Motion, Chain and Collision and counts the bones below it (or warns that there are none), the viewport draws a selected chain (the bones as posed, a ring at each joint, the tips) with the colliders it keeps out of, or a selected collider on its own, behind a Spring bones entry in the Gizmo menu, and View · Preview FX simulates the chain in the edit viewport, drawn solid over its dashed pose. Ending the preview gives the bones back as the scene has them.- **Spring bones.** Spring bones give a skeleton secondary motion: a `SpringBone` on the root of a chain of bones (hair, a tail, a cord) makes everything below it a spring that lags the animation, falls with gravity, is pulled back to its animated pose, never stretches, and is kept out of `SpringBoneCollider` spheres and capsules. It runs in C++ in the engine, so it costs the same on every target: 300 chains of six bones step in 0.28 ms. Only the bones' rotations are written, and switching it off gives the animation's own back.- **Water rows in the quality settings.** Project Settings → Rendering has a Level · Water group for the five water quality fields (waves, ripple cells, displacement, mirror, caustics) of the level chosen under Editing level. Each is saved as a difference to that level only, and the group is hidden while quality is off or the project excludes the water module.- **Built-in shaders ship with their modules.** The Water, Terrain, Foliage, Hair, Skin and Eye built-in shaders now ship with their modules instead of the core: a package that installs none of them no longer carries about 80 KB of shader source (a blank web package is 80 KB smaller, a blank WeChat bundle 7% smaller). A material that names one of them is what brings its module into an export, with no component in a scene needed; the three character shaders are a new `esengine/character-shaders` module.diff --git a/desktop b/desktopindex fac062c25..64cb4c582 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit fac062c254a91193bec579eef6d749f38fa9aeb1+Subproject commit 64cb4c582dcdf453d5700186e2a0fb74334d0ef3diff --git a/docs/astro/src/content/docs/animation/spring-bones.mdx b/docs/astro/src/content/docs/animation/spring-bones.mdxindex 3357b73b3..3729ab2c2 100644--- a/docs/astro/src/content/docs/animation/spring-bones.mdx+++ b/docs/astro/src/content/docs/animation/spring-bones.mdx@@ -29,6 +29,19 @@ is simulated.A `SpringBoneCollider` is a sphere, or a capsule along its entity's own Y axis, placed by the entity's transform (and its `offset`). Put them on the headand shoulders bones so hair does not pass through the body.+## In the editor++Details groups the chain's fields into **Motion** (stiffness, drag, gravity), **Chain** (end length, radius, weight) and **Collision** (colliders), and says on its first+line how many bones the chain has below its entity and how many end tips, or, in the warning colour, that it has no child bones and so simulates nothing.++Select a chain's root and the viewport draws it, and the colliders it keeps out of, in the **Spring bones** entry of the Gizmo menu: the bones as the animation poses them+as amber lines, a ring at each joint the width of the strand's `radius` (a dot where it is 0), a tip where `endLength` gives one, and each collider as a wireframe sphere or+capsule in the collider green. Select a `SpringBoneCollider` and its own shape is drawn. Nothing is drawn for what is not selected, so a character's hair does not fill the viewport.++**View → Preview FX** (on in a fresh editor, the same switch particles and trails use) runs the chain in the edit viewport: drag the head, or change a field, and the+hair swings. With it on, the simulated chain is drawn solid over the animated pose, dashed, so the difference you are tuning is the difference you see. Turning it off+ends the simulation and gives the bones back as the scene has them. The simulation is the editor's own: it never writes into the scene file.+## What it does each frameThe animation runs first and writes the bones' local rotations. Then, for each chain:@@ -54,5 +67,5 @@ cost 0.28 ms an update.** The test is `springbone` in the editor checks; `test_s- A bone with several children aims at its first child; the others follow by being children, and aim at their own.- Scale is taken from the bones' composed scale; non-uniform scale down a chain is not modelled.- Collision is bone against sphere or capsule: no collision between strands, no self-collision, and no collision with the world's physics shapes.-- There is no wind yet, and no authoring in the viewport: chains and colliders are set up in the Details panel. A hair importer that finds the strands and makes the chains- from the model's bone names does not exist yet either.+- There is no wind yet. A collider's radius, height and offset are typed in Details; the viewport has no handles to drag them. A hair importer that finds the strands and makes+ the chains from the model's bone names does not exist yet either.diff --git a/docs/astro/src/content/docs/zh-cn/animation/spring-bones.mdx b/docs/astro/src/content/docs/zh-cn/animation/spring-bones.mdxindex 904e12e78..1dac6c253 100644--- a/docs/astro/src/content/docs/zh-cn/animation/spring-bones.mdx+++ b/docs/astro/src/content/docs/zh-cn/animation/spring-bones.mdx@@ -24,6 +24,14 @@ description: 骨骼链的次级运动(头发、尾巴、绳索):放在链根上`SpringBoneCollider` 是一个球,或者沿它自己实体 Y 轴的胶囊,位置由实体的变换(和它的 `offset`)决定。把它们放在头和肩膀的骨头上,头发就不会穿过身体。+## 在编辑器里++Details 把链的字段分成 **Motion**(stiffness、drag、gravity)、**Chain**(end length、radius、weight)和 **Collision**(colliders)三组,第一行说明这条链在它的实体下有几根骨头、几个末端尖端;没有子骨头时用警告色说明它什么也不会模拟。++选中链的根,视口就会画出它,和它要避开的碰撞体,开关在 Gizmo 菜单的 **Spring bones** 一项:动画摆出的骨头是琥珀色的线,每个关节有一个与发丝 `radius` 同宽的圈(为 0 时是一个点),`endLength` 给出尖端的地方有一段尖端,每个碰撞体是碰撞体绿色的线框球或胶囊。选中 `SpringBoneCollider` 就画它自己的形状。没选中的什么也不画,所以角色的头发不会把视口填满。++**视图 → 预览特效**(新编辑器里默认开,和粒子、拖尾用同一个开关)会让链在编辑视口里运行:拖动头,或者改一个字段,头发就会摆动。开着时,模拟出的链画成实线,盖在虚线画的动画姿势上,所以你在调的那个差别就是你看到的差别。关掉它会结束模拟,并把骨头还给场景里原来的样子。这个模拟是编辑器自己的:它从不写进场景文件。+## 每帧做什么动画先运行,写入骨骼的局部旋转。然后对每条链:@@ -43,4 +51,4 @@ description: 骨骼链的次级运动(头发、尾巴、绳索):放在链根上- 有多个子骨头的骨头瞄准它的第一个子骨头;其他的因为是子骨头而跟着动,并各自瞄准自己的。- 缩放取骨头合成后的缩放;链上的非均匀缩放没有建模。- 碰撞是骨头对球或胶囊:没有发丝之间的碰撞,没有自碰撞,也没有和世界物理形状的碰撞。-- 还没有风,也没有视口里的创作:链和碰撞体在 Details 面板里设置。能从模型的骨骼名字找出发束并生成链的头发导入器也还没有。+- 还没有风。碰撞体的半径、高度和偏移在 Details 里输入;视口里没有可以拖动它们的手柄。能从模型的骨骼名字找出发束并生成链的头发导入器也还没有。diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 30b1ab9f0..36168fe79 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 159 beta · 1748 experimental · 3 deprecated+Symbols: 115 public · 159 beta · 1749 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -8890,7 +8890,9 @@ BuiltinComponentDef<SpringBoneData>## SpringBoneAPI — class @experimental```+release: (root: Entity) => voidreset: (root: Entity) => void+snapshot: (root: Entity) => SpringBoneParticle[]update: (dt: number) => voidstatic new (module: NonNullable<EngineApi>, registry: CppRegistry): SpringBoneAPIstatic prototype: SpringBoneAPI@@ -8921,6 +8923,13 @@ stiffness: numberweight: number```+## SpringBoneParticle — interface @experimental+```+parent: number+pose: [number, number, number]+position: [number, number, number]+```+## SpringBonePlugin — class @experimental```build: (app: App) => voiddiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 0bc1a746c..f3c64b643 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 164 beta · 1767 experimental · 3 deprecated+Symbols: 115 public · 164 beta · 1768 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -9103,7 +9103,9 @@ BuiltinComponentDef<SpringBoneData>## SpringBoneAPI — class @experimental```+release: (root: Entity) => voidreset: (root: Entity) => void+snapshot: (root: Entity) => SpringBoneParticle[]update: (dt: number) => voidstatic new (module: NonNullable<EngineApi>, registry: CppRegistry): SpringBoneAPIstatic prototype: SpringBoneAPI@@ -9134,6 +9136,13 @@ stiffness: numberweight: number```+## SpringBoneParticle — interface @experimental+```+parent: number+pose: [number, number, number]+position: [number, number, number]+```+## SpringBonePlugin — class @experimental```build: (app: App) => voiddiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex f8993b4be..87db70b83 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 161 beta · 1747 experimental · 3 deprecated+Symbols: 115 public · 161 beta · 1748 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -8885,7 +8885,9 @@ BuiltinComponentDef<SpringBoneData>## SpringBoneAPI — class @experimental```+release: (root: Entity) => voidreset: (root: Entity) => void+snapshot: (root: Entity) => SpringBoneParticle[]update: (dt: number) => voidstatic new (module: NonNullable<EngineApi>, registry: CppRegistry): SpringBoneAPIstatic prototype: SpringBoneAPI@@ -8916,6 +8918,13 @@ stiffness: numberweight: number```+## SpringBoneParticle — interface @experimental+```+parent: number+pose: [number, number, number]+position: [number, number, number]+```+## SpringBonePlugin — class @experimental```build: (app: App) => voiddiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 405c696d0..025b399cd 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 159 beta · 1769 experimental · 3 deprecated+Symbols: 115 public · 159 beta · 1770 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -9178,7 +9178,9 @@ BuiltinComponentDef<SpringBoneData>## SpringBoneAPI — class @experimental```+release: (root: Entity) => voidreset: (root: Entity) => void+snapshot: (root: Entity) => SpringBoneParticle[]update: (dt: number) => voidstatic new (module: NonNullable<EngineApi>, registry: CppRegistry): SpringBoneAPIstatic prototype: SpringBoneAPI@@ -9209,6 +9211,13 @@ stiffness: numberweight: number```+## SpringBoneParticle — interface @experimental+```+parent: number+pose: [number, number, number]+position: [number, number, number]+```+## SpringBonePlugin — class @experimental```build: (app: App) => voiddiff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.mdindex 7b2d8d92c..8ac6d8df1 100644--- a/sdk/etc/wasm.api.md+++ b/sdk/etc/wasm.api.md@@ -535,7 +535,11 @@ renderer_updateTransforms: (registry: CppRegistry) => voidsdfFromAlpha: ((alphaPtr: number, outPtr: number, width: number, height: number, spread: number) => void) | undefinedsetActiveContext: (ctx: CppEngineContext | null) => voidshutdownRenderer: () => void+springbone_release: ((registry: CppRegistry, entity: number) => void) | undefinedspringbone_reset: ((registry: CppRegistry, entity: number) => void) | undefined+springbone_snapshot: ((registry: CppRegistry, entity: number) => number) | undefined+springbone_snapshotCount: (() => number) | undefined+springbone_snapshotData: (() => number) | undefinedspringbone_update: ((registry: CppRegistry, dt: number) => void) | undefinedtilemap_destroyLayer: ((entity: number) => void) | undefinedtilemap_exportChunks: ((entity: number) => string) | undefineddiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 4c3a5c70d..0fd31e340 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 159 beta · 1760 experimental · 3 deprecated+Symbols: 115 public · 159 beta · 1761 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -8892,7 +8892,9 @@ BuiltinComponentDef<SpringBoneData>## SpringBoneAPI — class @experimental```+release: (root: Entity) => voidreset: (root: Entity) => void+snapshot: (root: Entity) => SpringBoneParticle[]update: (dt: number) => voidstatic new (module: NonNullable<EngineApi>, registry: CppRegistry): SpringBoneAPIstatic prototype: SpringBoneAPI@@ -8923,6 +8925,13 @@ stiffness: numberweight: number```+## SpringBoneParticle — interface @experimental+```+parent: number+pose: [number, number, number]+position: [number, number, number]+```+## SpringBonePlugin — class @experimental```build: (app: App) => voiddiff --git a/sdk/src/core-content.ts b/sdk/src/core-content.tsindex 7c0eac952..ec7be22d4 100644--- a/sdk/src/core-content.ts+++ b/sdk/src/core-content.ts@@ -772,6 +772,7 @@ export {export {SpringBoneRes,SpringBoneAPI,+ type SpringBoneParticle,SpringBonePlugin,springBonePlugin,} from './springbone';diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.tsindex 957739042..10a8ee9fb 100644--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts@@ -265,7 +265,11 @@ export interface NativeEngineApi {rm_trimTextureCache?(rm: unknown): number;rm_updateTextureSubregion?(rm: unknown, handleId: number, x: number, y: number, width: number, height: number, pixelsPtr: number, pixelsLen: number): void;rm_wrapDeviceTexture?(rm: unknown, textureId: number, width: number, height: number): number;+ springbone_release?(registry: unknown, entity: number): void;springbone_reset?(registry: unknown, entity: number): void;+ springbone_snapshot?(registry: unknown, entity: number): number;+ springbone_snapshotCount?(): number;+ springbone_snapshotData?(): number;springbone_update?(registry: unknown, dt: number): void;tilemap_advanceAnimations?(entity: number, dtMs: number): void;tilemap_clearTileAnimations?(entity: number): void;@@ -583,7 +587,11 @@ export function createNativeEngineApi(bind('rm_trimTextureCache', 'es_rm_trimTextureCache', true);bind('rm_updateTextureSubregion', 'es_rm_updateTextureSubregion', true);bind('rm_wrapDeviceTexture', 'es_rm_wrapDeviceTexture', true);+ bind('springbone_release', 'es_springbone_release', true);bind('springbone_reset', 'es_springbone_reset', true);+ bind('springbone_snapshot', 'es_springbone_snapshot', true);+ bind('springbone_snapshotCount', 'es_springbone_snapshotCount', false);+ bind('springbone_snapshotData', 'es_springbone_snapshotData', false);bind('springbone_update', 'es_springbone_update', true);bind('tilemap_advanceAnimations', 'es_tilemap_advanceAnimations', false);bind('tilemap_clearTileAnimations', 'es_tilemap_clearTileAnimations', false);diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.tsindex b956f105c..0aacc2651 100644--- a/sdk/src/ecs/component.generated.ts+++ b/sdk/src/ecs/component.generated.ts@@ -1033,13 +1033,13 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {animatableFields: [],fields: {enabled: { tooltip: "Off leaves the chain exactly as the animation poses it." },- stiffness: { min: 0, max: 1, step: 0.01, slider: true, tooltip: "How hard each bone is pulled back toward its animated pose. 0 hangs free, 1 follows the animation exactly." },- drag: { min: 0, max: 1, step: 0.01, slider: true, tooltip: "How much of its speed a bone loses each frame. Higher settles sooner." },- gravity: { tooltip: "Gravity on the chain, in world units a second squared (world y is up)." },- endLength: { min: 0, step: 0.1, tooltip: "Length of the tip past each end bone, in world units. 0 leaves the end bones unsimulated." },- radius: { min: 0, step: 0.1, tooltip: "Thickness of the strand, in world units, kept clear of the colliders." },- weight: { min: 0, max: 1, step: 0.01, slider: true, tooltip: "How much of the simulation is used. 0 is the animation alone." },- colliders: { tooltip: "Entities with a SpringBoneCollider that this chain is kept out of (the head, the shoulders)." },+ stiffness: { min: 0, max: 1, step: 0.01, slider: true, tooltip: "How hard each bone is pulled back toward its animated pose. 0 hangs free, 1 follows the animation exactly.", category: "Motion" },+ drag: { min: 0, max: 1, step: 0.01, slider: true, tooltip: "How much of its speed a bone loses each frame. Higher settles sooner.", category: "Motion" },+ gravity: { tooltip: "Gravity on the chain, in world units a second squared (world y is up).", category: "Motion" },+ endLength: { min: 0, step: 0.1, tooltip: "Length of the tip past each end bone, in world units. 0 leaves the end bones unsimulated.", category: "Chain" },+ radius: { min: 0, step: 0.1, tooltip: "Thickness of the strand, in world units, kept clear of the colliders.", category: "Chain" },+ weight: { min: 0, max: 1, step: 0.01, slider: true, tooltip: "How much of the simulation is used. 0 is the animation alone.", category: "Chain" },+ colliders: { tooltip: "Entities with a SpringBoneCollider that this chain is kept out of (the head, the shoulders).", category: "Collision" },},},SpringBoneCollider: {@@ -1054,10 +1054,10 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {colorFields: [],animatableFields: [],fields: {- shape: { enum: [{ label: 'Sphere', value: 0 }, { label: 'Capsule', value: 1 }], tooltip: "Sphere, or a capsule along the entity's own Y axis." },- radius: { min: 0, step: 0.1, tooltip: "Radius in world units, before the entity's scale." },- height: { min: 0, step: 0.1, tooltip: "A capsule's length between the centres of its end spheres, in world units before scale.", shownWhen: { field: "shape", values: [1] } },- offset: { tooltip: "Where the centre of the shape is, in the entity's own space." },+ shape: { enum: [{ label: 'Sphere', value: 0 }, { label: 'Capsule', value: 1 }], tooltip: "Sphere, or a capsule along the entity's own Y axis.", category: "Shape" },+ radius: { min: 0, step: 0.1, tooltip: "Radius in world units, before the entity's scale.", category: "Shape" },+ height: { min: 0, step: 0.1, tooltip: "A capsule's length between the centres of its end spheres, in world units before scale.", category: "Shape", shownWhen: { field: "shape", values: [1] } },+ offset: { tooltip: "Where the centre of the shape is, in the entity's own space.", category: "Shape" },},},Sprite: {diff --git a/sdk/src/springbone/SpringBoneAPI.ts b/sdk/src/springbone/SpringBoneAPI.tsindex a9858576c..e628b6e61 100644--- a/sdk/src/springbone/SpringBoneAPI.ts+++ b/sdk/src/springbone/SpringBoneAPI.ts@@ -5,6 +5,16 @@ import type { EngineApi } from '../ecs/bridge/engineApi';import type { Entity } from '../types';import { defineResource } from '../ecs/resource';+/** One simulated point of a chain. */+export interface SpringBoneParticle {+ /** Where the simulation has it, in world units. */+ position: [number, number, number];+ /** Where the animation puts it. */+ pose: [number, number, number];+ /** The index of its parent particle, -1 for the chain's root. */+ parent: number;+}+/*** Per-app secondary-motion API. Wraps the C++ registry-scoped spring-bone system, so two App instances (editor tabs) simulate* independent chains.@@ -26,6 +36,33 @@ export class SpringBoneAPI {this.module_.springbone_update?.(this.registry_, dt);}+ /**+ * A chain as the engine has it now, for an editor to draw: each particle's simulated position, the position the animation gives it, and+ * its parent's index (-1 for the root). Empty when the chain has not been stepped yet.+ */+ snapshot(root: Entity): SpringBoneParticle[] {+ this.module_.springbone_snapshot?.(this.registry_, root as number);+ const count = this.module_.springbone_snapshotCount?.() ?? 0;+ const ptr = this.module_.springbone_snapshotData?.() ?? 0;+ const heap = (this.module_ as { HEAPF32?: Float32Array }).HEAPF32;+ if (count <= 0 || !ptr || !heap) return [];+ const out: SpringBoneParticle[] = [];+ for (let i = 0; i < count; i++) {+ const k = ptr / 4 + i * 7;+ out.push({+ position: [heap[k]!, heap[k + 1]!, heap[k + 2]!],+ pose: [heap[k + 3]!, heap[k + 4]!, heap[k + 5]!],+ parent: heap[k + 6]!,+ });+ }+ return out;+ }++ /** Give a chain's bones back as the animation had them and forget its state: what ends a preview in an editor. */+ release(root: Entity): void {+ this.module_.springbone_release?.(this.registry_, root as number);+ }+/** Put a chain back at its animated pose on its next frame: a teleport, a respawn, a pose set by hand. */reset(root: Entity): void {this.module_.springbone_reset?.(this.registry_, root as number);diff --git a/sdk/src/springbone/index.ts b/sdk/src/springbone/index.tsindex 485461312..fdcd2396f 100644--- a/sdk/src/springbone/index.ts+++ b/sdk/src/springbone/index.ts@@ -1,4 +1,4 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-export { SpringBoneAPI, SpringBoneRes } from './SpringBoneAPI';+export { SpringBoneAPI, SpringBoneRes, type SpringBoneParticle } from './SpringBoneAPI';export { SpringBonePlugin, springBonePlugin } from './SpringBonePlugin';diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex 84a1b9681..e81faf55e 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -616,6 +616,10 @@ export interface ESEngineModule {trail_clear?(registry: CppRegistry, entity: number): void;springbone_update?(registry: CppRegistry, dt: number): void;springbone_reset?(registry: CppRegistry, entity: number): void;+ springbone_release?(registry: CppRegistry, entity: number): void;+ springbone_snapshot?(registry: CppRegistry, entity: number): number;+ springbone_snapshotCount?(): number;+ springbone_snapshotData?(): number;// Tilemap APItilemap_initLayer?(entity: number, width: number, height: number,diff --git a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snapindex 43d8eb841..f530560c6 100644--- a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap+++ b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap@@ -1301,9 +1301,11 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho},"SpringBone": {"colliders": {+ "category": "Collision","tooltip": "Entities with a SpringBoneCollider that this chain is kept out of (the head, the shoulders).",},"drag": {+ "category": "Motion","max": 1,"min": 0,"slider": true,@@ -1314,19 +1316,23 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho"tooltip": "Off leaves the chain exactly as the animation poses it.",},"endLength": {+ "category": "Chain","min": 0,"step": 0.1,"tooltip": "Length of the tip past each end bone, in world units. 0 leaves the end bones unsimulated.",},"gravity": {+ "category": "Motion","tooltip": "Gravity on the chain, in world units a second squared (world y is up).",},"radius": {+ "category": "Chain","min": 0,"step": 0.1,"tooltip": "Thickness of the strand, in world units, kept clear of the colliders.",},"stiffness": {+ "category": "Motion","max": 1,"min": 0,"slider": true,@@ -1334,6 +1340,7 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho"tooltip": "How hard each bone is pulled back toward its animated pose. 0 hangs free, 1 follows the animation exactly.",},"weight": {+ "category": "Chain","max": 1,"min": 0,"slider": true,@@ -1343,6 +1350,7 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho},"SpringBoneCollider": {"height": {+ "category": "Shape","min": 0,"shownWhen": {"field": "shape",@@ -1354,14 +1362,17 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho"tooltip": "A capsule's length between the centres of its end spheres, in world units before scale.",},"offset": {+ "category": "Shape","tooltip": "Where the centre of the shape is, in the entity's own space.",},"radius": {+ "category": "Shape","min": 0,"step": 0.1,"tooltip": "Radius in world units, before the entity's scale.",},"shape": {+ "category": "Shape","enum": [{"label": "Sphere",diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex a0e74bd85..e3f0d0598 100644--- a/src/esengine/bindings/EditorAPI.generated.cpp+++ b/src/esengine/bindings/EditorAPI.generated.cpp@@ -2,10 +2,10 @@* @file EditorAPI.generated.cpp* @brief Auto-generated editor API with string-dispatched component access* @details Generated by EHT - DO NOT EDIT- * @schema_hash 29368da0ccf13fa8+ * @schema_hash b8db52cc968a31ad*/-#define ES_EDITOR_API_SCHEMA_HASH "29368da0ccf13fa8"+#define ES_EDITOR_API_SCHEMA_HASH "b8db52cc968a31ad"#include <emscripten/bind.h>#include <string>diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cppindex cc7a30c41..6ed0dc08f 100644--- a/src/esengine/bindings/RendererBindings.cpp+++ b/src/esengine/bindings/RendererBindings.cpp@@ -792,6 +792,32 @@ void springbone_reset(ecs::Registry& registry, u32 entity) {g_springBoneSystem->reset(Entity::fromRaw(entity));}+void springbone_release(ecs::Registry& registry, u32 entity) {+ if (!g_springBoneSystem) return;+ g_springBoneSystem->release(registry, Entity::fromRaw(entity));+}++static std::vector<f32>& springBoneSnapshot() {+ static std::vector<f32> data;+ return data;+}++u32 springbone_snapshot(ecs::Registry& registry, u32 entity) {+ (void)registry;+ auto& data = springBoneSnapshot();+ if (!g_springBoneSystem) { data.clear(); return 0; }+ g_springBoneSystem->snapshot(Entity::fromRaw(entity), data);+ return static_cast<u32>(data.size() / 7);+}++u32 springbone_snapshotCount() {+ return static_cast<u32>(springBoneSnapshot().size() / 7);+}++uintptr_t springbone_snapshotData() {+ return reinterpret_cast<uintptr_t>(springBoneSnapshot().data());+}+void renderer_setStage(i32 stage) {if (!g_renderFrame) return;g_renderFrame->setStage(static_cast<RenderStage>(stage));diff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hppindex def45693d..4025c66cc 100644--- a/src/esengine/bindings/RendererBindings.hpp+++ b/src/esengine/bindings/RendererBindings.hpp@@ -171,6 +171,13 @@ void trail_clear(ecs::Registry& registry, u32 entity);void springbone_update(ecs::Registry& registry, f32 dt);/** Puts a chain back at its animated pose on its next frame (a teleport, a respawn). */void springbone_reset(ecs::Registry& registry, u32 entity);+/** Copies a chain's particles for the editor to draw and returns how many (seven floats each; see SpringBoneSystem::snapshot); read them at springbone_snapshotData(). */+/** Gives a chain's bones back as the animation had them and forgets its state: what ends a preview. */+void springbone_release(ecs::Registry& registry, u32 entity);+u32 springbone_snapshot(ecs::Registry& registry, u32 entity);+u32 springbone_snapshotCount();+// @heapreturn esengine::springbone_snapshotCount() * 28+uintptr_t springbone_snapshotData();void renderer_setStage(i32 stage);u32 renderer_createTarget(u32 width, u32 height, i32 flags);u32 renderer_getTargetDepthTexture(u32 handle);diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex adae181e3..7af252cb6 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -747,6 +747,10 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("trail_clear", &esengine::trail_clear);emscripten::function("springbone_update", &esengine::springbone_update);emscripten::function("springbone_reset", &esengine::springbone_reset);+ emscripten::function("springbone_release", &esengine::springbone_release);+ emscripten::function("springbone_snapshot", &esengine::springbone_snapshot);+ emscripten::function("springbone_snapshotCount", &esengine::springbone_snapshotCount);+ emscripten::function("springbone_snapshotData", &esengine::springbone_snapshotData);emscripten::function("renderer_setStage", &esengine::renderer_setStage);emscripten::function("renderer_createTarget", &esengine::renderer_createTarget);emscripten::function("renderer_releaseTarget", &esengine::renderer_releaseTarget);diff --git a/src/esengine/ecs/components/SpringBone.hpp b/src/esengine/ecs/components/SpringBone.hppindex d2e72ff9b..40c255a28 100644--- a/src/esengine/ecs/components/SpringBone.hpp+++ b/src/esengine/ecs/components/SpringBone.hpp@@ -40,31 +40,31 @@ struct SpringBone {bool enabled{true};/** @brief How hard each bone is pulled back toward the pose the animation gives it, 0 to 1. */- ES_PROPERTY(min=0, max=1, step=0.01, slider, tooltip="How hard each bone is pulled back toward its animated pose. 0 hangs free, 1 follows the animation exactly.")+ ES_PROPERTY(category=Motion, min=0, max=1, step=0.01, slider, tooltip="How hard each bone is pulled back toward its animated pose. 0 hangs free, 1 follows the animation exactly.")f32 stiffness{0.1f};/** @brief How much of its velocity a bone loses each frame, 0 to 1. */- ES_PROPERTY(min=0, max=1, step=0.01, slider, tooltip="How much of its speed a bone loses each frame. Higher settles sooner.")+ ES_PROPERTY(category=Motion, min=0, max=1, step=0.01, slider, tooltip="How much of its speed a bone loses each frame. Higher settles sooner.")f32 drag{0.5f};/** @brief Gravity on the chain, in world units a second squared. */- ES_PROPERTY(tooltip="Gravity on the chain, in world units a second squared (world y is up).")+ ES_PROPERTY(category=Motion, tooltip="Gravity on the chain, in world units a second squared (world y is up).")glm::vec3 gravity{0.0f, -980.0f, 0.0f};/** @brief How far the last bones of a chain reach past themselves, in world units: a leaf has no child to aim at, so this gives it a tip. 0 leaves leaves unsimulated. */- ES_PROPERTY(min=0, step=0.1, tooltip="Length of the tip past each end bone, in world units. 0 leaves the end bones unsimulated.")+ ES_PROPERTY(category=Chain, min=0, step=0.1, tooltip="Length of the tip past each end bone, in world units. 0 leaves the end bones unsimulated.")f32 endLength{0.0f};/** @brief The thickness of the strand, in world units, kept clear of every collider. */- ES_PROPERTY(min=0, step=0.1, tooltip="Thickness of the strand, in world units, kept clear of the colliders.")+ ES_PROPERTY(category=Chain, min=0, step=0.1, tooltip="Thickness of the strand, in world units, kept clear of the colliders.")f32 radius{0.0f};/** @brief How much of the simulated pose is used, 0 to 1: 0 is the animation alone. */- ES_PROPERTY(min=0, max=1, step=0.01, slider, tooltip="How much of the simulation is used. 0 is the animation alone.")+ ES_PROPERTY(category=Chain, min=0, max=1, step=0.01, slider, tooltip="How much of the simulation is used. 0 is the animation alone.")f32 weight{1.0f};/** @brief Entities with a SpringBoneCollider this chain keeps out of. */- ES_PROPERTY(entity_ref, tooltip="Entities with a SpringBoneCollider that this chain is kept out of (the head, the shoulders).")+ ES_PROPERTY(category=Collision, entity_ref, tooltip="Entities with a SpringBoneCollider that this chain is kept out of (the head, the shoulders).")std::vector<Entity> colliders;SpringBone() = default;@@ -75,19 +75,19 @@ struct SpringBone {*/ES_COMPONENT()struct SpringBoneCollider {- ES_PROPERTY(enum=SpringBoneShape, tooltip="Sphere, or a capsule along the entity's own Y axis.")+ ES_PROPERTY(category=Shape, enum=SpringBoneShape, tooltip="Sphere, or a capsule along the entity's own Y axis.")SpringBoneShape shape{SpringBoneShape::Sphere};/** @brief Radius, in world units before the entity's scale. */- ES_PROPERTY(min=0, step=0.1, tooltip="Radius in world units, before the entity's scale.")+ ES_PROPERTY(category=Shape, min=0, step=0.1, tooltip="Radius in world units, before the entity's scale.")f32 radius{10.0f};/** @brief A capsule's length between its two end spheres' centres, in world units before scale. */- ES_PROPERTY(min=0, step=0.1, shown_when=shape:Capsule, tooltip="A capsule's length between the centres of its end spheres, in world units before scale.")+ ES_PROPERTY(category=Shape, min=0, step=0.1, shown_when=shape:Capsule, tooltip="A capsule's length between the centres of its end spheres, in world units before scale.")f32 height{20.0f};/** @brief Where the shape's centre is, in the entity's own space. */- ES_PROPERTY(tooltip="Where the centre of the shape is, in the entity's own space.")+ ES_PROPERTY(category=Shape, tooltip="Where the centre of the shape is, in the entity's own space.")glm::vec3 offset{0.0f, 0.0f, 0.0f};SpringBoneCollider() = default;diff --git a/src/esengine/springbone/SpringBoneSystem.cpp b/src/esengine/springbone/SpringBoneSystem.cppindex 3d1bebab7..d0b0717c4 100644--- a/src/esengine/springbone/SpringBoneSystem.cpp+++ b/src/esengine/springbone/SpringBoneSystem.cpp@@ -53,11 +53,38 @@ bool SpringBoneSystem::gatherColliders(ecs::Registry& registry, const std::vectoreturn !out.empty();}+void SpringBoneSystem::restoreBones(ecs::Registry& registry, State& state) {+ for (size_t i = 1; i < state.entities.size() && i < state.animated.size(); ++i) {+ if (!registry.valid(state.entities[i])) continue;+ auto* t = registry.tryGet<ecs::Transform>(state.entities[i]);+ if (t && state.hasWritten[i] && t->rotation == state.written[i]) {+ t->rotation = state.animated[i];+ ecs::invalidateTransformComposition();+ }+ }+}++void SpringBoneSystem::release(ecs::Registry& registry, Entity root) {+ const auto it = states_.find(root);+ if (it == states_.end()) return;+ restoreBones(registry, it->second);+ states_.erase(it);+}+void SpringBoneSystem::reset(Entity root) {auto it = states_.find(root);if (it != states_.end()) it->second.primed = false;}+void SpringBoneSystem::snapshot(Entity root, std::vector<f32>& out) const {+ out.clear();+ const auto it = states_.find(root);+ if (it == states_.end()) return;+ for (const Particle& p : it->second.particles) {+ out.insert(out.end(), {p.position.x, p.position.y, p.position.z, p.target.x, p.target.y, p.target.z, static_cast<f32>(p.parent)});+ }+}+const std::vector<Particle>* SpringBoneSystem::chain(Entity root) const {const auto it = states_.find(root);return it == states_.end() ? nullptr : &it->second.particles;@@ -76,16 +103,7 @@ void SpringBoneSystem::update(ecs::Registry& registry, ecs::TransformSystem* traconst Entity root = it->first;const auto* sb = registry.valid(root) ? registry.tryGet<ecs::SpringBone>(root) : nullptr;if (sb && sb->enabled && sb->weight > 0.0f) { ++it; continue; }- const auto& entities = it->second.entities;- State& gone = it->second;- for (size_t i = 1; i < entities.size() && i < gone.animated.size(); ++i) {- if (!registry.valid(entities[i])) continue;- auto* t = registry.tryGet<ecs::Transform>(entities[i]);- if (t && gone.hasWritten[i] && t->rotation == gone.written[i]) {- t->rotation = gone.animated[i];- ecs::invalidateTransformComposition();- }- }+ restoreBones(registry, it->second);it = states_.erase(it);}diff --git a/src/esengine/springbone/SpringBoneSystem.hpp b/src/esengine/springbone/SpringBoneSystem.hppindex 3b45ae94f..e078ac2ee 100644--- a/src/esengine/springbone/SpringBoneSystem.hpp+++ b/src/esengine/springbone/SpringBoneSystem.hpp@@ -34,6 +34,12 @@ public:/** @brief Advance every enabled chain by `dt` seconds. Composes world transforms first if the animation moved any. */void update(ecs::Registry& registry, ecs::TransformSystem* transforms, f32 dt);+ /**+ * @brief Give a chain's bones back as the animation had them and forget its state: what stops a preview in the editor, where nothing animates the bones+ * and a chain left as the simulation last turned it would stay that way.+ */+ void release(ecs::Registry& registry, Entity root);+/** @brief Forget a chain's state: it starts again from the animated pose on its next frame (a teleport, a respawn). */void reset(Entity root);@@ -43,6 +49,12 @@ public:/** @brief The simulated world positions of a chain, root first, in the order its bones were found (tips last); null if it has no state. */const std::vector<Particle>* chain(Entity root) const;+ /**+ * @brief A chain's particles as flat floats for the editor to draw: seven a particle, the simulated position, the position the animation gives, then+ * the index of its parent (-1 for the root). Empty when the chain has no state.+ */+ void snapshot(Entity root, std::vector<f32>& out) const;+private:/** @brief One bone (or a virtual tip) of a chain, beside its particle. */struct Node {@@ -87,6 +99,7 @@ private:// RAII: unregisters from the registry's onDestroy when this system is torn down.Connection destroyConn_;+ void restoreBones(ecs::Registry& registry, State& state);void collectBones(ecs::Registry& registry, Entity root, std::vector<Entity>& out);bool gatherColliders(ecs::Registry& registry, const std::vector<Entity>& entities, std::vector<Collider>& out);};diff --git a/tests/springbone/test_springbone.cpp b/tests/springbone/test_springbone.cppindex 4025284c8..793a04444 100644--- a/tests/springbone/test_springbone.cpp+++ b/tests/springbone/test_springbone.cpp@@ -274,6 +274,19 @@ TEST_CASE("switching the chain off gives the bones back as the animation had theCHECK(rig.system.chain(rig.root) == nullptr);}+TEST_CASE("releasing a chain gives its bones back at once and forgets it") {+ Rig rig;+ rig.frame();+ rig.moveRoot({60.0f, 0.0f, 0.0f});+ rig.frame();+ CHECK(rig.turned(rig.b1) > 0.05f);+ rig.system.release(rig.registry, rig.root);+ CHECK(rig.turned(rig.b1) < 1e-4f);+ CHECK(rig.system.chain(rig.root) == nullptr);+ // Releasing what is not there is nothing.+ rig.system.release(rig.registry, rig.root);+}+TEST_CASE("weight blends between the animation and the simulation") {Rig full, half;half.registry.get<ecs::SpringBone>(half.root).weight = 0.5f;diff --git a/tools/census-transform-writers.mjs b/tools/census-transform-writers.mjsindex 13d41e201..e1dfd2e68 100644--- a/tools/census-transform-writers.mjs+++ b/tools/census-transform-writers.mjs@@ -63,6 +63,10 @@ const SEAMS = [file: 'src/esengine/springbone/SpringBoneSystem.cpp', fn: 'update', role: 'announces',why: 'writes the local rotation of every bone it aimed and announces once after the pass; positions are never written',},+ {+ file: 'src/esengine/springbone/SpringBoneSystem.cpp', fn: 'restoreBones', role: 'announces',+ why: 'gives the bones of a chain the rotation the animation had, and announces for each one it gave back',+ },{file: 'src/esengine/bindings/EditorAPI.generated.cpp', fn: 'editor_setFloat', role: 'announces',why: 'emitted from WRITE_HOOKS; check-transform-seam holds which arms get it',diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 5a8846645..b188d3f8f 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2567,6 +2567,8 @@ export const NOTED = {{"note":"Water holds things up. A Floating component on an entity with a RigidBody3D floats it: a buoyant force against gravity (`buoyancy` is the water's density against the body's, so 2 floats it half under) and a drag against its velocity relative to the water, which brings it to rest in a lake and carries it with a river's current, applied at a few points of the body so waves tip it. It works from the CPU's own water surface, so it needs no renderer, and it needs the 3D physics module, which gains force and mass queries."},"feat(water): a camera under the surface sees through the water, fogged and tinted by what it has crossed":{"note":"A camera under water sees through it. Whenever the active camera is below a water body's surface an Underwater effect is added to the post-process volumes: the light of each pixel is taken out colour by colour (red first) by the distance it crossed, with the same absorption and density the surface's material draws with, and the water gives back its own colour, dimmer the deeper the camera is. The surface seen from below turns over and, past the critical angle, reflects whole (Snell's window)."},+ "feat(editor): a selected spring-bone chain and its colliders are drawn in the viewport, Details groups and counts them, and Preview FX simulates the chain":+ {"note":"Spring bones can be authored in the editor: Details groups a chain's fields into Motion, Chain and Collision and counts the bones below it (or warns that there are none), the viewport draws a selected chain (the bones as posed, a ring at each joint, the tips) with the colliders it keeps out of, or a selected collider on its own, behind a Spring bones entry in the Gizmo menu, and View · Preview FX simulates the chain in the edit viewport, drawn solid over its dashed pose. Ending the preview gives the bones back as the scene has them."},"feat(animation): spring bones give a chain of bones secondary motion in the engine, with colliders to keep it out of the body":{"note":"Spring bones give a skeleton secondary motion: a `SpringBone` on the root of a chain of bones (hair, a tail, a cord) makes everything below it a spring that lags the animation, falls with gravity, is pulled back to its animated pose, never stretches, and is kept out of `SpringBoneCollider` spheres and capsules. It runs in C++ in the engine, so it costs the same on every target: 300 chains of six bones step in 0.28 ms. Only the bones' rotations are written, and switching it off gives the animation's own back."},"feat(editor): the quality settings page has a Level · Water group for waves, ripple cells, displacement, mirror and caustics":