oda-engine 0.0.0-stage → 0.1.0

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.
Files changed (204) hide show
  1. package/README.md +151 -2
  2. package/bin/nowhere.mjs +352 -0
  3. package/lib/account.mjs +57 -0
  4. package/lib/agentModules.mjs +57 -0
  5. package/lib/devServer.mjs +351 -0
  6. package/lib/headless.mjs +231 -0
  7. package/lib/headlessPreview.mjs +212 -0
  8. package/lib/keys.mjs +517 -0
  9. package/lib/make.mjs +855 -0
  10. package/lib/mcp.mjs +537 -0
  11. package/lib/open.mjs +22 -0
  12. package/lib/preview.mjs +87 -0
  13. package/lib/previewRpc.mjs +134 -0
  14. package/lib/project.mjs +359 -0
  15. package/lib/publishFlow.mjs +90 -0
  16. package/lib/resources.mjs +50 -0
  17. package/lib/rules.mjs +60 -0
  18. package/lib/scaffold.mjs +42 -0
  19. package/lib/setup.mjs +59 -0
  20. package/lib/tools.mjs +668 -0
  21. package/package.json +51 -4
  22. package/template/game.config.json +9 -0
  23. package/template/scene.json +4 -0
  24. package/template/src/main.ts +11 -0
  25. package/vendor/DOCS.md +447 -0
  26. package/vendor/agent/appRun.mjs +520 -0
  27. package/vendor/agent/assets/brief.mjs +242 -0
  28. package/vendor/agent/assets/collider.mjs +531 -0
  29. package/vendor/agent/assets/environments/index.mjs +12 -0
  30. package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
  31. package/vendor/agent/assets/fetch.mjs +168 -0
  32. package/vendor/agent/assets/footprint.mjs +13 -0
  33. package/vendor/agent/assets/gltf.mjs +547 -0
  34. package/vendor/agent/assets/hdr.mjs +269 -0
  35. package/vendor/agent/assets/imageOps.mjs +171 -0
  36. package/vendor/agent/assets/images/codex.mjs +307 -0
  37. package/vendor/agent/assets/images/fal.mjs +75 -0
  38. package/vendor/agent/assets/images/gemini.mjs +84 -0
  39. package/vendor/agent/assets/images/index.mjs +25 -0
  40. package/vendor/agent/assets/images/openai.mjs +75 -0
  41. package/vendor/agent/assets/images/stability.mjs +71 -0
  42. package/vendor/agent/assets/images/views.mjs +31 -0
  43. package/vendor/agent/assets/import.mjs +1352 -0
  44. package/vendor/agent/assets/inspect.mjs +465 -0
  45. package/vendor/agent/assets/jobs.mjs +196 -0
  46. package/vendor/agent/assets/ktx2.mjs +290 -0
  47. package/vendor/agent/assets/ledger.mjs +466 -0
  48. package/vendor/agent/assets/net.mjs +254 -0
  49. package/vendor/agent/assets/prices.json +39 -0
  50. package/vendor/agent/assets/providers/fal.mjs +115 -0
  51. package/vendor/agent/assets/providers/index.mjs +22 -0
  52. package/vendor/agent/assets/providers/meshy.mjs +119 -0
  53. package/vendor/agent/assets/providers/tripo.mjs +188 -0
  54. package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
  55. package/vendor/agent/assets/sources/index.mjs +23 -0
  56. package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
  57. package/vendor/agent/assets/sources/polypizza.mjs +121 -0
  58. package/vendor/agent/assets/splat.mjs +631 -0
  59. package/vendor/agent/assets/targets.mjs +122 -0
  60. package/vendor/agent/assets/tile.mjs +261 -0
  61. package/vendor/agent/assets/unzip.mjs +180 -0
  62. package/vendor/agent/blender/cleanup.py +360 -0
  63. package/vendor/agent/blender/convert.py +167 -0
  64. package/vendor/agent/blender/find.mjs +192 -0
  65. package/vendor/agent/blender/nw_export.py +104 -0
  66. package/vendor/agent/blender/nw_rubric.py +426 -0
  67. package/vendor/agent/blender/run.mjs +193 -0
  68. package/vendor/agent/blender/runner.py +252 -0
  69. package/vendor/agent/blender/sheet.py +743 -0
  70. package/vendor/agent/depth.mjs +134 -0
  71. package/vendor/agent/director/board.mjs +451 -0
  72. package/vendor/agent/director/contracts.mjs +663 -0
  73. package/vendor/agent/director/director.mjs +2365 -0
  74. package/vendor/agent/director/estimate.mjs +200 -0
  75. package/vendor/agent/director/gate.mjs +802 -0
  76. package/vendor/agent/director/limits.json +16 -0
  77. package/vendor/agent/director/methods.mjs +457 -0
  78. package/vendor/agent/director/policy.json +33 -0
  79. package/vendor/agent/director/prompts.mjs +244 -0
  80. package/vendor/agent/director/reading.mjs +341 -0
  81. package/vendor/agent/director/router.mjs +184 -0
  82. package/vendor/agent/director/seams.mjs +243 -0
  83. package/vendor/agent/director/session.mjs +643 -0
  84. package/vendor/agent/director/store.mjs +119 -0
  85. package/vendor/agent/director/taskGate.mjs +110 -0
  86. package/vendor/agent/director/teamLedger.mjs +118 -0
  87. package/vendor/agent/director/triage.mjs +63 -0
  88. package/vendor/agent/downloads.cjs +363 -0
  89. package/vendor/agent/flow.mjs +78 -0
  90. package/vendor/agent/guard.mjs +613 -0
  91. package/vendor/agent/host.mjs +1736 -0
  92. package/vendor/agent/language.mjs +58 -0
  93. package/vendor/agent/ledger.mjs +360 -0
  94. package/vendor/agent/locale.cjs +186 -0
  95. package/vendor/agent/loop/capacity.mjs +74 -0
  96. package/vendor/agent/loop/compose.mjs +127 -0
  97. package/vendor/agent/loop/gate.mjs +205 -0
  98. package/vendor/agent/loop/judge.mjs +189 -0
  99. package/vendor/agent/loop/levels.mjs +273 -0
  100. package/vendor/agent/loop/state.mjs +358 -0
  101. package/vendor/agent/notes.cjs +278 -0
  102. package/vendor/agent/pace.mjs +258 -0
  103. package/vendor/agent/panels.mjs +431 -0
  104. package/vendor/agent/prompt.mjs +342 -0
  105. package/vendor/agent/reference/board.mjs +410 -0
  106. package/vendor/agent/reference/compose.mjs +364 -0
  107. package/vendor/agent/reference/decode.mjs +56 -0
  108. package/vendor/agent/reference/facts.mjs +1874 -0
  109. package/vendor/agent/reference/png.mjs +107 -0
  110. package/vendor/agent/reference/records.mjs +63 -0
  111. package/vendor/agent/reference/web.mjs +252 -0
  112. package/vendor/agent/roles/artist.mjs +69 -0
  113. package/vendor/agent/roles/builder.mjs +79 -0
  114. package/vendor/agent/roles/checks.mjs +223 -0
  115. package/vendor/agent/roles/common.mjs +188 -0
  116. package/vendor/agent/roles/critic.mjs +171 -0
  117. package/vendor/agent/roles/index.mjs +39 -0
  118. package/vendor/agent/roles/modeller.mjs +142 -0
  119. package/vendor/agent/roles/qa.mjs +58 -0
  120. package/vendor/agent/roles/rubrics.mjs +79 -0
  121. package/vendor/agent/roles/sound.mjs +69 -0
  122. package/vendor/agent/rounds.cjs +333 -0
  123. package/vendor/agent/shared.mjs +284 -0
  124. package/vendor/agent/stopGate.mjs +574 -0
  125. package/vendor/agent/subagents.mjs +129 -0
  126. package/vendor/agent/tools/assets.mjs +499 -0
  127. package/vendor/agent/tools/blender.mjs +754 -0
  128. package/vendor/agent/tools/cards.mjs +479 -0
  129. package/vendor/agent/tools/choices.mjs +479 -0
  130. package/vendor/agent/tools/compose.mjs +74 -0
  131. package/vendor/agent/tools/environment.mjs +488 -0
  132. package/vendor/agent/tools/eyes.mjs +733 -0
  133. package/vendor/agent/tools/generate.mjs +338 -0
  134. package/vendor/agent/tools/guide.mjs +46 -0
  135. package/vendor/agent/tools/harness.mjs +193 -0
  136. package/vendor/agent/tools/image.mjs +643 -0
  137. package/vendor/agent/tools/index.mjs +162 -0
  138. package/vendor/agent/tools/look.mjs +578 -0
  139. package/vendor/agent/tools/loop.mjs +858 -0
  140. package/vendor/agent/tools/others.mjs +123 -0
  141. package/vendor/agent/tools/pictures.mjs +535 -0
  142. package/vendor/agent/tools/reference.mjs +366 -0
  143. package/vendor/agent/transcripts.mjs +118 -0
  144. package/vendor/agent-loop.mjs +602 -0
  145. package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
  146. package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
  147. package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
  148. package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
  149. package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
  150. package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
  151. package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
  152. package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
  153. package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
  154. package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
  155. package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
  156. package/vendor/auth.cjs +570 -0
  157. package/vendor/build.cjs +953 -0
  158. package/vendor/catalog.json +455 -0
  159. package/vendor/connectors.cjs +688 -0
  160. package/vendor/eyes.mjs +733 -0
  161. package/vendor/gameExports.json +1390 -0
  162. package/vendor/git.cjs +222 -0
  163. package/vendor/models.json +57 -0
  164. package/vendor/publish.cjs +1018 -0
  165. package/vendor/refBoard.cjs +301 -0
  166. package/vendor/schema/dist/assets.d.ts +335 -0
  167. package/vendor/schema/dist/assets.js +439 -0
  168. package/vendor/schema/dist/brief.d.ts +357 -0
  169. package/vendor/schema/dist/brief.js +302 -0
  170. package/vendor/schema/dist/common.d.ts +9 -0
  171. package/vendor/schema/dist/common.js +13 -0
  172. package/vendor/schema/dist/config.d.ts +406 -0
  173. package/vendor/schema/dist/config.js +355 -0
  174. package/vendor/schema/dist/contract.d.ts +599 -0
  175. package/vendor/schema/dist/contract.js +1146 -0
  176. package/vendor/schema/dist/index.d.ts +14 -0
  177. package/vendor/schema/dist/index.js +21 -0
  178. package/vendor/schema/dist/look.d.ts +463 -0
  179. package/vendor/schema/dist/look.js +681 -0
  180. package/vendor/schema/dist/lookStats.d.ts +230 -0
  181. package/vendor/schema/dist/lookStats.js +768 -0
  182. package/vendor/schema/dist/pilot.d.ts +32 -0
  183. package/vendor/schema/dist/pilot.js +44 -0
  184. package/vendor/schema/dist/publish.d.ts +214 -0
  185. package/vendor/schema/dist/publish.js +291 -0
  186. package/vendor/schema/dist/scene.d.ts +75 -0
  187. package/vendor/schema/dist/scene.js +120 -0
  188. package/vendor/schema/dist/skyLight.d.ts +141 -0
  189. package/vendor/schema/dist/skyLight.js +436 -0
  190. package/vendor/schema/dist/style.d.ts +131 -0
  191. package/vendor/schema/dist/style.js +155 -0
  192. package/vendor/schema/package.json +1 -0
  193. package/vendor/selectionPrompt.mjs +51 -0
  194. package/vendor/useTools.mjs +195 -0
  195. package/vendor/userMessage.mjs +26 -0
  196. package/web-dist/assets/GaussianSplatUtils-CB77cP9U.js +1 -0
  197. package/web-dist/assets/KTX2Loader-6OIWUF7s.js +2 -0
  198. package/web-dist/assets/SPZLoader-zYj0Alfv.js +1 -0
  199. package/web-dist/assets/gaussianSplat-CJTI1sEh.js +1 -0
  200. package/web-dist/assets/index-CcjyyQco.css +1 -0
  201. package/web-dist/assets/index-DMyJcoZJ.js +693 -0
  202. package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
  203. package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
  204. package/web-dist/index.html +34 -0
