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(foliage): a field of any size is cut into cells no wider than its cell size - past 200 cells a side each cell was left wider than the plants scattered in it, so a meadow over a large terrain grew in clumps with bare ground between
yhhd94811bda15c
diff --git a/sdk/src/foliage/foliagePlugin.ts b/sdk/src/foliage/foliagePlugin.tsindex 3b465c282..8b85225c7 100644--- a/sdk/src/foliage/foliagePlugin.ts+++ b/sdk/src/foliage/foliagePlugin.ts@@ -35,6 +35,15 @@ import { bakesOf } from '../runtime/bakes';import { firstSend, forgetSent, planPool } from '../runtime/planPool';import type { FoliageCellRequest, FoliageSurroundingsSpec } from '../worldgen/planWorker';+/**+ * How many cells an area is cut into along x and z: as many as it takes for none to be wider than `cellSize`, however large the area.+ * Only those near the eye are ever grown, so the count costs nothing; a cap on it would leave each cell wider than the plants scattered in it.+ */+export function foliageCellsAcross(sizeX: number, sizeZ: number, cellSize: number): { x: number; z: number } {+ const side = Math.max(1, cellSize);+ return { x: Math.max(1, Math.ceil(sizeX / side)), z: Math.max(1, Math.ceil(sizeZ / side)) };+}+/** The fields of the `Foliage` component. @experimental */export interface FoliageData {/** The plant to scatter. Empty grows grass, blades made here. */@@ -334,8 +343,7 @@ export class FoliagePlugin implements Plugin {}private cellsAcross(data: FoliageData): { x: number; z: number } {- const side = Math.max(1, data.cellSize);- return { x: Math.min(200, Math.max(1, Math.ceil(data.sizeX / side))), z: Math.min(200, Math.max(1, Math.ceil(data.sizeZ / side))) };+ return foliageCellsAcross(data.sizeX, data.sizeZ, data.cellSize);}/**diff --git a/sdk/tests/foliage-zones.test.ts b/sdk/tests/foliage-zones.test.tsindex 03edbce1e..02933fa57 100644--- a/sdk/tests/foliage-zones.test.ts+++ b/sdk/tests/foliage-zones.test.ts@@ -1,5 +1,6 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { foliageCellsAcross } from '../src/foliage/foliagePlugin';import { describe, expect, it } from 'vitest';import { App } from '../src/app/app';import { AppContext, setDefaultContext } from '../src/ecs/context';@@ -27,6 +28,17 @@ const boot = () => {};const cells = (app: App) => app.world.getEntitiesWithComponents([MeshRenderer]);+describe('the cells of a Foliage area', () => {+ it('are never wider than the cell size, over a field of any size', () => {+ expect(foliageCellsAcross(400, 400, 40)).toEqual({ x: 10, z: 10 });+ // An island of six kilometres on 12 m cells: 512 of them, not the 200 a cap once left 31 m wide with plants in 12 m of each.+ const island = foliageCellsAcross(6144, 6144, 12);+ expect(island).toEqual({ x: 512, z: 512 });+ expect(6144 / island.x).toBeLessThanOrEqual(12);+ expect(foliageCellsAcross(5, 5, 40)).toEqual({ x: 1, z: 1 });+ });+});+describe('grass reservations and shadows', () => {it('grows without worldgen and applies the authored shadow policy to generated cells', async () => {const { app, entity } = boot(); await tick(app);diff --git a/tools/render-lab/shot.mjs b/tools/render-lab/shot.mjsindex db53935c8..84f27385b 100644--- a/tools/render-lab/shot.mjs+++ b/tools/render-lab/shot.mjs@@ -15,7 +15,7 @@ try {page.on('pageerror', (e) => logs.push('pageerror ' + String(e)));page.on('console', (m) => { if (process.env.DEBUG_LOGS === '1' || m.type() === 'error' || m.type() === 'warning') logs.push(m.type() + ' ' + m.text().slice(0, 700)); });await page.goto(`http://127.0.0.1:${server.address().port}/${gpu ? "" : "?headless"}`, { waitUntil: 'load' });- await page.waitForTimeout(12000);+ await page.waitForTimeout(Number(process.env.WAIT_MS || 12000));await page.screenshot({ path: out + `/lab-${view}.png`, timeout: 120000 }).catch((e) => logs.push('screenshot ' + String(e).slice(0, 160)));console.log('context:', await page.evaluate(() => { const c = document.querySelector('canvas'); return c ? (c.getContext('webgpu') ? 'webgpu' : c.getContext('webgl2') ? 'webgl2' : 'unknown') : 'no canvas'; }).catch((e) => String(e)));const facts = await page.evaluate(() => (window.__estellaCooked ? window.__estellaCooked.facts() : 'no hook')).catch((e) => String(e));