Skip to content

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.

feat(anim): a silent layer says nothing, including with a sprite sheet

esengine89116783f97e
diff --git a/sdk/src/animation/Animator.ts b/sdk/src/animation/Animator.ts
index 37f0627c8..b87e790b5 100644
--- a/sdk/src/animation/Animator.ts
+++ b/sdk/src/animation/Animator.ts
@@ -816,7 +816,11 @@ export class AnimatorControllerAPI {
// posed; taking displacement from more than one would have two answers
// to a question the character controller asks once.
const drivesRoot = index === 0 && targetLeaf.rootMotion === true;
- const posed = motion !== null
+ // A layer at zero says nothing, a motion that WRITES the entity included:
+ // a sprite sheet switched by a silent layer is that layer speaking. Its
+ // machine still runs and still posts events — heard, not shown.
+ const weight = index === 0 ? 1 : (def.layers![index - 1]!.weight ?? 1);
+ const posed = motion !== null && weight > 0
&& this.poseLayer(world, ctx, lrt, motion, drivesRoot, stateChanged);
if (posed) this.compose(world, ctx, def, index, rt, posed, motion!);
diff --git a/sdk/tests/animatorLayers.test.ts b/sdk/tests/animatorLayers.test.ts
index 6b3a1896a..02d6fbd9a 100644
--- a/sdk/tests/animatorLayers.test.ts
+++ b/sdk/tests/animatorLayers.test.ts
@@ -14,6 +14,7 @@ import {
import { createTimelineMotionDriver, TIMELINE_MOTION } from '../src/timeline';
import { TimelineAPI } from '../src/timeline/TimelineControl';
import { defineComponent, Name, Children, Parent } from '../src/ecs/component';
+import { SpriteAnimator } from '../src/animation/SpriteAnimator';
import { WrapMode, TrackType, InterpType, type TimelineAsset } from '../src/timeline/TimelineTypes';
const E = 1;
@@ -538,3 +539,65 @@ describe('a masked layer', () => {
expect(liftAt(world, ids.legs)).toBe(10);
});
});
+
+// ---------------------------------------------------------------------------
+// A motion that writes the entity instead of stating a pose
+// ---------------------------------------------------------------------------
+
+describe('a layer playing something that cannot be sampled', () => {
+ /** A controller whose upper layer drives a sprite sheet. */
+ function spriteStack(weight: number, mask?: { paths: string[] }): AnimatorControllerAPI {
+ const ctrl = new AnimatorControllerAPI();
+ ctrl.registerController('rig', {
+ version: 2, parameters: [],
+ initialState: 'Base',
+ states: [{ name: 'Base', motion: { kind: 'sprite', clip: 'base_clip' }, transitions: [] }],
+ layers: [{
+ name: 'Upper', weight, mask, initialState: 'Over',
+ states: [{ name: 'Over', motion: { kind: 'sprite', clip: 'over_clip' }, transitions: [] }],
+ }],
+ });
+ return ctrl;
+ }
+
+ function seedSprite() {
+ const world = seedWorld();
+ world.insert(E, SpriteAnimator, {
+ clip: '', currentFrame: 0, frameTimer: 0, speed: 1,
+ loop: true, playing: false, finished: false, enabled: true,
+ });
+ return world;
+ }
+
+ const clipOf = (world: any) => (world.get(E, SpriteAnimator) as { clip: string }).clip;
+
+ it('drives the entity directly, so the upper layer simply wins', () => {
+ // A sprite sheet has nothing to be halfway between, so it joins no stack:
+ // it is switched, and the last layer to switch it is the one on screen.
+ const world = seedSprite();
+ const ctrl = spriteStack(1);
+ attach(world);
+ ctrl.update(world, 0.016);
+ expect(clipOf(world)).toBe('over_clip');
+ });
+
+ it('is not held back by a mask, which only a pose can be', () => {
+ // Worth stating rather than leaving to be discovered: an author who masks
+ // a sprite layer gets no masking and no complaint.
+ const world = seedSprite();
+ const ctrl = spriteStack(1, { paths: ['nothing'] });
+ attach(world);
+ ctrl.update(world, 0.016);
+ expect(clipOf(world)).toBe('over_clip');
+ });
+
+ it('says nothing at all at weight zero', () => {
+ // The one thing weight DOES reach here. A layer at zero that still
+ // switched the sheet would be a silent layer speaking.
+ const world = seedSprite();
+ const ctrl = spriteStack(0);
+ attach(world);
+ ctrl.update(world, 0.016);
+ expect(clipOf(world)).toBe('base_clip');
+ });
+});
diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjs
index 30bd2d614..c198549f3 100644
--- a/tools/goldenProjects.mjs
+++ b/tools/goldenProjects.mjs
@@ -296,6 +296,7 @@ export const CAPABILITIES = [
'lighting-2d',
'sprite-sorting', 'sprite-mask', 'ui-widgets', 'velocity-motion',
'ssao', 'navigation-3d', 'root-motion', 'animation-events', 'shader-readiness',
+ 'animation-layers', 'animation-ik',
'tilemap', 'tile-collision',
'touch', 'safe-area', 'pause-resume',
'texture-atlas',
@@ -361,6 +362,12 @@ export const EVIDENCE = {
ssao: /"type":\s*"ssao"/,
'navigation-3d': /\b(NavVolume|NavLink|NavAgent3D)\b/,
'root-motion': /\brootMotion\b/,
+ // The MASK, not the layer list: a controller can carry an empty `layers` and
+ // claim the stack, and what a stack is for is one machine reaching part of the
+ // rig while another reaches the rest.
+ 'animation-layers': /"mask":\s*\{\s*"paths"/,
+ // The constraint a controller declares, not the solver behind it.
+ 'animation-ik': /"kind":\s*"(two-bone|look-at)"/,
// The authored track, not any key called events: the runtime always read them,
// and what shipped is a format and an editor that can write them.
'animation-events': /"type":\s*"customEvent"/,
@@ -405,6 +412,9 @@ export const KNOWN_GAPS = {
// hot-update-demo ships one now, so the package SHAPE is a real project's.
// What no automated run reaches is the vendor mounting it: only a mini-game
// host implements the download, and none of the tiers builds for one.
+ 'animation-ik': 'two-bone and look-at constraints run in the engine and the editor authors them, '
+ + 'but no rig in the corpus has a limb: the 3D skeletons here are joints hanging off one root, '
+ + 'and a two-bone solve is the tip and the TWO joints above it — a chain nothing shipped has',
subpackage: 'hot-update-demo delivers `pack` as a 分包 and its button loads it, but no tier builds that project for a mini-game host — the vendor download itself is verified by hand in devtools',
};
@@ -521,7 +531,8 @@ export const GOLDEN = [
{
id: 'third-person-3d',
certifies: ['third-person', 'level-of-detail', 'ssao', 'navigation-3d',
- 'root-motion', 'animation-events', 'world-streaming', 'shader-readiness'],
+ 'root-motion', 'animation-events', 'world-streaming', 'shader-readiness',
+ 'animation-layers'],
// A packaged frame looks the same whether first sight of the outpost cost a
// compile or not; the run is what reads the counter on both sides of the
// boundary. Scheduled by `a-streamed-place-is-ready-before-it-is-seen`.