oda-engine 0.0.0-stage → 0.1.1
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 +151 -2
- package/bin/nowhere.mjs +352 -0
- package/lib/account.mjs +57 -0
- package/lib/agentModules.mjs +57 -0
- package/lib/devServer.mjs +351 -0
- package/lib/headless.mjs +231 -0
- package/lib/headlessPreview.mjs +212 -0
- package/lib/keys.mjs +517 -0
- package/lib/make.mjs +855 -0
- package/lib/mcp.mjs +537 -0
- package/lib/open.mjs +22 -0
- package/lib/preview.mjs +87 -0
- package/lib/previewRpc.mjs +134 -0
- package/lib/project.mjs +359 -0
- package/lib/publishFlow.mjs +131 -0
- package/lib/resources.mjs +50 -0
- package/lib/rules.mjs +60 -0
- package/lib/scaffold.mjs +42 -0
- package/lib/setup.mjs +59 -0
- package/lib/tools.mjs +668 -0
- package/package.json +51 -4
- package/template/game.config.json +9 -0
- package/template/scene.json +4 -0
- package/template/src/main.ts +11 -0
- package/vendor/DOCS.md +447 -0
- package/vendor/agent/appRun.mjs +520 -0
- package/vendor/agent/assets/brief.mjs +242 -0
- package/vendor/agent/assets/collider.mjs +531 -0
- package/vendor/agent/assets/environments/index.mjs +12 -0
- package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
- package/vendor/agent/assets/fetch.mjs +168 -0
- package/vendor/agent/assets/footprint.mjs +13 -0
- package/vendor/agent/assets/gltf.mjs +547 -0
- package/vendor/agent/assets/hdr.mjs +269 -0
- package/vendor/agent/assets/imageOps.mjs +171 -0
- package/vendor/agent/assets/images/codex.mjs +307 -0
- package/vendor/agent/assets/images/fal.mjs +75 -0
- package/vendor/agent/assets/images/gemini.mjs +84 -0
- package/vendor/agent/assets/images/index.mjs +25 -0
- package/vendor/agent/assets/images/openai.mjs +75 -0
- package/vendor/agent/assets/images/stability.mjs +71 -0
- package/vendor/agent/assets/images/views.mjs +31 -0
- package/vendor/agent/assets/import.mjs +1352 -0
- package/vendor/agent/assets/inspect.mjs +465 -0
- package/vendor/agent/assets/jobs.mjs +196 -0
- package/vendor/agent/assets/ktx2.mjs +290 -0
- package/vendor/agent/assets/ledger.mjs +466 -0
- package/vendor/agent/assets/net.mjs +254 -0
- package/vendor/agent/assets/prices.json +39 -0
- package/vendor/agent/assets/providers/fal.mjs +115 -0
- package/vendor/agent/assets/providers/index.mjs +22 -0
- package/vendor/agent/assets/providers/meshy.mjs +119 -0
- package/vendor/agent/assets/providers/tripo.mjs +188 -0
- package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
- package/vendor/agent/assets/sources/index.mjs +23 -0
- package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
- package/vendor/agent/assets/sources/polypizza.mjs +121 -0
- package/vendor/agent/assets/splat.mjs +631 -0
- package/vendor/agent/assets/targets.mjs +122 -0
- package/vendor/agent/assets/tile.mjs +261 -0
- package/vendor/agent/assets/unzip.mjs +180 -0
- package/vendor/agent/blender/cleanup.py +360 -0
- package/vendor/agent/blender/convert.py +167 -0
- package/vendor/agent/blender/find.mjs +192 -0
- package/vendor/agent/blender/nw_export.py +104 -0
- package/vendor/agent/blender/nw_rubric.py +426 -0
- package/vendor/agent/blender/run.mjs +193 -0
- package/vendor/agent/blender/runner.py +252 -0
- package/vendor/agent/blender/sheet.py +743 -0
- package/vendor/agent/depth.mjs +134 -0
- package/vendor/agent/director/board.mjs +451 -0
- package/vendor/agent/director/contracts.mjs +663 -0
- package/vendor/agent/director/director.mjs +2365 -0
- package/vendor/agent/director/estimate.mjs +200 -0
- package/vendor/agent/director/gate.mjs +802 -0
- package/vendor/agent/director/limits.json +16 -0
- package/vendor/agent/director/methods.mjs +457 -0
- package/vendor/agent/director/policy.json +33 -0
- package/vendor/agent/director/prompts.mjs +244 -0
- package/vendor/agent/director/reading.mjs +341 -0
- package/vendor/agent/director/router.mjs +184 -0
- package/vendor/agent/director/seams.mjs +243 -0
- package/vendor/agent/director/session.mjs +643 -0
- package/vendor/agent/director/store.mjs +119 -0
- package/vendor/agent/director/taskGate.mjs +110 -0
- package/vendor/agent/director/teamLedger.mjs +118 -0
- package/vendor/agent/director/triage.mjs +63 -0
- package/vendor/agent/downloads.cjs +363 -0
- package/vendor/agent/flow.mjs +78 -0
- package/vendor/agent/guard.mjs +613 -0
- package/vendor/agent/host.mjs +1736 -0
- package/vendor/agent/language.mjs +58 -0
- package/vendor/agent/ledger.mjs +360 -0
- package/vendor/agent/locale.cjs +186 -0
- package/vendor/agent/loop/capacity.mjs +74 -0
- package/vendor/agent/loop/compose.mjs +127 -0
- package/vendor/agent/loop/gate.mjs +205 -0
- package/vendor/agent/loop/judge.mjs +189 -0
- package/vendor/agent/loop/levels.mjs +273 -0
- package/vendor/agent/loop/state.mjs +358 -0
- package/vendor/agent/notes.cjs +278 -0
- package/vendor/agent/pace.mjs +258 -0
- package/vendor/agent/panels.mjs +431 -0
- package/vendor/agent/prompt.mjs +342 -0
- package/vendor/agent/reference/board.mjs +410 -0
- package/vendor/agent/reference/compose.mjs +364 -0
- package/vendor/agent/reference/decode.mjs +56 -0
- package/vendor/agent/reference/facts.mjs +1874 -0
- package/vendor/agent/reference/png.mjs +107 -0
- package/vendor/agent/reference/records.mjs +63 -0
- package/vendor/agent/reference/web.mjs +252 -0
- package/vendor/agent/roles/artist.mjs +69 -0
- package/vendor/agent/roles/builder.mjs +79 -0
- package/vendor/agent/roles/checks.mjs +223 -0
- package/vendor/agent/roles/common.mjs +188 -0
- package/vendor/agent/roles/critic.mjs +171 -0
- package/vendor/agent/roles/index.mjs +39 -0
- package/vendor/agent/roles/modeller.mjs +142 -0
- package/vendor/agent/roles/qa.mjs +58 -0
- package/vendor/agent/roles/rubrics.mjs +79 -0
- package/vendor/agent/roles/sound.mjs +69 -0
- package/vendor/agent/rounds.cjs +333 -0
- package/vendor/agent/shared.mjs +284 -0
- package/vendor/agent/stopGate.mjs +574 -0
- package/vendor/agent/subagents.mjs +129 -0
- package/vendor/agent/tools/assets.mjs +499 -0
- package/vendor/agent/tools/blender.mjs +754 -0
- package/vendor/agent/tools/cards.mjs +479 -0
- package/vendor/agent/tools/choices.mjs +479 -0
- package/vendor/agent/tools/compose.mjs +74 -0
- package/vendor/agent/tools/environment.mjs +488 -0
- package/vendor/agent/tools/eyes.mjs +733 -0
- package/vendor/agent/tools/generate.mjs +338 -0
- package/vendor/agent/tools/guide.mjs +46 -0
- package/vendor/agent/tools/harness.mjs +193 -0
- package/vendor/agent/tools/image.mjs +643 -0
- package/vendor/agent/tools/index.mjs +162 -0
- package/vendor/agent/tools/look.mjs +578 -0
- package/vendor/agent/tools/loop.mjs +858 -0
- package/vendor/agent/tools/others.mjs +123 -0
- package/vendor/agent/tools/pictures.mjs +535 -0
- package/vendor/agent/tools/reference.mjs +366 -0
- package/vendor/agent/transcripts.mjs +118 -0
- package/vendor/agent-loop.mjs +602 -0
- package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
- package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
- package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
- package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
- package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
- package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
- package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
- package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
- package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
- package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
- package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
- package/vendor/auth.cjs +570 -0
- package/vendor/build.cjs +953 -0
- package/vendor/catalog.json +455 -0
- package/vendor/connectors.cjs +688 -0
- package/vendor/eyes.mjs +733 -0
- package/vendor/gameExports.json +1390 -0
- package/vendor/git.cjs +222 -0
- package/vendor/models.json +57 -0
- package/vendor/publish.cjs +1018 -0
- package/vendor/refBoard.cjs +301 -0
- package/vendor/schema/dist/assets.d.ts +335 -0
- package/vendor/schema/dist/assets.js +439 -0
- package/vendor/schema/dist/brief.d.ts +357 -0
- package/vendor/schema/dist/brief.js +302 -0
- package/vendor/schema/dist/common.d.ts +9 -0
- package/vendor/schema/dist/common.js +13 -0
- package/vendor/schema/dist/config.d.ts +406 -0
- package/vendor/schema/dist/config.js +355 -0
- package/vendor/schema/dist/contract.d.ts +599 -0
- package/vendor/schema/dist/contract.js +1146 -0
- package/vendor/schema/dist/index.d.ts +14 -0
- package/vendor/schema/dist/index.js +21 -0
- package/vendor/schema/dist/look.d.ts +463 -0
- package/vendor/schema/dist/look.js +681 -0
- package/vendor/schema/dist/lookStats.d.ts +230 -0
- package/vendor/schema/dist/lookStats.js +768 -0
- package/vendor/schema/dist/pilot.d.ts +32 -0
- package/vendor/schema/dist/pilot.js +44 -0
- package/vendor/schema/dist/publish.d.ts +214 -0
- package/vendor/schema/dist/publish.js +291 -0
- package/vendor/schema/dist/scene.d.ts +75 -0
- package/vendor/schema/dist/scene.js +120 -0
- package/vendor/schema/dist/skyLight.d.ts +141 -0
- package/vendor/schema/dist/skyLight.js +436 -0
- package/vendor/schema/dist/style.d.ts +131 -0
- package/vendor/schema/dist/style.js +155 -0
- package/vendor/schema/package.json +1 -0
- package/vendor/selectionPrompt.mjs +51 -0
- package/vendor/useTools.mjs +195 -0
- package/vendor/userMessage.mjs +26 -0
- package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
- package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
- package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
- package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
- package/web-dist/assets/index-Baka-ZO7.js +693 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -0
- package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
- package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
- package/web-dist/index.html +34 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const PILOT: {
|
|
2
|
+
/** Whether the pilot carries a bag at all. On since 2026-11-09, for the
|
|
3
|
+
* items a planet declares in its config (config items): a give names one of
|
|
4
|
+
* them, and nothing else is given. Off, every give is refused, every take
|
|
5
|
+
* finds nothing, the bag reads empty and pickUpOnTouch does nothing. This
|
|
6
|
+
* and the world's src/play/protocol.ts must agree. */
|
|
7
|
+
readonly items: true;
|
|
8
|
+
/** Whether a host shows the pilot's HP as a meter: beside Play in the
|
|
9
|
+
* studio and in the CLI's preview (and over a planet in the universe,
|
|
10
|
+
* which the world keeps a rule of its own for). Off for now (2026-10-24,
|
|
11
|
+
* SPACE_FIRST W1): nowhere makes spaces first, and a heart at 100 over a
|
|
12
|
+
* library reads as a game. The HP itself is untouched: the SDK's damage
|
|
13
|
+
* and heal, the fall at 0 and its notice all work as before. To show the
|
|
14
|
+
* meter again, set this to true and put HP back in the guidance. */
|
|
15
|
+
readonly hpMeter: false;
|
|
16
|
+
/** HP when full, and what a pilot starts and restarts with. */
|
|
17
|
+
readonly maxHp: 100;
|
|
18
|
+
/** What the bag holds, in bytes: 100 MB, the same budget a planet gets for
|
|
19
|
+
* its own models, so even the heaviest model a planet may carry fits. */
|
|
20
|
+
readonly capacityBytes: number;
|
|
21
|
+
/** The weight of one item made in code, with no model file to weigh: small
|
|
22
|
+
* enough to carry plenty, heavy enough that a bag cannot hold millions. */
|
|
23
|
+
readonly codeItemBytes: number;
|
|
24
|
+
/** The longest an item's name may be, in characters. */
|
|
25
|
+
readonly nameMax: 40;
|
|
26
|
+
/** The most items one give or one take moves at once. */
|
|
27
|
+
readonly countMax: 999;
|
|
28
|
+
/** An item's icon is a square thumbnail this many pixels a side. */
|
|
29
|
+
readonly thumbPx: 96;
|
|
30
|
+
/** The most a data:image/png icon may weigh once decoded. */
|
|
31
|
+
readonly thumbMaxBytes: number;
|
|
32
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The pilot: the visitor's own character, the one thing that goes with them
|
|
2
|
+
// from planet to planet. Its HP and its bag are the visitor's, not any
|
|
3
|
+
// planet's, so a planet can hurt it, heal it and hand it things, and whatever
|
|
4
|
+
// it carries arrives with it on the next planet and back in the universe.
|
|
5
|
+
// A planet gives only what its config lists (config items).
|
|
6
|
+
//
|
|
7
|
+
// These numbers are shared by every side that has to agree on them: the SDK's
|
|
8
|
+
// local pilot (the studio and CLI preview, and World's fallback), the world's
|
|
9
|
+
// host that keeps the real one, and the player page in between, which mirrors
|
|
10
|
+
// them in its own protocol.ts because it must not import the engine. They are
|
|
11
|
+
// deliberately not in LIMITS: those are publishing gates, pinned by
|
|
12
|
+
// gates-check to the publish spec, and none of this decides what may publish.
|
|
13
|
+
export const PILOT = {
|
|
14
|
+
/** Whether the pilot carries a bag at all. On since 2026-11-09, for the
|
|
15
|
+
* items a planet declares in its config (config items): a give names one of
|
|
16
|
+
* them, and nothing else is given. Off, every give is refused, every take
|
|
17
|
+
* finds nothing, the bag reads empty and pickUpOnTouch does nothing. This
|
|
18
|
+
* and the world's src/play/protocol.ts must agree. */
|
|
19
|
+
items: true,
|
|
20
|
+
/** Whether a host shows the pilot's HP as a meter: beside Play in the
|
|
21
|
+
* studio and in the CLI's preview (and over a planet in the universe,
|
|
22
|
+
* which the world keeps a rule of its own for). Off for now (2026-10-24,
|
|
23
|
+
* SPACE_FIRST W1): nowhere makes spaces first, and a heart at 100 over a
|
|
24
|
+
* library reads as a game. The HP itself is untouched: the SDK's damage
|
|
25
|
+
* and heal, the fall at 0 and its notice all work as before. To show the
|
|
26
|
+
* meter again, set this to true and put HP back in the guidance. */
|
|
27
|
+
hpMeter: false,
|
|
28
|
+
/** HP when full, and what a pilot starts and restarts with. */
|
|
29
|
+
maxHp: 100,
|
|
30
|
+
/** What the bag holds, in bytes: 100 MB, the same budget a planet gets for
|
|
31
|
+
* its own models, so even the heaviest model a planet may carry fits. */
|
|
32
|
+
capacityBytes: 100 * 1024 * 1024,
|
|
33
|
+
/** The weight of one item made in code, with no model file to weigh: small
|
|
34
|
+
* enough to carry plenty, heavy enough that a bag cannot hold millions. */
|
|
35
|
+
codeItemBytes: 64 * 1024,
|
|
36
|
+
/** The longest an item's name may be, in characters. */
|
|
37
|
+
nameMax: 40,
|
|
38
|
+
/** The most items one give or one take moves at once. */
|
|
39
|
+
countMax: 999,
|
|
40
|
+
/** An item's icon is a square thumbnail this many pixels a side. */
|
|
41
|
+
thumbPx: 96,
|
|
42
|
+
/** The most a data:image/png icon may weigh once decoded. */
|
|
43
|
+
thumbMaxBytes: 24 * 1024,
|
|
44
|
+
};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { type AssetKind } from './assets.js';
|
|
2
|
+
/** Budgets and quotas, shared by the studio (pre-flight), the Edge Function
|
|
3
|
+
* (enforced) and the publish_game RPC (mirrored in SQL). */
|
|
4
|
+
export declare const LIMITS: {
|
|
5
|
+
readonly bundleKb: 1024;
|
|
6
|
+
readonly configKb: 64;
|
|
7
|
+
readonly previewKb: 1024;
|
|
8
|
+
/** The files a planet carries beside its code (models, textures, HDRIs,
|
|
9
|
+
* sounds, LUTs), in total, whatever its size. */
|
|
10
|
+
readonly assetsMb: 100;
|
|
11
|
+
/** The most one model file may weigh: Supabase Storage's own ceiling on a
|
|
12
|
+
* single upload on the free plan. The platform refuses a bigger file
|
|
13
|
+
* whatever this says; checking first turns that into a sentence. */
|
|
14
|
+
readonly assetFileMb: 50;
|
|
15
|
+
/** The planet's splat (splat.ts): what the world shows inside its glass. */
|
|
16
|
+
readonly splatKb: 8192;
|
|
17
|
+
/** The publish view of assets.lock.json (publishLock) as it goes up. */
|
|
18
|
+
readonly ledgerKb: 256;
|
|
19
|
+
/** The sounds a planet carries, in total, inside assetsMb. */
|
|
20
|
+
readonly audioMb: 20;
|
|
21
|
+
readonly worldsPerOwner: 10;
|
|
22
|
+
readonly minIntervalSec: 60;
|
|
23
|
+
readonly perDay: 30;
|
|
24
|
+
};
|
|
25
|
+
/** The only modules a bundle may reach for through globalThis.__nw_modules.
|
|
26
|
+
* The player page supplies exactly these; anything else is a build that
|
|
27
|
+
* bundled something it should not have, or wants something nobody hosts. */
|
|
28
|
+
export declare const SHIM_KEYS: readonly ["three", "three/webgpu", "three/tsl", "@nowhere/sdk"];
|
|
29
|
+
export type ShimKey = (typeof SHIM_KEYS)[number];
|
|
30
|
+
/** Model formats a planet may carry. Kept in step with MODEL_EXTENSIONS in
|
|
31
|
+
* apps/studio/src/three/loadModel.ts, which is the decoder that has to read
|
|
32
|
+
* them: a format allowed up here and not parsed down there publishes an
|
|
33
|
+
* object nobody can draw. workspace-check asserts that the lists agree. */
|
|
34
|
+
export declare const ASSET_EXTENSIONS: readonly [".glb", ".gltf", ".obj", ".fbx", ".stl", ".ply", ".dae", ".3mf"];
|
|
35
|
+
export type AssetExtension = (typeof ASSET_EXTENSIONS)[number];
|
|
36
|
+
/** How many bytes of models one planet may carry, in total: LIMITS.assetsMb,
|
|
37
|
+
* the same for every size of planet. It used to grow with the map (32 MB at S
|
|
38
|
+
* to 256 MB at XL), which made a heavy model a reason to build a bigger world;
|
|
39
|
+
* one generous number is what builders can plan around. `tiles` is kept so
|
|
40
|
+
* every caller, and the published verifier, keeps its signature. */
|
|
41
|
+
export declare function assetsBudgetBytes(_tiles?: number): number;
|
|
42
|
+
/** The most one model file may weigh (LIMITS.assetFileMb). */
|
|
43
|
+
export declare function assetFileBytes(): number;
|
|
44
|
+
/** The models a scene document names, in first-appearance order and without
|
|
45
|
+
* repeats: one file placed twenty times uploads once. Takes an unvalidated
|
|
46
|
+
* document on purpose, because the studio calls it on whatever is on disk. */
|
|
47
|
+
export declare function collectSceneAssets(scene: unknown): string[];
|
|
48
|
+
/** Whether a scene's `asset` value names a file this planet may publish: one
|
|
49
|
+
* model, directly inside assets/. The Storage key is built from this string,
|
|
50
|
+
* so anything that could climb out of the version directory (a parent
|
|
51
|
+
* segment, a leading slash, a Windows separator) or land somewhere a browser
|
|
52
|
+
* would read as a document is refused rather than uploaded. */
|
|
53
|
+
export declare function isAssetPath(p: string): boolean;
|
|
54
|
+
/** A git commit SHA: the exact build a publish deploys. */
|
|
55
|
+
export declare function isSha(s: unknown): s is string;
|
|
56
|
+
/** A repo key is the SHA of a project's root commit: the link between a
|
|
57
|
+
* project and its planet that survives clones and a wiped .nowhere/. */
|
|
58
|
+
export declare function isRepoKey(s: unknown): s is string;
|
|
59
|
+
export interface BundleFinding {
|
|
60
|
+
code: string;
|
|
61
|
+
message: string;
|
|
62
|
+
}
|
|
63
|
+
export interface BundleResult {
|
|
64
|
+
ok: boolean;
|
|
65
|
+
/** Shim keys the bundle references, sorted and unique. */
|
|
66
|
+
requires: string[];
|
|
67
|
+
/** The names the bundle reads from @nowhere/sdk, sorted and unique: what
|
|
68
|
+
* the SDK of the player that runs it has to export (sdkNamesOf). */
|
|
69
|
+
sdk: string[];
|
|
70
|
+
findings: BundleFinding[];
|
|
71
|
+
}
|
|
72
|
+
/** The names a built main.js reads from @nowhere/sdk, sorted and each once:
|
|
73
|
+
* `import_sdk.World`, `sdk["pickTier"]` and `const { createLook } = sdk`
|
|
74
|
+
* all count. A name read through a key the code computes is not seen, and
|
|
75
|
+
* neither is anything in a bundle that does not reach the SDK the way the
|
|
76
|
+
* studio's builder does; a string that spells out a read ("import_sdk.X")
|
|
77
|
+
* counts as one, which errs towards stopping a publish. Pure string work,
|
|
78
|
+
* like the gates. */
|
|
79
|
+
export declare function sdkNamesOf(text: string): string[];
|
|
80
|
+
/** Static gates on a built main.js. Pure string checks, so the Edge Function
|
|
81
|
+
* can run them without executing a byte of the game. */
|
|
82
|
+
export declare function checkBundle(text: string): BundleResult;
|
|
83
|
+
export interface ManifestInput {
|
|
84
|
+
id: string;
|
|
85
|
+
title: string;
|
|
86
|
+
tiles?: number;
|
|
87
|
+
sha: string;
|
|
88
|
+
version: number;
|
|
89
|
+
requires: string[];
|
|
90
|
+
hasPreview: boolean;
|
|
91
|
+
/** Whether a scene.json went up beside the bundle. */
|
|
92
|
+
scene: boolean;
|
|
93
|
+
/** The models it names, as they are written in it ("assets/foo.glb"). */
|
|
94
|
+
assets: string[];
|
|
95
|
+
/** Whether a splat.bin went up beside it. */
|
|
96
|
+
hasSplat?: boolean;
|
|
97
|
+
/** Every file under assets/ this version carries, of every kind, placed by
|
|
98
|
+
* the scene or not: what a host may fetch for the game's own code. */
|
|
99
|
+
files?: {
|
|
100
|
+
path: string;
|
|
101
|
+
kind: AssetKind;
|
|
102
|
+
bytes: number;
|
|
103
|
+
}[];
|
|
104
|
+
/** The credit lines a planet shows its visitors (creditsFor). */
|
|
105
|
+
credits?: {
|
|
106
|
+
path: string;
|
|
107
|
+
credit: string;
|
|
108
|
+
license: string;
|
|
109
|
+
}[];
|
|
110
|
+
/** The publish contract the server took it under (PUBLISH_CONTRACT). */
|
|
111
|
+
contract?: number;
|
|
112
|
+
/** What the planet needs of the player that plays it (planetNeeds). A
|
|
113
|
+
* player that lacks one says so instead of starting the game. */
|
|
114
|
+
needs?: readonly string[];
|
|
115
|
+
}
|
|
116
|
+
/** The manifest the Edge Function writes beside main.js. Paths are relative
|
|
117
|
+
* to the version directory (<id>/<sha>/), so the file never needs to know
|
|
118
|
+
* the bucket URL, and the scene's own asset values resolve against the same
|
|
119
|
+
* base without being rewritten. */
|
|
120
|
+
export declare function buildManifest(input: ManifestInput): {
|
|
121
|
+
needs?: string[] | undefined;
|
|
122
|
+
contract?: number | undefined;
|
|
123
|
+
credits?: {
|
|
124
|
+
path: string;
|
|
125
|
+
credit: string;
|
|
126
|
+
license: string;
|
|
127
|
+
}[] | undefined;
|
|
128
|
+
files?: {
|
|
129
|
+
path: string;
|
|
130
|
+
kind: AssetKind;
|
|
131
|
+
bytes: number;
|
|
132
|
+
}[] | undefined;
|
|
133
|
+
schema: "nowhere/published@3";
|
|
134
|
+
id: string;
|
|
135
|
+
title: string;
|
|
136
|
+
tiles: number | undefined;
|
|
137
|
+
sha: string;
|
|
138
|
+
version: number;
|
|
139
|
+
bundle: "main.js";
|
|
140
|
+
config: "game.config.json";
|
|
141
|
+
preview: "preview.png" | null;
|
|
142
|
+
scene: "scene.json" | null;
|
|
143
|
+
splat: "splat.bin" | null;
|
|
144
|
+
assets: string[];
|
|
145
|
+
requires: string[];
|
|
146
|
+
sdk: "sdk@1";
|
|
147
|
+
};
|
|
148
|
+
export type PublishedManifest = ReturnType<typeof buildManifest>;
|
|
149
|
+
/** Where a planet's splat sits in its version directory. */
|
|
150
|
+
export declare const SPLAT_FILE = "splat.bin";
|
|
151
|
+
/** "NWSP" */
|
|
152
|
+
export declare const SPLAT_MAGIC: readonly [78, 87, 83, 80];
|
|
153
|
+
/** The version a bake writes. Readers take this one and every one before it. */
|
|
154
|
+
export declare const SPLAT_VERSION = 2;
|
|
155
|
+
/** The header a bake writes (version 2), and version 1's, which had no
|
|
156
|
+
* backdrop. */
|
|
157
|
+
export declare const SPLAT_HEADER_BYTES = 56;
|
|
158
|
+
export declare const SPLAT_HEADER_BYTES_V1 = 48;
|
|
159
|
+
export declare const SPLAT_STRIDE = 16;
|
|
160
|
+
/** The backdrop a bake stores: an equirectangular picture this many texels
|
|
161
|
+
* round and half as many from the nadir to the zenith, or one texel round
|
|
162
|
+
* for a sky that is the same all the way round. */
|
|
163
|
+
export declare const SPLAT_BACKDROP_W = 512;
|
|
164
|
+
export declare const SPLAT_BACKDROP_H = 256;
|
|
165
|
+
/**
|
|
166
|
+
* A planet's splat: the world it holds, baked by the studio at publish time
|
|
167
|
+
* into flat soft discs lying on its surfaces, each with the colour the lit
|
|
168
|
+
* scene showed there, and the backdrop round it. The nowhere world draws it
|
|
169
|
+
* inside the planet's glass, so a planet seen from space is its own world in
|
|
170
|
+
* miniature, in the round, under its own sky.
|
|
171
|
+
*
|
|
172
|
+
* header, 56 bytes (48 in version 1), little-endian
|
|
173
|
+
* 0 "NWSP"
|
|
174
|
+
* 4 u16 version (2, or 1) 6 u16 header bytes (56, or 48)
|
|
175
|
+
* 8 u32 count
|
|
176
|
+
* 12 f32 radius scale the largest disc radius, world units
|
|
177
|
+
* 16 f32 x3 min 28 f32 x3 max the bounds positions span
|
|
178
|
+
* 40 u8 x4 sky top, sRGB, then 1 44 u8 x4 sky bottom, the same
|
|
179
|
+
* the sky in two colours; zeros read as white
|
|
180
|
+
* 48 u16 backdrop width 50 u16 backdrop height (version 2; 0 x 0
|
|
181
|
+
* is none, and the sky's two colours stand in for it)
|
|
182
|
+
* 52 4 bytes reserved
|
|
183
|
+
* then count records of 16 bytes
|
|
184
|
+
* 0 u16 x3 position, quantised across [min, max]
|
|
185
|
+
* 6 i8 x2 normal, octahedral
|
|
186
|
+
* 8 u8 radius, x radius scale / 255
|
|
187
|
+
* 9 u8 reserved
|
|
188
|
+
* 10 u8 x4 colour, sRGB, and opacity
|
|
189
|
+
* 14 2 bytes reserved
|
|
190
|
+
* then, version 2, the backdrop: width x height texels of u8 x3, sRGB
|
|
191
|
+
* what the world shows round it where no disc is (its sky, its fog on
|
|
192
|
+
* the scenery beyond the map, the scenery itself), seen from the middle
|
|
193
|
+
* of the discs' bounds: equirectangular as three reads it, the texel at
|
|
194
|
+
* column i and row j looking along u = (i + 0.5) / width round
|
|
195
|
+
* (atan2(z, x) / 2pi + 0.5) and v = (j + 0.5) / height up (asin(y) / pi
|
|
196
|
+
* + 0.5), so the first row looks straight down
|
|
197
|
+
*/
|
|
198
|
+
export interface SplatCheck {
|
|
199
|
+
ok: boolean;
|
|
200
|
+
count: number;
|
|
201
|
+
/** The file's version, and its backdrop's size (0 x 0 for none). */
|
|
202
|
+
version?: number;
|
|
203
|
+
backdrop?: {
|
|
204
|
+
width: number;
|
|
205
|
+
height: number;
|
|
206
|
+
};
|
|
207
|
+
error?: string;
|
|
208
|
+
}
|
|
209
|
+
/** Whether bytes are a splat file this version can read: version 2, or a
|
|
210
|
+
* version 1 file from before the backdrop. Checks the header and the length
|
|
211
|
+
* only: the records and the backdrop are numbers in fixed ranges, and there
|
|
212
|
+
* is nothing in one a reader could be hurt by. */
|
|
213
|
+
export declare function checkSplat(bytes: Uint8Array): SplatCheck;
|
|
214
|
+
export * from './assets.js';
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// Publishing gates: the checks a game bundle must pass before nowhere hosts
|
|
2
|
+
// it as a planet. One implementation, run in three places: the studio's
|
|
3
|
+
// Publish button, scripts/publish-to-world.mjs for direct-load planets, and
|
|
4
|
+
// the `publish` Edge Function (which gets this file bundled into _verifier.js
|
|
5
|
+
// by scripts/build-verifier.mjs). The function's verdict is the one that
|
|
6
|
+
// counts; the studio runs the same code first so a refusal never surprises.
|
|
7
|
+
import { ASSETS_TOTAL_MB, AUDIO_TOTAL_MB } from './assets.js';
|
|
8
|
+
/** Budgets and quotas, shared by the studio (pre-flight), the Edge Function
|
|
9
|
+
* (enforced) and the publish_game RPC (mirrored in SQL). */
|
|
10
|
+
export const LIMITS = {
|
|
11
|
+
bundleKb: 1024,
|
|
12
|
+
configKb: 64,
|
|
13
|
+
previewKb: 1024,
|
|
14
|
+
/** The files a planet carries beside its code (models, textures, HDRIs,
|
|
15
|
+
* sounds, LUTs), in total, whatever its size. */
|
|
16
|
+
assetsMb: ASSETS_TOTAL_MB,
|
|
17
|
+
/** The most one model file may weigh: Supabase Storage's own ceiling on a
|
|
18
|
+
* single upload on the free plan. The platform refuses a bigger file
|
|
19
|
+
* whatever this says; checking first turns that into a sentence. */
|
|
20
|
+
assetFileMb: 50,
|
|
21
|
+
/** The planet's splat (splat.ts): what the world shows inside its glass. */
|
|
22
|
+
splatKb: 8192,
|
|
23
|
+
/** The publish view of assets.lock.json (publishLock) as it goes up. */
|
|
24
|
+
ledgerKb: 256,
|
|
25
|
+
/** The sounds a planet carries, in total, inside assetsMb. */
|
|
26
|
+
audioMb: AUDIO_TOTAL_MB,
|
|
27
|
+
worldsPerOwner: 10,
|
|
28
|
+
minIntervalSec: 60,
|
|
29
|
+
perDay: 30,
|
|
30
|
+
};
|
|
31
|
+
/** The only modules a bundle may reach for through globalThis.__nw_modules.
|
|
32
|
+
* The player page supplies exactly these; anything else is a build that
|
|
33
|
+
* bundled something it should not have, or wants something nobody hosts. */
|
|
34
|
+
export const SHIM_KEYS = ['three', 'three/webgpu', 'three/tsl', '@nowhere/sdk'];
|
|
35
|
+
/** Model formats a planet may carry. Kept in step with MODEL_EXTENSIONS in
|
|
36
|
+
* apps/studio/src/three/loadModel.ts, which is the decoder that has to read
|
|
37
|
+
* them: a format allowed up here and not parsed down there publishes an
|
|
38
|
+
* object nobody can draw. workspace-check asserts that the lists agree. */
|
|
39
|
+
export const ASSET_EXTENSIONS = ['.glb', '.gltf', '.obj', '.fbx', '.stl', '.ply', '.dae', '.3mf'];
|
|
40
|
+
/** How many bytes of models one planet may carry, in total: LIMITS.assetsMb,
|
|
41
|
+
* the same for every size of planet. It used to grow with the map (32 MB at S
|
|
42
|
+
* to 256 MB at XL), which made a heavy model a reason to build a bigger world;
|
|
43
|
+
* one generous number is what builders can plan around. `tiles` is kept so
|
|
44
|
+
* every caller, and the published verifier, keeps its signature. */
|
|
45
|
+
export function assetsBudgetBytes(_tiles) {
|
|
46
|
+
return LIMITS.assetsMb * 1024 * 1024;
|
|
47
|
+
}
|
|
48
|
+
/** The most one model file may weigh (LIMITS.assetFileMb). */
|
|
49
|
+
export function assetFileBytes() {
|
|
50
|
+
return LIMITS.assetFileMb * 1024 * 1024;
|
|
51
|
+
}
|
|
52
|
+
/** The models a scene document names, in first-appearance order and without
|
|
53
|
+
* repeats: one file placed twenty times uploads once. Takes an unvalidated
|
|
54
|
+
* document on purpose, because the studio calls it on whatever is on disk. */
|
|
55
|
+
export function collectSceneAssets(scene) {
|
|
56
|
+
const objects = scene?.objects;
|
|
57
|
+
if (!Array.isArray(objects))
|
|
58
|
+
return [];
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
const out = [];
|
|
61
|
+
for (const object of objects) {
|
|
62
|
+
const asset = object?.asset;
|
|
63
|
+
if (typeof asset !== 'string' || seen.has(asset))
|
|
64
|
+
continue;
|
|
65
|
+
seen.add(asset);
|
|
66
|
+
out.push(asset);
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/** Whether a scene's `asset` value names a file this planet may publish: one
|
|
71
|
+
* model, directly inside assets/. The Storage key is built from this string,
|
|
72
|
+
* so anything that could climb out of the version directory (a parent
|
|
73
|
+
* segment, a leading slash, a Windows separator) or land somewhere a browser
|
|
74
|
+
* would read as a document is refused rather than uploaded. */
|
|
75
|
+
export function isAssetPath(p) {
|
|
76
|
+
if (!p.startsWith('assets/'))
|
|
77
|
+
return false;
|
|
78
|
+
if (p.includes('..') || p.includes('\\'))
|
|
79
|
+
return false;
|
|
80
|
+
if (p.split('/').length !== 2)
|
|
81
|
+
return false;
|
|
82
|
+
const name = p.slice('assets/'.length);
|
|
83
|
+
const dot = name.lastIndexOf('.');
|
|
84
|
+
if (dot < 1)
|
|
85
|
+
return false;
|
|
86
|
+
return ASSET_EXTENSIONS.includes(name.slice(dot).toLowerCase());
|
|
87
|
+
}
|
|
88
|
+
const HEX40 = /^[0-9a-f]{40}$/;
|
|
89
|
+
/** A git commit SHA: the exact build a publish deploys. */
|
|
90
|
+
export function isSha(s) {
|
|
91
|
+
return typeof s === 'string' && HEX40.test(s);
|
|
92
|
+
}
|
|
93
|
+
/** A repo key is the SHA of a project's root commit: the link between a
|
|
94
|
+
* project and its planet that survives clones and a wiped .nowhere/. */
|
|
95
|
+
export function isRepoKey(s) {
|
|
96
|
+
return typeof s === 'string' && HEX40.test(s);
|
|
97
|
+
}
|
|
98
|
+
// Anything the host is meant to supply must have been left unresolved and
|
|
99
|
+
// routed through the shim. This is what the studio's builder emits.
|
|
100
|
+
const SHIM_REF = /__nw_modules\[["']([^"']+)["']\]/g;
|
|
101
|
+
// A bare import that survived bundling means the bundle was not built by the
|
|
102
|
+
// studio's builder (or the shim plugin was bypassed). The host cannot resolve
|
|
103
|
+
// it, so the module would fail on load.
|
|
104
|
+
const BARE_IMPORT = /(?:^|\n)\s*(?:import|export)[^;\n]*?from\s*["'](three(?:\/[a-z]+)?|@nowhere\/sdk)["']/;
|
|
105
|
+
// Dynamic code is refused outright: it defeats every static check above and
|
|
106
|
+
// has no legitimate use in a game bundle.
|
|
107
|
+
const DYNAMIC_CODE = /\beval\s*\(|new\s+Function\s*\(/;
|
|
108
|
+
// Shapes of credentials that must never ship in a public bundle: a JWT (a
|
|
109
|
+
// Supabase key or session), an OpenAI style key, a Google API key.
|
|
110
|
+
const SECRETS = [
|
|
111
|
+
{ name: 'a JWT', re: /eyJ[A-Za-z0-9_-]{20,}/ },
|
|
112
|
+
{ name: 'an sk- API key', re: /sk-[A-Za-z0-9]{20,}/ },
|
|
113
|
+
{ name: 'a Google API key', re: /AIza[0-9A-Za-z_-]{30,}/ },
|
|
114
|
+
];
|
|
115
|
+
// How a bundle the studio built reaches the SDK (build.cjs): one CommonJS
|
|
116
|
+
// wrapper around the shim, then a variable for each file that imports it,
|
|
117
|
+
// read member by member:
|
|
118
|
+
//
|
|
119
|
+
// var require_sdk = __commonJS({ "nw-shared:@nowhere/sdk"(exports, module) {
|
|
120
|
+
// module.exports = globalThis.__nw_modules["@nowhere/sdk"]; } });
|
|
121
|
+
// var import_sdk = __toESM(require_sdk());
|
|
122
|
+
// const world = new import_sdk.World(ctx);
|
|
123
|
+
//
|
|
124
|
+
// A bundle made some other way may hold the shim in a variable of its own.
|
|
125
|
+
const SDK_WRAPPER = /var\s+([\w$]+)\s*=\s*__commonJS\(\{\s*["'][^"']*["']\s*\(\s*exports\s*,\s*module\s*\)\s*\{\s*module\.exports\s*=\s*globalThis\.__nw_modules\[["']@nowhere\/sdk["']\]/g;
|
|
126
|
+
const SDK_DIRECT = /(?:var|let|const)\s+([\w$]+)\s*=\s*globalThis\.__nw_modules\[["']@nowhere\/sdk["']\]/g;
|
|
127
|
+
// What every module object has, which no SDK exports.
|
|
128
|
+
const NOT_EXPORTS = new Set(['default', '__esModule']);
|
|
129
|
+
const literal = (name) => name.replace(/\$/g, '\\$');
|
|
130
|
+
/** The names a built main.js reads from @nowhere/sdk, sorted and each once:
|
|
131
|
+
* `import_sdk.World`, `sdk["pickTier"]` and `const { createLook } = sdk`
|
|
132
|
+
* all count. A name read through a key the code computes is not seen, and
|
|
133
|
+
* neither is anything in a bundle that does not reach the SDK the way the
|
|
134
|
+
* studio's builder does; a string that spells out a read ("import_sdk.X")
|
|
135
|
+
* counts as one, which errs towards stopping a publish. Pure string work,
|
|
136
|
+
* like the gates. */
|
|
137
|
+
export function sdkNamesOf(text) {
|
|
138
|
+
const holders = new Set();
|
|
139
|
+
for (const m of text.matchAll(SDK_DIRECT))
|
|
140
|
+
holders.add(m[1]);
|
|
141
|
+
for (const w of text.matchAll(SDK_WRAPPER)) {
|
|
142
|
+
const binding = new RegExp(`(?:var|let|const)\\s+([\\w$]+)\\s*=\\s*(?:__toESM\\(\\s*)?${literal(w[1])}\\(\\)`, 'g');
|
|
143
|
+
for (const m of text.matchAll(binding))
|
|
144
|
+
holders.add(m[1]);
|
|
145
|
+
}
|
|
146
|
+
const names = new Set();
|
|
147
|
+
for (const holder of holders) {
|
|
148
|
+
const h = literal(holder);
|
|
149
|
+
const member = new RegExp(`(?<![\\w$.])${h}\\s*(?:\\?\\.\\s*|\\.\\s*)([A-Za-z_$][\\w$]*)|(?<![\\w$.])${h}\\s*(?:\\?\\.)?\\[\\s*(["'\`])([A-Za-z_$][\\w$]*)\\2\\s*\\]`, 'g');
|
|
150
|
+
for (const m of text.matchAll(member))
|
|
151
|
+
names.add(m[1] ?? m[3]);
|
|
152
|
+
const destructured = new RegExp(`\\{([^{}]*)\\}\\s*=\\s*${h}(?![\\w$])`, 'g');
|
|
153
|
+
for (const m of text.matchAll(destructured)) {
|
|
154
|
+
for (const part of m[1].split(',')) {
|
|
155
|
+
const key = part.trim().split(/[:=]/)[0].trim().replace(/^["']|["']$/g, '');
|
|
156
|
+
if (key && !key.startsWith('...') && /^[A-Za-z_$][\w$]*$/.test(key))
|
|
157
|
+
names.add(key);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return [...names].filter((n) => !NOT_EXPORTS.has(n)).sort();
|
|
162
|
+
}
|
|
163
|
+
/** Static gates on a built main.js. Pure string checks, so the Edge Function
|
|
164
|
+
* can run them without executing a byte of the game. */
|
|
165
|
+
export function checkBundle(text) {
|
|
166
|
+
const findings = [];
|
|
167
|
+
if (!/createGame/.test(text)) {
|
|
168
|
+
findings.push({ code: 'contract:createGame', message: 'the bundle does not export createGame(ctx)' });
|
|
169
|
+
}
|
|
170
|
+
const requires = [...new Set([...text.matchAll(SHIM_REF)].map((m) => m[1]))].sort();
|
|
171
|
+
if (requires.length === 0) {
|
|
172
|
+
findings.push({
|
|
173
|
+
code: 'contract:shim',
|
|
174
|
+
message: 'nothing comes from the shared shim, so three was bundled in',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const unknown = requires.filter((k) => !SHIM_KEYS.includes(k));
|
|
178
|
+
if (unknown.length > 0) {
|
|
179
|
+
findings.push({
|
|
180
|
+
code: 'contract:shim',
|
|
181
|
+
message: `the bundle asks the host for modules it does not supply: ${unknown.join(', ')}`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (BARE_IMPORT.test(text)) {
|
|
185
|
+
findings.push({ code: 'contract:bare-import', message: 'a bare three/SDK import survived the bundle' });
|
|
186
|
+
}
|
|
187
|
+
if (DYNAMIC_CODE.test(text)) {
|
|
188
|
+
findings.push({ code: 'contract:eval', message: 'eval() and new Function() are not allowed in a bundle' });
|
|
189
|
+
}
|
|
190
|
+
for (const s of SECRETS) {
|
|
191
|
+
if (s.re.test(text)) {
|
|
192
|
+
findings.push({ code: 'contract:secret', message: `the bundle contains what looks like ${s.name}` });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { ok: findings.length === 0, requires, sdk: sdkNamesOf(text), findings };
|
|
196
|
+
}
|
|
197
|
+
/** The manifest the Edge Function writes beside main.js. Paths are relative
|
|
198
|
+
* to the version directory (<id>/<sha>/), so the file never needs to know
|
|
199
|
+
* the bucket URL, and the scene's own asset values resolve against the same
|
|
200
|
+
* base without being rewritten. */
|
|
201
|
+
export function buildManifest(input) {
|
|
202
|
+
return {
|
|
203
|
+
schema: 'nowhere/published@3',
|
|
204
|
+
id: input.id,
|
|
205
|
+
title: input.title,
|
|
206
|
+
tiles: input.tiles,
|
|
207
|
+
sha: input.sha,
|
|
208
|
+
version: input.version,
|
|
209
|
+
bundle: 'main.js',
|
|
210
|
+
config: 'game.config.json',
|
|
211
|
+
preview: input.hasPreview ? 'preview.png' : null,
|
|
212
|
+
scene: input.scene ? 'scene.json' : null,
|
|
213
|
+
splat: input.hasSplat ? SPLAT_FILE : null,
|
|
214
|
+
assets: input.assets,
|
|
215
|
+
requires: input.requires,
|
|
216
|
+
sdk: 'sdk@1',
|
|
217
|
+
// Additive, and only when given: a manifest from before them still
|
|
218
|
+
// parses everywhere (the world's PublishedManifest is lenient).
|
|
219
|
+
...(input.files ? { files: input.files } : {}),
|
|
220
|
+
...(input.credits ? { credits: input.credits } : {}),
|
|
221
|
+
// Contract 3 on: a manifest without them (every planet before it) needs
|
|
222
|
+
// nothing a player from before it lacks.
|
|
223
|
+
...(input.contract !== undefined ? { contract: input.contract } : {}),
|
|
224
|
+
...(input.needs ? { needs: [...input.needs] } : {}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
// the planet's splat
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
/** Where a planet's splat sits in its version directory. */
|
|
231
|
+
export const SPLAT_FILE = 'splat.bin';
|
|
232
|
+
/** "NWSP" */
|
|
233
|
+
export const SPLAT_MAGIC = [0x4e, 0x57, 0x53, 0x50];
|
|
234
|
+
/** The version a bake writes. Readers take this one and every one before it. */
|
|
235
|
+
export const SPLAT_VERSION = 2;
|
|
236
|
+
/** The header a bake writes (version 2), and version 1's, which had no
|
|
237
|
+
* backdrop. */
|
|
238
|
+
export const SPLAT_HEADER_BYTES = 56;
|
|
239
|
+
export const SPLAT_HEADER_BYTES_V1 = 48;
|
|
240
|
+
export const SPLAT_STRIDE = 16;
|
|
241
|
+
/** The backdrop a bake stores: an equirectangular picture this many texels
|
|
242
|
+
* round and half as many from the nadir to the zenith, or one texel round
|
|
243
|
+
* for a sky that is the same all the way round. */
|
|
244
|
+
export const SPLAT_BACKDROP_W = 512;
|
|
245
|
+
export const SPLAT_BACKDROP_H = 256;
|
|
246
|
+
/** The largest backdrop a reader takes, round and up. */
|
|
247
|
+
const BACKDROP_MAX_W = 1024;
|
|
248
|
+
const BACKDROP_MAX_H = 512;
|
|
249
|
+
/** Whether bytes are a splat file this version can read: version 2, or a
|
|
250
|
+
* version 1 file from before the backdrop. Checks the header and the length
|
|
251
|
+
* only: the records and the backdrop are numbers in fixed ranges, and there
|
|
252
|
+
* is nothing in one a reader could be hurt by. */
|
|
253
|
+
export function checkSplat(bytes) {
|
|
254
|
+
const no = (error) => ({ ok: false, count: 0, error });
|
|
255
|
+
if (bytes.byteLength < SPLAT_HEADER_BYTES_V1)
|
|
256
|
+
return no('shorter than its header');
|
|
257
|
+
for (let i = 0; i < SPLAT_MAGIC.length; i++) {
|
|
258
|
+
if (bytes[i] !== SPLAT_MAGIC[i])
|
|
259
|
+
return no('not an Oda splat');
|
|
260
|
+
}
|
|
261
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
262
|
+
const version = view.getUint16(4, true);
|
|
263
|
+
if (version !== 1 && version !== SPLAT_VERSION)
|
|
264
|
+
return no('a splat version this reader does not know');
|
|
265
|
+
const header = version === 1 ? SPLAT_HEADER_BYTES_V1 : SPLAT_HEADER_BYTES;
|
|
266
|
+
if (view.getUint16(6, true) !== header || bytes.byteLength < header)
|
|
267
|
+
return no('a header of the wrong size');
|
|
268
|
+
const count = view.getUint32(8, true);
|
|
269
|
+
if (count === 0)
|
|
270
|
+
return no('no discs');
|
|
271
|
+
let width = 0;
|
|
272
|
+
let height = 0;
|
|
273
|
+
if (version >= 2) {
|
|
274
|
+
width = view.getUint16(48, true);
|
|
275
|
+
height = view.getUint16(50, true);
|
|
276
|
+
if ((width === 0) !== (height === 0) || width > BACKDROP_MAX_W || height > BACKDROP_MAX_H) {
|
|
277
|
+
return no('a backdrop of a size this reader does not take');
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (bytes.byteLength !== header + count * SPLAT_STRIDE + width * height * 3)
|
|
281
|
+
return no('its length does not match its count');
|
|
282
|
+
if (bytes.byteLength > LIMITS.splatKb * 1024)
|
|
283
|
+
return no(`over ${LIMITS.splatKb} KB`);
|
|
284
|
+
for (let o = 12; o < 40; o += 4) {
|
|
285
|
+
if (!Number.isFinite(view.getFloat32(o, true)))
|
|
286
|
+
return no('bounds that are not numbers');
|
|
287
|
+
}
|
|
288
|
+
return { ok: true, count, version, backdrop: { width, height } };
|
|
289
|
+
}
|
|
290
|
+
// The kinds of file a planet carries, the asset ledger and its gates.
|
|
291
|
+
export * from './assets.js';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Caps the schema enforces, exported so the studio can stay inside them
|
|
3
|
+
* rather than writing documents its own validator would reject. */
|
|
4
|
+
export declare const MAX_ID_LENGTH = 80;
|
|
5
|
+
export declare const MAX_OBJECTS = 2000;
|
|
6
|
+
/** What the studio does to a model's size on import (normalizeImport in the
|
|
7
|
+
* studio's loadModel.ts, which cannot import this package and keeps its own
|
|
8
|
+
* copy of the rule): a model whose largest side is over `max` or under `min`
|
|
9
|
+
* units is scaled to `target`, unless its placement says normalize: false.
|
|
10
|
+
* Written down here so the docs, the agent's tools and the checks name the
|
|
11
|
+
* same numbers. */
|
|
12
|
+
export declare const AUTO_SIZE: {
|
|
13
|
+
readonly target: 3;
|
|
14
|
+
readonly max: 12;
|
|
15
|
+
readonly min: 0.375;
|
|
16
|
+
};
|
|
17
|
+
/** The group a placement falls into when scene.json names none: the id with
|
|
18
|
+
* the "-2", "-3" a collision suffix adds taken off, so oak, oak-2 and oak-3
|
|
19
|
+
* are one "oak" to the game's rules. An id that is nothing but a suffix keeps
|
|
20
|
+
* itself, since a kind cannot be empty. */
|
|
21
|
+
export declare function placementKind(id: string): string;
|
|
22
|
+
export declare const Placement: z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
asset: z.ZodString;
|
|
25
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
26
|
+
solid: z.ZodDefault<z.ZodBoolean>;
|
|
27
|
+
position: z.ZodDefault<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
28
|
+
rotation: z.ZodDefault<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
29
|
+
scale: z.ZodDefault<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
30
|
+
normalize: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
/** A placement as every consumer sees it: validateScene has filled the kind,
|
|
33
|
+
* so it is never absent past the parse. */
|
|
34
|
+
export type PlacementT = Omit<z.infer<typeof Placement>, 'kind'> & {
|
|
35
|
+
kind: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const SceneDoc: z.ZodObject<{
|
|
38
|
+
schema: z.ZodLiteral<"nowhere/scene@1">;
|
|
39
|
+
objects: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
asset: z.ZodString;
|
|
42
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
43
|
+
solid: z.ZodDefault<z.ZodBoolean>;
|
|
44
|
+
position: z.ZodDefault<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
45
|
+
rotation: z.ZodDefault<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
46
|
+
scale: z.ZodDefault<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
47
|
+
normalize: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
}, z.core.$strip>>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export type SceneDocT = Omit<z.infer<typeof SceneDoc>, 'objects'> & {
|
|
51
|
+
objects: PlacementT[];
|
|
52
|
+
};
|
|
53
|
+
export declare const EMPTY_SCENE: SceneDocT;
|
|
54
|
+
export interface SceneFinding {
|
|
55
|
+
path: string;
|
|
56
|
+
code: string;
|
|
57
|
+
message: string;
|
|
58
|
+
}
|
|
59
|
+
export type SceneResult = {
|
|
60
|
+
ok: true;
|
|
61
|
+
scene: SceneDocT;
|
|
62
|
+
findings: [];
|
|
63
|
+
} | {
|
|
64
|
+
ok: false;
|
|
65
|
+
scene: null;
|
|
66
|
+
findings: SceneFinding[];
|
|
67
|
+
};
|
|
68
|
+
/** Validates a scene document, with findings that point into it. A project with
|
|
69
|
+
* no scene.json has an empty scene, which is not an error. */
|
|
70
|
+
export declare function validateScene(raw: unknown): SceneResult;
|
|
71
|
+
/** A free id derived from a file name: "Oak Tree.glb" -> "oak-tree", then
|
|
72
|
+
* "oak-tree-2" and so on. */
|
|
73
|
+
export declare function nextPlacementId(objects: {
|
|
74
|
+
id: string;
|
|
75
|
+
}[], base: string): string;
|