@bitmagic/world-forger 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 (105) hide show
  1. package/dist/artifact-types.d.ts +295 -0
  2. package/dist/artifact-types.d.ts.map +1 -0
  3. package/dist/artifact-types.js +17 -0
  4. package/dist/artifact-types.js.map +1 -0
  5. package/dist/forge-constants.d.ts +106 -0
  6. package/dist/forge-constants.d.ts.map +1 -0
  7. package/dist/forge-constants.js +111 -0
  8. package/dist/forge-constants.js.map +1 -0
  9. package/dist/index.d.ts +28 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +28 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/log.d.ts +26 -0
  14. package/dist/log.d.ts.map +1 -0
  15. package/dist/log.js +14 -0
  16. package/dist/log.js.map +1 -0
  17. package/dist/pipeline/archetype-skips.d.ts +57 -0
  18. package/dist/pipeline/archetype-skips.d.ts.map +1 -0
  19. package/dist/pipeline/archetype-skips.js +51 -0
  20. package/dist/pipeline/archetype-skips.js.map +1 -0
  21. package/dist/pipeline/artifact-store.d.ts +4 -0
  22. package/dist/pipeline/artifact-store.d.ts.map +1 -0
  23. package/dist/pipeline/artifact-store.js +10 -0
  24. package/dist/pipeline/artifact-store.js.map +1 -0
  25. package/dist/pipeline/asset-catalog.d.ts +27 -0
  26. package/dist/pipeline/asset-catalog.d.ts.map +1 -0
  27. package/dist/pipeline/asset-catalog.js +47 -0
  28. package/dist/pipeline/asset-catalog.js.map +1 -0
  29. package/dist/pipeline/create-level-archetypes.d.ts +45 -0
  30. package/dist/pipeline/create-level-archetypes.d.ts.map +1 -0
  31. package/dist/pipeline/create-level-archetypes.js +197 -0
  32. package/dist/pipeline/create-level-archetypes.js.map +1 -0
  33. package/dist/pipeline/deps.d.ts +72 -0
  34. package/dist/pipeline/deps.d.ts.map +1 -0
  35. package/dist/pipeline/deps.js +2 -0
  36. package/dist/pipeline/deps.js.map +1 -0
  37. package/dist/pipeline/errors.d.ts +10 -0
  38. package/dist/pipeline/errors.d.ts.map +1 -0
  39. package/dist/pipeline/errors.js +13 -0
  40. package/dist/pipeline/errors.js.map +1 -0
  41. package/dist/pipeline/forged-work-store.d.ts +46 -0
  42. package/dist/pipeline/forged-work-store.d.ts.map +1 -0
  43. package/dist/pipeline/forged-work-store.js +69 -0
  44. package/dist/pipeline/forged-work-store.js.map +1 -0
  45. package/dist/pipeline/index.d.ts +36 -0
  46. package/dist/pipeline/index.d.ts.map +1 -0
  47. package/dist/pipeline/index.js +36 -0
  48. package/dist/pipeline/index.js.map +1 -0
  49. package/dist/pipeline/job-types.d.ts +145 -0
  50. package/dist/pipeline/job-types.d.ts.map +1 -0
  51. package/dist/pipeline/job-types.js +2 -0
  52. package/dist/pipeline/job-types.js.map +1 -0
  53. package/dist/pipeline/level-registry.d.ts +57 -0
  54. package/dist/pipeline/level-registry.d.ts.map +1 -0
  55. package/dist/pipeline/level-registry.js +108 -0
  56. package/dist/pipeline/level-registry.js.map +1 -0
  57. package/dist/pipeline/model-types.d.ts +51 -0
  58. package/dist/pipeline/model-types.d.ts.map +1 -0
  59. package/dist/pipeline/model-types.js +2 -0
  60. package/dist/pipeline/model-types.js.map +1 -0
  61. package/dist/pipeline/persist-level.d.ts +82 -0
  62. package/dist/pipeline/persist-level.d.ts.map +1 -0
  63. package/dist/pipeline/persist-level.js +201 -0
  64. package/dist/pipeline/persist-level.js.map +1 -0
  65. package/dist/pipeline/place-and-persist-level.d.ts +83 -0
  66. package/dist/pipeline/place-and-persist-level.d.ts.map +1 -0
  67. package/dist/pipeline/place-and-persist-level.js +405 -0
  68. package/dist/pipeline/place-and-persist-level.js.map +1 -0
  69. package/dist/pipeline/request-id.d.ts +7 -0
  70. package/dist/pipeline/request-id.d.ts.map +1 -0
  71. package/dist/pipeline/request-id.js +10 -0
  72. package/dist/pipeline/request-id.js.map +1 -0
  73. package/dist/pipeline/spawn-points.d.ts +47 -0
  74. package/dist/pipeline/spawn-points.d.ts.map +1 -0
  75. package/dist/pipeline/spawn-points.js +100 -0
  76. package/dist/pipeline/spawn-points.js.map +1 -0
  77. package/dist/pipeline/starter-scatter.d.ts +34 -0
  78. package/dist/pipeline/starter-scatter.d.ts.map +1 -0
  79. package/dist/pipeline/starter-scatter.js +49 -0
  80. package/dist/pipeline/starter-scatter.js.map +1 -0
  81. package/dist/pipeline/storage-types.d.ts +48 -0
  82. package/dist/pipeline/storage-types.d.ts.map +1 -0
  83. package/dist/pipeline/storage-types.js +19 -0
  84. package/dist/pipeline/storage-types.js.map +1 -0
  85. package/dist/pipeline/transport-types.d.ts +35 -0
  86. package/dist/pipeline/transport-types.d.ts.map +1 -0
  87. package/dist/pipeline/transport-types.js +2 -0
  88. package/dist/pipeline/transport-types.js.map +1 -0
  89. package/dist/pipeline/voxelize-level.d.ts +24 -0
  90. package/dist/pipeline/voxelize-level.d.ts.map +1 -0
  91. package/dist/pipeline/voxelize-level.js +63 -0
  92. package/dist/pipeline/voxelize-level.js.map +1 -0
  93. package/dist/pipeline/world-json-source.d.ts +78 -0
  94. package/dist/pipeline/world-json-source.d.ts.map +1 -0
  95. package/dist/pipeline/world-json-source.js +2 -0
  96. package/dist/pipeline/world-json-source.js.map +1 -0
  97. package/dist/pipeline/world-json-types.d.ts +104 -0
  98. package/dist/pipeline/world-json-types.d.ts.map +1 -0
  99. package/dist/pipeline/world-json-types.js +15 -0
  100. package/dist/pipeline/world-json-types.js.map +1 -0
  101. package/dist/terrain-height-grid.d.ts +45 -0
  102. package/dist/terrain-height-grid.d.ts.map +1 -0
  103. package/dist/terrain-height-grid.js +50 -0
  104. package/dist/terrain-height-grid.js.map +1 -0
  105. package/package.json +72 -0
