@threenative/terrain 0.1.7 → 0.1.8

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 (127) hide show
  1. package/AGENT_GUIDE.md +19 -4
  2. package/dist/editor/index.d.ts +160 -5
  3. package/dist/editor/index.js +3783 -1406
  4. package/dist/editor/server.d.ts +2 -2
  5. package/dist/editor/server.js +555 -121
  6. package/dist/editor/worker.d.ts +33 -1
  7. package/dist/editor/worker.js +444 -110
  8. package/dist/export.d.ts +11 -9
  9. package/dist/export.js +22 -34
  10. package/dist/index.d.ts +727 -73
  11. package/dist/index.js +2434 -553
  12. package/dist/kit.d.ts +56 -0
  13. package/dist/kit.js +2524 -0
  14. package/dist/mcp/cook-child.d.ts +2 -0
  15. package/dist/mcp/cook-child.js +3705 -0
  16. package/dist/mcp/server.d.ts +7 -0
  17. package/dist/mcp/server.js +3279 -0
  18. package/dist/{server-ByM2hmYJ.d.ts → server-C8Ydr_IM.d.ts} +3 -2
  19. package/dist/starter.d.ts +143 -0
  20. package/dist/starter.js +1030 -0
  21. package/dist/{terrain-gPnkCU6S.d.ts → terrain-B3DkduPw.d.ts} +3 -2
  22. package/dist/three.d.ts +1 -1
  23. package/dist/{types-Ant8-Axc.d.ts → types-CPYAc9vo.d.ts} +13 -4
  24. package/dist/world-package-B7KGYIou.d.ts +94 -0
  25. package/package.json +28 -6
  26. package/starter/alpine/README.md +77 -1
  27. package/starter/alpine/bake.mjs +4 -116
  28. package/starter/alpine/biome.data.json +114 -0
  29. package/starter/alpine/heightmap.r16 +0 -0
  30. package/starter/alpine/recipe.json +3 -66051
  31. package/starter/alpine/world.ts +45 -293
  32. package/starter/coastal/README.md +77 -1
  33. package/starter/coastal/bake.mjs +4 -116
  34. package/starter/coastal/biome.data.json +135 -0
  35. package/starter/coastal/heightmap.r16 +0 -0
  36. package/starter/coastal/recipe.json +3 -66051
  37. package/starter/coastal/sea.ts +49 -16
  38. package/starter/coastal/world.ts +53 -318
  39. package/starter/desert/README.md +77 -1
  40. package/starter/desert/bake.mjs +4 -116
  41. package/starter/desert/biome.data.json +114 -0
  42. package/starter/desert/heightmap.r16 +0 -0
  43. package/starter/desert/recipe.json +3 -66051
  44. package/starter/desert/world.ts +45 -293
  45. package/starter/forest/README.md +84 -4
  46. package/starter/forest/assets.json +32 -0
  47. package/starter/forest/bake.mjs +6 -116
  48. package/starter/forest/biome.data.json +150 -0
  49. package/starter/forest/heightmap.r16 +0 -0
  50. package/starter/forest/recipe.json +192 -4428
  51. package/starter/forest/sky.ts +11 -0
  52. package/starter/forest/water.ts +30 -20
  53. package/starter/forest/world.ts +86 -322
  54. package/starter/tundra/README.md +77 -1
  55. package/starter/tundra/bake.mjs +4 -116
  56. package/starter/tundra/biome.data.json +131 -0
  57. package/starter/tundra/heightmap.r16 +0 -0
  58. package/starter/tundra/recipe.json +18 -66066
  59. package/starter/tundra/world.ts +65 -319
  60. package/starter-assets.json +6 -0
  61. package/{starter-assets/credits.json → starter-credits.json} +12 -105
  62. package/starter-assets/bark_brown_02/bark_brown_02_diff_1k.jpg +0 -0
  63. package/starter-assets/bark_brown_02/bark_brown_02_nor_gl_1k.jpg +0 -0
  64. package/starter-assets/bark_brown_02/bark_brown_02_rough_1k.jpg +0 -0
  65. package/starter-assets/boulder_01/boulder-mid.glb +0 -0
  66. package/starter-assets/boulder_01/boulder-near.glb +0 -0
  67. package/starter-assets/cliff_side/cliff_side_ao_1k.jpg +0 -0
  68. package/starter-assets/cliff_side/cliff_side_diff_1k.jpg +0 -0
  69. package/starter-assets/cliff_side/cliff_side_nor_gl_1k.jpg +0 -0
  70. package/starter-assets/cliff_side/cliff_side_rough_1k.jpg +0 -0
  71. package/starter-assets/fern_02/fern_02_alpha_512.png +0 -0
  72. package/starter-assets/fern_02/fern_02_diff_512.jpg +0 -0
  73. package/starter-assets/fern_02/fern_02_nor_gl_512.jpg +0 -0
  74. package/starter-assets/fir_tree_01/fir-b-lod1.glb +0 -0
  75. package/starter-assets/fir_tree_01/fir-b-lod2.glb +0 -0
  76. package/starter-assets/fir_tree_01/fir-c-lod1.glb +0 -0
  77. package/starter-assets/fir_tree_01/fir-c-lod2.glb +0 -0
  78. package/starter-assets/fir_tree_01/fir_tree_01_twig_arm_1k.jpg +0 -0
  79. package/starter-assets/fir_tree_01/fir_tree_01_twig_diff_1k.jpg +0 -0
  80. package/starter-assets/fir_tree_01/fir_tree_01_twig_nor_gl_1k.jpg +0 -0
  81. package/starter-assets/forest_ground_04/forest_ground_04_ao_1k.jpg +0 -0
  82. package/starter-assets/forest_ground_04/forest_ground_04_diff_1k.jpg +0 -0
  83. package/starter-assets/forest_ground_04/forest_ground_04_nor_gl_1k.jpg +0 -0
  84. package/starter-assets/forest_ground_04/forest_ground_04_rough_1k.jpg +0 -0
  85. package/starter-assets/forest_leaves_02/forest_leaves_02_arm_512.jpg +0 -0
  86. package/starter-assets/forest_leaves_02/forest_leaves_02_diff_512.jpg +0 -0
  87. package/starter-assets/forest_leaves_02/forest_leaves_02_nor_gl_512.jpg +0 -0
  88. package/starter-assets/grass_medium_02/grass_medium_02_alpha_512.png +0 -0
  89. package/starter-assets/grass_medium_02/grass_medium_02_diff_512.jpg +0 -0
  90. package/starter-assets/grass_medium_02/grass_medium_02_nor_gl_512.jpg +0 -0
  91. package/starter-assets/hdri/kloofendal_48d_partly_cloudy_1k.hdr +0 -0
  92. package/starter-assets/leafy_grass/leafy_grass_ao_1k.jpg +0 -0
  93. package/starter-assets/leafy_grass/leafy_grass_diff_1k.jpg +0 -0
  94. package/starter-assets/leafy_grass/leafy_grass_nor_gl_1k.jpg +0 -0
  95. package/starter-assets/leafy_grass/leafy_grass_rough_1k.jpg +0 -0
  96. package/starter-assets/lichen_rock/lichen_rock_arm_512.jpg +0 -0
  97. package/starter-assets/lichen_rock/lichen_rock_diff_512.jpg +0 -0
  98. package/starter-assets/lichen_rock/lichen_rock_nor_gl_512.jpg +0 -0
  99. package/starter-assets/mossy_rock/mossy_rock_ao_1k.jpg +0 -0
  100. package/starter-assets/mossy_rock/mossy_rock_diff_1k.jpg +0 -0
  101. package/starter-assets/mossy_rock/mossy_rock_nor_gl_1k.jpg +0 -0
  102. package/starter-assets/mossy_rock/mossy_rock_rough_1k.jpg +0 -0
  103. package/starter-assets/needle-atlas.png +0 -0
  104. package/starter-assets/needle-surface.png +0 -0
  105. package/starter-assets/river_small_rocks/river_small_rocks_arm_512.jpg +0 -0
  106. package/starter-assets/river_small_rocks/river_small_rocks_diff_512.jpg +0 -0
  107. package/starter-assets/river_small_rocks/river_small_rocks_nor_gl_512.jpg +0 -0
  108. package/starter-assets/rock_boulder_dry/rock_boulder_dry_arm_512.jpg +0 -0
  109. package/starter-assets/rock_boulder_dry/rock_boulder_dry_diff_512.jpg +0 -0
  110. package/starter-assets/rock_boulder_dry/rock_boulder_dry_nor_gl_512.jpg +0 -0
  111. package/starter-assets/rocks/boulder-mid.glb +0 -0
  112. package/starter-assets/rocks/boulder-near.glb +0 -0
  113. package/starter-assets/rocks/boulder-prep.json +0 -37
  114. package/starter-assets/rocks/rock01-mid.glb +0 -0
  115. package/starter-assets/rocks/rock01-near.glb +0 -0
  116. package/starter-assets/rocks/rock01-prep.json +0 -37
  117. package/starter-assets/rocks/rock04-mid.glb +0 -0
  118. package/starter-assets/rocks/rock04-near.glb +0 -0
  119. package/starter-assets/rocks/rock04-prep.json +0 -37
  120. package/starter-assets/sand_01/sand_01_ao_1k.jpg +0 -0
  121. package/starter-assets/sand_01/sand_01_diff_1k.jpg +0 -0
  122. package/starter-assets/sand_01/sand_01_nor_gl_1k.jpg +0 -0
  123. package/starter-assets/sand_01/sand_01_rough_1k.jpg +0 -0
  124. package/starter-assets/snow_02/snow_02_ao_1k.jpg +0 -0
  125. package/starter-assets/snow_02/snow_02_diff_1k.jpg +0 -0
  126. package/starter-assets/snow_02/snow_02_nor_gl_1k.jpg +0 -0
  127. package/starter-assets/snow_02/snow_02_rough_1k.jpg +0 -0
