nucleation 0.3.12 → 0.3.14

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/Geo.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError"
3
+ import type { Schematic } from "./Schematic"
4
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
5
+
6
+
7
+
8
+ /**
9
+ * Namespace for the geodata entry points (no network — data goes in,
10
+ * blocks come out).
11
+ */
12
+ export class Geo {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Extrude building footprints into a massed schematic. `buildings_json`
21
+ * is a JSON array of objects:
22
+ * `{"polygon": [[x, z], ...], "height": <blocks>, "block": "minecraft:...",
23
+ * "min_y": <optional base, default 1>}`. Footprints are stamped
24
+ * tallest-last, so overlaps keep the tallest occupant per column.
25
+ * `base_block` (empty string = none) lays a ground slab at y=0 under the
26
+ * whole extent. Errors `Parse` on bad JSON, `InvalidArgument` on non-UTF-8.
27
+ */
28
+ static extrudeFootprints(buildingsJson: string, baseBlock: string, name: string): Schematic;
29
+
30
+ /**
31
+ * Raise terrain from a heightmap. `heights_json` is a flat row-major
32
+ * JSON array of per-column heights (blocks); `width` is columns per row.
33
+ * `surface_blocks_json` is a JSON array of block names — one entry (the
34
+ * same surface everywhere) or one per column, row-major and the same
35
+ * length as `heights`, for elevation/slope banding. Each column's top
36
+ * `surface_depth` blocks are its surface block, the rest are
37
+ * `subsurface_block`. Errors `Parse` on bad JSON, `InvalidArgument` on a
38
+ * non-positive width, empty surface list, or non-UTF-8.
39
+ */
40
+ static heightmapTerrain(heightsJson: string, width: number, surfaceBlocksJson: string, subsurfaceBlock: string, surfaceDepth: number, name: string): Schematic;
41
+ }
package/Geo.mjs ADDED
@@ -0,0 +1,121 @@
1
+ // generated by diplomat-tool
2
+ import { NucleationError } from "./NucleationError.mjs"
3
+ import { Schematic } from "./Schematic.mjs"
4
+ import wasm from "./diplomat-wasm.mjs";
5
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
+
7
+ const Geo_box_destroy_registry = new FinalizationRegistry((ptr) => {
8
+ wasm.Geo_destroy(ptr);
9
+ });
10
+
11
+ /**
12
+ * Namespace for the geodata entry points (no network — data goes in,
13
+ * blocks come out).
14
+ */
15
+ export class Geo {
16
+ // Internal ptr reference:
17
+ #ptr = null;
18
+
19
+ // Lifetimes are only to keep dependencies alive.
20
+ // Since JS won't garbage collect until there are no incoming edges.
21
+ #selfEdge = [];
22
+
23
+ #internalConstructor(symbol, ptr, selfEdge) {
24
+ if (symbol !== diplomatRuntime.internalConstructor) {
25
+ console.error("Geo is an Opaque type. You cannot call its constructor.");
26
+ return;
27
+ }
28
+ this.#ptr = ptr;
29
+ this.#selfEdge = selfEdge;
30
+
31
+ // Are we being borrowed? If not, we can register.
32
+ if (this.#selfEdge.length === 0) {
33
+ Geo_box_destroy_registry.register(this, this.#ptr);
34
+ }
35
+
36
+ return this;
37
+ }
38
+ /** @internal */
39
+ get ffiValue() {
40
+ return this.#ptr;
41
+ }
42
+
43
+
44
+ /**
45
+ * Extrude building footprints into a massed schematic. `buildings_json`
46
+ * is a JSON array of objects:
47
+ * `{"polygon": [[x, z], ...], "height": <blocks>, "block": "minecraft:...",
48
+ * "min_y": <optional base, default 1>}`. Footprints are stamped
49
+ * tallest-last, so overlaps keep the tallest occupant per column.
50
+ * `base_block` (empty string = none) lays a ground slab at y=0 under the
51
+ * whole extent. Errors `Parse` on bad JSON, `InvalidArgument` on non-UTF-8.
52
+ */
53
+ static extrudeFootprints(buildingsJson, baseBlock, name) {
54
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
55
+
56
+ const buildingsJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, buildingsJson)));
57
+ const baseBlockSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, baseBlock)));
58
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
59
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
60
+
61
+
62
+ const result = wasm.Geo_extrude_footprints(diplomatReceive.buffer, buildingsJsonSlice.ptr, baseBlockSlice.ptr, nameSlice.ptr);
63
+
64
+ try {
65
+ if (!diplomatReceive.resultFlag) {
66
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
67
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
68
+ }
69
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
70
+ }
71
+
72
+ finally {
73
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
74
+ functionCleanupArena.free();
75
+
76
+ diplomatReceive.free();
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Raise terrain from a heightmap. `heights_json` is a flat row-major
82
+ * JSON array of per-column heights (blocks); `width` is columns per row.
83
+ * `surface_blocks_json` is a JSON array of block names — one entry (the
84
+ * same surface everywhere) or one per column, row-major and the same
85
+ * length as `heights`, for elevation/slope banding. Each column's top
86
+ * `surface_depth` blocks are its surface block, the rest are
87
+ * `subsurface_block`. Errors `Parse` on bad JSON, `InvalidArgument` on a
88
+ * non-positive width, empty surface list, or non-UTF-8.
89
+ */
90
+ static heightmapTerrain(heightsJson, width, surfaceBlocksJson, subsurfaceBlock, surfaceDepth, name) {
91
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
92
+
93
+ const heightsJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, heightsJson)));
94
+ const surfaceBlocksJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, surfaceBlocksJson)));
95
+ const subsurfaceBlockSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, subsurfaceBlock)));
96
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
97
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
98
+
99
+
100
+ const result = wasm.Geo_heightmap_terrain(diplomatReceive.buffer, heightsJsonSlice.ptr, width, surfaceBlocksJsonSlice.ptr, subsurfaceBlockSlice.ptr, surfaceDepth, nameSlice.ptr);
101
+
102
+ try {
103
+ if (!diplomatReceive.resultFlag) {
104
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
105
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
106
+ }
107
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
108
+ }
109
+
110
+ finally {
111
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
112
+ functionCleanupArena.free();
113
+
114
+ diplomatReceive.free();
115
+ }
116
+ }
117
+
118
+ constructor(symbol, ptr, selfEdge) {
119
+ return this.#internalConstructor(...arguments)
120
+ }
121
+ }
package/Shape.d.ts CHANGED
@@ -26,6 +26,17 @@ export class Shape {
26
26
  */
27
27
  static cuboid(minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): Shape;
28
28
 
29
+ /**
30
+ * A closed 2D polygon extruded between two Y levels (inclusive). The
31
+ * footprint is `polygon_json`, a JSON array of `[x, z]` world-coordinate
32
+ * pairs in order (winding does not matter; the ring closes implicitly);
33
+ * any simple polygon works, concave ones included. This is the shape
34
+ * behind extruded building footprints, lake outlines, and plot fills.
35
+ * Errors with `Parse` on invalid JSON and `InvalidArgument` on non-UTF-8
36
+ * or fewer than three vertices.
37
+ */
38
+ static polygonPrism(polygonJson: string, yMin: number, yMax: number): Shape;
39
+
29
40
  /**
30
41
  * Ellipsoid centered at (`cx`, `cy`, `cz`) with per-axis radii.
31
42
  */
package/Shape.mjs CHANGED
@@ -73,6 +73,40 @@ export class Shape {
73
73
  }
74
74
  }