@@ -0,0 +1,531 @@
1
+ // A splat environment's collider: the mesh the walker stands on and walks
2
+ // into while the splat is what is seen. It comes with the splat (World Labs
3
+ // exports one per world, 100 to 200 thousand triangles) or is made over it
4
+ // (Blender, World Labs' Collider Builder), and goes into the planet as one
5
+ // GLB of bare triangles: no materials, no textures, no normals, since nothing
6
+ // ever draws it (ctx.assets.splat gives it a material that is not visible).
7
+ //
8
+ // It is baked into the same frame the splat was (splat.mjs transformSplat):
9
+ // metres, y up, the floor at y = 0, so the two sit together with no
10
+ // transform in the code. Over MAX_TRIANGLES it is simplified with meshopt,
11
+ // which keeps its shape within SIMPLIFY_METRES; the collisions test every
12
+ // triangle near the walker (three-mesh-bvh), so fewer is cheaper but a
13
+ // quarter of a million is still quick. Then it is walked (walkMap): where a
14
+ // walker gets to from the spawn, and where its floor ends over nothing.
15
+
16
+ import { Document } from '@gltf-transform/core'
17
+ import { simplify, weld } from '@gltf-transform/functions'
18
+ import { MeshoptSimplifier } from 'meshoptimizer'
19
+ import { boundsOf, countTriangles, gltfIO, readGltf, validateGlb } from './gltf.mjs'
20
+
21
+ export const MAX_TRIANGLES = 250_000
22
+ /** How far simplifying may move a surface, in metres: meshopt's error is a
23
+ * fraction of the mesh's radius, so a fixed fraction let a 100 m capture's
24
+ * floor move half a metre, enough to float or sink the walker. */
25
+ const SIMPLIFY_METRES = 0.02
26
+
27
+ const round = (v, d = 3) => Math.round(v * 10 ** d) / 10 ** d
28
+
29
+ /** A column-major 4 x 4 matrix times a point. */
30
+ function apply(m, x, y, z, out, o) {
31
+ out[o] = m[0] * x + m[4] * y + m[8] * z + m[12]
32
+ out[o + 1] = m[1] * x + m[5] * y + m[9] * z + m[13]
33
+ out[o + 2] = m[2] * x + m[6] * y + m[10] * z + m[14]
34
+ }
35
+
36
+ /**
37
+ * The collider for a splat: every triangle of the file's default scene, in
38
+ * world space, then scaled, turned (a half turn about x when `flip`) and
39
+ * moved as the splat was, as one GLB, and its walk map from `start` (the
40
+ * spawn) inside `limit` (the map's half side, less World's margin).
41
+ *
42
+ * @returns {Promise<{ ok: true, glb: Uint8Array, triangles: number, before: number, bounds: { min: number[], max: number[], size: number[] }, walk: ReturnType<typeof walkMap>, steps: { op: string, detail: string }[] } | { ok: false, error: string }>}
43
+ */
44
+ export async function prepareCollider(file, { flip = false, scale = 1, offset = [0, 0, 0], maxTriangles = MAX_TRIANGLES, start = null, limit = Infinity } = {}) {
45
+ let doc
46
+ try {
47
+ doc = await readGltf(file)
48
+ } catch (err) {
49
+ return { ok: false, error: `the collider could not be read: ${err?.message ?? err}` }
50
+ }
51
+ const before = countTriangles(doc)
52
+ if (before === 0) return { ok: false, error: 'the collider has no triangles to stand on' }
53
+ const root = doc.getRoot()
54
+ const scene = root.getDefaultScene() ?? root.listScenes()[0]
55
+ const chunks = []
56
+ let vertices = 0
57
+ let skipped = 0
58
+ scene.traverse((node) => {
59
+ const mesh = node.getMesh()
60
+ if (!mesh) return
61
+ const m = node.getWorldMatrix()
62
+ for (const prim of mesh.listPrimitives()) {
63
+ // Triangles only: a collider's lines or points stop nothing.
64
+ if (prim.getMode() !== 4) {
65
+ skipped++
66
+ continue
67
+ }
68
+ const pos = prim.getAttribute('POSITION')
69
+ if (!pos) continue
70
+ const n = pos.getCount()
71
+ const out = new Float32Array(n * 3)
72
+ const v = [0, 0, 0]
73
+ for (let i = 0; i < n; i++) {
74
+ pos.getElement(i, v)
75
+ apply(m, v[0], v[1], v[2], out, i * 3)
76
+ const x = out[i * 3] * scale
77
+ const y = out[i * 3 + 1] * scale
78
+ const z = out[i * 3 + 2] * scale
79
+ out[i * 3] = x + offset[0]
80
+ out[i * 3 + 1] = (flip ? -y : y) + offset[1]
81
+ out[i * 3 + 2] = (flip ? -z : z) + offset[2]
82
+ }
83
+ const idx = prim.getIndices()
84
+ const indices = idx ? Uint32Array.from(idx.getArray()) : Uint32Array.from({ length: n }, (_, i) => i)
85
+ // The node's own mirror (a negative scale) turns its triangles inside
86
+ // out; a half turn does not. Either way the collision tests both faces.
87
+ chunks.push({ positions: out, indices, base: vertices })
88
+ vertices += n
89
+ }
90
+ })
91
+ if (chunks.length === 0) return { ok: false, error: 'the collider has no triangle meshes' }
92
+ const positions = new Float32Array(vertices * 3)
93
+ const indexCount = chunks.reduce((k, c) => k + c.indices.length, 0)
94
+ const indices = new Uint32Array(indexCount)
95
+ let at = 0
96
+ for (const c of chunks) {
97
+ positions.set(c.positions, c.base * 3)
98
+ for (let i = 0; i < c.indices.length; i++) indices[at + i] = c.indices[i] + c.base
99
+ at += c.indices.length
100
+ }
101
+
102
+ const out = new Document()
103
+ const buffer = out.createBuffer()
104
+ const position = out.createAccessor('position').setType('VEC3').setArray(positions).setBuffer(buffer)
105
+ const index = out.createAccessor('index').setType('SCALAR').setArray(vertices < 65536 ? Uint16Array.from(indices) : indices).setBuffer(buffer)
106
+ const prim = out.createPrimitive().setAttribute('POSITION', position).setIndices(index)
107
+ const mesh = out.createMesh('collider').addPrimitive(prim)
108
+ const node = out.createNode('collider').setMesh(mesh)
109
+ out.createScene('collider').addChild(node)
110
+ out.getRoot().setDefaultScene(out.getRoot().listScenes()[0])
111
+
112
+ const steps = [
113
+ {
114
+ op: 'collider',
115
+ detail: `${before.toLocaleString('en-US')} triangles in world space${scale !== 1 ? `, scaled ${round(scale, 4)}` : ''}${flip ? ', turned upright (y-down to y-up)' : ''}, moved by ${offset.map((v) => round(v)).join(', ')} m; materials, normals and textures dropped${skipped ? `; ${skipped} primitives that are not triangles left out` : ''}`,
116
+ },
117
+ ]
118
+ await out.transform(weld())
119
+ let triangles = countTriangles(out)
120
+ if (triangles > maxTriangles) {
121
+ await MeshoptSimplifier.ready
122
+ const b0 = boundsOf(out)
123
+ const radius = b0 ? Math.hypot(...b0.size) / 2 : 1
124
+ const error = Math.min(0.01, SIMPLIFY_METRES / Math.max(radius, 1e-6))
125
+ await out.transform(simplify({ simplifier: MeshoptSimplifier, ratio: maxTriangles / triangles, error }))
126
+ const after = countTriangles(out)
127
+ steps.push({ op: 'simplify', detail: `${triangles.toLocaleString('en-US')} to ${after.toLocaleString('en-US')} triangles (meshopt, its surfaces within ${Math.round(Math.min(SIMPLIFY_METRES, radius * 0.01) * 1000)} mm)` })
128
+ triangles = after
129
+ }
130
+ const io = await gltfIO()
131
+ const glb = await io.writeBinary(out)
132
+ const checked = await validateGlb(glb)
133
+ if (checked.numErrors > 0) return { ok: false, error: `the collider GLB did not pass the glTF validator (${checked.errors[0]})` }
134
+ const b = boundsOf(out)
135
+ // The map is a report: a collider it cannot walk is still a collider.
136
+ let walk = null
137
+ try {
138
+ const prim = out.getRoot().listMeshes()[0]?.listPrimitives()[0]
139
+ const p = prim?.getAttribute('POSITION')?.getArray()
140
+ const i = prim?.getIndices()?.getArray()
141
+ if (p && i) walk = walkMap(p, i, { start, limit })
142
+ } catch {
143
+ walk = null
144
+ }
145
+ return {
146
+ ok: true,
147
+ glb,
148
+ triangles,
149
+ before,
150
+ bounds: b ? { min: b.min.map((v) => round(v)), max: b.max.map((v) => round(v)), size: b.size.map((v) => round(v)) } : null,
151
+ walk,
152
+ steps,
153
+ }
154
+ }
155
+
156
+ // ---------------------------------------------------------------- walking
157
+
158
+ /** The body World walks (world.ts) as the map sees it: what it steps up
159
+ * (0.3 m), its height (1.6 m), the furthest it steps down at a held edge
160
+ * (2 m, World's EDGE_DROP), the slope it stands on (a surface whose normal
161
+ * is more than 0.55 up, World's FLOOR_UP), and the map's cells: a quarter
162
+ * metre, larger for a large collider so it stays under maxCells. A
163
+ * collider too detailed to sample in maxSamples points is not mapped. */
164
+ const WALK = { step: 0.3, height: 1.6, drop: 2, slope: 0.55, cell: 0.25, maxCells: 600_000, maxSamples: 8_000_000 }
165
+ /** Heights in a cell are kept to 2 cm. */
166
+ const WALK_Q = 0.02
167
+ /** The longest stretch of open edge said as one place, in metres. */
168
+ const WALK_PIECE = 6
169
+ /** The shortest stretch said at all: about the body's width (0.72 m). */
170
+ const WALK_WIDE = 0.75
171
+ const N4 = [
172
+ [1, 0],
173
+ [-1, 0],
174
+ [0, 1],
175
+ [0, -1],
176
+ ]
177
+
178
+ /**
179
+ * Where a walker can go on a collider in the space's frame, walked from
180
+ * `start` (a body's middle, as config.player.spawn is) the way World walks
181
+ * it: across floor it can step onto, round what stands in its way, and up
182
+ * to the edges where the floor ends. Those open edges are where a visitor
183
+ * would walk off into the void under a splat (World Labs' example kitchen
184
+ * has a doorway onto nothing and floor that runs out at two sides, where
185
+ * the collider only runs on down as the outside of a wall); ctx.assets.splat
186
+ * holds the walker at them unless told not to (world.ts noFloorNear, the
187
+ * same rule), and the import names them so the agent knows where its space
188
+ * ends.
189
+ *
190
+ * Every triangle is sampled at half a cell into the cells it covers, each
191
+ * sample a height and whether it is something to stand on. A cell is walked
192
+ * into when it has a floor within a step up or EDGE_DROP down of the one
193
+ * walked from and nothing between that floor and head height in it or its
194
+ * four neighbours (the body is 0.72 m wide, about three cells). A cell with
195
+ * no such floor and nothing in the way is an open edge. Past `limit` (the
196
+ * map's edge, which World holds the walker inside) nothing is walked.
197
+ *
198
+ * @param {Float32Array} positions x, y, z in metres, y up
199
+ * @param {Uint32Array | Uint16Array} indices triangles
200
+ * @param {{ start?: number[] | null, limit?: number }} opts
201
+ * @returns {null | { cell: number, start: number[], spawnOnFloor: boolean, area: number, bounds: { min: number[], max: number[] }, openEdge: number, openEdges: { at: number[], length: number, walked: boolean }[], openPieces: number }}
202
+ */
203
+ export function walkMap(positions, indices, { start = null, limit = Infinity } = {}) {
204
+ let minX = Infinity
205
+ let minY = Infinity
206
+ let minZ = Infinity
207
+ let maxX = -Infinity
208
+ let maxZ = -Infinity
209
+ for (let i = 0; i < positions.length; i += 3) {
210
+ const x = positions[i]
211
+ const y = positions[i + 1]
212
+ const z = positions[i + 2]
213
+ if (x < minX) minX = x
214
+ if (x > maxX) maxX = x
215
+ if (y < minY) minY = y
216
+ if (z < minZ) minZ = z
217
+ if (z > maxZ) maxZ = z
218
+ }
219
+ if (!Number.isFinite(minX)) return null
220
+ let cell = WALK.cell
221
+ const cellsAt = (c) => (Math.floor((maxX - minX) / c) + 3) * (Math.floor((maxZ - minZ) / c) + 3)
222
+ while (cellsAt(cell) > WALK.maxCells) cell *= 1.25
223
+ // A ring of empty cells round the collider: past its last triangle is the void.
224
+ const nx = Math.floor((maxX - minX) / cell) + 3
225
+ const nz = Math.floor((maxZ - minZ) / cell) + 3
226
+ const x0 = minX - cell
227
+ const z0 = minZ - cell
228
+ const cells = nx * nz
229
+
230
+ // Every sample as one number, cell then height then whether it is floor,
231
+ // so one sort groups them by cell in height order.
232
+ const YQ = 2 ** 20
233
+ let keys = new Float64Array(1 << 20)
234
+ let n = 0
235
+ const push = (x, y, z, floor) => {
236
+ const ix = Math.floor((x - x0) / cell)
237
+ const iz = Math.floor((z - z0) / cell)
238
+ const yq = Math.min(YQ - 1, Math.max(0, Math.round((y - minY) / WALK_Q)))
239
+ if (n === keys.length) {
240
+ const more = new Float64Array(keys.length * 2)
241
+ more.set(keys)
242
+ keys = more
243
+ }
244
+ keys[n++] = (iz * nx + ix) * YQ * 2 + yq * 2 + floor
245
+ }
246
+ const tris = Math.floor(indices.length / 3)
247
+ let planned = 0
248
+ for (let t = 0; t < tris; t++) {
249
+ const a = indices[t * 3] * 3
250
+ const b = indices[t * 3 + 1] * 3
251
+ const c = indices[t * 3 + 2] * 3
252
+ const ax = positions[a]
253
+ const ay = positions[a + 1]
254
+ const az = positions[a + 2]
255
+ const e1x = positions[b] - ax
256
+ const e1y = positions[b + 1] - ay
257
+ const e1z = positions[b + 2] - az
258
+ const e2x = positions[c] - ax
259
+ const e2y = positions[c + 1] - ay
260
+ const e2z = positions[c + 2] - az
261
+ const cx = e1y * e2z - e1z * e2y
262
+ const cy = e1z * e2x - e1x * e2z
263
+ const cz = e1x * e2y - e1y * e2x
264
+ const len = Math.hypot(cx, cy, cz)
265
+ if (len < 1e-12) continue
266
+ const floor = Math.abs(cy) / len > WALK.slope ? 1 : 0
267
+ const longest = Math.max(Math.hypot(e1x, e1y, e1z), Math.hypot(e2x, e2y, e2z), Math.hypot(e2x - e1x, e2y - e1y, e2z - e1z))
268
+ const sub = Math.max(1, Math.ceil(longest / (cell * 0.5)))
269
+ planned += ((sub + 1) * (sub + 2)) / 2
270
+ if (planned > WALK.maxSamples) return null
271
+ for (let i = 0; i <= sub; i++) {
272
+ for (let j = 0; j <= sub - i; j++) {
273
+ const u = i / sub
274
+ const v = j / sub
275
+ push(ax + e1x * u + e2x * v, ay + e1y * u + e2y * v, az + e1z * u + e2z * v, floor)
276
+ }
277
+ }
278
+ }
279
+ const sorted = keys.subarray(0, n).sort()
280
+
281
+ // Per cell, its heights in order and which of them are floor.
282
+ const first = new Int32Array(cells + 1)
283
+ const ys = new Float32Array(n)
284
+ const floors = new Uint8Array(n)
285
+ let m = 0
286
+ let last = -1
287
+ for (let k = 0; k < n; k++) {
288
+ if (sorted[k] === last) continue
289
+ last = sorted[k]
290
+ const c = Math.floor(last / (YQ * 2))
291
+ const rest = last - c * YQ * 2
292
+ ys[m] = minY + Math.floor(rest / 2) * WALK_Q
293
+ floors[m] = rest % 2
294
+ first[c + 1]++
295
+ m++
296
+ }
297
+ for (let c = 0; c < cells; c++) first[c + 1] += first[c]
298
+
299
+ /** The index of the first height in cell c above y, in [first[c], first[c + 1]]. */
300
+ const above = (c, y) => {
301
+ let lo = first[c]
302
+ let hi = first[c + 1]
303
+ while (lo < hi) {
304
+ const mid = (lo + hi) >> 1
305
+ if (ys[mid] <= y) lo = mid + 1
306
+ else hi = mid
307
+ }
308
+ return lo
309
+ }
310
+ /** The highest floor in cell c no more than a step above y, or null. */
311
+ const floorUnder = (c, y) => {
312
+ for (let k = above(c, y + WALK.step) - 1; k >= first[c]; k--) if (floors[k]) return ys[k]
313
+ return null
314
+ }
315
+ /** Something between a step above floor f and head height in cell c. */
316
+ const blocks = (c, f) => {
317
+ const k = above(c, f + WALK.step)
318
+ return k < first[c + 1] && ys[k] < f + WALK.height
319
+ }
320
+ const centre = (c) => [x0 + ((c % nx) + 0.5) * cell, z0 + (Math.floor(c / nx) + 0.5) * cell]
321
+
322
+ // Where the walk starts: the spawn's floor, or the nearest floor to it,
323
+ // or the floor nearest the middle at y = 0 (asset_import's floor).
324
+ let s = null
325
+ let sf = null
326
+ let spawnOnFloor = false
327
+ if (Array.isArray(start) && start.length === 3 && start.every(Number.isFinite)) {
328
+ const feet = start[1] - 0.8
329
+ const ix = Math.floor((start[0] - x0) / cell)
330
+ const iz = Math.floor((start[2] - z0) / cell)
331
+ if (ix >= 0 && ix < nx && iz >= 0 && iz < nz) {
332
+ const f = floorUnder(iz * nx + ix, feet)
333
+ if (f !== null) {
334
+ s = iz * nx + ix
335
+ sf = f
336
+ spawnOnFloor = true
337
+ }
338
+ }
339
+ for (let r = 1; s === null && r <= Math.ceil(3 / cell); r++) {
340
+ for (let dz = -r; dz <= r && s === null; dz++) {
341
+ for (let dx = -r; dx <= r && s === null; dx++) {
342
+ if (Math.max(Math.abs(dx), Math.abs(dz)) !== r) continue
343
+ const jx = ix + dx
344
+ const jz = iz + dz
345
+ if (jx < 0 || jx >= nx || jz < 0 || jz >= nz) continue
346
+ const f = floorUnder(jz * nx + jx, feet)
347
+ if (f !== null && f > feet - WALK.drop) {
348
+ s = jz * nx + jx
349
+ sf = f
350
+ }
351
+ }
352
+ }
353
+ }
354
+ }
355
+ if (s === null) {
356
+ let best = Infinity
357
+ for (let c = 0; c < cells; c++) {
358
+ const f = floorUnder(c, 0.5)
359
+ if (f === null || f < -0.5) continue
360
+ const [x, z] = centre(c)
361
+ const d = x * x + z * z
362
+ if (d < best) {
363
+ best = d
364
+ s = c
365
+ sf = f
366
+ }
367
+ }
368
+ }
369
+ if (s === null) return null
370
+
371
+ // The walk: each cell at the floor it was reached on (a second level over
372
+ // the same cell, a balcony over a room, is a floor of its own).
373
+ const reached = new Float32Array(cells).fill(NaN)
374
+ const levels = new Map()
375
+ const seen = (c, f) => {
376
+ if (Number.isNaN(reached[c])) return false
377
+ if (Math.abs(reached[c] - f) < WALK.height) return true
378
+ return (levels.get(c) ?? []).some((g) => Math.abs(g - f) < WALK.height)
379
+ }
380
+ const mark = (c, f) => {
381
+ if (Number.isNaN(reached[c])) reached[c] = f
382
+ else levels.set(c, [...(levels.get(c) ?? []), f])
383
+ }
384
+ const beyond = (c) => {
385
+ const [x, z] = centre(c)
386
+ return Math.abs(x) > limit || Math.abs(z) > limit
387
+ }
388
+ const queue = [s, sf]
389
+ mark(s, sf)
390
+ let count = 0
391
+ const lo = [Infinity, Infinity]
392
+ const hi = [-Infinity, -Infinity]
393
+ for (let q = 0; q < queue.length; q += 2) {
394
+ const c = queue[q]
395
+ const f = queue[q + 1]
396
+ count++
397
+ const [x, z] = centre(c)
398
+ lo[0] = Math.min(lo[0], x)
399
+ lo[1] = Math.min(lo[1], z)
400
+ hi[0] = Math.max(hi[0], x)
401
+ hi[1] = Math.max(hi[1], z)
402
+ const ix = c % nx
403
+ const iz = Math.floor(c / nx)
404
+ for (const [dx, dz] of N4) {
405
+ const jx = ix + dx
406
+ const jz = iz + dz
407
+ if (jx < 0 || jx >= nx || jz < 0 || jz >= nz) continue
408
+ const nb = jz * nx + jx
409
+ if (beyond(nb)) continue
410
+ const g = floorUnder(nb, f)
411
+ if (g === null || g < f - WALK.drop || blocks(nb, g)) continue
412
+ let narrow = false
413
+ for (const [ex, ez] of N4) {
414
+ const kx = jx + ex
415
+ const kz = jz + ez
416
+ if (kx >= 0 && kx < nx && kz >= 0 && kz < nz && blocks(kz * nx + kx, g)) narrow = true
417
+ }
418
+ if (narrow || seen(nb, g)) continue
419
+ mark(nb, g)
420
+ queue.push(nb, g)
421
+ }
422
+ }
423
+
424
+ // The open edges: every floor from EDGE_DROP below the start to a counter's
425
+ // height above it (a walker gets onto those in a generated collider's
426
+ // clutter, where World's push-out lifts it, even under a low ceiling),
427
+ // beside a cell where a body stepping over would find no floor: nothing,
428
+ // the side of something, or a floor more than EDGE_DROP down. Not only
429
+ // the cells the walk reached: a generated collider's crossing triangles
430
+ // carry a walker where no step would (World Labs' kitchen threw it onto a
431
+ // counter top, and off its end into nothing).
432
+ const edge = new Float32Array(cells).fill(NaN)
433
+ for (let c = 0; c < cells; c++) {
434
+ if (first[c] === first[c + 1] || beyond(c)) continue
435
+ for (let k = first[c]; k < first[c + 1]; k++) {
436
+ const y = ys[k]
437
+ if (!floors[k] || y < sf - WALK.drop || y > sf + 1) continue
438
+ // The top of each floor only: the next floor above it is not within a step.
439
+ let top = true
440
+ for (let j = k + 1; j < first[c + 1] && ys[j] <= y + WALK.step; j++) if (floors[j]) top = false
441
+ if (!top) continue
442
+ const ix = c % nx
443
+ const iz = Math.floor(c / nx)
444
+ for (const [dx, dz] of N4) {
445
+ const jx = ix + dx
446
+ const jz = iz + dz
447
+ const nb = jz * nx + jx
448
+ const off = jx < 0 || jx >= nx || jz < 0 || jz >= nz
449
+ if (!off && beyond(nb)) continue
450
+ const g = off ? null : floorUnder(nb, y)
451
+ if ((g === null || g < y - WALK.drop) && (off || !blocks(nb, y))) {
452
+ edge[c] = Number.isNaN(edge[c]) ? y : Math.max(edge[c], y)
453
+ break
454
+ }
455
+ }
456
+ }
457
+ }
458
+
459
+ // As stretches: edge cells that touch, corners included, cut into pieces
460
+ // no longer than WALK_PIECE so a rim round a whole floor is said where it
461
+ // runs, not at its middle; each with where it is, how long, how high, and
462
+ // whether the walk reached it on foot. A stretch shorter than the body is
463
+ // wide is left out: in a generated collider those are the tops of walls
464
+ // and sills, a cell or two each, where nobody stands.
465
+ const near = (k) => {
466
+ const kx = k % nx
467
+ const kz = Math.floor(k / nx)
468
+ for (let dz = -1; dz <= 1; dz++) {
469
+ for (let dx = -1; dx <= 1; dx++) {
470
+ const jx = kx + dx
471
+ const jz = kz + dz
472
+ if (jx >= 0 && jx < nx && jz >= 0 && jz < nz && !Number.isNaN(reached[jz * nx + jx])) return true
473
+ }
474
+ }
475
+ return false
476
+ }
477
+ const pieces = new Map()
478
+ const taken = new Uint8Array(cells)
479
+ let cluster = 0
480
+ for (let c = 0; c < cells; c++) {
481
+ if (Number.isNaN(edge[c]) || taken[c]) continue
482
+ cluster++
483
+ const group = [c]
484
+ taken[c] = 1
485
+ for (let g = 0; g < group.length; g++) {
486
+ const k = group[g]
487
+ const kx = k % nx
488
+ const kz = Math.floor(k / nx)
489
+ for (let dz = -1; dz <= 1; dz++) {
490
+ for (let dx = -1; dx <= 1; dx++) {
491
+ const jx = kx + dx
492
+ const jz = kz + dz
493
+ if (jx < 0 || jx >= nx || jz < 0 || jz >= nz) continue
494
+ const j = jz * nx + jx
495
+ if (!Number.isNaN(edge[j]) && !taken[j]) {
496
+ taken[j] = 1
497
+ group.push(j)
498
+ }
499
+ }
500
+ }
501
+ }
502
+ if (group.length * cell < WALK_WIDE) continue
503
+ for (const k of group) {
504
+ const [x, z] = centre(k)
505
+ const key = `${cluster}:${Math.floor(x / WALK_PIECE)}:${Math.floor(z / WALK_PIECE)}`
506
+ const piece = pieces.get(key) ?? { n: 0, x: 0, y: 0, z: 0, walked: false }
507
+ piece.n++
508
+ piece.x += x
509
+ piece.y += edge[k]
510
+ piece.z += z
511
+ if (!piece.walked && near(k)) piece.walked = true
512
+ pieces.set(key, piece)
513
+ }
514
+ }
515
+ const stretches = [...pieces.values()].map((p) => ({ at: [round(p.x / p.n, 2), round(p.y / p.n, 2), round(p.z / p.n, 2)], length: round(p.n * cell, 2), walked: p.walked }))
516
+ // Those the walk reached first, and of them the nearest the start: where a
517
+ // visitor meets one first is what matters most.
518
+ const [sx, sz] = centre(s)
519
+ const away = (e) => Math.hypot(e.at[0] - sx, e.at[2] - sz)
520
+ stretches.sort((a, b) => Number(b.walked) - Number(a.walked) || away(a) - away(b))
521
+ return {
522
+ cell: round(cell, 3),
523
+ start: [round(sx, 2), round(sf, 2), round(sz, 2)],
524
+ spawnOnFloor,
525
+ area: round(count * cell * cell, 1),
526
+ bounds: { min: [round(lo[0], 2), round(lo[1], 2)], max: [round(hi[0], 2), round(hi[1], 2)] },
527
+ openEdge: round(stretches.reduce((t, e) => t + e.length, 0), 1),
528
+ openEdges: stretches.slice(0, 8),
529
+ openPieces: stretches.length,
530
+ }
531
+ }
@@ -0,0 +1,12 @@
1
+ // The world generators environment_generate can run, behind one shape:
2
+ // { id, label, connector, envVar, keyUrl, billingUrl, hosts, fileHosts,
3
+ // models, inputs, resolutions, defaultModel(), licenseOf(model),
4
+ // price(input, model, prices), credits?(...), submit(...), poll(...),
5
+ // files(world, { resolution }) }
6
+ // World Labs' Marble first. Each is only ever called after the creator
7
+ // approved a cost card that covers it, and every check drives them with a
8
+ // fake fetch.
9
+
10
+ import { worldlabs } from './worldlabs.mjs'
11
+
12
+ export const ENVIRONMENT_PROVIDERS = { worldlabs }