package/dist/export.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Mesh, Object3D, Matrix4 } from 'three';
2
- import { I as ITerrainState } from './types-Ant8-Axc.js';
2
+ import { I as ITerrainState } from './types-CPYAc9vo.js';
3
3
 
4
4
  interface IWorldGLBInput {
5
5
  readonly revision: string;
@@ -41,14 +41,16 @@ interface IWorldGLBExport {
41
41
  };
42
42
  }
43
43
  /**
44
- * Export a committed evaluated world using ordinary glTF 2.0 nodes and embedded PBR images.
44
+ * Prepare the game's validated, frozen portable scene; the server cook owns GLB encoding.
45
45
  * @requires npm i -D @threenative/terrain
46
- * @situation export terrain, resolved models and final manual placement transforms as a portable GLB
47
- * @situation export the whole terrain world as one glb for another three.js project
48
- * @constraint browser authoring (FileReader/canvas); caller supplies all appearance and coherent baked water; root and /three remain headless
49
- * @example const output = await exportWorldGLB({ revision, snapshotTime: 0, state, terrain, assets, transforms });
50
- * @override actual static models, final matrices and baked PBR maps are supplied by the game
46
+ * @situation export the terrain as a glb for another three.js project via the headless cook
47
+ * @situation prepare the terrain editor's resolved world for headless portable GLB cooking
48
+ * @constraint browser authoring FileReader/canvas; all appearance and coherent water come from the game
49
+ * @example const prepared = await prepareWorldGLTF(input);
51
50
  */