@@ -0,0 +1,50 @@
1
+ /**
2
+ * World-space terrain height grid — the bridge that lets objects placed AFTER
3
+ * a forge (e.g. collectibles the coding/asset agent scatters via the voxel CLI)
4
+ * sit on the forged surface instead of the world floor.
5
+ *
6
+ * The forge knows each prop's exact ground height because it samples its own
7
+ * GLB-space `Heightfield` and maps the result to world space with the level
8
+ * transform (see `forge-world.ts`). Agent-driven placements happen later, in a
9
+ * separate process, with no access to that in-memory heightfield — and a
10
+ * placement raycast can't help because the freshly-forged terrain only loads
11
+ * after the session reload. So the forge persists THIS grid (a sidecar next to
12
+ * world.json); the CLI samples it to resolve `placeOnTerrain` Y the same way
13
+ * the forge resolved its props.
14
+ *
15
+ * The grid is the carved heightfield expressed in WORLD coordinates. Because the
16
+ * level transform is affine and axis-aligned (uniform scale + translate, no
17
+ * rotation — see `marker-transform.ts`), a GLB-regular grid maps to a
18
+ * world-regular grid, so the conversion is a per-vertex scale/translate.
19
+ *
20
+ * The GRID and its SAMPLER live on the publishable side, because the host that
21
+ * writes the sidecar and the tools that read it are CLIENTS of the forge, not
22
+ * part of it. The producer — `heightfieldToWorldGrid`, which needs the forge's
23
+ * own heightfield and level transform — stays with the geometry, in the private
24
+ * package's module of the same name.
25
+ */
26
+ /** Sidecar filename written next to world.json. The CLI hardcodes the same name. */
27
+ export const FORGED_HEIGHTFIELD_FILE = 'forged-heightfield.json';
28
+ /**
29
+ * Bilinear height sample in world space, clamped to the grid edge. Mirrors
30
+ * `heightfield.ts` `heightAt` so the CLI's sampler and this one agree.
31
+ */
32
+ export function sampleWorldHeight(g, x, z) {
33
+ const fx = (x - g.minX) / g.cellSize;
34
+ const fz = (z - g.minZ) / g.cellSize;
35
+ const cx = Math.min(Math.max(fx, 0), g.nx - 1e-9);
36
+ const cz = Math.min(Math.max(fz, 0), g.nz - 1e-9);
37
+ const i = Math.floor(cx);
38
+ const j = Math.floor(cz);
39
+ const tx = cx - i;
40
+ const tz = cz - j;
41
+ const stride = g.nx + 1;
42
+ const h00 = g.heights[j * stride + i];
43
+ const h10 = g.heights[j * stride + i + 1];
44
+ const h01 = g.heights[(j + 1) * stride + i];
45
+ const h11 = g.heights[(j + 1) * stride + i + 1];
46
+ const a = h00 + (h10 - h00) * tx;
47
+ const b = h01 + (h11 - h01) * tx;
48
+ return a + (b - a) * tz;
49
+ }
50
+ //# sourceMappingURL=terrain-height-grid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terrain-height-grid.js","sourceRoot":"","sources":["../src/terrain-height-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAejE;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAmB,EAAE,CAAS,EAAE,CAAS;IACzE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACrC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACrC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACzB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxB,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAE,CAAC;IACvC,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,CAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAE,CAAC;IAC7C,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,CAAE,CAAC;IACjD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;IACjC,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AAC1B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@bitmagic/world-forger",
3
+ "version": "0.1.0",
4
+ "description": "Client half of the Bitmagic world forger: the forged-level artifact schema, the host seams, and the browser pipeline steps that bake archetypes, bake a level and place its instances.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./*.js": {
15
+ "types": "./dist/*.d.ts",
16
+ "default": "./dist/*.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "devDependencies": {
26
+ "@eslint/js": "^9.38.0",
27
+ "@types/jest": "^29.5.0",
28
+ "@types/node": "^24.9.1",
29
+ "@typescript-eslint/eslint-plugin": "^8.46.2",
30
+ "@typescript-eslint/parser": "^8.46.2",
31
+ "eslint": "^9.38.0",
32
+ "jest": "^29.7.0",
33
+ "ts-jest": "^29.4.5",
34
+ "typescript": "^5.9.3"
35
+ },
36
+ "jest": {
37
+ "preset": "ts-jest/presets/default-esm",
38
+ "extensionsToTreatAsEsm": [
39
+ ".ts"
40
+ ],
41
+ "transform": {
42
+ "^.+\\.ts$": [
43
+ "ts-jest",
44
+ {
45
+ "useESM": true,
46
+ "tsconfig": {
47
+ "target": "ES2020",
48
+ "module": "ES2020",
49
+ "moduleResolution": "node",
50
+ "verbatimModuleSyntax": false,
51
+ "esModuleInterop": true
52
+ }
53
+ }
54
+ ]
55
+ },
56
+ "moduleNameMapper": {
57
+ "^(\\.{1,2}/.*)\\.js$": "$1"
58
+ },
59
+ "testEnvironment": "node",
60
+ "testMatch": [
61
+ "**/__tests__/**/*.test.ts"
62
+ ],
63
+ "maxWorkers": "50%"
64
+ },
65
+ "scripts": {
66
+ "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
67
+ "build": "pnpm run clean && tsc",
68
+ "check": "pnpm run lint && pnpm run build",
69
+ "lint": "eslint src --cache",
70
+ "test": "jest"
71
+ }
72
+ }