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(worldgen): a generated world lays out over a planet's six faces
yhh985366d19e0a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b08b9f7eb..dd4886b00 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,7 @@ published separately; it ships inside the editor.### Added+- **A generated world on a planet.** A `WorldGen` with `surface` Planet, on a `Planet`'s entity, lays the world out over the cube's six faces, each as a plane of metres, by the same rules a flat world has: biomes over fields, recipes and layers. A direction is planned by the face it falls on; what is placed is taken to the planet and stands along its up. The fields are the planet's own (height, slope, noise in three dimensions with no seam between faces, `paint.<layer>`, and the fields a planet provider names with `fields`), the biomes paint the ground too, and `seaLevel` and `WorldZone`s work over a planet.- **A planet pulls and answers.** `Planet.gravity` pulls every dynamic 3D body toward the centre of the nearest planet that pulls (the world's gravity is taken off the body and the planet's put on, as a force each fixed step), and the `PlanetRegistryRes` resource answers `up`, `altitude`, `groundHeight`, `groundPoint` and `nearest` for what stands, aims or falls on a round world.- **A render origin for large worlds.** `setRenderOriginStep(step)` turns on drawing relative to a point near the camera: the origin is the camera's position rounded to `step` and moves only when the camera is further than `step` from it, the renderer takes every mesh, light, probe and shadow bound from it before the GPU sees them, and the camera's view-projection is built for the same origin, so a world tens of kilometres across stops jittering. It is off by default and changes nothing then. It covers meshes, lights, probes, occluders, planar reflections, sprites, text, particles (GPU too), trails, tilemaps, world-space UI, 2D shadows, and the terrain, planet, water, foliage, height fog and cloud shaders, which read the world's own position back from a new `u_renderOrigin` frame constant. Debug and custom draws stay in the world's coordinates, and the previous frame's view and meshes are taken to the new origin when it steps, so motion vectors and temporal effects carry on.- **A planet's ground has the layers' textures.** `Planet.layers` names up to four `.esterrainlayer` files, as on a flat terrain: each layer's albedo and normal map are read on the planes of the world's axes by how much the ground faces them, with a wider read mixed in far off so the repeat is lost. Without layers the ground is still the four colours.diff --git a/docs/astro/src/content/docs/graphics/terrain.mdx b/docs/astro/src/content/docs/graphics/terrain.mdxindex 68538f069..db4974ed2 100644--- a/docs/astro/src/content/docs/graphics/terrain.mdx+++ b/docs/astro/src/content/docs/graphics/terrain.mdx@@ -284,6 +284,8 @@ registerPlanetProvider({A planet answers the questions a round world puts to everything standing on it, through the `PlanetRegistryRes` resource: `up(planet, x, y, z)` is the unit direction away from its centre, `altitude` the height above the radius, `groundHeight` the generator's own height under a position (null while a provider answers later) and `groundPoint` the point on the ground under it. `nearest(x, y, z)` names the planet whose surface is nearest. Set `gravity` (metres a second squared at the surface) and 3D physics pulls every dynamic body toward the centre of the nearest planet that pulls: the world's one gravity is taken off the body and the planet's put on, as a force each fixed step, so with the world's gravity at zero a body simply falls toward the planet.+A generated world can be laid out over a planet: put a `WorldGen` with `surface` set to Planet on the `Planet`'s entity. Each of the cube's six faces is laid out as a plane of metres by the same rules a flat world has (biomes over fields, recipes, layers), a direction is planned by the face it falls on, and what is placed is taken to the planet and stands along its up. The fields are the planet's own: the ground's height, its slope, noise read in three dimensions (so a field wanders over an edge between two faces with no seam), `paint.<layer>` for each of the planet's layers, and the fields the provider names with `fields` (an ecology). The biomes also paint the ground (`paintGround`), so what is drawn and what grows are one map. `seaLevel` is the height of the sea: lower ground is under water. Zones (`WorldZone`) stand at a position in the world and are kept on the face they fall on.+The ground collides: the finest nodes within `collisionDistance` of every moving 3D body and character are built as collision geometry from the same samples the ground is drawn from (`collision`, `collisionDistance`, `collisionLayer`, `friction`, as on a flat terrain). A planet's transform is a position only: a turned or scaled planet's collision stands where it would be unturned. `layers` names up to four `.esterrainlayer` files, as on a flat terrain; each is read on the planes of the world's axes by how much the ground faces them, with a wider read mixed in far off so the repeat is lost. Without layers the ground is the four colours. The sea, a sky that follows the horizon round and gravity toward the centre are not in it yet; a body falls along the world's one gravity, so toward the centre only at the top of the planet.## Limitsdiff --git a/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx b/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdxindex b86bbe015..65a4602d1 100644--- a/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx+++ b/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx@@ -195,6 +195,8 @@ registerTerrainProvider(planet);星球回答圆形世界向站在上面的一切提出的问题,通过 `PlanetRegistryRes` 资源:`up(planet, x, y, z)` 是背离球心的单位方向,`altitude` 是高出半径的高度,`groundHeight` 是生成器自己在某位置下的地面高度(提供器稍后才回答时为 null),`groundPoint` 是它下面地面上的那个点。`nearest(x, y, z)` 给出表面最近的星球。设置 `gravity`(表面处的米每二次方秒),3D 物理就把每个动态刚体拉向最近的、有引力的星球中心:世界唯一的重力从刚体上拿掉,换上星球的,每个固定步长作为一个力施加;世界重力设为 0 时,刚体就是朝星球落下。+生成的世界可以铺在星球上:在 `Planet` 所在的实体上放一个 `surface` 设为 Planet 的 `WorldGen`。立方体的六个面各按米制平面,用和平面世界一样的规则(字段之上的群落、配方、图层)铺设;一个方向由它落在的那个面来规划,放出来的东西被带到星球上,沿着当地的"上"站立。字段是星球自己的:地面高度、坡度、在三维里读的噪声(所以字段越过两个面之间的边没有接缝)、星球每个图层的 `paint.<层名>`,以及提供器用 `fields` 命名的字段(比如生态)。群落同时给地面上色(`paintGround`),画出来的和长出来的是同一张图。`seaLevel` 是海平面高度,比它低的地面在水下。区域(`WorldZone`)站在世界里的一个位置上,归它落在的那个面。+地面有碰撞:每个运动的 3D 刚体和角色在 `collisionDistance` 内的最细节点,会用画地面的同一批采样建成碰撞几何(`collision`、`collisionDistance`、`collisionLayer`、`friction`,和平面地形一样)。星球的变换只有位置:旋转或缩放过的星球,碰撞仍站在没旋转时的位置。`layers` 可以写最多四个 `.esterrainlayer` 文件,和平面地形一样;每层按地面朝向世界坐标轴的程度,在三个投影面上取样,远处混入更宽的一次取样,看不出重复。不写图层时地面就是四种颜色。海、跟着地平线转的天空和指向球心的重力还没有;物体沿世界唯一的重力下落,所以只有在星球顶部才是朝向球心。## 限制diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.jsonindex c772e8387..06104b153 100644--- a/docs/astro/src/data/apiStability.generated.json+++ b/docs/astro/src/data/apiStability.generated.json@@ -3,10 +3,10 @@"counts": {"public": 115,"beta": 171,- "experimental": 2551,+ "experimental": 2560,"deprecated": 3},- "total": 2837,+ "total": 2846,"subsystems": [{"id": "mobile-controls",diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.jsonindex f3548ad53..3934ade23 100644--- a/docs/astro/src/data/components.generated.json+++ b/docs/astro/src/data/components.generated.json@@ -3921,6 +3921,13 @@"range": "≥ 0","advanced": true},+ {+ "key": "gravity",+ "type": "number",+ "default": "0",+ "doc": "How hard the planet pulls bodies toward its centre, in metres a second squared at the surface (9.81 is the Earth's). Needs 3D physics; the world's own gravity is taken off the bodies it pulls.",+ "range": "≥ 0"+ },{"key": "layers","type": "array",@@ -3954,7 +3961,8 @@"macroVariation","collisionDistance","collisionLayer",- "friction"+ "friction",+ "gravity"]},{@@ -7993,11 +8001,29 @@"type": "boolean","default": "true","doc": "Whether the biomes paint the terrain."+ },+ {+ "key": "surface",+ "type": "enum",+ "default": "Plane",+ "doc": "Plane: laid out over a Terrain. Planet: this entity is also a Planet, and the world is laid out over its six faces.",+ "values": [+ "Plane",+ "Planet"+ ]+ },+ {+ "key": "seaLevel",+ "type": "number",+ "default": "0",+ "doc": "The height of the sea above the planet's radius: ground lower than this is under water."}],"animatable": ["version",- "seed"+ "seed",+ "surface",+ "seaLevel"]},{diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 439f873a7..6531a82c8 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -6655,6 +6655,7 @@ plant: string | nullrecipe: stringrecipeVersion: numberscale: number+up: [number, number, number] | undefinedx: numbery: numberyaw: number@@ -6774,9 +6775,10 @@ static prototype: PlanetPlugin## PlanetProvider — interface @experimental```+fields: readonly string[] | undefinedid: stringrange: (seed: number, version: number, radius: number) => [number, number]-sample: (region: PlanetRegion) => TerrainSamples | Promise<TerrainSamples>+sample: (region: PlanetRegion) => PlanetSamples | Promise<PlanetSamples>versions: readonly number[]```@@ -12331,7 +12333,9 @@ ComponentDef<WorldGenData>```paintGround: booleanrules: string+seaLevel: numberseed: number+surface: numberversion: numberworld: string```@@ -12603,8 +12607,8 @@ shape: ZoneShape## ZoneShape — type @experimental```-| { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number }+| { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] }```## ZoneShapeKind — const @experimentaldiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 0b9152b90..7463ec24a 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -6858,6 +6858,7 @@ plant: string | nullrecipe: stringrecipeVersion: numberscale: number+up: [number, number, number] | undefinedx: numbery: numberyaw: number@@ -6977,9 +6978,10 @@ static prototype: PlanetPlugin## PlanetProvider — interface @experimental```+fields: readonly string[] | undefinedid: stringrange: (seed: number, version: number, radius: number) => [number, number]-sample: (region: PlanetRegion) => TerrainSamples | Promise<TerrainSamples>+sample: (region: PlanetRegion) => PlanetSamples | Promise<PlanetSamples>versions: readonly number[]```@@ -12544,7 +12546,9 @@ ComponentDef<WorldGenData>```paintGround: booleanrules: string+seaLevel: numberseed: number+surface: numberversion: numberworld: string```@@ -12816,8 +12820,8 @@ shape: ZoneShape## ZoneShape — type @experimental```-| { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number }+| { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] }```## ZoneShapeKind — const @experimentaldiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 43dbf3133..d9046aba6 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -6650,6 +6650,7 @@ plant: string | nullrecipe: stringrecipeVersion: numberscale: number+up: [number, number, number] | undefinedx: numbery: numberyaw: number@@ -6769,9 +6770,10 @@ static prototype: PlanetPlugin## PlanetProvider — interface @experimental```+fields: readonly string[] | undefinedid: stringrange: (seed: number, version: number, radius: number) => [number, number]-sample: (region: PlanetRegion) => TerrainSamples | Promise<TerrainSamples>+sample: (region: PlanetRegion) => PlanetSamples | Promise<PlanetSamples>versions: readonly number[]```@@ -12326,7 +12328,9 @@ ComponentDef<WorldGenData>```paintGround: booleanrules: string+seaLevel: numberseed: number+surface: numberversion: numberworld: string```@@ -12598,8 +12602,8 @@ shape: ZoneShape## ZoneShape — type @experimental```-| { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number }+| { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] }```## ZoneShapeKind — const @experimentaldiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex ad9ac0625..2d44ee5b6 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -6943,6 +6943,7 @@ plant: string | nullrecipe: stringrecipeVersion: numberscale: number+up: [number, number, number] | undefinedx: numbery: numberyaw: number@@ -7062,9 +7063,10 @@ static prototype: PlanetPlugin## PlanetProvider — interface @experimental```+fields: readonly string[] | undefinedid: stringrange: (seed: number, version: number, radius: number) => [number, number]-sample: (region: PlanetRegion) => TerrainSamples | Promise<TerrainSamples>+sample: (region: PlanetRegion) => PlanetSamples | Promise<PlanetSamples>versions: readonly number[]```@@ -12625,7 +12627,9 @@ ComponentDef<WorldGenData>```paintGround: booleanrules: string+seaLevel: numberseed: number+surface: numberversion: numberworld: string```@@ -12897,8 +12901,8 @@ shape: ZoneShape## ZoneShape — type @experimental```-| { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number }+| { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] }```## ZoneShapeKind — const @experimentaldiff --git a/sdk/etc/terrain.api.md b/sdk/etc/terrain.api.mdindex 738e79c78..03ec79c9e 100644--- a/sdk/etc/terrain.api.md+++ b/sdk/etc/terrain.api.md@@ -1,7 +1,7 @@# API surface — esengine/terrain<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 0 public · 0 beta · 97 experimental · 0 deprecated+Symbols: 0 public · 0 beta · 98 experimental · 0 deprecated## Eroded — interface @experimental```@@ -201,8 +201,12 @@ world: string## PlanetFacts — interface @experimental```centre: [number, number, number]+fieldNames: readonly string[]+fieldsAt: ((dx: number, dy: number, dz: number) => readonly number[] | null) | nullgravity: numberheight: ((dx: number, dy: number, dz: number) => number | null) | null+layers: readonly string[]+paint: ((dx: number, dy: number, dz: number) => readonly number[] | null) | nullradius: number```@@ -211,6 +215,7 @@ radius: numberlevels: numbermaxHeight: numberminHeight: number+paint: (() => PlanetPainter | null) | undefinedprovider: PlanetProviderradius: numberseed: number@@ -229,9 +234,10 @@ static prototype: PlanetPlugin## PlanetProvider — interface @experimental```+fields: readonly string[] | undefinedid: stringrange: (seed: number, version: number, radius: number) => [number, number]-sample: (region: PlanetRegion) => TerrainSamples | Promise<TerrainSamples>+sample: (region: PlanetRegion) => PlanetSamples | Promise<PlanetSamples>versions: readonly number[]```@@ -251,7 +257,10 @@ altitude: (entity: Entity, x: number, y: number, z: number) => number | nullgroundHeight: (entity: Entity, x: number, y: number, z: number) => number | nullgroundPoint: (entity: Entity, x: number, y: number, z: number) => [number, number, number] | nullnearest: (x: number, y: number, z: number) => Entity | null+paintOf: (entity: Entity) => PlanetPainter | null+paintRevision: numberplanets: Map<number, PlanetFacts>+setPaint: (entity: Entity, painter: PlanetPainter | null) => voidup: (entity: Entity, x: number, y: number, z: number) => [number, number, number] | nullstatic new (): PlanetRegistrystatic prototype: PlanetRegistry@@ -262,6 +271,13 @@ static prototype: PlanetRegistryResourceDef<PlanetRegistry>```+## PlanetSamples — interface @experimental+```+fields: Float32Array<ArrayBufferLike> | undefined+heights: Float32Array<ArrayBufferLike>+paint: Float32Array<ArrayBufferLike> | undefined+```+## PlanetStatus — interface @experimental```reason: string | undefineddiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 78cff04f2..0e0db55ae 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -6657,6 +6657,7 @@ plant: string | nullrecipe: stringrecipeVersion: numberscale: number+up: [number, number, number] | undefinedx: numbery: numberyaw: number@@ -6776,9 +6777,10 @@ static prototype: PlanetPlugin## PlanetProvider — interface @experimental```+fields: readonly string[] | undefinedid: stringrange: (seed: number, version: number, radius: number) => [number, number]-sample: (region: PlanetRegion) => TerrainSamples | Promise<TerrainSamples>+sample: (region: PlanetRegion) => PlanetSamples | Promise<PlanetSamples>versions: readonly number[]```@@ -12357,7 +12359,9 @@ ComponentDef<WorldGenData>```paintGround: booleanrules: string+seaLevel: numberseed: number+surface: numberversion: numberworld: string```@@ -12629,8 +12633,8 @@ shape: ZoneShape## ZoneShape — type @experimental```-| { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number }+| { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] }```## ZoneShapeKind — const @experimentaldiff --git a/sdk/etc/worldgen.api.md b/sdk/etc/worldgen.api.mdindex a63a429b5..a27722086 100644--- a/sdk/etc/worldgen.api.md+++ b/sdk/etc/worldgen.api.md@@ -1,7 +1,7 @@# API surface — esengine/worldgen<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 0 public · 0 beta · 46 experimental · 0 deprecated+Symbols: 0 public · 0 beta · 54 experimental · 0 deprecated## BiomeCondition — interface @experimental```@@ -45,9 +45,19 @@ noise: Partial<Record<string, NoiseField>> | undefinedoverrides: ((x: number, z: number) => { field: string; value: number; weight: number; }[]) | undefinedseed: numbershoreDistance: ((x: number, z: number) => number | null) | undefined+space: ((x: number, z: number) => readonly [number, number, number]) | undefinedwaterDepth: ((x: number, z: number, y: number) => number | null) | undefined```+## FaceZones — class @experimental+```+face: PlanetFace+sync: (world: Iterable<ZoneDef>) => void+zones: Zones+static new (face: PlanetFace): FaceZones+static prototype: FaceZones+```+## FieldFn — type @experimental```(x: number, z: number, at: Readonly<FieldValues>) => number@@ -106,6 +116,7 @@ plant: string | nullrecipe: stringrecipeVersion: numberscale: number+up: [number, number, number] | undefinedx: numbery: numberyaw: number@@ -156,6 +167,30 @@ spacing: numberversion: number | undefined```+## PlaneFrame — interface @experimental+```+dir: [number, number, number]+eu: [number, number, number]+ev: [number, number, number]+```++## PlanetFace — class @experimental+```+directionAt: (x: number, z: number) => [number, number, number]+environment: () => Pick<EnvironmentInputs, "ground" | "space">+face: number+frameAt: (x: number, z: number) => PlaneFrame+ground: (x: number, z: number) => { y: number; up: number; normal: [number, number, number]; } | null+planeOf: (dx: number, dy: number, dz: number) => { x: number; z: number; } | null+planet: () => PlanetFacts | null+sourcesOnFace: (sources: Iterable<{ x: number; y?: number; z: number; }>, reach: number) => { x: number; z: number; }[]+world: (x: number, y: number, z: number) => [number, number, number]+worldNormal: (normal: readonly [number, number, number], x: number, z: number) => [number, number, number]+zoneOnFace: (zone: ZoneDef) => ZoneDef | null+static new (face: number, planet: () => PlanetFacts | null): PlanetFace+static prototype: PlanetFace+```+## Recipe — interface @experimental```anchor: RecipeMember@@ -200,7 +235,9 @@ ComponentDef<WorldGenData>```paintGround: booleanrules: string+seaLevel: numberseed: number+surface: numberversion: numberworld: string```@@ -283,6 +320,11 @@ static new (): WorldRulesAssetLoaderstatic prototype: WorldRulesAssetLoader```+## WorldSurface — const @experimental+```+{ readonly Plane: 0; readonly Planet: 1; }+```+## WorldZone — const @experimental```ComponentDef<WorldZoneData>@@ -317,8 +359,8 @@ shape: ZoneShape## ZoneShape — type @experimental```-| { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number }+| { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] }```## ZoneShapeKind — const @experimental@@ -345,11 +387,26 @@ static prototype: Zones(c: BiomeCondition, v: number): number```+## faceHalf — const @experimental+```+(radius: number) => number+```++## faceUnit — const @experimental+```+(radius: number) => number+```+## fbm — function @experimental```(x: number, z: number, seed: number, octaves: number): number```+## fbm3 — function @experimental+```+(x: number, y: number, z: number, seed: number, octaves: number): number+```+## hash01 — function @experimental```(...v: number[]): number@@ -370,6 +427,11 @@ static prototype: Zones(json: unknown, file?: string): WorldRules```+## planetFaces — function @experimental+```+(planet: () => PlanetFacts | null): PlanetFace[]+```+## registerWorldRules — function @experimental```(rules: WorldRules): voiddiff --git a/sdk/src/physics3d/Physics3DPlugin.ts b/sdk/src/physics3d/Physics3DPlugin.tsindex 86136fa97..daa7f904d 100644--- a/sdk/src/physics3d/Physics3DPlugin.ts+++ b/sdk/src/physics3d/Physics3DPlugin.ts@@ -5,6 +5,7 @@* @brief Loads the 3D physics module and drives one world from the ECS.*/import { installPlanetGravity } from './planetGravity';+import { Physics3DRuntime } from './physics3dRuntime';import type { App, Plugin } from '../app/app';import { Schedule, defineSystem } from '../ecs/system';import { defineResource } from '../ecs/resource';@@ -24,27 +25,7 @@ import type { Joint3DMap } from './Physics3DJoints';/** Ask the 3D world what is where. Present once the module has loaded. */export const Physics3D = defineResource<Physics3DQueries | null>(null, 'Physics3D');-/** The live module and the promise that resolves it, for a caller that must wait. */-export interface Physics3DRuntime {- module: Physics3DWasmModule | null;- initPromise: Promise<unknown> | null;- /** Entity -> body id, so a scene teardown can drop the world's population. */- bodies: Map<Entity, number>;- /** Entity -> character id. Characters are not bodies and are kept apart. */- characters: Map<Entity, number>;- /** Entity -> the joint it declared, with the bodies it was built between. */- joints: Joint3DMap;- /** Key -> the body built for that piece of the app's collision geometry. */- pieces: PieceMap;- /** The world's configuration (gravity, the scale of a world unit), for what applies forces to it. Null until the plugin is built. */- config: Physics3DConfig | null;-}--export const Physics3DRuntime = defineResource<Physics3DRuntime>(- { module: null, initPromise: null, bodies: new Map(), characters: new Map(),- joints: new Map(), pieces: new Map(), config: null },- 'Physics3DRuntime',-);+export { Physics3DRuntime } from './physics3dRuntime';export class Physics3DPlugin implements Plugin {name = 'physics3d';diff --git a/sdk/src/physics3d/physics3dRuntime.ts b/sdk/src/physics3d/physics3dRuntime.tsnew file mode 100644index 000000000..0e12a303c--- /dev/null+++ b/sdk/src/physics3d/physics3dRuntime.ts@@ -0,0 +1,35 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file physics3dRuntime.ts+ * @brief The 3D physics world's live state, as a resource: the module, the bodies built, the world's configuration.+ *+ * @details Apart from the plugin that fills it so that what only reads it (water's floating, a planet's gravity) need not import the plugin.+ */+import { defineResource } from '../ecs/resource';+import type { Entity } from '../types';+import type { Physics3DWasmModule } from './Physics3DModule';+import type { Physics3DConfig, PieceMap } from './Physics3DSystem';+import type { Joint3DMap } from './Physics3DJoints';++/** The live module and the promise that resolves it, for a caller that must wait. */+export interface Physics3DRuntime {+ module: Physics3DWasmModule | null;+ initPromise: Promise<unknown> | null;+ /** Entity -> body id, so a scene teardown can drop the world's population. */+ bodies: Map<Entity, number>;+ /** Entity -> character id. Characters are not bodies and are kept apart. */+ characters: Map<Entity, number>;+ /** Entity -> the joint it declared, with the bodies it was built between. */+ joints: Joint3DMap;+ /** Key -> the body built for that piece of the app's collision geometry. */+ pieces: PieceMap;+ /** The world's configuration (gravity, the scale of a world unit), for what applies forces to it. Null until the plugin is built. */+ config: Physics3DConfig | null;+}++export const Physics3DRuntime = defineResource<Physics3DRuntime>(+ { module: null, initPromise: null, bodies: new Map(), characters: new Map(),+ joints: new Map(), pieces: new Map(), config: null },+ 'Physics3DRuntime',+);diff --git a/sdk/src/physics3d/planetGravity.ts b/sdk/src/physics3d/planetGravity.tsindex 2de5cfe88..dde356d94 100644--- a/sdk/src/physics3d/planetGravity.ts+++ b/sdk/src/physics3d/planetGravity.ts@@ -15,7 +15,7 @@ import { defineSystem, Schedule } from '../ecs/system';import { Transform } from '../ecs/component';import type { Entity } from '../types';import { PlanetRegistryRes } from '../terrain/planetQuery';-import { Physics3DRuntime } from './Physics3DPlugin';+import { Physics3DRuntime } from './physics3dRuntime';import { RigidBody3D, type RigidBody3DData } from './Physics3DComponents';/** The force on a body of `mass` that the planet's pull is, over the world's gravity: all in metres, kilograms and seconds. */diff --git a/sdk/src/residency/chunks.ts b/sdk/src/residency/chunks.tsindex 1691b43f1..c41bf6032 100644--- a/sdk/src/residency/chunks.ts+++ b/sdk/src/residency/chunks.ts@@ -343,20 +343,20 @@ export function streamingSourcesOf(app: App): ChunkSource[] {for (const e of world.getEntitiesWithComponents([WorldStreamingSource, Transform])) {if (!(world.get(e, WorldStreamingSource) as WorldStreamingSourceData).enabled) continue;const p = (world.get(e, Transform) as TransformData).worldPosition;- out.push({ x: p.x, z: p.z });+ out.push({ x: p.x, y: p.y, z: p.z });}if (out.length > 0) return out;if (app.hasResource(EditorView)) {const view = app.getResource(EditorView);if (view.active && view.perspective) {const eye = editorViewEye(view);- return [{ x: eye.x, z: eye.z }];+ return [{ x: eye.x, y: eye.y, z: eye.z }];}}for (const e of world.getEntitiesWithComponents([Camera, Transform])) {if (!(world.get(e, Camera) as CameraData).isActive) continue;const p = (world.get(e, Transform) as TransformData).worldPosition;- out.push({ x: p.x, z: p.z });+ out.push({ x: p.x, y: p.y, z: p.z });}return out;}diff --git a/sdk/src/terrain/index.ts b/sdk/src/terrain/index.tsindex daa671d50..9fa0aa757 100644--- a/sdk/src/terrain/index.ts+++ b/sdk/src/terrain/index.ts@@ -25,7 +25,7 @@ registerTerrainSupport();export { paintWeights } from './paint';export { PlanetRegistry, PlanetRegistryRes, type PlanetFacts } from './planetQuery';export { Planet, Planets, PlanetPlugin, planetPlugin, type PlanetData, type PlanetStatus } from './planetPlugin';-export { registerPlanetProvider, planetProvider, type PlanetProvider, type PlanetRegion } from './planetProvider';+export { registerPlanetProvider, planetProvider, type PlanetProvider, type PlanetRegion, type PlanetSamples } from './planetProvider';export { makePlanetPage, tangentFrame, type PlanetPageSource } from './planetPages';export {FACES, direction, faceOf, levelsFor, nodeAt, nodeBound, nodeDistance, nodePoint, nodeRect, nodeSpan, selectSphereNodes, sphereNodeKey, sphereRange,diff --git a/sdk/src/terrain/planetPages.ts b/sdk/src/terrain/planetPages.tsindex ce55a0b3d..166c1818c 100644--- a/sdk/src/terrain/planetPages.ts+++ b/sdk/src/terrain/planetPages.ts@@ -25,6 +25,8 @@ export interface PlanetPageSource {levels: number;minHeight: number;maxHeight: number;+ /** What paints the ground over the provider's paint, if anything does; asked for each page, so one that is set later is used from then on. */+ paint?: () => import('./planetQuery').PlanetPainter | null;}/** The frame at a unit direction on a face: the face's u and v directions made perpendicular to it. */@@ -67,6 +69,8 @@ function encodePlanetPage(src: PlanetPageSource, node: SphereNode, dirs: Float32};const a: [number, number, number] = [0, 0, 0], b: [number, number, number] = [0, 0, 0], c: [number, number, number] = [0, 0, 0], e: [number, number, number] = [0, 0, 0];const eu: [number, number, number] = [0, 0, 0], ev: [number, number, number] = [0, 0, 0];+ const painter = src.paint?.() ?? null;+ const lattice = painter ? paintLattice(painter, dirs, given) : null;for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) {const k = j * n + i;const enc = Math.round(Math.min(Math.max((h[k]! - src.minHeight) / span, 0), 1) * 65535);@@ -88,7 +92,8 @@ function encodePlanetPage(src: PlanetPageSource, node: SphereNode, dirs: Float32heights[k * 4 + 3] = Math.round((lz / len * 0.5 + 0.5) * 255);// The paint the provider gave; without it, rock where it is steep and grass elsewhere, so a planet with no paint is still readable.let w0 = 0, w1 = 0, w2 = 0, w3 = 0;- if (given) { w0 = given[k * 4]!; w1 = given[k * 4 + 1]!; w2 = given[k * 4 + 2]!; w3 = given[k * 4 + 3]!; }+ if (lattice) { const w = lattice(i, j); w0 = w[0]!; w1 = w[1]!; w2 = w[2]!; w3 = w[3]!; }+ else if (given) { w0 = given[k * 4]!; w1 = given[k * 4 + 1]!; w2 = given[k * 4 + 2]!; w3 = given[k * 4 + 3]!; }else { const steep = Math.min(Math.max((0.9 - up / len) * 6, 0), 1); w0 = 1 - steep; w3 = steep; }paint[k * 4] = Math.round(Math.min(Math.max(w0, 0), 1) * 255);paint[k * 4 + 1] = Math.round(Math.min(Math.max(w1, 0), 1) * 255);@@ -97,3 +102,31 @@ function encodePlanetPage(src: PlanetPageSource, node: SphereNode, dirs: Float32}return { heights, paint, paint2, min: Number.isFinite(min) ? min : src.minHeight, max: Number.isFinite(max) ? max : src.maxHeight };}++/** How many samples apart a painter is asked: it paints as a biome does, over many metres, and is read at every few texels and filtered between. */+const PAINT_STRIDE = 4;++/**+ * The page's paint from a painter asked every PAINT_STRIDE samples (from the first sample inside the page, so two pages that share an edge ask the same+ * places there and agree on it), filtered between. A sample outside the lattice takes the nearest.+ */+function paintLattice(painter: import('./planetQuery').PlanetPainter, dirs: Float32Array, given: Float32Array | undefined): (i: number, j: number) => number[] {+ const n = PAGE_SIDE;+ const cells = Math.floor((n - 3) / PAINT_STRIDE) + 1;+ const grid: number[][] = new Array(cells * cells);+ for (let b = 0; b < cells; b++) for (let a = 0; a < cells; a++) {+ const i = 1 + a * PAINT_STRIDE, j = 1 + b * PAINT_STRIDE, k = j * n + i;+ const base = given ? [given[k * 4]!, given[k * 4 + 1]!, given[k * 4 + 2]!, given[k * 4 + 3]!] : [1, 0, 0, 0];+ const got = painter(dirs[k * 3]!, dirs[k * 3 + 1]!, dirs[k * 3 + 2]!, base);+ grid[b * cells + a] = [got[0] ?? 0, got[1] ?? 0, got[2] ?? 0, got[3] ?? 0];+ }+ return (i, j) => {+ const fa = Math.min(Math.max((i - 1) / PAINT_STRIDE, 0), cells - 1), fb = Math.min(Math.max((j - 1) / PAINT_STRIDE, 0), cells - 1);+ const a0 = Math.min(Math.floor(fa), cells - 2), b0 = Math.min(Math.floor(fb), cells - 2);+ const ta = fa - a0, tb = fb - b0;+ const p00 = grid[b0 * cells + a0]!, p10 = grid[b0 * cells + a0 + 1]!, p01 = grid[(b0 + 1) * cells + a0]!, p11 = grid[(b0 + 1) * cells + a0 + 1]!;+ const out = [0, 0, 0, 0];+ for (let c = 0; c < 4; c++) out[c] = (p00[c]! * (1 - ta) + p10[c]! * ta) * (1 - tb) + (p01[c]! * (1 - ta) + p11[c]! * ta) * tb;+ return out;+ };+}diff --git a/sdk/src/terrain/planetPlugin.ts b/sdk/src/terrain/planetPlugin.tsindex 2e40194d7..20948c882 100644--- a/sdk/src/terrain/planetPlugin.ts+++ b/sdk/src/terrain/planetPlugin.ts@@ -37,6 +37,7 @@ import { PlanetRegistry, PlanetRegistryRes } from './planetQuery';import { removePlanetCollision, updatePlanetCollision } from './planetCollision';import { planetProvider, planetProvidersRevision, type PlanetProvider } from './planetProvider';import { makePlanetPage, type PlanetPageSource } from './planetPages';+import type { PlanetSamples } from './planetProvider';import { levelsFor, nodePoint, selectSphereNodes, sphereNodeKey, type SphereNode, type SphereTreeParams } from './sphere';/** The fields of the `Planet` component. @experimental */@@ -139,6 +140,8 @@ interface Built {packing: boolean;/** The registry's revision when the provider was last looked for, so a late registration is noticed. */providers: number;+ /** The painters' revision the pages were last painted at. */+ painted: number;}/** Where a planet stands: still being made, ready, or failed (with why). */@@ -190,12 +193,16 @@ export class PlanetPlugin implements Plugin {if (built.failure || !built.source || !built.tree) continue;const at = (app.world.get(entity, Transform) as TransformData).worldPosition;const source = built.source;+ source.paint = () => registry.paintOf(entity);+ // A painter set, changed or taken away paints every page again.+ if (built.painted !== registry.paintRevision) { built.painted = registry.paintRevision; built.table.clear(); }registry.planets.set(entity, {centre: [at.x, at.y, at.z], radius: built.data.radius, gravity: built.data.gravity,- height: (dx, dy, dz) => {- const got = source.provider.sample({ world: source.world, seed: source.seed, version: source.version, radius: source.radius, directions: Float32Array.of(dx, dy, dz), count: 1 });- return got instanceof Promise ? null : (got.heights[0] ?? null);- },+ height: (dx, dy, dz) => sampleAt(source, dx, dy, dz)?.heights[0] ?? null,+ paint: (dx, dy, dz) => { const got = sampleAt(source, dx, dy, dz); return got?.paint ? Array.from(got.paint.subarray(0, 4)) : null; },+ fieldNames: source.provider.fields ?? [],+ fieldsAt: source.provider.fields ? (dx, dy, dz) => { const got = sampleAt(source, dx, dy, dz); return got?.fields ? Array.from(got.fields) : null; } : null,+ layers: built.data.layers.map((ref, i) => (ref.split('/').pop() ?? '').replace(/\.[^.]*$/, '') || `layer${i}`),});updatePlanetCollision(app, entity, built.source, built.epoch, built.data);if (!built.instance) {@@ -220,7 +227,7 @@ export class PlanetPlugin implements Plugin {const built: Built = {signature, data: { ...data }, provider: null, source: null, tree: null, epoch, table: new PageTable(ATLAS_SIZE),heights: 0, paint: 0, mesh: 0, instance: 0, nodes: new Map(), spare: [], wanted: new Map(), asked: new Set(), pending: false, failure: null, arrays: [], packed: '', packing: false,- providers: planetProvidersRevision(),+ providers: planetProvidersRevision(), painted: 0,};const provider = planetProvider(data.provider);if (!provider) {@@ -518,6 +525,19 @@ export class PlanetPlugin implements Plugin {}}+/** The last place asked of a provider, and what it said: a generated world reads the height, the paint and each field of one point in turn. */+let lastAsked: { source: PlanetPageSource; key: string; got: PlanetSamples } | null = null;++/** The provider's answer for one direction, from its last answer where it is the same place; null while it answers later. */+function sampleAt(source: PlanetPageSource, dx: number, dy: number, dz: number): PlanetSamples | null {+ const key = `${dx},${dy},${dz}`;+ if (lastAsked && lastAsked.source === source && lastAsked.key === key) return lastAsked.got;+ const got = source.provider.sample({ world: source.world, seed: source.seed, version: source.version, radius: source.radius, directions: Float32Array.of(dx, dy, dz), count: 1 });+ if (got instanceof Promise) return null;+ lastAsked = { source, key, got };+ return got;+}+/** What, changed, makes the planet again: everything but the colours and the wander, which are read each frame. */function signatureOf(d: PlanetData): string {return JSON.stringify([d.radius, d.provider, d.world, d.generatorVersion, d.seed, d.cellSize, d.detail]);diff --git a/sdk/src/terrain/planetProvider.ts b/sdk/src/terrain/planetProvider.tsindex 4803fbb37..4b5184319 100644--- a/sdk/src/terrain/planetProvider.ts+++ b/sdk/src/terrain/planetProvider.ts@@ -11,6 +11,12 @@*/import type { TerrainSamples } from './provider';+/** What a planet provider answers: the heights and paint of a terrain's, and the values of the fields it names, a sample after another. */+export interface PlanetSamples extends TerrainSamples {+ /** `fields.length` values a sample, in the order the provider's `fields` names them. */+ fields?: Float32Array;+}+/** What a provider is asked to sample: a list of unit directions from the planet's centre. */export interface PlanetRegion {/** The world (a planet) the ground belongs to, as the game names it. */@@ -33,8 +39,13 @@ export interface PlanetProvider {readonly versions: readonly number[];/** The least and most height above the radius its ground can have for this seed, version and radius: what the GPU encodes heights over. */range(seed: number, version: number, radius: number): [number, number];- /** The ground in the directions asked: heights in metres above the radius, and the layer weights if it paints. May answer later. */- sample(region: PlanetRegion): TerrainSamples | Promise<TerrainSamples>;+ /**+ * The names of fields the ground has beyond its height and paint, which a generated world reads as part of its environment (an ecology: how much of+ * a place is a wetland). A game's own generator decides them, so the ground that is drawn and what grows on it come from one function.+ */+ readonly fields?: readonly string[];+ /** The ground in the directions asked: heights in metres above the radius, the layer weights if it paints, and its fields if it has any. May answer later. */+ sample(region: PlanetRegion): PlanetSamples | Promise<PlanetSamples>;}const providers_ = new Map<string, PlanetProvider>();diff --git a/sdk/src/terrain/planetQuery.ts b/sdk/src/terrain/planetQuery.tsindex 7d18d3a91..8d117506a 100644--- a/sdk/src/terrain/planetQuery.ts+++ b/sdk/src/terrain/planetQuery.ts@@ -22,11 +22,37 @@ export interface PlanetFacts {gravity: number;/** The ground's height above the radius in a direction from the centre, or null while the provider answers later or the planet is not made. */height: ((dx: number, dy: number, dz: number) => number | null) | null;+ /** The weights of the planet's layers there, as its provider paints them (null where it does not, or cannot say yet), and the layers' names (their files', without the extension). */+ paint: ((dx: number, dy: number, dz: number) => readonly number[] | null) | null;+ layers: readonly string[];+ /** The names of the provider's own fields, and their values in a direction (null where it cannot say yet). */+ fieldNames: readonly string[];+ fieldsAt: ((dx: number, dy: number, dz: number) => readonly number[] | null) | null;}+/**+ * What paints a planet's ground: given a direction from the centre and the paint the provider gave there (the weights of the planet's layers), the paint+ * to use. A generated world's biomes are one.+ */+export type PlanetPainter = (dx: number, dy: number, dz: number, base: readonly number[]) => readonly number[];+/** The planets of the app. @experimental */export class PlanetRegistry {readonly planets = new Map<Entity, PlanetFacts>();+ private readonly painters_ = new Map<Entity, PlanetPainter>();+ /** Bumped when a painter is set, changed or taken away, so the planet's pages are painted again. */+ paintRevision = 0;++ /** Sets what paints the planet `entity`'s ground (null takes it away); a planet paints with its provider's paint until then. */+ setPaint(entity: Entity, painter: PlanetPainter | null): void {+ if (painter) this.painters_.set(entity, painter); else this.painters_.delete(entity);+ this.paintRevision++;+ }++ /** What paints the planet `entity`'s ground, if anything does. */+ paintOf(entity: Entity): PlanetPainter | null {+ return this.painters_.get(entity) ?? null;+ }/** The planet whose surface is nearest the position (a planet pulls from any distance), or null with none. */nearest(x: number, y: number, z: number): Entity | null {diff --git a/sdk/src/worldgen/fields.ts b/sdk/src/worldgen/fields.tsindex 8f72cdaf6..25c1d6192 100644--- a/sdk/src/worldgen/fields.ts+++ b/sdk/src/worldgen/fields.ts@@ -30,6 +30,11 @@ export interface EnvironmentInputs {waterDepth?(x: number, z: number, y: number): number | null;/** How far (x, z) is from the water's edge across the ground: above zero on land, below in the water, null where no water is known. */shoreDistance?(x: number, z: number): number | null;+ /**+ * Where (x, z) is in the space the noise fields are read from. Absent, the noise is flat, over x and z; a round world gives the point's place in+ * three dimensions, so a field wanders over it with no seam where its ground's patches meet.+ */+ space?(x: number, z: number): readonly [number, number, number];/** The noise fields; absent ones keep their defaults (moisture 900, temperature 2400, rock 500 world units). */noise?: Partial<Record<string, NoiseField>>;/** Fields of the game's own. */@@ -63,6 +68,34 @@ export function hashString(s: string): number {return h | 0;}+/** Fractal value noise in three dimensions, 0 to 1: what a round world's slow fields are read from, which has no seam and no pole. */+export function fbm3(x: number, y: number, z: number, seed: number, octaves: number): number {+ let sum = 0, norm = 0, amp = 1, freq = 1;+ for (let o = 0; o < octaves; o++) {+ sum += noise3(x * freq, y * freq, z * freq, seed + o * 131) * amp;+ norm += amp;+ amp *= 0.5;+ freq *= 2;+ }+ return sum / norm;+}++function hash3(x: number, y: number, z: number, seed: number): number {+ return hash01(x, y, z, seed);+}++/** Smooth value noise in three dimensions, 0 to 1, at a point measured in lattice cells. */+function noise3(x: number, y: number, z: number, seed: number): number {+ const ix = Math.floor(x), iy = Math.floor(y), iz = Math.floor(z);+ const fx = x - ix, fy = y - iy, fz = z - iz;+ const sx = fx * fx * (3 - 2 * fx), sy = fy * fy * (3 - 2 * fy), sz = fz * fz * (3 - 2 * fz);+ const c = (dx: number, dy: number, dz: number): number => hash3(ix + dx, iy + dy, iz + dz, seed);+ const x00 = c(0, 0, 0) + (c(1, 0, 0) - c(0, 0, 0)) * sx, x10 = c(0, 1, 0) + (c(1, 1, 0) - c(0, 1, 0)) * sx;+ const x01 = c(0, 0, 1) + (c(1, 0, 1) - c(0, 0, 1)) * sx, x11 = c(0, 1, 1) + (c(1, 1, 1) - c(0, 1, 1)) * sx;+ const y0 = x00 + (x10 - x00) * sy, y1 = x01 + (x11 - x01) * sy;+ return y0 + (y1 - y0) * sz;+}+/** Fractal value noise, 0 to 1. */export function fbm(x: number, z: number, seed: number, octaves: number): number {let sum = 0, norm = 0, amp = 1, freq = 1;@@ -108,7 +141,10 @@ export class Environment {lazy('waterDepth', () => { const gr = ground(); return gr && this.inputs.waterDepth ? this.inputs.waterDepth(x, z, gr.y) ?? -Infinity : -Infinity; });lazy('shoreDistance', () => this.inputs.shoreDistance?.(x, z) ?? Infinity);for (const [name, f] of Object.entries(this.noise_)) {- lazy(name, () => fbm(x / Math.max(f.scale, 1e-6), z / Math.max(f.scale, 1e-6), this.seeds_[name]!, Math.max(1, f.octaves ?? 3)));+ const scale = Math.max(f.scale, 1e-6), octaves = Math.max(1, f.octaves ?? 3);+ if (this.inputs.space) {+ lazy(name, () => { const p = this.inputs.space!(x, z); return fbm3(p[0] / scale, p[1] / scale, p[2] / scale, this.seeds_[name]!, octaves); });+ } else lazy(name, () => fbm(x / scale, z / scale, this.seeds_[name]!, octaves));}for (const [name, f] of Object.entries(this.inputs.fields ?? {})) lazy(name, () => f(x, z, at));for (const o of this.inputs.overrides?.(x, z) ?? []) {diff --git a/sdk/src/worldgen/index.ts b/sdk/src/worldgen/index.tsindex 75135cd95..61ababeb0 100644--- a/sdk/src/worldgen/index.ts+++ b/sdk/src/worldgen/index.ts@@ -1,7 +1,7 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamexport {- WorldGen, WorldZone, PlacedObject, ZoneShapeKind, WorldGens, WorldGenRes, WorldGenPlugin, worldGenPlugin,+ WorldGen, WorldZone, PlacedObject, ZoneShapeKind, WorldSurface, WorldGens, WorldGenRes, WorldGenPlugin, worldGenPlugin,type WorldGenData, type WorldZoneData, type PlacedObjectData, type WorldGenStatus,} from './worldgenPlugin';export {@@ -13,9 +13,11 @@ export { WorldPlan, type Placement, type Group, type Rejection } from './plan';export { Zones, zoneDistance, zoneWeight, zoneBounds, type ZoneDef, type ZoneShape } from './zones';export { PlacementDiffs, type PlacementChange, type PlacementDiffsData } from './diffs';export {- Environment, fbm, hash01, hashString, type FieldValues, type FieldFn, type NoiseField, type EnvironmentInputs,+ Environment, fbm, fbm3, hash01, hashString, type FieldValues, type FieldFn, type NoiseField, type EnvironmentInputs,} from './fields';+export { PlanetFace, FaceZones, planetFaces, faceHalf, faceUnit, type PlaneFrame } from './planetSurface';+// Importing this subpath INSTALLS generated worlds — see tilemap/index.ts. Their ground is the terrain's when the scene has one.import { registerWorldGenSupport } from './worldgenSupport';diff --git a/sdk/src/worldgen/plan.ts b/sdk/src/worldgen/plan.tsindex 6acc2093d..a1a1888e7 100644--- a/sdk/src/worldgen/plan.ts+++ b/sdk/src/worldgen/plan.ts@@ -42,6 +42,8 @@ export interface Placement {scale: number;/** The ground's normal under it, which an aligned one leans with. */normal: [number, number, number];+ /** Which way is up where it stands, on a round world (where it is not +Y); an upright one stands along it. */+ up?: [number, number, number];attach: 'upright' | 'align';mesh: number;material: number;diff --git a/sdk/src/worldgen/planetSurface.ts b/sdk/src/worldgen/planetSurface.tsnew file mode 100644index 000000000..870220950--- /dev/null+++ b/sdk/src/worldgen/planetSurface.ts@@ -0,0 +1,168 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file planetSurface.ts+ * @brief A planet's ground as a plane for laying a world out on: each face of the cube is one, in metres.+ *+ * @details The plan (plan.ts) works on a plane of x and z. A round world has none, but each face of the cube the planet is cut into (terrain/sphere.ts)+ * is a square of ground that reads as one: x and z are metres across the face from its middle (a quarter turn of the great circle+ * is a face's width, so a metre on the plane is a metre on the ground at the middle and a third less at the corner), and the+ * height is the ground's height above the radius. A world is laid out face by face, and a direction is laid out by the face it falls on, so+ * a point is planned once. What is placed is taken from the plane to the planet here: its place, and which way is up.+ */+import type { PlanetFacts } from '../terrain/planetQuery';+import { FACES, direction, facePlace } from '../terrain/sphere';+import { tangentFrame } from '../terrain/planetPages';+import type { EnvironmentInputs } from './fields';+import { Zones, type ZoneDef } from './zones';++/** The metres a unit of a face's -1 to 1 is, at its middle. */+export const faceUnit = (radius: number): number => radius * Math.PI / 4;++/** How wide a face is, in metres across the plane (-half to +half). */+export const faceHalf = (radius: number): number => faceUnit(radius);++/** Where a point of the plane stands on the planet: its direction from the centre, the unit vectors along the plane's x, up and z there. */+export interface PlaneFrame {+ dir: [number, number, number];+ eu: [number, number, number];+ ev: [number, number, number];+}++/** One face of a planet as a plane. */+export class PlanetFace {+ constructor(readonly face: number, readonly planet: () => PlanetFacts | null) {}++ private facts(): PlanetFacts | null { return this.planet(); }++ /** The unit direction from the centre at a point of the plane (beyond the face's edge it carries on over the next). */+ directionAt(x: number, z: number): [number, number, number] {+ const f = this.facts();+ const unit = faceUnit(f?.radius ?? 1);+ return direction(this.face, x / unit, z / unit);+ }++ /** The point of the plane under a direction from the centre, or null for a direction that does not face this one. */+ planeOf(dx: number, dy: number, dz: number): { x: number; z: number } | null {+ const f = this.facts();+ const at = facePlace(this.face, dx, dy, dz);+ if (!f || !at) return null;+ const unit = faceUnit(f.radius);+ return { x: at.u * unit, z: at.v * unit };+ }++ /** The frame at a point of the plane. */+ frameAt(x: number, z: number): PlaneFrame {+ const dir = this.directionAt(x, z);+ const eu: [number, number, number] = [0, 0, 0], ev: [number, number, number] = [0, 0, 0];+ tangentFrame(this.face, dir, eu, ev);+ return { dir, eu, ev };+ }++ /** The world position of a point of the plane at a height above the radius. */+ world(x: number, y: number, z: number): [number, number, number] {+ const f = this.facts()!;+ const d = this.directionAt(x, z), r = f.radius + y;+ return [f.centre[0] + d[0] * r, f.centre[1] + d[1] * r, f.centre[2] + d[2] * r];+ }++ /** The ground under a point of the plane: its height above the radius, how much it faces away from the centre, and its normal along the plane's x, up and z. */+ ground(x: number, z: number): { y: number; up: number; normal: [number, number, number] } | null {+ const f = this.facts();+ if (!f?.height) return null;+ const at = (px: number, pz: number): number | null => { const d = this.directionAt(px, pz); return f.height!(d[0], d[1], d[2]); };+ const h = at(x, z);+ if (h === null) return null;+ // The normal from the ground a couple of metres either way along the plane, taken in the frame there.+ const step = 2;+ const hx0 = at(x - step, z), hx1 = at(x + step, z), hz0 = at(x, z - step), hz1 = at(x, z + step);+ if (hx0 === null || hx1 === null || hz0 === null || hz1 === null) return { y: h, up: 1, normal: [0, 1, 0] };+ // The ground's rise along each axis, over the run of the chord between the two points (the curve itself is not a slope).+ const run = 2 * step;+ const nx = -(hx1 - hx0) / run, nz = -(hz1 - hz0) / run;+ const len = Math.hypot(nx, 1, nz);+ return { y: h, up: 1 / len, normal: [nx / len, 1 / len, nz / len] };+ }++ /** What a plane normal is in the world: along the frame's x, up and z. */+ worldNormal(normal: readonly [number, number, number], x: number, z: number): [number, number, number] {+ const fr = this.frameAt(x, z);+ return [+ normal[0] * fr.eu[0] + normal[1] * fr.dir[0] + normal[2] * fr.ev[0],+ normal[0] * fr.eu[1] + normal[1] * fr.dir[1] + normal[2] * fr.ev[1],+ normal[0] * fr.eu[2] + normal[1] * fr.dir[2] + normal[2] * fr.ev[2],+ ];+ }++ /** The environment's inputs for this face: the ground, and the noise read in three dimensions from the point's place on the sphere. */+ environment(): Pick<EnvironmentInputs, 'ground' | 'space'> {+ return {+ ground: (x, z) => this.ground(x, z),+ space: (x, z) => {+ const f = this.facts()!;+ const d = this.directionAt(x, z);+ return [d[0] * f.radius, d[1] * f.radius, d[2] * f.radius];+ },+ };+ }++ /** A zone of the world (a circle or a box standing at a world position) as this face's plane has it, or null where its centre is not over this face. */+ zoneOnFace(zone: ZoneDef): ZoneDef | null {+ const f = this.facts();+ const s = zone.shape;+ if (!f || s.y === undefined) return null;+ const dx = s.x - f.centre[0], dy = s.y - f.centre[1], dz = s.z - f.centre[2];+ const len = Math.hypot(dx, dy, dz);+ if (len < 1e-9) return null;+ const at = this.planeOf(dx / len, dy / len, dz / len);+ const half = faceHalf(f.radius);+ // A zone is kept on the face its centre falls on, and on a neighbour when it reaches over the edge.+ const reach = (s.type === 'circle' ? s.radius : Math.hypot(s.halfX, s.halfZ)) + zone.falloff;+ if (!at || Math.abs(at.x) > half + reach || Math.abs(at.z) > half + reach) return null;+ if (s.type === 'circle') return { ...zone, shape: { type: 'circle', x: at.x, z: at.z, radius: s.radius } };+ // A box's own turn: where its x axis points, as an angle from the plane's x toward its z there (the world's own turn when it names no facing).+ const fr = this.frameAt(at.x, at.z);+ const ax = s.facing ?? [Math.cos(s.yaw ?? 0), 0, Math.sin(s.yaw ?? 0)];+ const yaw = Math.atan2(ax[0] * fr.ev[0] + ax[1] * fr.ev[1] + ax[2] * fr.ev[2], ax[0] * fr.eu[0] + ax[1] * fr.eu[1] + ax[2] * fr.eu[2]);+ return { ...zone, shape: { type: 'rect', x: at.x, z: at.z, halfX: s.halfX, halfZ: s.halfZ, yaw } };+ }++ /** The streaming sources, in this face's plane (those over it, and over its neighbours' edges within `reach`). */+ sourcesOnFace(sources: Iterable<{ x: number; y?: number; z: number }>, reach: number): { x: number; z: number }[] {+ const f = this.facts();+ const out: { x: number; z: number }[] = [];+ if (!f) return out;+ const half = faceHalf(f.radius);+ for (const s of sources) {+ const dx = s.x - f.centre[0], dy = (s.y ?? 0) - f.centre[1], dz = s.z - f.centre[2];+ const len = Math.hypot(dx, dy, dz);+ if (len < 1e-9) continue;+ const at = this.planeOf(dx / len, dy / len, dz / len);+ if (at && Math.abs(at.x) <= half + reach && Math.abs(at.z) <= half + reach) out.push(at);+ }+ return out;+ }+}++/** The six faces of a planet, as planes. */+export function planetFaces(planet: () => PlanetFacts | null): PlanetFace[] {+ return FACES.map((_f, i) => new PlanetFace(i, planet));+}++/** The zones of a world as each face has them: those over it, in its plane. Kept in step by `sync`. */+export class FaceZones {+ readonly zones = new Zones();+ constructor(readonly face: PlanetFace) {}++ /** Takes the world's zones, replacing what was there: only what changed touches the plan. */+ sync(world: Iterable<ZoneDef>): void {+ const keep = new Set<string>();+ for (const z of world) {+ const mine = this.face.zoneOnFace(z);+ if (!mine) continue;+ this.zones.set(mine);+ keep.add(mine.id);+ }+ for (const z of [...this.zones.all()]) if (!keep.has(z.id)) this.zones.delete(z.id);+ }+}diff --git a/sdk/src/worldgen/worldgenPlugin.ts b/sdk/src/worldgen/worldgenPlugin.tsindex de4b8ad7b..be4c536fe 100644--- a/sdk/src/worldgen/worldgenPlugin.ts+++ b/sdk/src/worldgen/worldgenPlugin.ts@@ -31,9 +31,12 @@ import type { Entity } from '../types';import { Terrains, TerrainsRes } from '../terrain/terrainPlugin';import { flattenModifier, type TerrainModifier } from '../terrain/source';import { buildBillboardMesh, buildInstancedMesh, type Plant } from '../foliage/builder';-import { chunksOf, ProceduralChunksRes, type ChunkLayerStatus } from '../residency/chunks';+import { chunksOf, ProceduralChunksRes, streamingSourcesOf, type ChunkLayerStatus, type ChunkSource } from '../residency/chunks';import { plantGrowthOf, prepareKinds, type GrownCell, type ReadyKinds } from '../foliage/plantGrowth';+import { PlanetRegistryRes, type PlanetFacts } from '../terrain/planetQuery';+import { faceOf } from '../terrain/sphere';import { Environment } from './fields';+import { FaceZones, faceHalf, planetFaces, type PlanetFace } from './planetSurface';import { expandPlants, type PlantSet } from './plants';import { WorldPlan, type Placement } from './plan';import { worldRules, worldRulesRevision, type PlacementLayer, type RecipeMember, type WorldRules } from './rules';@@ -51,15 +54,22 @@ export interface WorldGenData {seed: number;/** Whether the biomes paint the terrain. */paintGround: boolean;+ /** {@link WorldSurface}: a plane (a Terrain of x and z), or a planet (the entity is also a `Planet`, and the world is laid out over its six faces). */+ surface: number;+ /** The height of the sea above a planet's radius: a point lower than this is under water. */+ seaLevel: number;}+/** What a world is laid out on. */+export const WorldSurface = { Plane: 0, Planet: 1 } as const;+/*** A generated world: the rules it is laid out by. Presence is the opt-in; what the rules place is published as its children.** @experimental*/export const WorldGen: ComponentDef<WorldGenData> = defineComponent<WorldGenData>('WorldGen', {- rules: '', version: 1, world: '', seed: 1, paintGround: true,+ rules: '', version: 1, world: '', seed: 1, paintGround: true, surface: WorldSurface.Plane, seaLevel: 0,}, {fields: {rules: { tooltip: 'The rules the world is laid out by: a .esworld file, or the id of rules the game registered with registerWorldRules.' },@@ -67,6 +77,8 @@ export const WorldGen: ComponentDef<WorldGenData> = defineComponent<WorldGenDataworld: { tooltip: 'The world (a planet, a level) as the game names it.' },seed: { step: 1, tooltip: 'Another seed lays out another world by the same rules.' },paintGround: { tooltip: 'Whether the biomes paint the terrain.' },+ surface: { enum: [{ label: 'Plane', value: WorldSurface.Plane }, { label: 'Planet', value: WorldSurface.Planet }], tooltip: 'Plane: laid out over a Terrain. Planet: this entity is also a Planet, and the world is laid out over its six faces.' },+ seaLevel: { shownWhen: { field: 'surface', values: [WorldSurface.Planet] }, tooltip: 'The height of the sea above the planet\'s radius: ground lower than this is under water.' },},});@@ -154,6 +166,26 @@ interface BuiltWorld {/** The rules' plants as kinds, and their parts once the assets are in hand (null while they are being loaded, or when the rules have no plants). */plants: PlantSet | null;plantsReady: ReadyKinds | null;+ /** A planet's six faces, each laid out as a plane (null for a world on a plane). */+ faces: FaceUnit[] | null;+ /** A world on a planet whose plan waits for the planet to say what it is (its ground and layers), which it does a frame after it is made. */+ waitingForPlanet: boolean;+}++/** One face of a planet's world: its plane, its plan (and the sparser one for far versions) and the zones over it. */+interface FaceUnit { face: PlanetFace; plan: WorldPlan; farPlan: WorldPlan | null; zones: FaceZones }++/** One piece of a world laid out and published in chunks: the whole of a plane, or a face of a planet. */+interface Unit {+ /** Names its layers' chunks: empty for a plane, `f0` to `f5` for a face. */+ key: string;+ plan: WorldPlan;+ farPlan: WorldPlan | null;+ face: PlanetFace | null;+ /** The area in the unit's plane its chunks are counted over, or null for no end. */+ bounds: [number, number, number, number] | null;+ /** Whether the ground at a point of the plane is known (a chunk waits for the corners of its square). */+ known(x: number, z: number): boolean;}/** A chunk of a layer: what it places (its decoration merged by mesh, its interactive placements), and what it put in the world. */@@ -183,8 +215,15 @@ function waterOf(app: App): WaterQuery | null {return w && typeof w.depthAt === 'function' ? w as WaterQuery : null;}-const layerIdOf = (entity: Entity, layer: string): string => `worldgen:${entity}:${layer}`;+const layerIdOf = (entity: Entity, layer: string, key = ''): string => `worldgen:${entity}:${key ? `${key}:` : ''}${layer}`;const zoneIdOf = (entity: Entity): string => `zone:${entity}`;+const FACE_KEYS = ['f0', 'f1', 'f2', 'f3', 'f4', 'f5'] as const;++/** Lets go of a layer's chunks, near and far, on a plane and on every face of a planet. */+function dropLayer(app: App, entity: Entity, layer: string): void {+ const chunks = chunksOf(app);+ for (const key of ['', ...FACE_KEYS]) { chunks.remove(layerIdOf(entity, layer, key)); chunks.remove(layerIdOf(entity, `${layer}:far`, key)); }+}/** Run-time access to the generated worlds. */export class WorldGens {@@ -225,8 +264,15 @@ export class WorldGens {const layers: Record<string, ChunkLayerStatus> = {};const chunks = this.app_?.hasResource(ProceduralChunksRes) ? this.app_.getResource(ProceduralChunksRes) : null;for (const l of built.rules?.layers ?? []) {- const s = chunks?.status(layerIdOf(entity, l.id));- if (s) layers[l.id] = s;+ // A planet's layer is one of chunks on each of its six faces: counted together.+ for (const key of built.faces ? FACE_KEYS : ['']) {+ const s = chunks?.status(layerIdOf(entity, l.id, key));+ if (!s) continue;+ const had = layers[l.id];+ layers[l.id] = had+ ? { ready: had.ready + s.ready, stale: had.stale + s.stale, pending: had.pending + s.pending, making: had.making + s.making, failed: had.failed + s.failed, reason: had.reason ?? s.reason }+ : s;+ }}if (built.failure) return { state: 'failed', reason: built.failure, layers };return { state: built.plan ? 'ready' : 'loading', layers };@@ -277,6 +323,10 @@ export class WorldGenPlugin implements Plugin {built = this.make(app, gens, entity, data, built);gens.built_.set(entity, built);}+ if (built.waitingForPlanet && built.rules && app.hasResource(PlanetRegistryRes) && app.getResource(PlanetRegistryRes).planets.has(entity)) {+ built.waitingForPlanet = false;+ this.plan(app, gens, entity, built, built.rules);+ }this.syncZones(app, gens, entity, built);this.publish(app, gens, entity, built);}@@ -293,7 +343,7 @@ export class WorldGenPlugin implements Plugin {/** A WorldGen's rules and plan, or why it has none. */private make(app: App, gens: WorldGens, entity: Entity, data: WorldGenData, had: BuiltWorld | undefined): BuiltWorld {- const built: BuiltWorld = { signature: `${JSON.stringify(data)}#${worldRulesRevision()}`, data: { ...data }, rules: null, plan: null, farPlan: null, failure: null, ground: '', authored: had?.authored ?? new Set(), levelling: new Set(), plants: null, plantsReady: null };+ const built: BuiltWorld = { signature: `${JSON.stringify(data)}#${worldRulesRevision()}`, data: { ...data }, rules: null, plan: null, farPlan: null, failure: null, ground: '', authored: had?.authored ?? new Set(), levelling: new Set(), plants: null, plantsReady: null, faces: null, waitingForPlanet: false };// Rules in a project file are read first, then made like rules registered by code.if (isRulesFile(data.rules)) {if (!app.hasResource(Assets)) {@@ -323,7 +373,7 @@ export class WorldGenPlugin implements Plugin {if (!rules) {built.failure = `no world rules ${data.rules || '(none named)'} are registered`;log.error('worldgen', `the world ${data.world} cannot be laid out: ${built.failure}`);- for (const l of had?.rules?.layers ?? []) chunksOf(app).remove(layerIdOf(entity, l.id));+ for (const l of had?.rules?.layers ?? []) dropLayer(app, entity, l.id);return built;}this.adopt(app, gens, entity, built, rules, had);@@ -338,11 +388,11 @@ export class WorldGenPlugin implements Plugin {if (built.failure) {log.error('worldgen', `the world ${data.world} cannot be laid out: ${built.failure}`);// A world that cannot be laid out shows nothing of the one before it.- for (const l of had?.rules?.layers ?? []) { chunksOf(app).remove(layerIdOf(entity, l.id)); chunksOf(app).remove(layerIdOf(entity, `${l.id}:far`)); }+ for (const l of had?.rules?.layers ?? []) dropLayer(app, entity, l.id);return;}// Layers the new rules no longer have are let go; the ones they keep keep their chunks until they are made again.- for (const l of had?.rules?.layers ?? []) if (!rules.layers.some((n) => n.id === l.id)) { chunksOf(app).remove(layerIdOf(entity, l.id)); chunksOf(app).remove(layerIdOf(entity, `${l.id}:far`)); }+ for (const l of had?.rules?.layers ?? []) if (!rules.layers.some((n) => n.id === l.id)) dropLayer(app, entity, l.id);// The plants the recipes name: as kinds, and their parts read once there is a renderer to grow them with. A chunk waits for them.if (rules.plants && Object.keys(rules.plants).length > 0 && app.hasResource(Assets)) {const set = expandPlants(rules.plants);@@ -389,6 +439,7 @@ export class WorldGenPlugin implements Plugin {/** Makes a WorldGen's plan from its rules, and what keeps it current. */private plan(app: App, gens: WorldGens, entity: Entity, built: BuiltWorld, rules: WorldRules): void {const data = built.data;+ if (data.surface === WorldSurface.Planet) { this.planPlanet(app, gens, entity, built, rules); return; }const terrains = app.hasResource(TerrainsRes) ? app.getResource(TerrainsRes) : null;const zones = gens.zones(data.world);// The terrain's paint is a field for each of its layers, `paint.grass` for a layer file grass.esterrainlayer: how much of the ground there is that.@@ -452,6 +503,69 @@ export class WorldGenPlugin implements Plugin {if (terrains) for (const zone of zones.all()) if (zone.flatten !== undefined) this.level(terrains, built, zone);}+ /**+ * Makes a planet's plans: one for each face of the cube, each on the face's plane. The plan of a face is the same plan as a plane's, read from the+ * planet's ground by direction and from noise in three dimensions, so a field wanders over an edge between two faces without a seam; a direction is+ * planned by the face it falls on, and the faces' plans paint the planet's ground by the same biomes that place what stands on it.+ */+ private planPlanet(app: App, gens: WorldGens, entity: Entity, built: BuiltWorld, rules: WorldRules): void {+ const data = built.data;+ if (!app.hasResource(PlanetRegistryRes)) { built.failure = 'a world on a planet needs the Planet plugin'; log.error('worldgen', built.failure); return; }+ const registry = app.getResource(PlanetRegistryRes);+ const facts = (): PlanetFacts | null => registry.planets.get(entity) ?? null;+ if (!facts()) { built.waitingForPlanet = true; return; }+ const sparse = rules.layers.some((l) => (l.farSpacing ?? 1) > 1);+ const farRules: WorldRules | null = sparse+ ? { ...rules, layers: rules.layers.map((l) => (l.farSpacing ?? 1) > 1 ? { ...l, spacing: l.spacing * l.farSpacing! } : l) } : null;+ built.faces = planetFaces(facts).map((face) => {+ const zones = new FaceZones(face);+ // The planet's layers, as the provider paints them, are fields (`paint.grass` for a layer file grass.esterrainlayer), as a terrain's are.+ const paintFields: Record<string, (x: number, z: number) => number> = {};+ (facts()?.layers ?? []).forEach((name, i) => {+ paintFields[`paint.${name}`] = (x, z) => { const d = face.directionAt(x, z); return facts()?.paint?.(d[0], d[1], d[2])?.[i] ?? 0; };+ });+ // And the provider's own fields (an ecology) by the names it gives them.+ (facts()?.fieldNames ?? []).forEach((name, i) => {+ paintFields[name] = (x, z) => { const d = face.directionAt(x, z); return facts()?.fieldsAt?.(d[0], d[1], d[2])?.[i] ?? 0; };+ });+ const env = new Environment({+ seed: data.seed, noise: rules.noise, fields: { ...paintFields, ...rules.fields },+ ...face.environment(),+ // The sea stands at a height, so the water over a point is how far it is below it (negative on land, by how far above).+ waterDepth: (_x, _z, y) => data.seaLevel - y,+ overrides: (x, z) => {+ const out: { field: string; value: number; weight: number }[] = [];+ for (const { zone, weight } of zones.zones.at(x, z)) for (const [field, value] of Object.entries(zone.fields ?? {})) out.push({ field, value, weight });+ return out;+ },+ });+ const plan = new WorldPlan(rules, env, zones.zones, data.seed, `${data.world}#${face.face}`);+ const farPlan = farRules ? new WorldPlan(farRules, env, zones.zones, data.seed, `${data.world}#${face.face}`) : null;+ // A zone that changes makes again only the chunks of this face it reaches, and paints the ground under it again.+ zones.zones.onChange = (bounds, zone) => {+ plan.invalidate();+ farPlan?.invalidate();+ const chunks = chunksOf(app);+ for (const l of rules.layers) {+ const reach = l.spacing * 3;+ chunks.invalidate(layerIdOf(entity, l.id, FACE_KEYS[face.face]), bounds[0] - reach, bounds[1] - reach, bounds[2] + reach, bounds[3] + reach);+ }+ if (data.paintGround && (zone.biome || zone.fields)) registry.setPaint(entity, registry.paintOf(entity));+ };+ return { face, plan, farPlan, zones };+ });+ built.plan = built.faces[2]!.plan;+ const faces = built.faces;+ // The ground is painted where the direction falls: by the plan of the face it is on.+ if (data.paintGround) {+ registry.setPaint(entity, (dx, dy, dz, base) => {+ const unit = faces[faceOf(dx, dy, dz).face]!;+ const at = unit.face.planeOf(dx, dy, dz);+ return at ? unit.plan.paint(at.x, at.z, base) : base;+ });+ }+ }+/** Levels a zone's ground, or (the ground under its centre not known yet) keeps it to level once it is. */private level(terrains: Terrains, built: BuiltWorld, zone: ZoneDef): void {const modifier = levelling(terrains, zone);@@ -482,11 +596,14 @@ export class WorldGenPlugin implements Plugin {const t = app.world.get(e, Transform) as TransformData;const p = t.worldPosition, q = t.worldRotation;const yaw = Math.atan2(2 * (q.w * q.y + q.x * q.z), 1 - 2 * (q.y * q.y + q.z * q.z));+ // On a planet a zone stands at a place in the world (its height too), and a box carries where its own x axis points.+ const onPlanet = built.data.surface === WorldSurface.Planet;+ const facing: [number, number, number] = [1 - 2 * (q.y * q.y + q.z * q.z), 2 * (q.x * q.y + q.w * q.z), 2 * (q.x * q.z - q.w * q.y)];const def: ZoneDef = {id: zoneIdOf(e), kind: z.kind, falloff: z.falloff, priority: z.priority,shape: z.shape === ZoneShapeKind.Box- ? { type: 'rect', x: p.x, z: p.z, halfX: z.sizeX / 2, halfZ: z.sizeZ / 2, yaw: -yaw }- : { type: 'circle', x: p.x, z: p.z, radius: z.radius },+ ? { type: 'rect', x: p.x, z: p.z, halfX: z.sizeX / 2, halfZ: z.sizeZ / 2, yaw: -yaw, ...(onPlanet ? { y: p.y, facing } : {}) }+ : { type: 'circle', x: p.x, z: p.z, radius: z.radius, ...(onPlanet ? { y: p.y } : {}) },excludes: z.excludes.split(',').map((s) => s.trim()).filter(Boolean),...(z.biome ? { biome: z.biome } : {}),...(z.flatten ? { flatten: 'ground' as const } : {}),@@ -498,12 +615,28 @@ export class WorldGenPlugin implements Plugin {built.authored = seen;}- /** Hands each of the rules' layers to the chunks, made from the plan. */+ /** Hands each of the rules' layers to the chunks, made from the plan: of the one plane, or of each face of a planet. */private publish(app: App, gens: WorldGens, entity: Entity, built: BuiltWorld): void {const plan = built.plan, rules = built.rules;if (!plan || !rules) return;const terrains = app.hasResource(TerrainsRes) ? app.getResource(TerrainsRes) : null;const water = waterOf(app);+ if (built.faces) {+ const registry = app.getResource(PlanetRegistryRes);+ const facts = registry.planets.get(entity);+ if (!facts) return;+ // The world's zones, over each face: those whose centre falls on it, in its plane.+ const world = [...gens.zones(built.data.world).all()];+ for (const unit of built.faces) unit.zones.sync(world);+ const half = faceHalf(facts.radius);+ for (const unit of built.faces) {+ this.publishUnit(app, gens, entity, built, {+ key: FACE_KEYS[unit.face.face]!, plan: unit.plan, farPlan: unit.farPlan, face: unit.face,+ bounds: [-half, -half, half, half], known: (x, z) => unit.face.ground(x, z) !== null,+ }, `planet:${facts.radius}`, false);+ }+ return;+ }// What the plan read the ground and the water from: when either changes everything is read again.const ground = `${terrains?.revision_ ?? 0}:${water?.revision_ ?? 0}`;if (ground !== built.ground) { plan.invalidate(); built.farPlan?.invalidate(); built.ground = ground; }@@ -514,33 +647,46 @@ export class WorldGenPlugin implements Plugin {if (zone?.flatten !== undefined) this.level(terrains, built, zone); else built.levelling.delete(id);}}+ // A world on a terrain of an area ends where the terrain does: its chunks are counted over that, and not over a radius of empty world.+ this.publishUnit(app, gens, entity, built, {+ key: '', plan, farPlan: built.farPlan, face: null, bounds: terrains?.areaBounds() ?? null,+ known: (x, z) => !terrains || terrains.groundKnownAt(x, z),+ }, ground, waiting);+ }++ /** One unit's layers as chunks: nearest first within the frame's budget, with the far versions of its plants a layer of their own. */+ private publishUnit(app: App, gens: WorldGens, entity: Entity, built: BuiltWorld, unit: Unit, ground: string, waiting: boolean): void {+ const rules = built.rules!;const diffs = gens.diffs(built.data.world);const rendering = app.hasResource(Assets);const chunks = chunksOf(app);- // A world on a terrain of an area ends where the terrain does: its chunks are counted over that, and not over a radius of empty world.- const bounds = terrains?.areaBounds() ?? null;+ const { plan, bounds, face } = unit;+ const known = (x0: number, z0: number, side: number): boolean => [[x0, z0], [x0 + side, z0], [x0, z0 + side], [x0 + side, z0 + side]].every(([x, z]) => unit.known(x!, z!));+ // Where the layer is wanted round: the world's streaming sources, put in the face's plane on a planet.+ const sourcesFor = face ? (reach: number) => (): Iterable<ChunkSource> => face.sourcesOnFace(streamingSourcesOf(app), reach) : null;for (const layer of rules.layers) {const size = layer.chunkSize ?? 64;const extent: [number, number, number, number] | null = bounds? [Math.floor(bounds[0] / size), Math.floor(bounds[1] / size), Math.ceil(bounds[2] / size), Math.ceil(bounds[3] / size)] : null;- chunks.set<PlacedChunk>(layerIdOf(entity, layer.id), {+ chunks.set<PlacedChunk>(layerIdOf(entity, layer.id, unit.key), {label: 'Laying out the world',originX: 0, originZ: 0, sizeX: size, sizeZ: size, extent,loadRadius: layer.drawDistance, unloadRadius: layer.drawDistance + size,generation: `${built.signature}:${ground}`,+ ...(sourcesFor ? { sources: sourcesFor(layer.drawDistance + size) } : {}),make: (cx, cz) => {const x0 = cx * size, z0 = cz * size;- if (waiting || (terrains && ![[x0, z0], [x0 + size, z0], [x0, z0 + size], [x0 + size, z0 + size]].every(([x, z]) => terrains.groundKnownAt(x!, z!)))) return null;+ if (waiting || !known(x0, z0, size)) return null;// The plants' parts are read before any chunk: a chunk made without them would leave the plants out until it is made again.if (rendering && built.plants && !built.plantsReady) return null;- return this.chunk(app, plan, diffs, layer, x0, z0, size, rendering, built.plants);+ return this.chunk(app, plan, diffs, layer, x0, z0, size, rendering, built.plants, face);},publish: (_cx, _cz, value) => this.place(app, gens, entity, value),release: (_cx, _cz, value) => this.unplace(app, gens, value),});// The plants' far versions are a layer of their own, wanted as far as the furthest of them goes: they are cheap, so the whole world stands at once,// where the plants themselves are only grown near the eye. They are shown from past what their kinds draw as themselves.- const farId = layerIdOf(entity, `${layer.id}:far`);+ const farId = layerIdOf(entity, `${layer.id}:far`, unit.key);if (!rendering || !built.plants || built.plants.reach <= layer.drawDistance) { chunks.remove(farId); continue; }// A far cell is as many chunks wide as the shortest span a far version is shown over allows: the far versions are one draw a kind a cell, and a ring// of ground cover a few chunks wide would otherwise be thousands of them.@@ -553,12 +699,13 @@ export class WorldGenPlugin implements Plugin {originX: 0, originZ: 0, sizeX: fsize, sizeZ: fsize, extent: fextent,loadRadius: built.plants.reach, unloadRadius: built.plants.reach + fsize,generation: `${built.signature}:${ground}`,+ ...(sourcesFor ? { sources: sourcesFor(built.plants.reach + fsize) } : {}),make: (cx, cz) => {const x0 = cx * fsize, z0 = cz * fsize;- if (waiting || (terrains && ![[x0, z0], [x0 + fsize, z0], [x0, z0 + fsize], [x0 + fsize, z0 + fsize]].every(([x, z]) => terrains.groundKnownAt(x!, z!)))) return null;+ if (waiting || !known(x0, z0, fsize)) return null;if (!built.plantsReady) return null;- const sparse = (layer.farSpacing ?? 1) > 1 && built.farPlan;- return this.chunk(app, sparse ? built.farPlan! : plan, diffs, layer, x0, z0, fsize, rendering, built.plants, true, sparse ? layer.farSpacing! ** 2 : 1);+ const sparse = (layer.farSpacing ?? 1) > 1 && unit.farPlan;+ return this.chunk(app, sparse ? unit.farPlan! : plan, diffs, layer, x0, z0, fsize, rendering, built.plants, face, true, sparse ? layer.farSpacing! ** 2 : 1);},publish: (_cx, _cz, value) => this.place(app, gens, entity, value),release: (_cx, _cz, value) => this.unplace(app, gens, value),@@ -568,18 +715,22 @@ export class WorldGenPlugin implements Plugin {/** What one chunk of a layer places: its decoration merged by mesh, and its interactive placements, with the changes laid over. */private chunk(app: App, plan: WorldPlan, diffs: PlacementDiffs, layer: PlacementLayer, x0: number, z0: number, size: number,- rendering: boolean, plants: PlantSet | null, far = false, thinnedBy = 1): PlacedChunk | Promise<PlacedChunk> {+ rendering: boolean, plants: PlantSet | null, face: PlanetFace | null, far = false, thinnedBy = 1): PlacedChunk | Promise<PlacedChunk> {const placements: Placement[] = [];- for (const p of plan.placementsIn(x0, z0, x0 + size, z0 + size, [layer.id])) {+ for (const planned of plan.placementsIn(x0, z0, x0 + size, z0 + size, [layer.id])) {+ // On a planet a placement is taken from its face's plane to the planet, and named for its face: the same cell of two faces is two places.+ const p = face ? onPlanet(planned, face) : planned;if (diffs.isRemoved(p.id)) continue;const c = diffs.changeOf(p.id);placements.push(c ? { ...p, ...c } : p);}+ // Where the chunk stands: the middle of its square, on the plane's zero height (a planet: that point of the ground's sphere).+ const centre: [number, number, number] = face ? face.world(x0 + size / 2, 0, z0 + size / 2) : [x0 + size / 2, 0, z0 + size / 2];const objects = far ? [] : placements.filter((p) => p.interactive !== null);const decor = rendering && !far ? placements.filter((p) => p.interactive === null && p.mesh) : [];const meshes = [...new Set(decor.map((p) => p.mesh))];const finish = (): PlacedChunk => {- const out: PlacedChunk = { decor: [], objects, planted: null, at: [x0 + size / 2, 0, z0 + size / 2], side: size, grown: null, far, thinnedBy, entities: [], meshes: [] };+ const out: PlacedChunk = { decor: [], objects, planted: null, at: centre, side: size, grown: null, far, thinnedBy, entities: [], meshes: [] };// The plants: each at its kind (its colouring there), relative to the chunk's centre, sunk by what its kind says.if (plants && rendering) {const by = new Map<number, Plant[]>();@@ -589,8 +740,8 @@ export class WorldGenPlugin implements Plugin {if (k < 0) continue;let list = by.get(k);if (!list) by.set(k, list = []);- list.push({ x: p.x - out.at[0], y: p.y - plants.sinkOf(p.plant), z: p.z - out.at[2], yaw: p.yaw, scale: p.scale * plants.unitOf(p.plant), phase: 0, shade: 1,- ...(p.attach === 'align' ? { up: p.normal } : {}) });+ list.push({ x: p.x - out.at[0], y: p.y - out.at[1] - plants.sinkOf(p.plant), z: p.z - out.at[2], yaw: p.yaw, scale: p.scale * plants.unitOf(p.plant), phase: 0, shade: 1,+ ...(leanOf(p) ? { up: leanOf(p)! } : {}) });}if (by.size > 0) out.planted = by;}@@ -601,13 +752,13 @@ export class WorldGenPlugin implements Plugin {if (!list) byKind.set(k, list = []);list.push(p);}- const origin: [number, number, number] = [x0 + size / 2, 0, z0 + size / 2];+ const origin = out.at;for (const list of byKind.values()) {const source = this.meshData_.get(list[0]!.mesh);if (!source || source instanceof Promise) continue;const plants: Plant[] = list.map((p, i) => ({- x: p.x - origin[0], y: p.y, z: p.z - origin[2], yaw: p.yaw, scale: p.scale, phase: (i * 0.618) % 1, shade: 1,- ...(p.attach === 'align' ? { up: p.normal } : {}),+ x: p.x - origin[0], y: p.y - origin[1], z: p.z - origin[2], yaw: p.yaw, scale: p.scale, phase: (i * 0.618) % 1, shade: 1,+ ...(leanOf(p) ? { up: leanOf(p)! } : {}),}));const far = list[0]!.far;const width = Math.max(source.aabbMax[0] - source.aabbMin[0], source.aabbMax[2] - source.aabbMin[2]);@@ -648,7 +799,7 @@ export class WorldGenPlugin implements Plugin {// The plants of the chunk: its entity stands at once, and they grow in it over the frames, as a placed foliage's do.const e = world.spawn('WorldGenPlants');world.insert(e, RuntimeOnly);- world.insert(e, Transform, { position: { x: chunk.at[0] - base.x, y: -base.y, z: chunk.at[2] - base.z } });+ world.insert(e, Transform, { position: { x: chunk.at[0] - base.x, y: chunk.at[1] - base.y, z: chunk.at[2] - base.z } });world.setParent(e, parent);chunk.entities.push(e);chunk.grown = { entity: e, handles: [], dead: false };@@ -665,7 +816,7 @@ export class WorldGenPlugin implements Plugin {const e = world.spawn('WorldGenDecor');// Made again from the rules whenever its chunk is: a scene or a save never holds it.world.insert(e, RuntimeOnly);- world.insert(e, Transform, { position: { x: d.origin[0] - base.x, y: -base.y, z: d.origin[2] - base.z } });+ world.insert(e, Transform, { position: { x: d.origin[0] - base.x, y: d.origin[1] - base.y, z: d.origin[2] - base.z } });world.insert(e, MeshRenderer, {mesh: handle, material: d.material, lit: true, opaque: true, cullBackfaces: false, color: { r: 1, g: 1, b: 1, a: 1 },} as Partial<MeshRendererData>);@@ -715,7 +866,8 @@ export class WorldGenPlugin implements Plugin {private drop(app: App, gens: WorldGens, entity: Entity): void {const built = gens.built_.get(entity);if (app.hasResource(ProceduralChunksRes)) {- for (const l of built?.rules?.layers ?? []) { app.getResource(ProceduralChunksRes).remove(layerIdOf(entity, l.id)); app.getResource(ProceduralChunksRes).remove(layerIdOf(entity, `${l.id}:far`)); }+ for (const l of built?.rules?.layers ?? []) dropLayer(app, entity, l.id);+ if (built?.faces && app.hasResource(PlanetRegistryRes)) app.getResource(PlanetRegistryRes).setPaint(entity, null);}if (built && app.hasResource(TerrainsRes)) app.getResource(TerrainsRes).setPaint(null);gens.built_.delete(entity);@@ -746,13 +898,28 @@ function assetRefsOf(rules: WorldRules): { kind: 'mesh' | 'material'; ref: strinreturn [...seen.values()];}-/** A placement's turn: about the vertical, and leaning with the ground when it is aligned. */+/** What a placement leans toward: the ground's normal when it is aligned, else which way is up where it stands on a round world; null when it stands along +Y. */+function leanOf(p: Placement): [number, number, number] | null {+ return p.attach === 'align' ? p.normal : (p.up ?? null);+}++/** A placement of a face's plane as it stands on the planet: its place in the world, its normal and up in the world, and its face in its names. */+function onPlanet(p: Placement, face: PlanetFace): Placement {+ const at = face.world(p.x, p.y, p.z);+ return {+ ...p, id: `f${face.face}:${p.id}`, group: `f${face.face}:${p.group}`, x: at[0], y: at[1], z: at[2],+ normal: face.worldNormal(p.normal, p.x, p.z), up: face.frameAt(p.x, p.z).dir,+ };+}++/** A placement's turn: about the vertical, and leaning with the ground when it is aligned (or with up, on a round world). */function orientation(p: Placement): { x: number; y: number; z: number; w: number } {const half = p.yaw / 2;const yawQ = { x: 0, y: Math.sin(half), z: 0, w: Math.cos(half) };- if (p.attach !== 'align') return yawQ;+ const lean = leanOf(p);+ if (!lean) return yawQ;// The turn that takes up to the normal, after the yaw.- const [nx, ny, nz] = p.normal;+ const [nx, ny, nz] = lean;const ax = nz, az = -nx, s = Math.hypot(ax, az);if (s < 1e-6) return yawQ;const angle = Math.acos(Math.min(Math.max(ny, -1), 1)) / 2;diff --git a/sdk/src/worldgen/zones.ts b/sdk/src/worldgen/zones.tsindex 0290ddf0e..dee5b6310 100644--- a/sdk/src/worldgen/zones.ts+++ b/sdk/src/worldgen/zones.ts@@ -13,8 +13,8 @@ import { hash01, hashString } from './fields';/** A zone's outline: a circle, or a rectangle turned by `yaw` radians about the vertical. */export type ZoneShape =- | { type: 'circle'; x: number; z: number; radius: number }- | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number };+ | { type: 'circle'; x: number; z: number; radius: number; y?: number }+ | { type: 'rect'; x: number; z: number; halfX: number; halfZ: number; yaw?: number; y?: number; facing?: readonly [number, number, number] };export interface ZoneDef {/** Stable: what a placement records as the zone it stands in or was kept out by. */diff --git a/sdk/tests/planet-gravity.test.ts b/sdk/tests/planet-gravity.test.tsindex 5b266adde..f4712e1ee 100644--- a/sdk/tests/planet-gravity.test.ts+++ b/sdk/tests/planet-gravity.test.ts@@ -9,8 +9,8 @@ const a = 1 as Entity, b = 2 as Entity;describe('the planets of a world', () => {const registry = new PlanetRegistry();- registry.planets.set(a, { centre: [0, -4000, 0], radius: 4000, gravity: 9.81, height: (dx, dy, dz) => 10 * dy + 0 * dx * dz });- registry.planets.set(b, { centre: [50000, 0, 0], radius: 1000, gravity: 3, height: null });+ registry.planets.set(a, { centre: [0, -4000, 0], radius: 4000, gravity: 9.81, height: (dx, dy, dz) => 10 * dy + 0 * dx * dz, paint: null, layers: [], fieldNames: [], fieldsAt: null });+ registry.planets.set(b, { centre: [50000, 0, 0], radius: 1000, gravity: 3, height: null, paint: null, layers: [], fieldNames: [], fieldsAt: null });it('name the planet whose surface is nearest, from anywhere', () => {expect(registry.nearest(0, 100, 0)).toBe(a);diff --git a/sdk/tests/worldgen-planet.test.ts b/sdk/tests/worldgen-planet.test.tsnew file mode 100644index 000000000..9115160e1--- /dev/null+++ b/sdk/tests/worldgen-planet.test.ts@@ -0,0 +1,110 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { describe, expect, it } from 'vitest';+import type { PlanetFacts } from '../src/terrain/planetQuery';+import { Environment } from '../src/worldgen/fields';+import { PlanetFace, FaceZones, faceHalf, planetFaces } from '../src/worldgen/planetSurface';+import { WorldPlan } from '../src/worldgen/plan';+import type { WorldRules } from '../src/worldgen/rules';+import { Zones } from '../src/worldgen/zones';++const radius = 4000;+/** A planet whose ground is a gentle function of the direction, with a hill, so slope and height both vary. */+const facts: PlanetFacts = {+ centre: [0, -radius, 0], radius, gravity: 0, paint: null, layers: [], fieldNames: [], fieldsAt: null,+ height: (dx, dy, dz) => 6 + 5 * Math.sin(dx * 40) * Math.cos(dz * 33) + 3 * dy,+};+const planet = (): PlanetFacts => facts;++const rules: WorldRules = {+ id: 't', versions: [1],+ biomes: [{ id: 'meadow', conditions: [{ field: 'height', min: -100, max: 100 }], recipes: [{ recipe: 'tuft', layer: 'cover', density: 1 }] }],+ recipes: [{ id: 'tuft', version: 1, anchor: { id: 'a', mesh: 1, material: 1, footprint: 0.4 } }],+ layers: [{ id: 'cover', spacing: 6, drawDistance: 100 }],+};++describe('a planet\'s face as a plane', () => {+ const faces = planetFaces(planet);++ it('takes a point of the plane to the planet and back', () => {+ for (const f of faces) for (const [x, z] of [[0, 0], [300, -120], [-1500, 900], [2800, 2800]] as const) {+ const d = f.directionAt(x, z);+ expect(Math.hypot(...d)).toBeCloseTo(1, 12);+ const at = f.planeOf(d[0], d[1], d[2])!;+ expect(at.x).toBeCloseTo(x, 6);+ expect(at.z).toBeCloseTo(z, 6);+ }+ });++ it('puts a point at the radius plus its height, and its frame is square and up is the direction', () => {+ const f = faces[3]!;+ const w = f.world(120, 7, -300);+ const away = Math.hypot(w[0] - facts.centre[0], w[1] - facts.centre[1], w[2] - facts.centre[2]);+ expect(away).toBeCloseTo(radius + 7, 6);+ const fr = f.frameAt(120, -300);+ const dot = (a: number[], b: number[]) => a[0]! * b[0]! + a[1]! * b[1]! + a[2]! * b[2]!;+ expect(dot(fr.eu, fr.dir)).toBeCloseTo(0, 9);+ expect(dot(fr.ev, fr.dir)).toBeCloseTo(0, 9);+ expect(dot(fr.eu, fr.ev)).toBeLessThan(0.05);+ });++ it('reads the ground and its normal, level ground facing up', () => {+ const flat: PlanetFacts = { ...facts, height: () => 4 };+ const f = new PlanetFace(2, () => flat);+ const g = f.ground(10, 20)!;+ expect(g.y).toBe(4);+ expect(g.up).toBeCloseTo(1, 9);+ expect(g.normal[1]).toBeCloseTo(1, 9);+ const tilted: PlanetFacts = { ...facts, height: (dx) => dx * 4000 * 0.5 };+ const t = new PlanetFace(2, () => tilted).ground(0, 0)!;+ expect(t.up).toBeLessThan(0.95);+ });++ it('reads noise in three dimensions: a field has no seam where two faces meet', () => {+ const noiseOf = (face: PlanetFace) => new Environment({ seed: 5, ground: () => ({ y: 0, up: 1 }), ...face.environment() });+ const a = faces[0]!, b = faces[5]!;+ // The same point of the planet, found on two faces at their shared edge.+ const half = faceHalf(radius);+ const d = a.directionAt(half, 250);+ const pa = a.planeOf(d[0], d[1], d[2])!, pb = b.planeOf(d[0], d[1], d[2])!;+ expect(noiseOf(a).sample(pa.x, pa.z).moisture).toBeCloseTo(noiseOf(b).sample(pb.x, pb.z).moisture, 9);+ });++ it('lays a world out so every plant stands on the ground, and no two faces name a thing alike', () => {+ const names = new Set<string>();+ for (const f of faces) {+ const zones = new FaceZones(f);+ const env = new Environment({ seed: 9, noise: undefined, ...f.environment() });+ const plan = new WorldPlan(rules, env, zones.zones, 9, `w#${f.face}`);+ const found = plan.placementsIn(-120, -120, 120, 120, ['cover']);+ expect(found.length).toBeGreaterThan(10);+ for (const p of found) {+ const w = f.world(p.x, p.y, p.z);+ const g = f.ground(p.x, p.z)!;+ expect(p.y).toBeCloseTo(g.y, 6);+ expect(Math.hypot(w[0] - facts.centre[0], w[1] - facts.centre[1], w[2] - facts.centre[2])).toBeCloseTo(radius + g.y, 5);+ names.add(`f${f.face}:${p.id}`);+ }+ }+ expect(names.size).toBeGreaterThan(60);+ });+});++describe('the zones of a world over a planet\'s faces', () => {+ it('are kept on the face their centre falls on, in its plane', () => {+ const faces = planetFaces(planet);+ const spot = faces[2]!.world(300, 0, -150);+ const zone = { id: 'home', kind: 'home', shape: { type: 'circle' as const, x: spot[0], y: spot[1], z: spot[2], radius: 20 }, falloff: 5, priority: 1, excludes: ['*'] };+ const mine = faces[2]!.zoneOnFace(zone)!;+ expect(mine.shape.type).toBe('circle');+ expect(mine.shape.x).toBeCloseTo(300, 4);+ expect(mine.shape.z).toBeCloseTo(-150, 4);+ expect(faces[3]!.zoneOnFace(zone)).toBeNull();+ const fz = new FaceZones(faces[2]!);+ fz.sync([zone]);+ expect([...fz.zones.all()].length).toBe(1);+ fz.sync([]);+ expect([...fz.zones.all()].length).toBe(0);+ void Zones;+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex b7ee3175b..d01f46852 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2916,6 +2916,8 @@ export const NOTED = {{"note":"The editor's own eye shows the scene's post-processing."},"feat(terrain): the maths of ground on a cube sphere and the nodes drawn round an eye":{"internal":"The first layer of spherical terrain: pure maths and node selection, not yet drawn."},+ "feat(worldgen): a generated world lays out over a planet's six faces":+ {"note":"A generated world on a planet."},"feat(terrain): a planet pulls bodies toward its centre and answers up, altitude and ground height":{"note":"A planet pulls and answers."},"feat(render): temporal history follows the render origin when it steps":