75
75
 
76
+ /**
77
+ * A closed 2D polygon extruded between two Y levels (inclusive). The
78
+ * footprint is `polygon_json`, a JSON array of `[x, z]` world-coordinate
79
+ * pairs in order (winding does not matter; the ring closes implicitly);
80
+ * any simple polygon works, concave ones included. This is the shape
81
+ * behind extruded building footprints, lake outlines, and plot fills.
82
+ * Errors with `Parse` on invalid JSON and `InvalidArgument` on non-UTF-8
83
+ * or fewer than three vertices.
84
+ */
85
+ static polygonPrism(polygonJson, yMin, yMax) {
86
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
87
+
88
+ const polygonJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, polygonJson)));
89
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
90
+
91
+
92
+ const result = wasm.Shape_polygon_prism(diplomatReceive.buffer, polygonJsonSlice.ptr, yMin, yMax);
93
+
94
+ try {
95
+ if (!diplomatReceive.resultFlag) {
96
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
97
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
98
+ }
99
+ return new Shape(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
100
+ }
101
+
102
+ finally {
103
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
104
+ functionCleanupArena.free();
105
+
106
+ diplomatReceive.free();
107
+ }
108
+ }
109
+
76
110
  /**
77
111
  * Ellipsoid centered at (`cx`, `cy`, `cz`) with per-axis radii.
78
112
  */