52
- declare function exportWorldGLB(input: IWorldGLBInput): Promise<IWorldGLBExport>;
51
+ declare function prepareWorldGLTF(input: IWorldGLBInput): Promise<{
52
+ json: Record<string, unknown>;
53
+ report: IWorldGLBExport["report"];
54
+ }>;
53
55
 
54
- export { type IWorldGLBExport, type IWorldGLBInput, exportWorldGLB };
56
+ export { type IWorldGLBExport, type IWorldGLBInput, prepareWorldGLTF };
package/dist/export.js CHANGED
@@ -110,7 +110,7 @@ function staticModel(source, name, terrain = false) {
110
110
  for (const object of excluded) object.removeFromParent();
111
111
  return copy;
112
112
  }
113
- async function exportWorldGLB(input) {
113
+ async function prepareWorldGLTF(input) {
114
114
  const { state } = input;
115
115
  if (!/^[a-f0-9]{64}$/.test(input.revision) || !Number.isFinite(input.snapshotTime))
116
116
  throw new Error("World export requires a content revision and finite snapshot time");
@@ -198,7 +198,7 @@ async function exportWorldGLB(input) {
198
198
  root.add(copy);
199
199
  }
200
200
  if (typeof FileReader === "undefined" || typeof document === "undefined")
201
- throw new Error("exportWorldGLB needs browser authoring FileReader/canvas");
201
+ throw new Error("prepareWorldGLTF needs browser authoring FileReader/canvas");
202
202
  const geometries = /* @__PURE__ */ new Map();
203
203
  const materials = /* @__PURE__ */ new Map();
204
204
  const textures = /* @__PURE__ */ new Map();
@@ -243,7 +243,7 @@ async function exportWorldGLB(input) {
243
243
  materials.set(source, copy);
244
244
  return copy;
245
245
  }
246
- let binary;
246
+ let json;
247
247
  try {
248
248
  root.traverse((object) => {
249
249
  if (!(object instanceof Mesh)) return;
@@ -253,8 +253,8 @@ async function exportWorldGLB(input) {
253
253
  object.material = Array.isArray(object.material) ? object.material.map(freezeMaterial) : freezeMaterial(object.material);
254
254
  });
255
255
  root.updateMatrixWorld(true);
256
- binary = await new GLTFExporter().parseAsync(root, {
257
- binary: true,
256
+ json = await new GLTFExporter().parseAsync(root, {
257
+ binary: false,
258
258
  onlyVisible: true,
259
259
  includeCustomExtensions: false
260
260
  });
@@ -263,35 +263,23 @@ async function exportWorldGLB(input) {
263
263
  for (const value of materials.values()) value.dispose();
264
264
  for (const value of textures.values()) value.dispose();
265
265
  }
266
- if (!(binary instanceof ArrayBuffer)) throw new Error("GLTFExporter did not return a GLB");
267
- const header = new DataView(binary);
268
- if (header.getUint32(0, true) !== 1179937895 || header.getUint32(4, true) !== 2 || header.getUint32(8, true) !== binary.byteLength || header.getUint32(16, true) !== 1313821514)
269
- throw new Error("GLTFExporter returned a malformed GLB");
270
- const json = JSON.parse(
271
- new TextDecoder().decode(new Uint8Array(binary, 20, header.getUint32(12, true)))
272
- );
273
- if ([...json.images ?? [], ...json.buffers ?? []].some((resource) => resource.uri) || json.extensionsRequired?.some((name) => !name.startsWith("KHR_")))
274
- throw new Error("World GLB contains an external resource or nonportable required extension");
275
- return {
276
- name: "world.glb",
277
- mime: "model/gltf-binary",
278
- bytes: new Uint8Array(binary),
279
- report: {
280
- revision: input.revision,
281
- resolution: n,
282
- snapshotTime: input.snapshotTime,
283
- placementIds: [...ids],
284
- waterIds: [...waterIds],
285
- receivingGameSupplies: [
286
- "lighting",
287
- "sky/environment",
288
- "fog",
289
- "exposure",
290
- "post-processing",
291
- "live water/wind"
292
- ]
293
- }
266
+ const report = {
267
+ revision: input.revision,
268
+ resolution: n,
269
+ snapshotTime: input.snapshotTime,
270
+ placementIds: [...ids],
271
+ waterIds: [...waterIds],
272
+ receivingGameSupplies: [
273
+ "lighting",
274
+ "sky/environment",
275
+ "fog",
276
+ "exposure",
277
+ "post-processing",
278
+ "live water/wind"
279
+ ]
294
280
  };
281
+ if (json instanceof ArrayBuffer) throw new Error("Expected prepared glTF JSON");
282
+ return { json, report };
295
283
  }
296
284
 
297
- export { exportWorldGLB };
285
+ export { prepareWorldGLTF };