@bendyline/molen-tooling 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/capture/harness.js +231 -231
- package/dist/capture/worldgen-preview.js +206 -206
- package/dist/cli.mjs +54 -2
- package/dist/docs-src/guide/adaptive-performance.md +5 -2
- package/dist/docs-src/guide/aircraft.md +12 -0
- package/dist/docs-src/guide/ambient-life.md +389 -0
- package/dist/docs-src/guide/browser-mount.md +5 -0
- package/dist/docs-src/guide/capability-authoring.md +5 -0
- package/dist/docs-src/guide/determinism.md +24 -16
- package/dist/docs-src/guide/earth-view.md +108 -20
- package/dist/docs-src/guide/entities.md +8 -0
- package/dist/docs-src/guide/examples.md +4 -1
- package/dist/docs-src/guide/figures.md +3 -0
- package/dist/docs-src/guide/game-samples.md +1 -1
- package/dist/docs-src/guide/markers.md +7 -1
- package/dist/docs-src/guide/navigation.md +10 -1
- package/dist/docs-src/guide/sky.md +5 -0
- package/dist/docs-src/guide/surface-rendering.md +7 -4
- package/dist/docs-src/guide/terrain.md +58 -3
- package/dist/docs-src/guide/vehicles.md +14 -1
- package/dist/docs-src/guide/worldgen.md +30 -17
- package/dist/docs-src/llms.txt +7 -4
- package/dist/docs-src/schemas/README.md +1 -0
- package/dist/docs-src/schemas/components.md +530 -1
- package/dist/docs-src/schemas/scene.md +105 -0
- package/dist/docs-src/schemas/terrain-package.md +102 -0
- package/dist/docs-src/schemas/transport-network.md +351 -0
- package/dist/index.d.mts +44 -1
- package/dist/index.mjs +81 -4
- package/dist/{mcp-BTVwVKFb.mjs → mcp-DKm1h9hD.mjs} +22 -1
- package/dist/{ops-BPdHodFR.mjs → ops-DHyZWZUE.mjs} +291 -66
- package/dist/templates/city-courier/README.md +1 -1
- package/dist/templates/city-courier/delivery-run.replay.json +151 -151
- package/dist/templates/city-courier/gen/molen-types.ts +82 -2
- package/dist/templates/city-courier/package.json +1 -0
- package/dist/templates/city-courier/scene.json +99 -282
- package/dist/templates/city-courier/scripts/game.ts +2 -14
- package/dist/templates/city-courier/scripts/molen-scripts.d.ts +86 -13
- package/dist/templates/city-courier/src/worker.ts +3 -1
- package/dist/templates/city-courier/test/headless.test.ts +3 -2
- package/dist/templates/data-viz/README.md +1 -1
- package/dist/templates/index.json +19 -1
- package/dist/templates/skybound/gen/molen-types.ts +82 -2
- package/dist/templates/skybound/scripts/molen-scripts.d.ts +81 -1
- package/dist/templates/terrain-flyover/README.md +2 -2
- package/dist/templates/top-down-arena/README.md +1 -1
- package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +81 -1
- package/dist/templates/top-down-arena/src/gen/molen-types.ts +82 -2
- package/package.json +13 -12
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { access, copyFile, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import { basename, delimiter, dirname, extname, isAbsolute, join, normalize, posix, relative, resolve, sep } from "node:path";
|
|
4
3
|
import { PNG } from "pngjs";
|
|
4
|
+
import { basename, delimiter, dirname, extname, isAbsolute, join, normalize, posix, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { applyUvPaint, bakeMatGraph, bakePalette, bakePixelGrid, bakeSvg } from "@bendyline/molen-materials";
|
|
6
|
+
import { TransportNetwork, ambientCapability, ambientOf, networkToDocument } from "@bendyline/molen-ambient/kernel";
|
|
6
7
|
import { FIGURE_PRESET_IDS, deriveRig, descriptorKey, figuresScriptApi, generateFigureBody, installFigures, resolveFigureDescriptor, strideRateFor } from "@bendyline/molen-figures/kernel";
|
|
7
|
-
import { heightfieldFromPng, terrainPyramidTileOrigin, terrainPyramidTileSize, wgs84ToWebMercatorTile } from "@bendyline/molen-terrain/kernel";
|
|
8
|
+
import { heightfieldFromPng, terrainPyramidTileOrigin, terrainPyramidTileSize, wgs84ToWebMercatorTile, worldToWgs84 } from "@bendyline/molen-terrain/kernel";
|
|
8
9
|
import { createLandmarkLibrary, encodeGlb, generateLandmarkModel, generateWorldgenBatch, groundSamplerForBatch, resolveStylePackDocuments, stylePackAssetIndex, stylePackMaterialRefs, validateStylePackBundle } from "@bendyline/molen-worldgen/kernel";
|
|
9
10
|
import { createPlacesContent, createRegionResolver, semanticTileToBatch, tileGroundSampler, worldgenTileBudgetForQuality } from "@bendyline/molen-worldgen-earth/kernel";
|
|
10
11
|
import { evaluateCameraTrack, registerCameraTrackSchema } from "@bendyline/molen-client/camera-track";
|
|
@@ -1448,6 +1449,17 @@ async function loadSceneTerrain(sceneDir, manifest) {
|
|
|
1448
1449
|
};
|
|
1449
1450
|
}
|
|
1450
1451
|
/**
|
|
1452
|
+
* Load the transport network a scene's `ambient.network` path names (scene-file-relative),
|
|
1453
|
+
* validated. Undefined when the scene has no ambient block or its network is inline.
|
|
1454
|
+
*/
|
|
1455
|
+
async function loadSceneAmbient(sceneDir, manifest) {
|
|
1456
|
+
const network = manifest.ambient?.network;
|
|
1457
|
+
if (typeof network !== "string") return void 0;
|
|
1458
|
+
const result = validateByKind("transport-network", parseJson(await readFile(join(sceneDir, network), "utf8")));
|
|
1459
|
+
if (!result.ok) throw new Error(result.formatted);
|
|
1460
|
+
return { [network]: result.value };
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1451
1463
|
* Everything a loaded scene needs to build its world: registry types, physics shape resolvers
|
|
1452
1464
|
* (rapier scenes in a project), and the terrain ground field. The one preamble every scene op
|
|
1453
1465
|
* shares (sim run, shot, drive, frames).
|
|
@@ -1459,6 +1471,8 @@ async function sceneBuildOptionsFor(loaded) {
|
|
|
1459
1471
|
if (loaded.project !== void 0 && loaded.manifest.physics?.engine === "rapier") opts.resolvers = await collisionResolvers(loaded.project);
|
|
1460
1472
|
const terrain = await loadSceneTerrain(dirname(loaded.scenePath), loaded.manifest);
|
|
1461
1473
|
if (terrain !== void 0) opts.terrain = terrain;
|
|
1474
|
+
const networks = await loadSceneAmbient(dirname(loaded.scenePath), loaded.manifest);
|
|
1475
|
+
if (networks !== void 0) opts.ambientNetworks = networks;
|
|
1462
1476
|
return opts;
|
|
1463
1477
|
}
|
|
1464
1478
|
/** The rapier heightfield resolver convention: `collider3d.shape = { type: 'heightfield', ref: 'scene' }`. */
|
|
@@ -1475,7 +1489,10 @@ async function prepareSceneBuilder(manifest, setup, opts) {
|
|
|
1475
1489
|
registry: opts?.registry,
|
|
1476
1490
|
...opts?.types !== void 0 ? { types: opts.types } : {},
|
|
1477
1491
|
...opts?.content !== void 0 ? { content: opts.content } : {},
|
|
1478
|
-
capabilities: [(world) => ({ figures: figuresScriptApi(installFigures(world)) })
|
|
1492
|
+
capabilities: [(world) => ({ figures: figuresScriptApi(installFigures(world)) }), ambientCapability({
|
|
1493
|
+
...opts?.ambientNetworks !== void 0 ? { networks: opts.ambientNetworks } : {},
|
|
1494
|
+
...terrain !== void 0 ? { ground: (x, z) => terrain.heightfield.sampleHeight(x, z) } : {}
|
|
1495
|
+
})],
|
|
1479
1496
|
...terrain !== void 0 ? { terrain: (world) => ({ terrain: terrainScriptApi(installTerrain(world, terrain.heightfield)) }) } : {}
|
|
1480
1497
|
};
|
|
1481
1498
|
if (manifest.physics?.engine !== "rapier") return () => buildWorld(manifest, setup, buildOpts);
|
|
@@ -3013,7 +3030,8 @@ const CAPABILITY_DOC = {
|
|
|
3013
3030
|
physics: "Rapier queries: raycast / overlapSphere / velocityOf (see guide/physics.md).",
|
|
3014
3031
|
terrain: "Terrain sampling: heightAt / normalAt / slopeAt / raycast (see guide/terrain.md).",
|
|
3015
3032
|
figures: "Figure verbs: mount / dismount / socket / … (see guide/figures.md).",
|
|
3016
|
-
worldgen: "Worldgen queries: buildingAt / … (see guide/worldgen.md)."
|
|
3033
|
+
worldgen: "Worldgen queries: buildingAt / … (see guide/worldgen.md).",
|
|
3034
|
+
ambient: "Ambient life: stats / laneAt / agentsNear / setObserver / addRoad / … (see guide/ambient-life.md)."
|
|
3017
3035
|
};
|
|
3018
3036
|
function quote$1(value) {
|
|
3019
3037
|
return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
@@ -3377,6 +3395,7 @@ function capabilitiesFor(manifest) {
|
|
|
3377
3395
|
const caps = ["figures"];
|
|
3378
3396
|
if (manifest.physics?.engine === "rapier") caps.push("physics");
|
|
3379
3397
|
if (manifest.terrain !== void 0) caps.push("terrain");
|
|
3398
|
+
if (manifest.ambient !== void 0) caps.push("ambient");
|
|
3380
3399
|
return caps;
|
|
3381
3400
|
}
|
|
3382
3401
|
function componentsFor(registry) {
|
|
@@ -4161,6 +4180,21 @@ const OPS_CATALOG = [
|
|
|
4161
4180
|
p("dumpPath", "string", false, "Write the adapted molen/worldgen-batch@1 here.")
|
|
4162
4181
|
]
|
|
4163
4182
|
},
|
|
4183
|
+
{
|
|
4184
|
+
name: "network_bake",
|
|
4185
|
+
summary: "Bake the roads, railways and paths of a local terrain package into a molen/transport-network@1 document for ambient traffic in scenes without map tiles.",
|
|
4186
|
+
cli: "molen network bake <terrain-package.json> (--tile z/x/y [--radius n] | --bbox w,s,e,n) --out network.json [--classes road,rail,path] [--heights] [--json]",
|
|
4187
|
+
mcpTool: "network_bake",
|
|
4188
|
+
params: [
|
|
4189
|
+
p("packagePath", "string", true, "terrain-package.json path (local PMTiles archives)."),
|
|
4190
|
+
p("tile", "string", false, "Centre tile \"z/x/y\" at the finest features level."),
|
|
4191
|
+
p("radius", "number", false, "Tiles around the centre tile to include (default 0)."),
|
|
4192
|
+
p("bbox", "number[4]", false, "Area [west, south, east, north] in degrees, instead of tile."),
|
|
4193
|
+
p("classes", "string[]", false, "Classes to keep: 'road', 'rail', 'path' (default all)."),
|
|
4194
|
+
p("outPath", "string", true, "Write the transport-network document here."),
|
|
4195
|
+
p("heights", "boolean", false, "Include surface heights from the elevation (default flat).")
|
|
4196
|
+
]
|
|
4197
|
+
},
|
|
4164
4198
|
{
|
|
4165
4199
|
name: "mcp_server",
|
|
4166
4200
|
summary: "Start the MCP server over stdio (exposes every mcpTool in this catalog).",
|
|
@@ -5099,6 +5133,210 @@ async function generateTypes(input) {
|
|
|
5099
5133
|
}
|
|
5100
5134
|
}
|
|
5101
5135
|
//#endregion
|
|
5136
|
+
//#region src/ops/pmtiles-node.ts
|
|
5137
|
+
/**
|
|
5138
|
+
* PMTiles over a local file for Node ops. The `pmtiles` package ships fetch and browser File
|
|
5139
|
+
* sources only; this range source reads through one file handle so the terrain package
|
|
5140
|
+
* adapters (elevation pyramid, semantic sidecars) work unchanged off disk.
|
|
5141
|
+
*/
|
|
5142
|
+
var NodeFileRangeSource = class {
|
|
5143
|
+
path;
|
|
5144
|
+
handle;
|
|
5145
|
+
constructor(path) {
|
|
5146
|
+
this.path = path;
|
|
5147
|
+
}
|
|
5148
|
+
getKey() {
|
|
5149
|
+
return this.path;
|
|
5150
|
+
}
|
|
5151
|
+
async getBytes(offset, length) {
|
|
5152
|
+
this.handle ??= open(this.path, "r");
|
|
5153
|
+
const handle = await this.handle;
|
|
5154
|
+
const buffer = new Uint8Array(length);
|
|
5155
|
+
const { bytesRead } = await handle.read(buffer, 0, length, offset);
|
|
5156
|
+
return { data: buffer.buffer.slice(0, bytesRead) };
|
|
5157
|
+
}
|
|
5158
|
+
async close() {
|
|
5159
|
+
if (this.handle === void 0) return;
|
|
5160
|
+
const handle = await this.handle;
|
|
5161
|
+
this.handle = void 0;
|
|
5162
|
+
await handle.close();
|
|
5163
|
+
}
|
|
5164
|
+
};
|
|
5165
|
+
/** Open a local PMTiles archive; `archive` satisfies the terrain `TerrainTileArchive` seam. */
|
|
5166
|
+
function openNodePmtiles(path) {
|
|
5167
|
+
const source = new NodeFileRangeSource(path);
|
|
5168
|
+
return {
|
|
5169
|
+
archive: new PMTiles(source),
|
|
5170
|
+
source,
|
|
5171
|
+
close: () => source.close()
|
|
5172
|
+
};
|
|
5173
|
+
}
|
|
5174
|
+
//#endregion
|
|
5175
|
+
//#region src/ops/network-bake.ts
|
|
5176
|
+
/**
|
|
5177
|
+
* Bake the roads, railways and paths of a local terrain package into a
|
|
5178
|
+
* `molen/transport-network@1` document, so a scene without streamed map tiles can run ambient
|
|
5179
|
+
* traffic on real streets. Tiles load at the features sidecar's finest level, stitch across their
|
|
5180
|
+
* borders, and are recentred on the baked area (its geographic centre is recorded as `origin`).
|
|
5181
|
+
*/
|
|
5182
|
+
const MAX_TILES = 64;
|
|
5183
|
+
function archivePath$1(source) {
|
|
5184
|
+
if (source.kind === "pmtiles-set" || !("path" in source)) throw new Error("network bake reads single local PMTiles archives only");
|
|
5185
|
+
return source.path;
|
|
5186
|
+
}
|
|
5187
|
+
function parseTile$1(text) {
|
|
5188
|
+
const parts = text.split("/").map(Number);
|
|
5189
|
+
if (parts.length !== 3 || parts.some((value) => !Number.isSafeInteger(value) || value < 0)) throw new Error(`tile must be "z/x/y", got "${text}"`);
|
|
5190
|
+
return {
|
|
5191
|
+
level: parts[0],
|
|
5192
|
+
x: parts[1],
|
|
5193
|
+
z: parts[2]
|
|
5194
|
+
};
|
|
5195
|
+
}
|
|
5196
|
+
/** Bake a terrain package's transport features into a transport-network document. */
|
|
5197
|
+
function bakeNetwork(input) {
|
|
5198
|
+
return guardOp((error) => ({
|
|
5199
|
+
ok: false,
|
|
5200
|
+
error
|
|
5201
|
+
}), () => bakeNetworkImpl(input));
|
|
5202
|
+
}
|
|
5203
|
+
async function bakeNetworkImpl(input) {
|
|
5204
|
+
const packagePath = resolve(input.packagePath);
|
|
5205
|
+
const parsed = validateByKind("terrain-package", parseJson(await readFile(packagePath, "utf8")));
|
|
5206
|
+
if (!parsed.ok) return {
|
|
5207
|
+
ok: false,
|
|
5208
|
+
error: parsed.formatted
|
|
5209
|
+
};
|
|
5210
|
+
const pkg = parsed.value;
|
|
5211
|
+
if (pkg.features === void 0) return {
|
|
5212
|
+
ok: false,
|
|
5213
|
+
error: "the package has no features sidecar"
|
|
5214
|
+
};
|
|
5215
|
+
if (input.tile === void 0 && input.bbox === void 0) return {
|
|
5216
|
+
ok: false,
|
|
5217
|
+
error: "pass tile (z/x/y) or bbox (west,south,east,north)"
|
|
5218
|
+
};
|
|
5219
|
+
const dir = dirname(packagePath);
|
|
5220
|
+
const terrain = await import("@bendyline/molen-terrain/client");
|
|
5221
|
+
const elevation = openNodePmtiles(resolve(dir, archivePath$1(pkg.elevation.source)));
|
|
5222
|
+
const featuresPath = resolve(dir, archivePath$1(pkg.features.source));
|
|
5223
|
+
const features = openNodePmtiles(featuresPath);
|
|
5224
|
+
const landcoverPath = pkg.landcover !== void 0 ? resolve(dir, archivePath$1(pkg.landcover.source)) : void 0;
|
|
5225
|
+
const landcover = landcoverPath === void 0 ? void 0 : landcoverPath === featuresPath ? features : openNodePmtiles(landcoverPath);
|
|
5226
|
+
const warnings = [];
|
|
5227
|
+
try {
|
|
5228
|
+
const pyramid = await terrain.openTerrainPackagePyramid(pkg, { archive: elevation.archive });
|
|
5229
|
+
const sidecar = (await terrain.openTerrainPackageSemantics(pkg, {
|
|
5230
|
+
decoder: terrain.createProtomapsTerrainMvtDecoder(),
|
|
5231
|
+
featuresArchive: features.archive,
|
|
5232
|
+
...landcover !== void 0 ? { landcoverArchive: landcover.archive } : {}
|
|
5233
|
+
})).features;
|
|
5234
|
+
if (sidecar === void 0) return {
|
|
5235
|
+
ok: false,
|
|
5236
|
+
error: "the features sidecar did not open"
|
|
5237
|
+
};
|
|
5238
|
+
const level = sidecar.maxLevel;
|
|
5239
|
+
const addresses = [];
|
|
5240
|
+
if (input.tile !== void 0) {
|
|
5241
|
+
const centre = parseTile$1(input.tile);
|
|
5242
|
+
if (centre.level !== level) warnings.push(`tile level ${centre.level} is not the finest features level ${level}`);
|
|
5243
|
+
const r = Math.max(0, Math.floor(input.radius ?? 0));
|
|
5244
|
+
for (let dz = -r; dz <= r; dz++) for (let dx = -r; dx <= r; dx++) addresses.push({
|
|
5245
|
+
level: centre.level,
|
|
5246
|
+
x: centre.x + dx,
|
|
5247
|
+
z: centre.z + dz
|
|
5248
|
+
});
|
|
5249
|
+
} else {
|
|
5250
|
+
const [west, south, east, north] = input.bbox;
|
|
5251
|
+
const a = wgs84ToWebMercatorTile(west, north, level);
|
|
5252
|
+
const b = wgs84ToWebMercatorTile(east, south, level);
|
|
5253
|
+
for (let z = Math.min(a.y, b.y); z <= Math.max(a.y, b.y); z++) for (let x = Math.min(a.x, b.x); x <= Math.max(a.x, b.x); x++) addresses.push({
|
|
5254
|
+
level,
|
|
5255
|
+
x,
|
|
5256
|
+
z
|
|
5257
|
+
});
|
|
5258
|
+
}
|
|
5259
|
+
if (addresses.length > MAX_TILES) return {
|
|
5260
|
+
ok: false,
|
|
5261
|
+
error: `${addresses.length} tiles requested; at most ${MAX_TILES}`
|
|
5262
|
+
};
|
|
5263
|
+
const descriptor = pyramid.descriptor;
|
|
5264
|
+
const origins = addresses.map((address) => terrainPyramidTileOrigin(descriptor, address));
|
|
5265
|
+
const sizes = addresses.map((address) => terrainPyramidTileSize(descriptor, address.level));
|
|
5266
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
5267
|
+
let minZ = Number.POSITIVE_INFINITY;
|
|
5268
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
5269
|
+
let maxZ = Number.NEGATIVE_INFINITY;
|
|
5270
|
+
origins.forEach((o, i) => {
|
|
5271
|
+
minX = Math.min(minX, o[0]);
|
|
5272
|
+
minZ = Math.min(minZ, o[1]);
|
|
5273
|
+
maxX = Math.max(maxX, o[0] + sizes[i]);
|
|
5274
|
+
maxZ = Math.max(maxZ, o[1] + sizes[i]);
|
|
5275
|
+
});
|
|
5276
|
+
const cx = (minX + maxX) / 2;
|
|
5277
|
+
const cz = (minZ + maxZ) / 2;
|
|
5278
|
+
const classes = new Set(input.classes ?? [
|
|
5279
|
+
"road",
|
|
5280
|
+
"rail",
|
|
5281
|
+
"path"
|
|
5282
|
+
]);
|
|
5283
|
+
const network = new TransportNetwork({ classes: [
|
|
5284
|
+
...classes.has("road") ? ["road"] : [],
|
|
5285
|
+
...classes.has("rail") ? ["rail"] : [],
|
|
5286
|
+
...classes.has("path") ? ["walk"] : []
|
|
5287
|
+
] });
|
|
5288
|
+
let loaded = 0;
|
|
5289
|
+
for (const [i, address] of addresses.entries()) {
|
|
5290
|
+
const signal = new AbortController().signal;
|
|
5291
|
+
const tile = await sidecar.source.load(address, signal);
|
|
5292
|
+
if (tile === void 0) {
|
|
5293
|
+
warnings.push(`no features at ${address.level}/${address.x}/${address.z}`);
|
|
5294
|
+
continue;
|
|
5295
|
+
}
|
|
5296
|
+
const origin = origins[i];
|
|
5297
|
+
const heightfield = input.heights === true ? await pyramid.source.load(address, signal) : void 0;
|
|
5298
|
+
network.registerTile({
|
|
5299
|
+
key: `${address.level}/${address.x}/${address.z}`,
|
|
5300
|
+
origin: [origin[0] - cx, origin[1] - cz],
|
|
5301
|
+
tileSize: sizes[i],
|
|
5302
|
+
features: tile.transportation,
|
|
5303
|
+
...tile.pois !== void 0 ? { pois: tile.pois } : {},
|
|
5304
|
+
sidewalks: false,
|
|
5305
|
+
...heightfield !== void 0 ? { heightAt: (x, z) => heightfield.sampleHeight(x + cx, z + cz) } : {}
|
|
5306
|
+
});
|
|
5307
|
+
loaded++;
|
|
5308
|
+
}
|
|
5309
|
+
const [longitude, latitude] = worldToWgs84(descriptor.metersPerUnit ?? 1, cx, cz);
|
|
5310
|
+
const round = (v) => Math.round(v * 1e6) / 1e6;
|
|
5311
|
+
const origin = {
|
|
5312
|
+
latitude: round(latitude),
|
|
5313
|
+
longitude: round(longitude)
|
|
5314
|
+
};
|
|
5315
|
+
const doc = networkToDocument(network, {
|
|
5316
|
+
name: `${pkg.name} transport network`,
|
|
5317
|
+
origin
|
|
5318
|
+
}, { heights: input.heights === true });
|
|
5319
|
+
const counts = {};
|
|
5320
|
+
for (const way of doc.ways) counts[way.class] = (counts[way.class] ?? 0) + 1;
|
|
5321
|
+
const outPath = resolve(input.outPath);
|
|
5322
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
5323
|
+
await writeFile(outPath, `${JSON.stringify(doc)}\n`);
|
|
5324
|
+
return {
|
|
5325
|
+
ok: true,
|
|
5326
|
+
path: outPath,
|
|
5327
|
+
tiles: loaded,
|
|
5328
|
+
ways: doc.ways.length,
|
|
5329
|
+
classes: counts,
|
|
5330
|
+
origin,
|
|
5331
|
+
...warnings.length > 0 ? { warnings } : {}
|
|
5332
|
+
};
|
|
5333
|
+
} finally {
|
|
5334
|
+
await elevation.close();
|
|
5335
|
+
await features.close();
|
|
5336
|
+
if (landcover !== void 0 && landcover !== features) await landcover.close();
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
//#endregion
|
|
5102
5340
|
//#region src/ops/pack.ts
|
|
5103
5341
|
async function buildContentPack(input) {
|
|
5104
5342
|
return guardOp((error) => ({
|
|
@@ -5337,45 +5575,6 @@ async function fetchContentPack(input) {
|
|
|
5337
5575
|
});
|
|
5338
5576
|
}
|
|
5339
5577
|
//#endregion
|
|
5340
|
-
//#region src/ops/pmtiles-node.ts
|
|
5341
|
-
/**
|
|
5342
|
-
* PMTiles over a local file for Node ops. The `pmtiles` package ships fetch and browser File
|
|
5343
|
-
* sources only; this range source reads through one file handle so the terrain package
|
|
5344
|
-
* adapters (elevation pyramid, semantic sidecars) work unchanged off disk.
|
|
5345
|
-
*/
|
|
5346
|
-
var NodeFileRangeSource = class {
|
|
5347
|
-
path;
|
|
5348
|
-
handle;
|
|
5349
|
-
constructor(path) {
|
|
5350
|
-
this.path = path;
|
|
5351
|
-
}
|
|
5352
|
-
getKey() {
|
|
5353
|
-
return this.path;
|
|
5354
|
-
}
|
|
5355
|
-
async getBytes(offset, length) {
|
|
5356
|
-
this.handle ??= open(this.path, "r");
|
|
5357
|
-
const handle = await this.handle;
|
|
5358
|
-
const buffer = new Uint8Array(length);
|
|
5359
|
-
const { bytesRead } = await handle.read(buffer, 0, length, offset);
|
|
5360
|
-
return { data: buffer.buffer.slice(0, bytesRead) };
|
|
5361
|
-
}
|
|
5362
|
-
async close() {
|
|
5363
|
-
if (this.handle === void 0) return;
|
|
5364
|
-
const handle = await this.handle;
|
|
5365
|
-
this.handle = void 0;
|
|
5366
|
-
await handle.close();
|
|
5367
|
-
}
|
|
5368
|
-
};
|
|
5369
|
-
/** Open a local PMTiles archive; `archive` satisfies the terrain `TerrainTileArchive` seam. */
|
|
5370
|
-
function openNodePmtiles(path) {
|
|
5371
|
-
const source = new NodeFileRangeSource(path);
|
|
5372
|
-
return {
|
|
5373
|
-
archive: new PMTiles(source),
|
|
5374
|
-
source,
|
|
5375
|
-
close: () => source.close()
|
|
5376
|
-
};
|
|
5377
|
-
}
|
|
5378
|
-
//#endregion
|
|
5379
5578
|
//#region src/ops/project-ops.ts
|
|
5380
5579
|
async function resolveProjectPath(input) {
|
|
5381
5580
|
return input.projectPath ?? await findProjectFile(input.cwd ?? process.cwd());
|
|
@@ -5820,9 +6019,11 @@ async function locateTemplates() {
|
|
|
5820
6019
|
async function loadTemplateBundle() {
|
|
5821
6020
|
const root = await locateTemplates();
|
|
5822
6021
|
if (root === void 0) throw new Error("Molen template bundle is missing; reinstall @bendyline/molen-tooling (in the engine repository, build the tooling package)");
|
|
6022
|
+
const index = JSON.parse(await readFile(join(root, "index.json"), "utf8"));
|
|
5823
6023
|
return {
|
|
5824
6024
|
root,
|
|
5825
|
-
templates:
|
|
6025
|
+
templates: index.templates,
|
|
6026
|
+
versions: index.versions
|
|
5826
6027
|
};
|
|
5827
6028
|
}
|
|
5828
6029
|
/** The sample templates `molen new --template <id>` can scaffold. */
|
|
@@ -6195,6 +6396,7 @@ export function project() {
|
|
|
6195
6396
|
}
|
|
6196
6397
|
`;
|
|
6197
6398
|
const WORKER_TS = `/// <reference lib="webworker" />
|
|
6399
|
+
import { ambientCapability } from '@bendyline/molen-ambient/kernel';
|
|
6198
6400
|
import { figuresScriptApi, installFigures } from '@bendyline/molen-figures/kernel';
|
|
6199
6401
|
import { startKernelWorker } from '@bendyline/molen-kernel';
|
|
6200
6402
|
// import { hardenScripts } from '@bendyline/molen-kernel';
|
|
@@ -6215,10 +6417,12 @@ startKernelWorker({
|
|
|
6215
6417
|
...project(),
|
|
6216
6418
|
setup,
|
|
6217
6419
|
// Figures (people and animals) are available to every scene: molen.figures.* in scripts.
|
|
6218
|
-
|
|
6420
|
+
// Ambient traffic runs when the scene has an \`ambient\` block (molen.ambient.* in scripts).
|
|
6421
|
+
capabilities: [(w) => ({ figures: figuresScriptApi(installFigures(w)) }), ambientCapability()],
|
|
6219
6422
|
});
|
|
6220
6423
|
`;
|
|
6221
|
-
const MAIN_TS = `import {
|
|
6424
|
+
const MAIN_TS = `import { ambientVehicleKind } from '@bendyline/molen-ambient/client';
|
|
6425
|
+
import { mountExperience } from '@bendyline/molen-client';
|
|
6222
6426
|
import { figureKind } from '@bendyline/molen-figures/client';
|
|
6223
6427
|
import { project } from './project';
|
|
6224
6428
|
|
|
@@ -6232,7 +6436,7 @@ const { client } = await mountExperience({
|
|
|
6232
6436
|
scene: project().scene,
|
|
6233
6437
|
canvas,
|
|
6234
6438
|
clearColor: '#11131a',
|
|
6235
|
-
kinds: [figureKind()],
|
|
6439
|
+
kinds: [figureKind(), ambientVehicleKind()],
|
|
6236
6440
|
});
|
|
6237
6441
|
|
|
6238
6442
|
// A HUD from mirrored state: no wire-protocol parsing.
|
|
@@ -6280,9 +6484,19 @@ const TSCONFIG = `{
|
|
|
6280
6484
|
"include": ["src", "setup.mjs"]
|
|
6281
6485
|
}
|
|
6282
6486
|
`;
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6487
|
+
/**
|
|
6488
|
+
* The range a new project declares for a Molen package: the version released with this CLI. Each
|
|
6489
|
+
* package has its own version line, and on 0.x a minor bump may break, so the caret pins the
|
|
6490
|
+
* project to the release it was generated from.
|
|
6491
|
+
*/
|
|
6492
|
+
function molenRange(versions, name) {
|
|
6493
|
+
const version = versions[name];
|
|
6494
|
+
if (version === void 0) throw new Error(`the template bundle records no version for ${name}; rebuild the tooling`);
|
|
6495
|
+
return `^${version}`;
|
|
6496
|
+
}
|
|
6497
|
+
function packageJson(name, versions) {
|
|
6498
|
+
const molen = (pkg) => molenRange(versions, `@bendyline/molen-${pkg}`);
|
|
6499
|
+
const pkg = {
|
|
6286
6500
|
name,
|
|
6287
6501
|
private: true,
|
|
6288
6502
|
type: "module",
|
|
@@ -6292,19 +6506,21 @@ function packageJson(name) {
|
|
|
6292
6506
|
typecheck: "tsc -p tsconfig.json && tsc -p scenes/scripts/tsconfig.json"
|
|
6293
6507
|
},
|
|
6294
6508
|
dependencies: {
|
|
6295
|
-
"@bendyline/molen-
|
|
6296
|
-
"@bendyline/molen-
|
|
6297
|
-
"@bendyline/molen-
|
|
6298
|
-
"@bendyline/molen-
|
|
6509
|
+
"@bendyline/molen-ambient": molen("ambient"),
|
|
6510
|
+
"@bendyline/molen-client": molen("client"),
|
|
6511
|
+
"@bendyline/molen-figures": molen("figures"),
|
|
6512
|
+
"@bendyline/molen-kernel": molen("kernel"),
|
|
6513
|
+
"@bendyline/molen-schema": molen("schema"),
|
|
6299
6514
|
three: "^0.184.0"
|
|
6300
6515
|
},
|
|
6301
6516
|
devDependencies: {
|
|
6302
|
-
"@bendyline/molen-tooling":
|
|
6517
|
+
"@bendyline/molen-tooling": molen("tooling"),
|
|
6303
6518
|
"@types/three": "^0.184.0",
|
|
6304
6519
|
typescript: "^6.0.3",
|
|
6305
6520
|
vite: "^6.0.7"
|
|
6306
6521
|
}
|
|
6307
|
-
}
|
|
6522
|
+
};
|
|
6523
|
+
return `${JSON.stringify(pkg, null, 2)}\n`;
|
|
6308
6524
|
}
|
|
6309
6525
|
function readme(name) {
|
|
6310
6526
|
return `# ${name}
|
|
@@ -6489,15 +6705,15 @@ function templateLoop(template, scriptsCheck) {
|
|
|
6489
6705
|
...template.tests ? ["npm test"] : []
|
|
6490
6706
|
];
|
|
6491
6707
|
}
|
|
6492
|
-
/** The template's manifest as the new project's: its name,
|
|
6493
|
-
function templatePackageJson(source, name) {
|
|
6708
|
+
/** The template's manifest as the new project's: its name, Molen deps released with this CLI. */
|
|
6709
|
+
function templatePackageJson(source, name, versions) {
|
|
6494
6710
|
const { name: _name, ...manifest } = JSON.parse(source);
|
|
6495
|
-
const
|
|
6711
|
+
const released = (deps) => deps === void 0 ? void 0 : Object.fromEntries(Object.entries(deps).map(([dep, spec]) => [dep, spec.startsWith("workspace:") ? molenRange(versions, dep) : spec]));
|
|
6496
6712
|
const pkg = {
|
|
6497
6713
|
name,
|
|
6498
6714
|
...manifest,
|
|
6499
|
-
dependencies:
|
|
6500
|
-
devDependencies:
|
|
6715
|
+
dependencies: released(manifest.dependencies),
|
|
6716
|
+
devDependencies: released(manifest.devDependencies)
|
|
6501
6717
|
};
|
|
6502
6718
|
return `${JSON.stringify(pkg, null, 2)}\n`;
|
|
6503
6719
|
}
|
|
@@ -6512,7 +6728,7 @@ async function scaffoldTemplate(input, dir) {
|
|
|
6512
6728
|
const files = [];
|
|
6513
6729
|
for (const rel of template.files) {
|
|
6514
6730
|
const source = await readFile(join(bundle.root, template.id, rel));
|
|
6515
|
-
files.push([rel, rel === "package.json" ? templatePackageJson(source.toString("utf8"), input.name) : source]);
|
|
6731
|
+
files.push([rel, rel === "package.json" ? templatePackageJson(source.toString("utf8"), input.name, bundle.versions) : source]);
|
|
6516
6732
|
}
|
|
6517
6733
|
if (!force) {
|
|
6518
6734
|
const existing = await existingFiles(dir, [...files.map(([rel]) => rel), AGENTS_MD]);
|
|
@@ -6571,6 +6787,7 @@ async function scaffoldExperience(input) {
|
|
|
6571
6787
|
...input,
|
|
6572
6788
|
template: input.template
|
|
6573
6789
|
}, dir);
|
|
6790
|
+
const { versions } = await loadTemplateBundle();
|
|
6574
6791
|
const files = [
|
|
6575
6792
|
["project.json", projectJson(input.name)],
|
|
6576
6793
|
["scenes/main.scene.json", sceneJson(input.name)],
|
|
@@ -6588,7 +6805,7 @@ async function scaffoldExperience(input) {
|
|
|
6588
6805
|
["src/vite-env.d.ts", VITE_ENV_DTS],
|
|
6589
6806
|
["vite.config.ts", VITE_CONFIG],
|
|
6590
6807
|
["tsconfig.json", TSCONFIG],
|
|
6591
|
-
["package.json", packageJson(input.name)],
|
|
6808
|
+
["package.json", packageJson(input.name, versions)],
|
|
6592
6809
|
["README.md", readme(input.name)]
|
|
6593
6810
|
];
|
|
6594
6811
|
const force = input.force === true;
|
|
@@ -6918,8 +7135,10 @@ async function runSimulationImpl(input) {
|
|
|
6918
7135
|
ticks: input.ticks
|
|
6919
7136
|
});
|
|
6920
7137
|
const assertionResults = assertDoc ? runAssertions(headless.world, assertDoc, { events: headless.events }) : [];
|
|
7138
|
+
const allPass = assertionResults.every((r) => r.pass);
|
|
7139
|
+
const ambient = ambientOf(headless.world)?.stats();
|
|
6921
7140
|
return {
|
|
6922
|
-
ok:
|
|
7141
|
+
ok: allPass,
|
|
6923
7142
|
tick: headless.world.tick,
|
|
6924
7143
|
stateHash: headless.finalHash,
|
|
6925
7144
|
...buildOpts.content !== void 0 ? { content: buildOpts.content } : {},
|
|
@@ -6928,6 +7147,12 @@ async function runSimulationImpl(input) {
|
|
|
6928
7147
|
assertionResults,
|
|
6929
7148
|
assertionsFormatted: assertionResults.length > 0 ? formatAssertionResults(assertionResults) : void 0,
|
|
6930
7149
|
...manifest.physics !== void 0 ? { physics: manifest.physics.engine } : {},
|
|
7150
|
+
...ambient !== void 0 ? { ambient: {
|
|
7151
|
+
agents: ambient.agents,
|
|
7152
|
+
spawned: ambient.spawned,
|
|
7153
|
+
despawned: ambient.despawned,
|
|
7154
|
+
lanes: ambient.network.lanes
|
|
7155
|
+
} } : {},
|
|
6931
7156
|
...notices.length > 0 ? { notices } : {}
|
|
6932
7157
|
};
|
|
6933
7158
|
}
|
|
@@ -7883,7 +8108,7 @@ function worldgenPreviewBounds(output, landmarks = {}) {
|
|
|
7883
8108
|
if (positions !== void 0) for (let index = 0; index + 2 < positions.length; index += 3) include(positions[index], positions[index + 1], positions[index + 2]);
|
|
7884
8109
|
for (const set of output.placements) {
|
|
7885
8110
|
const model = set.modelRef.startsWith("builtin:") ? generateLandmarkModel(set.modelRef.slice(8), landmarks) : void 0;
|
|
7886
|
-
const points = set.modelRef === "builtin:box" || set.modelRef.startsWith("builtin:tree.mapped.") ? [
|
|
8111
|
+
const points = set.modelRef === "builtin:box" || set.modelRef === "builtin:box.gable" || set.modelRef.startsWith("builtin:tree.mapped.") ? [
|
|
7887
8112
|
-.5,
|
|
7888
8113
|
0,
|
|
7889
8114
|
-.5,
|
|
@@ -8363,4 +8588,4 @@ function formatWorldgenStats(result) {
|
|
|
8363
8588
|
registerCameraTrackSchema();
|
|
8364
8589
|
registerExperiencePlaySchema();
|
|
8365
8590
|
//#endregion
|
|
8366
|
-
export {
|
|
8591
|
+
export { formatPacked as $, inspectContentPack as A, searchDocs as B, checkTypesOp as C, buildContentPack as D, reserveNamespace as E, previewFigure as F, schemaToTsType as G, describeOps as H, listFigurePresets as I, checkSoundbank as J, planAudio as K, exportFrames as L, bakeNetwork as M, generateTypes as N, extractContentPack as O, renderTypesModule as P, formatBytes as Q, driveScene as R, rasterizeMaterial as S, projectInfo as T, formatOp as U, OPS_CATALOG as V, checkScripts as W, stageAssets as X, ASSET_INDEX_FILE as Y, screenshotAsset as Z, loadComponentRegistry as _, lineupBatchDoc as a, findProjectFile as at, diffSnapshots as b, validateAsset as c, loadSetupLike as ct, runSimulation as d, playExperience as dt, packAsset as et, screenshotScene as f, registerExperiencePlaySchema as ft, listSchemasOp as g, listComponentsOp as h, bakeWorldgen as i, importAsset as it, verifyContentPack as j, fetchContentPack as k, applyUvPaintOp as l, updateProjectFile as lt, getSchemaOp as m, worldgenStats as n, listAssets as nt, loadStylePackFromDisk as o, loadProject as ot, getComponentOp as p, importSound as q, previewWorldgen as r, assetFileIndex as rt, simWatch as s, loadSceneDocument as st, formatWorldgenStats as t, inspectAsset as tt, testTypes as u, parseExperiencePlayScenario as ut, scaffoldExperience as v, listTypes as w, runReplayFile as x, listTemplates as y, locateDocsRoot as z };
|
|
@@ -27,7 +27,7 @@ W/S or Up/Down: accelerate and reverse. A/D or Left/Right: steer. Space: handbra
|
|
|
27
27
|
- `commands.json` + `checks.json`: a short reproducible headless smoke scenario.
|
|
28
28
|
- `test/playthrough.test.js`: a bounded agent that wins with **only player commands**, then restarts. It never teleports entities or grants inventory.
|
|
29
29
|
|
|
30
|
-
The car is an arcade controller with a conservative circular collision footprint in XZ. It is not a suspension/tire simulation. Change handling and the delivery route in `scripts[0].config`, vehicle dimensions in the `vehicle` prefab, and traffic
|
|
30
|
+
The car is an arcade controller with a conservative circular collision footprint in XZ. It is not a suspension/tire simulation. Change handling and the delivery route in `scripts[0].config`, vehicle dimensions in the `vehicle` prefab, and traffic in the scene's `ambient` block: the street grid is an inline `molen/transport-network@1` network, and NPC cars spawn around the player from the `npc-car` prefab, follow their lanes, give way at junctions and stop for the courier (see [ambient life](https://molen.dev/guide/ambient-life)).
|
|
31
31
|
|
|
32
32
|
## Sound
|
|
33
33
|
|