nucleation 0.10.20 → 0.10.21

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/Palette.d.mts CHANGED
@@ -17,6 +17,18 @@ export class Palette {
17
17
  constructor();
18
18
 
19
19
 
20
+ /**
21
+ * Opaque building blocks and full glass blocks, for material-aware imports.
22
+ */
23
+ static materials(): Palette;
24
+
25
+ /**
26
+ * Keep only opaque blocks (`false`) or full glass blocks (`true`).
27
+ * Includes/excludes remain respected. Returns an empty palette when
28
+ * no suitable block exists; check `len()` before matching colours.
29
+ */
30
+ forMaterial(translucent: boolean): Palette;
31
+
20
32
  /**
21
33
  * Every block blockpedia knows a color for (the default palette
22
34
  * brushes use when none is set).
package/Palette.d.ts CHANGED
@@ -17,6 +17,18 @@ export class Palette {
17
17
  constructor();
18
18
 
19
19
 
20
+ /**
21
+ * Opaque building blocks and full glass blocks, for material-aware imports.
22
+ */
23
+ static materials(): Palette;
24
+
25
+ /**
26
+ * Keep only opaque blocks (`false`) or full glass blocks (`true`).
27
+ * Includes/excludes remain respected. Returns an empty palette when
28
+ * no suitable block exists; check `len()` before matching colours.
29
+ */
30
+ forMaterial(translucent: boolean): Palette;
31
+
20
32
  /**
21
33
  * Every block blockpedia knows a color for (the default palette
22
34
  * brushes use when none is set).
package/Palette.mjs CHANGED
@@ -42,6 +42,40 @@ export class Palette {
42
42
  }
43
43
 
44
44
 
45
+ /**
46
+ * Opaque building blocks and full glass blocks, for material-aware imports.
47
+ */
48
+ static materials() {
49
+
50
+ const result = wasm.Palette_materials();
51
+
52
+ try {
53
+ return new Palette(diplomatRuntime.internalConstructor, result, []);
54
+ }
55
+
56
+ finally {
57
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Keep only opaque blocks (`false`) or full glass blocks (`true`).
63
+ * Includes/excludes remain respected. Returns an empty palette when
64
+ * no suitable block exists; check `len()` before matching colours.
65
+ */
66
+ forMaterial(translucent) {
67
+
68
+ const result = wasm.Palette_for_material(this.ffiValue, translucent);
69
+
70
+ try {
71
+ return new Palette(diplomatRuntime.internalConstructor, result, []);
72
+ }
73
+
74
+ finally {
75
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
76
+ }
77
+ }
78
+
45
79
  /**
46
80
  * Every block blockpedia knows a color for (the default palette
47
81
  * brushes use when none is set).
@@ -0,0 +1,34 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError.mjs"
3
+ import type { Palette } from "./Palette.mjs"
4
+ import type { Schematic } from "./Schematic.mjs"
5
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
6
+
7
+
8
+
9
+ /**
10
+ * A parsed GLB/OBJ, reusable for size estimates and configured imports.
11
+ */
12
+ export class VoxelModel {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Return {dimensions:[width,height,depth],volume} or {error:message}.
21
+ * Options: target_size, axis (longest/x/y/z), hollow, optional lighting
22
+ * {direction:[x,y,z],strength:0..1}, optional untextured_block.
23
+ * Estimates preserve proportions and run before voxel-grid allocation.
24
+ */
25
+ planJson(optionsJson: string): string;
26
+
27
+ /**
28
+ * Import using plan_json's options. Anchored at (0,0,0), with exact
29
+ * axis-based uniform scaling. Hollow uses a sparse surface raster;
30
+ * lighting darkens sampled texture colours before palette matching.
31
+ * Rejects oversized/over-complex output with InvalidArgument.
32
+ */
33
+ toSchematic(optionsJson: string, palette: Palette, name: string): Schematic;
34
+ }
@@ -0,0 +1,34 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError.mjs"
3
+ import type { Palette } from "./Palette.mjs"
4
+ import type { Schematic } from "./Schematic.mjs"
5
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
6
+
7
+
8
+
9
+ /**
10
+ * A parsed GLB/OBJ, reusable for size estimates and configured imports.
11
+ */
12
+ export class VoxelModel {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Return {dimensions:[width,height,depth],volume} or {error:message}.
21
+ * Options: target_size, axis (longest/x/y/z), hollow, optional lighting
22
+ * {direction:[x,y,z],strength:0..1}, optional untextured_block.
23
+ * Estimates preserve proportions and run before voxel-grid allocation.
24
+ */
25
+ planJson(optionsJson: string): string;
26
+
27
+ /**
28
+ * Import using plan_json's options. Anchored at (0,0,0), with exact
29
+ * axis-based uniform scaling. Hollow uses a sparse surface raster;
30
+ * lighting darkens sampled texture colours before palette matching.
31
+ * Rejects oversized/over-complex output with InvalidArgument.
32
+ */
33
+ toSchematic(optionsJson: string, palette: Palette, name: string): Schematic;
34
+ }
package/VoxelModel.mjs ADDED
@@ -0,0 +1,113 @@
1
+ // generated by diplomat-tool
2
+ import { NucleationError } from "./NucleationError.mjs"
3
+ import { Palette } from "./Palette.mjs"
4
+ import { Schematic } from "./Schematic.mjs"
5
+ import wasm from "./diplomat-wasm.mjs";
6
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
+
8
+ const VoxelModel_box_destroy_registry = new FinalizationRegistry((ptr) => {
9
+ wasm.VoxelModel_destroy(ptr);
10
+ });
11
+
12
+ /**
13
+ * A parsed GLB/OBJ, reusable for size estimates and configured imports.
14
+ */
15
+ export class VoxelModel {
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("VoxelModel 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
+ VoxelModel_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
+ * Return {dimensions:[width,height,depth],volume} or {error:message}.
46
+ * Options: target_size, axis (longest/x/y/z), hollow, optional lighting
47
+ * {direction:[x,y,z],strength:0..1}, optional untextured_block.
48
+ * Estimates preserve proportions and run before voxel-grid allocation.
49
+ */
50
+ planJson(optionsJson) {
51
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
52
+
53
+ const optionsJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, optionsJson)));
54
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
55
+
56
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
57
+
58
+
59
+ const result = wasm.VoxelModel_plan_json(diplomatReceive.buffer, this.ffiValue, optionsJsonSlice.ptr, write.buffer);
60
+
61
+ try {
62
+ if (!diplomatReceive.resultFlag) {
63
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
64
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
65
+ }
66
+ return write.readString8();
67
+ }
68
+
69
+ finally {
70
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
71
+ functionCleanupArena.free();
72
+
73
+ diplomatReceive.free();
74
+ write.free();
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Import using plan_json's options. Anchored at (0,0,0), with exact
80
+ * axis-based uniform scaling. Hollow uses a sparse surface raster;
81
+ * lighting darkens sampled texture colours before palette matching.
82
+ * Rejects oversized/over-complex output with InvalidArgument.
83
+ */
84
+ toSchematic(optionsJson, palette, name) {
85
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
86
+
87
+ const optionsJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, optionsJson)));
88
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
89
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
90
+
91
+
92
+ const result = wasm.VoxelModel_to_schematic(diplomatReceive.buffer, this.ffiValue, optionsJsonSlice.ptr, palette.ffiValue, nameSlice.ptr);
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 Schematic(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
+
110
+ constructor(symbol, ptr, selfEdge) {
111
+ return this.#internalConstructor(...arguments)
112
+ }
113
+ }
package/Voxelizer.d.mts CHANGED
@@ -3,6 +3,7 @@ import type { NucleationError } from "./NucleationError.mjs"
3
3
  import type { Palette } from "./Palette.mjs"
4
4
  import type { Schematic } from "./Schematic.mjs"
5
5
  import type { Shape } from "./Shape.mjs"
6
+ import type { VoxelModel } from "./VoxelModel.mjs"
6
7
  import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
7
8
 
8
9
 
@@ -18,6 +19,27 @@ export class Voxelizer {
18
19
  constructor();
19
20
 
20
21
 
22
+ /**
23
+ * Reason the last configured model import failed; cleared on success.
24
+ */
25
+ static lastErrorDetail(): string;
26
+
27
+ /**
28
+ * PHP-friendly GLB input: avoids expanding every byte into a boxed
29
+ * integer array before copying it over FFI.
30
+ */
31
+ static loadGlbBase64(data: string): VoxelModel;
32
+
33
+ /**
34
+ * Parse a GLB once for axis-based size estimates and lit voxelization.
35
+ */
36
+ static loadGlb(data: Array<number>): VoxelModel;
37
+
38
+ /**
39
+ * Parse an OBJ once for axis-based size estimates and lit voxelization.
40
+ */
41
+ static loadObj(text: string): VoxelModel;
42
+
21
43
  /**
22
44
  * Load a binary glTF (`.glb`, embedded buffers/images) and voxelize
23
45
  * it into a fillable Shape: the model is uniformly scaled so its
package/Voxelizer.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { NucleationError } from "./NucleationError.mjs"
3
3
  import type { Palette } from "./Palette.mjs"
4
4
  import type { Schematic } from "./Schematic.mjs"
5
5
  import type { Shape } from "./Shape.mjs"
6
+ import type { VoxelModel } from "./VoxelModel.mjs"
6
7
  import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
7
8
 
8
9
 
@@ -18,6 +19,27 @@ export class Voxelizer {
18
19
  constructor();
19
20
 
20
21
 
22
+ /**
23
+ * Reason the last configured model import failed; cleared on success.
24
+ */
25
+ static lastErrorDetail(): string;
26
+
27
+ /**
28
+ * PHP-friendly GLB input: avoids expanding every byte into a boxed
29
+ * integer array before copying it over FFI.
30
+ */
31
+ static loadGlbBase64(data: string): VoxelModel;
32
+
33
+ /**
34
+ * Parse a GLB once for axis-based size estimates and lit voxelization.
35
+ */
36
+ static loadGlb(data: Array<number>): VoxelModel;
37
+
38
+ /**
39
+ * Parse an OBJ once for axis-based size estimates and lit voxelization.
40
+ */
41
+ static loadObj(text: string): VoxelModel;
42
+
21
43
  /**
22
44
  * Load a binary glTF (`.glb`, embedded buffers/images) and voxelize
23
45
  * it into a fillable Shape: the model is uniformly scaled so its
package/Voxelizer.mjs CHANGED
@@ -3,6 +3,7 @@ import { NucleationError } from "./NucleationError.mjs"
3
3
  import { Palette } from "./Palette.mjs"
4
4
  import { Schematic } from "./Schematic.mjs"
5
5
  import { Shape } from "./Shape.mjs"
6
+ import { VoxelModel } from "./VoxelModel.mjs"
6
7
  import wasm from "./diplomat-wasm.mjs";
7
8
  import * as diplomatRuntime from "./diplomat-runtime.mjs";
8
9
 
@@ -43,6 +44,109 @@ export class Voxelizer {
43
44
  }
44
45
 
45
46
 
47
+ /**
48
+ * Reason the last configured model import failed; cleared on success.
49
+ */
50
+ static lastErrorDetail() {
51
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
52
+
53
+ wasm.Voxelizer_last_error_detail(write.buffer);
54
+
55
+ try {
56
+ return write.readString8();
57
+ }
58
+
59
+ finally {
60
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
61
+ write.free();
62
+ }
63
+ }
64
+
65
+ /**
66
+ * PHP-friendly GLB input: avoids expanding every byte into a boxed
67
+ * integer array before copying it over FFI.
68
+ */
69
+ static loadGlbBase64(data) {
70
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
71
+
72
+ const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, data)));
73
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
74
+
75
+
76
+ const result = wasm.Voxelizer_load_glb_base64(diplomatReceive.buffer, dataSlice.ptr);
77
+
78
+ try {
79
+ if (!diplomatReceive.resultFlag) {
80
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
81
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
82
+ }
83
+ return new VoxelModel(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
84
+ }
85
+
86
+ finally {
87
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
88
+ functionCleanupArena.free();
89
+
90
+ diplomatReceive.free();
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Parse a GLB once for axis-based size estimates and lit voxelization.
96
+ */
97
+ static loadGlb(data) {
98
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
99
+
100
+ const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
101
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
102
+
103
+
104
+ const result = wasm.Voxelizer_load_glb(diplomatReceive.buffer, dataSlice.ptr);
105
+
106
+ try {
107
+ if (!diplomatReceive.resultFlag) {
108
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
109
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
110
+ }
111
+ return new VoxelModel(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
112
+ }
113
+
114
+ finally {
115
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
116
+ functionCleanupArena.free();
117
+
118
+ diplomatReceive.free();
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Parse an OBJ once for axis-based size estimates and lit voxelization.
124
+ */
125
+ static loadObj(text) {
126
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
127
+
128
+ const textSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, text)));
129
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
130
+
131
+
132
+ const result = wasm.Voxelizer_load_obj(diplomatReceive.buffer, textSlice.ptr);
133
+
134
+ try {
135
+ if (!diplomatReceive.resultFlag) {
136
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
137
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
138
+ }
139
+ return new VoxelModel(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
140
+ }
141
+
142
+ finally {
143
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
144
+ functionCleanupArena.free();
145
+
146
+ diplomatReceive.free();
147
+ }
148
+ }
149
+
46
150
  /**
47
151
  * Load a binary glTF (`.glb`, embedded buffers/images) and voxelize
48
152
  * it into a fillable Shape: the model is uniformly scaled so its
package/index.d.mts CHANGED
@@ -142,6 +142,8 @@ export { Store } from "./Store.mjs"
142
142
 
143
143
  export { StoreIo } from "./StoreIo.mjs"
144
144
 
145
+ export { VoxelModel } from "./VoxelModel.mjs"
146
+
145
147
  export { Voxelizer } from "./Voxelizer.mjs"
146
148
 
147
149
  export { CellularSdfConfig } from "./CellularSdfConfig.mjs"
package/index.d.ts CHANGED
@@ -142,6 +142,8 @@ export { Store } from "./Store.mjs"
142
142
 
143
143
  export { StoreIo } from "./StoreIo.mjs"
144
144
 
145
+ export { VoxelModel } from "./VoxelModel.mjs"
146
+
145
147
  export { Voxelizer } from "./Voxelizer.mjs"
146
148
 
147
149
  export { CellularSdfConfig } from "./CellularSdfConfig.mjs"
package/index.mjs CHANGED
@@ -140,6 +140,8 @@ export { Store } from "./Store.mjs"
140
140
 
141
141
  export { StoreIo } from "./StoreIo.mjs"
142
142
 
143
+ export { VoxelModel } from "./VoxelModel.mjs"
144
+
143
145
  export { Voxelizer } from "./Voxelizer.mjs"
144
146
 
145
147
  export { CellularSdfConfig } from "./CellularSdfConfig.mjs"
package/nucleation.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nucleation",
3
- "version": "0.10.20",
3
+ "version": "0.10.21",
4
4
  "description": "A high-performance Minecraft schematic parser and utility library",
5
5
  "type": "module",
6
6
  "main": "index.mjs",