package/Voxelizer.d.ts CHANGED
@@ -26,7 +26,9 @@ export class Voxelizer {
26
26
  * voxel center (robust on closed meshes), plus — when `shell` > 0 —
27
27
  * every voxel whose center is within `shell` blocks of the surface,
28
28
  * which rescues thin walls and hollow vessels (0.7–1.0 closes
29
- * single-voxel shells; 0 = pure parity). Errors with `Parse` on
29
+ * single-voxel shells; 0 = pure parity; a *negative* `shell` is
30
+ * surface-only — a skin |shell| blocks thick with no interior fill,
31
+ * for open sheets/ribbons that dip or self-overlap). Errors with `Parse` on
30
32
  * malformed/triangle-less GLB and `InvalidArgument` on a
31
33
  * non-positive `target_size`.
32
34
  */
package/Voxelizer.mjs CHANGED
@@ -51,7 +51,9 @@ export class Voxelizer {
51
51
  * voxel center (robust on closed meshes), plus — when `shell` > 0 —
52
52
  * every voxel whose center is within `shell` blocks of the surface,
53
53
  * which rescues thin walls and hollow vessels (0.7–1.0 closes
54
- * single-voxel shells; 0 = pure parity). Errors with `Parse` on
54
+ * single-voxel shells; 0 = pure parity; a *negative* `shell` is
55
+ * surface-only — a skin |shell| blocks thick with no interior fill,
56
+ * for open sheets/ribbons that dip or self-overlap). Errors with `Parse` on
55
57
  * malformed/triangle-less GLB and `InvalidArgument` on a
56
58
  * non-positive `target_size`.
57
59
  */
package/index.d.ts CHANGED
@@ -38,6 +38,8 @@ export { Diff } from "./Diff"
38
38
 
39
39
  export { Fingerprint } from "./Fingerprint"
40
40
 
41
+ export { Geo } from "./Geo"
42
+
41
43
  export { ChunkMeshResult } from "./ChunkMeshResult"
42
44
 
43
45
  export { ItemModelConfig } from "./ItemModelConfig"
package/index.mjs CHANGED
@@ -36,6 +36,8 @@ export { Diff } from "./Diff.mjs"
36
36
 
37
37
  export { Fingerprint } from "./Fingerprint.mjs"
38
38
 
39
+ export { Geo } from "./Geo.mjs"
40
+
39
41
  export { ChunkMeshResult } from "./ChunkMeshResult.mjs"
40
42
 
41
43
  export { ItemModelConfig } from "./ItemModelConfig.mjs"
package/nucleation.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nucleation",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "description": "A high-performance Minecraft schematic parser and utility library",
5
5
  "type": "module",
6
6
  "main": "index.mjs",