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
fix(spline): TerrainBand2D and PathFollower pull the spline module into a build; a band rebuilds a mesh the editor cleared
yhhc4f2467c8c55
diff --git a/pipeline/src/project/targetSupport.ts b/pipeline/src/project/targetSupport.tsindex 5f956605d..26811c9bd 100644--- a/pipeline/src/project/targetSupport.ts+++ b/pipeline/src/project/targetSupport.ts@@ -48,7 +48,7 @@ export const SUBSYSTEM_COMPONENTS: Readonly<Record<Subsystem, readonly string[]>foliage: ['Foliage', 'PlacedFoliage'],worldgen: ['WorldGen', 'WorldZone'],water: ['WaterBody', 'WaterZone', 'Floating'],- spline: ['Spline'],+ spline: ['Spline', 'PathFollower', 'TerrainBand2D'],// Hair, Skin and Eye are shaders, not components: a character's materials are what name them (see SHADER_SUBSYSTEM).characterShaders: [],particles: ['ParticleEmitter', 'ParticleForceField'],diff --git a/sdk/src/spline/terrainBand2D.ts b/sdk/src/spline/terrainBand2D.tsindex e772bb837..48ed2a102 100644--- a/sdk/src/spline/terrainBand2D.ts+++ b/sdk/src/spline/terrainBand2D.ts@@ -152,7 +152,8 @@ function pixelsPerUnit(app: App): number {/** Keeps every `TerrainBand2D`'s mesh and collider matching its spline. Called once by the spline plugin. */export function installTerrainBands(app: App): void {- const built = new Map<Entity, string>();+ /** What each entity's mesh was last built from, and whether that left it any (an empty one is not worth looking for). */+ const built = new Map<Entity, { key: string; empty: boolean }>();const wroteCollider = new Set<Entity>();app.world.onDespawn((entity: Entity) => { built.delete(entity); wroteCollider.delete(entity); });@@ -165,9 +166,12 @@ export function installTerrainBands(app: App): void {const spline = world.get(entity, Spline) as SplineData;const ppu = band.collider ? pixelsPerUnit(app) : 0;const key = JSON.stringify([spline.points, spline.closed, band, ppu]);- if (built.get(entity) === key) continue;- built.set(entity, key);+ const held = built.get(entity);+ // The editor re-imports a MeshRenderer from its scene model, which carries no geometry, and that clears what was uploaded: a mesh+ // that has gone missing is built again, not trusted to still be there.+ if (held && held.key === key && (held.empty || api.getGeometry(entity))) continue;const result = buildTerrainBand(spline.points, spline.closed, band);+ built.set(entity, { key, empty: !result });if (!world.has(entity, MeshRenderer)) world.insert(entity, MeshRenderer, { enabled: true });if (result) api.setGeometry(entity, result.geometry); else api.clearGeometry(entity);if (band.collider && result && result.outline.length >= 4) {diff --git a/sdk/tests/terrain-band-2d.test.ts b/sdk/tests/terrain-band-2d.test.tsindex 5ef761049..a91b9ac0f 100644--- a/sdk/tests/terrain-band-2d.test.ts+++ b/sdk/tests/terrain-band-2d.test.ts@@ -102,7 +102,12 @@ describe.skipIf(!HAS_WASM)('TerrainBand2D system', () => {function install() {const uploads: number[] = [];- const api = { setGeometry: (e: number) => { uploads.push(e); }, clearGeometry: () => {} };+ const held = new Set<number>();+ const api = {+ setGeometry: (e: number) => { uploads.push(e); held.add(e); },+ clearGeometry: (e: number) => { held.delete(e); },+ getGeometry: (e: number) => (held.has(e) ? {} : undefined),+ };let system: { _fn: () => void } | null = null;const app = {world,@@ -111,7 +116,7 @@ describe.skipIf(!HAS_WASM)('TerrainBand2D system', () => {addSystemToSchedule: (_s: unknown, def: { _fn: () => void }) => { system = def; },};installTerrainBands(app as never);- return { run: () => system!._fn(), uploads };+ return { run: () => system!._fn(), uploads, lose: (e: number) => { held.delete(e); } };}function ground(over: Partial<TerrainBand2DData> = {}) {@@ -133,6 +138,15 @@ describe.skipIf(!HAS_WASM)('TerrainBand2D system', () => {expect(uploads).toEqual([e, e]);});+ it('builds the mesh again when the editor has cleared it', () => {+ const { run, uploads, lose } = install();+ const e = ground();+ run();+ lose(e);+ run();+ expect(uploads).toEqual([e, e]);+ });+it('writes a chain collider along the surface in physics units, and takes it back', () => {const { run } = install();const e = ground({ collider: true });