nucleation 0.3.17 → 0.3.19

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/Curve3D.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError"
3
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
4
+
5
+
6
+
7
+ /**
8
+ * A sampled 3D polyline. Closed curves include the final segment back to
9
+ * the first point and retain arc-length parameterisation for animation.
10
+ * Oversized point sets and overflowing segment lengths are rejected.
11
+ */
12
+ export class Curve3D {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Create a curve from flat `[x0, y0, z0, x1, y1, z1, …]` coordinates.
21
+ */
22
+ static fromPoints(coordinates: Array<number>, closed: boolean): Curve3D;
23
+
24
+ pointCount(): number;
25
+
26
+ isClosed(): boolean;
27
+ }
package/Curve3D.mjs ADDED
@@ -0,0 +1,101 @@
1
+ // generated by diplomat-tool
2
+ import { NucleationError } from "./NucleationError.mjs"
3
+ import wasm from "./diplomat-wasm.mjs";
4
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
+
6
+ const Curve3D_box_destroy_registry = new FinalizationRegistry((ptr) => {
7
+ wasm.Curve3D_destroy(ptr);
8
+ });
9
+
10
+ /**
11
+ * A sampled 3D polyline. Closed curves include the final segment back to
12
+ * the first point and retain arc-length parameterisation for animation.
13
+ * Oversized point sets and overflowing segment lengths are rejected.
14
+ */
15
+ export class Curve3D {
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("Curve3D 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
+ Curve3D_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
+ * Create a curve from flat `[x0, y0, z0, x1, y1, z1, …]` coordinates.
46
+ */
47
+ static fromPoints(coordinates, closed) {
48
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
49
+
50
+ const coordinatesSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, coordinates, "f64")));
51
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
52
+
53
+
54
+ const result = wasm.Curve3D_from_points(diplomatReceive.buffer, coordinatesSlice.ptr, closed);
55
+
56
+ try {
57
+ if (!diplomatReceive.resultFlag) {
58
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
59
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
60
+ }
61
+ return new Curve3D(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
62
+ }
63
+
64
+ finally {
65
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
66
+ functionCleanupArena.free();
67
+
68
+ diplomatReceive.free();
69
+ }
70
+ }
71
+
72
+ pointCount() {
73
+
74
+ const result = wasm.Curve3D_point_count(this.ffiValue);
75
+
76
+ try {
77
+ return result;
78
+ }
79
+
80
+ finally {
81
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
82
+ }
83
+ }
84
+
85
+ isClosed() {
86
+
87
+ const result = wasm.Curve3D_is_closed(this.ffiValue);
88
+
89
+ try {
90
+ return result;
91
+ }
92
+
93
+ finally {
94
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
95
+ }
96
+ }
97
+
98
+ constructor(symbol, ptr, selfEdge) {
99
+ return this.#internalConstructor(...arguments)
100
+ }
101
+ }
@@ -0,0 +1,39 @@
1
+ // generated by diplomat-tool
2
+ import type { Schematic } from "./Schematic"
3
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
4
+
5
+
6
+
7
+ export class DistanceField {
8
+ /** @internal */
9
+ get ffiValue(): pointer;
10
+ /** @internal */
11
+ constructor();
12
+
13
+
14
+ /**
15
+ * Distance transform of a build's occupied voxels: every solid block
16
+ * learns how many blocks it sits below the surface, and the gradient of
17
+ * that depth gives the outward normal. Computed once over the
18
+ * schematic's bounding box.
19
+ */
20
+ static fromSchematic(schematic: Schematic): DistanceField;
21
+
22
+ /**
23
+ * Blocks below the surface at a voxel: 0 for empty/outside, 1 at the
24
+ * surface, increasing inward.
25
+ */
26
+ depth(x: number, y: number, z: number): number;
27
+
28
+ /**
29
+ * The upward component of the outward surface normal: 1 on flat ground,
30
+ * 0 on a vertical face, negative under an overhang. The scalar to key
31
+ * slope-based landscaping on (grass on the flats, stone on the steeps).
32
+ */
33
+ slope(x: number, y: number, z: number): number;
34
+
35
+ /**
36
+ * The full outward surface normal as JSON `[nx, ny, nz]`.
37
+ */
38
+ normalJson(x: number, y: number, z: number): string;
39
+ }
@@ -0,0 +1,114 @@
1
+ // generated by diplomat-tool
2
+ import { Schematic } from "./Schematic.mjs"
3
+ import wasm from "./diplomat-wasm.mjs";
4
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
+
6
+ const DistanceField_box_destroy_registry = new FinalizationRegistry((ptr) => {
7
+ wasm.DistanceField_destroy(ptr);
8
+ });
9
+
10
+ export class DistanceField {
11
+ // Internal ptr reference:
12
+ #ptr = null;
13
+
14
+ // Lifetimes are only to keep dependencies alive.
15
+ // Since JS won't garbage collect until there are no incoming edges.
16
+ #selfEdge = [];
17
+
18
+ #internalConstructor(symbol, ptr, selfEdge) {
19
+ if (symbol !== diplomatRuntime.internalConstructor) {
20
+ console.error("DistanceField is an Opaque type. You cannot call its constructor.");
21
+ return;
22
+ }
23
+ this.#ptr = ptr;
24
+ this.#selfEdge = selfEdge;
25
+
26
+ // Are we being borrowed? If not, we can register.
27
+ if (this.#selfEdge.length === 0) {
28
+ DistanceField_box_destroy_registry.register(this, this.#ptr);
29
+ }
30
+
31
+ return this;
32
+ }
33
+ /** @internal */
34
+ get ffiValue() {
35
+ return this.#ptr;
36
+ }
37
+
38
+
39
+ /**
40
+ * Distance transform of a build's occupied voxels: every solid block
41
+ * learns how many blocks it sits below the surface, and the gradient of
42
+ * that depth gives the outward normal. Computed once over the
43
+ * schematic's bounding box.
44
+ */
45
+ static fromSchematic(schematic) {
46
+
47
+ const result = wasm.DistanceField_from_schematic(schematic.ffiValue);
48
+
49
+ try {
50
+ return new DistanceField(diplomatRuntime.internalConstructor, result, []);
51
+ }
52
+
53
+ finally {
54
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Blocks below the surface at a voxel: 0 for empty/outside, 1 at the
60
+ * surface, increasing inward.
61
+ */
62
+ depth(x, y, z) {
63
+
64
+ const result = wasm.DistanceField_depth(this.ffiValue, x, y, z);
65
+
66
+ try {
67
+ return result;
68
+ }
69
+
70
+ finally {
71
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
72
+ }
73
+ }
74
+
75
+ /**
76
+ * The upward component of the outward surface normal: 1 on flat ground,
77
+ * 0 on a vertical face, negative under an overhang. The scalar to key
78
+ * slope-based landscaping on (grass on the flats, stone on the steeps).
79
+ */
80
+ slope(x, y, z) {
81
+
82
+ const result = wasm.DistanceField_slope(this.ffiValue, x, y, z);
83
+
84
+ try {
85
+ return result;
86
+ }
87
+
88
+ finally {
89
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
90
+ }
91
+ }
92
+
93
+ /**
94
+ * The full outward surface normal as JSON `[nx, ny, nz]`.
95
+ */
96
+ normalJson(x, y, z) {
97
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
98
+
99
+ wasm.DistanceField_normal_json(this.ffiValue, x, y, z, write.buffer);
100
+
101
+ try {
102
+ return write.readString8();
103
+ }
104
+
105
+ finally {
106
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
107
+ write.free();
108
+ }
109
+ }
110
+
111
+ constructor(symbol, ptr, selfEdge) {
112
+ return this.#internalConstructor(...arguments)
113
+ }
114
+ }
package/RenderConfig.d.ts CHANGED
@@ -63,6 +63,20 @@ export class RenderConfig {
63
63
  */
64
64
  clearBackground(): void;
65
65
 
66
+ /**
67
+ * Configure a one-block world grid. Models are centred on integer
68
+ * schematic coordinates, so grid lines are placed on half-integer
69
+ * block boundaries automatically.
70
+ */
71
+ setGrid(halfExtent: number, spacing: number, planeY: number, showAxes: boolean, red: number, green: number, blue: number, alpha: number): void;
72
+
73
+ /**
74
+ * Configure a compact grid fitted to half-integer block boundaries.
75
+ */
76
+ setFittedGrid(margin: number, spacing: number, planeY: number, showAxes: boolean, red: number, green: number, blue: number, alpha: number): void;
77
+
78
+ clearGrid(): void;
79
+
66
80
  /**
67
81
  * Enable (`true`) or disable orthographic projection.
68
82
  */
package/RenderConfig.mjs CHANGED
@@ -155,6 +155,44 @@ export class RenderConfig {
155
155
  }
156
156
  }
157
157
 
158
+ /**
159
+ * Configure a one-block world grid. Models are centred on integer
160
+ * schematic coordinates, so grid lines are placed on half-integer
161
+ * block boundaries automatically.
162
+ */
163
+ setGrid(halfExtent, spacing, planeY, showAxes, red, green, blue, alpha) {
164
+ wasm.RenderConfig_set_grid(this.ffiValue, halfExtent, spacing, planeY, showAxes, red, green, blue, alpha);
165
+
166
+ try {}
167
+
168
+ finally {
169
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Configure a compact grid fitted to half-integer block boundaries.
175
+ */
176
+ setFittedGrid(margin, spacing, planeY, showAxes, red, green, blue, alpha) {
177
+ wasm.RenderConfig_set_fitted_grid(this.ffiValue, margin, spacing, planeY, showAxes, red, green, blue, alpha);
178
+
179
+ try {}
180
+
181
+ finally {
182
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
183
+ }
184
+ }
185
+
186
+ clearGrid() {
187
+ wasm.RenderConfig_clear_grid(this.ffiValue);
188
+
189
+ try {}
190
+
191
+ finally {
192
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
193
+ }
194
+ }
195
+
158
196
  /**
159
197
  * Enable (`true`) or disable orthographic projection.
160
198
  */
package/Schematic.d.ts CHANGED
@@ -19,6 +19,12 @@ export class Schematic {
19
19
  */
20
20
  static create(name: string): Schematic;
21
21
 
22
+ /**
23
+ * Return an independent deep copy. Subsequent block, region, entity,
24
+ * metadata, or transform changes do not affect the original.
25
+ */
26
+ deepClone(): Schematic;
27
+
22
28
  /**
23
29
  * The allocated dimensions (width, height, length) of the schematic's
24
30
  * bounding box.
@@ -174,16 +180,46 @@ export class Schematic {
174
180
  getBlocksJson(positions: Array<number>): string;
175
181
 
176
182
  /**
177
- * Copy a region from `source` into this schematic. `excluded_blocks_json`
178
- * is a JSON array of block strings to skip (empty string or `[]` for none).
183
+ * Stamp a merged source box into the default region. Excluded blocks
184
+ * are skipped, preserving destination content. Empty string or `[]`
185
+ * means no exclusions.
186
+ */
187
+ stampBox(source: Schematic, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number, targetX: number, targetY: number, targetZ: number, excludedBlocksJson: string): void;
188
+
189
+ /**
190
+ * Stamp one explicitly named source region into the default region.
191
+ * The region's minimum corner is mapped to the target position.
192
+ */
193
+ stampRegion(source: Schematic, sourceRegionName: string, targetX: number, targetY: number, targetZ: number, excludedBlocksJson: string): void;
194
+
195
+ /**
196
+ * Compatibility alias for `stamp_box`.
179
197
  */
180
198
  copyRegion(source: Schematic, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number, targetX: number, targetY: number, targetZ: number, excludedBlocksJson: string): void;
181
199
 
200
+ /**
201
+ * The full block state at a position. `NotFound` if the position is
202
+ * outside every region.
203
+ */
204
+ getBlock(x: number, y: number, z: number): BlockState;
205
+
182
206
  /**
183
207
  * The block at a position with its properties, as a `BlockState`.
208
+ * Kept as an explicit alias for callers migrating from the older API.
184
209
  */
185
210
  getBlockWithProperties(x: number, y: number, z: number): BlockState;
186
211
 
212
+ /**
213
+ * The full block state at a position in one specific region. This
214
+ * avoids composite lookup ambiguity when regions overlap.
215
+ */
216
+ getBlockInRegion(regionName: string, x: number, y: number, z: number): BlockState;
217
+
218
+ /**
219
+ * The block string at a position in one specific region.
220
+ */
221
+ getBlockStringInRegion(regionName: string, x: number, y: number, z: number): string;
222
+
187
223
  /**
188
224
  * The full block string (name, properties, NBT) at a position.
189
225
  */
@@ -195,6 +231,11 @@ export class Schematic {
195
231
  */
196
232
  getBlockEntityJson(x: number, y: number, z: number): string;
197
233
 
234
+ /**
235
+ * The block entity at a position in one specific region as JSON.
236
+ */
237
+ getBlockEntityJsonInRegion(regionName: string, x: number, y: number, z: number): string;
238
+
198
239
  /**
199
240
  * Every block entity as a JSON array of
200
241
  * `{"id": ..., "position": [x,y,z], "nbt": {...}}`.
@@ -217,6 +258,14 @@ export class Schematic {
217
258
  */
218
259
  addEntity(id: string, x: number, y: number, z: number, nbtJson: string): void;
219
260
 
261
+ /**
262
+ * Add an armor stand without hand-authoring entity NBT.
263
+ *
264
+ * `armor_material` accepts `diamond`, `netherite`, `iron`, etc.; an
265
+ * empty string creates an unarmored stand. `yaw` uses Minecraft degrees.
266
+ */
267
+ addArmorStand(x: number, y: number, z: number, yaw: number, armorMaterial: string): void;
268
+
220
269
  /**
221
270
  * Remove a mobile entity by index.
222
271
  */
@@ -445,87 +494,116 @@ export class Schematic {
445
494
 
446
495
  /**
447
496
  * Mirror the default region along the X axis (in place). Block
448
- * orientations (e.g. `facing` properties), block entities, and
449
- * entities are mirrored too.
497
+ * orientations, block entities, and entities are mirrored too.
450
498
  */
451
499
  flipX(): void;
452
500
 
453
501
  /**
454
- * Mirror the default region along the Y axis (in place). Block
455
- * orientations, block entities, and entities are mirrored too.
502
+ * Mirror the default region along the Y axis (in place).
456
503
  */
457
504
  flipY(): void;
458
505
 
459
506
  /**
460
- * Mirror the default region along the Z axis (in place). Block
461
- * orientations, block entities, and entities are mirrored too.
507
+ * Mirror the default region along the Z axis (in place).
462
508
  */
463
509
  flipZ(): void;
464
510
 
465
511
  /**
466
- * Rotate the default region about the X axis. `degrees` must be a
467
- * multiple of 90 (anything else is a no-op; negative values wrap).
468
- * +90° maps +Z onto +Y (south face rotates up). The region keeps its
469
- * minimum corner; block orientations and entities are updated.
512
+ * Rotate the default region about the X axis. +90° maps south (+Z)
513
+ * to down (-Y). Only multiples of 90 are accepted; invalid angles
514
+ * return `InvalidArgument` without changing the schematic. Negative
515
+ * values wrap.
470
516
  */
471
517
  rotateX(degrees: number): void;
472
518
 
473
519
  /**
474
- * Rotate the default region about the Y axis (horizontal plane).
475
- * `degrees` must be a multiple of 90 (anything else is a no-op;
476
- * negative values wrap). +90° maps +X onto -Z (east to north, i.e.
477
- * counterclockwise seen from above). The region keeps its minimum
478
- * corner; block orientations and entities are updated.
520
+ * Rotate the default region clockwise about the Y axis when viewed
521
+ * from above. +90° maps east (+X) to south (+Z).
479
522
  */
480
523
  rotateY(degrees: number): void;
481
524
 
482
525
  /**
483
- * Rotate the default region about the Z axis. `degrees` must be a
484
- * multiple of 90 (anything else is a no-op; negative values wrap).
485
- * +90° maps +Y onto +X (up rotates east). The region keeps its
486
- * minimum corner; block orientations and entities are updated.
526
+ * Rotate the default region about the Z axis. +90° maps up (+Y) to
527
+ * west (-X).
487
528
  */
488
529
  rotateZ(degrees: number): void;
489
530
 
490
531
  /**
491
- * Mirror a named region along the X axis (like `flip_x`). `NotFound`
492
- * if no region has that name.
532
+ * Move the default region and all attached block entities/entities.
533
+ */
534
+ translate(dx: number, dy: number, dz: number): void;
535
+
536
+ /**
537
+ * Mirror a named region along the X axis.
493
538
  */
494
539
  flipRegionX(regionName: string): void;
495
540
 
496
541
  /**
497
- * Mirror a named region along the Y axis (like `flip_y`). `NotFound`
498
- * if no region has that name.
542
+ * Mirror a named region along the Y axis.
499
543
  */
500
544
  flipRegionY(regionName: string): void;
501
545
 
502
546
  /**
503
- * Mirror a named region along the Z axis (like `flip_z`). `NotFound`
504
- * if no region has that name.
547
+ * Mirror a named region along the Z axis.
505
548
  */
506
549
  flipRegionZ(regionName: string): void;
507
550
 
508
551
  /**
509
- * Rotate a named region about the X axis by a multiple of 90 degrees
510
- * (same semantics as `rotate_x`). `NotFound` if no region has that
511
- * name.
552
+ * Rotate a named region about the X axis by a multiple of 90 degrees.
512
553
  */
513
554
  rotateRegionX(regionName: string, degrees: number): void;
514
555
 
515
556
  /**
516
- * Rotate a named region about the Y axis by a multiple of 90 degrees
517
- * (same semantics as `rotate_y`). `NotFound` if no region has that
518
- * name.
557
+ * Rotate a named region clockwise about the Y axis by a multiple of
558
+ * 90 degrees.
519
559
  */
520
560
  rotateRegionY(regionName: string, degrees: number): void;
521
561
 
522
562
  /**
523
- * Rotate a named region about the Z axis by a multiple of 90 degrees
524
- * (same semantics as `rotate_z`). `NotFound` if no region has that
525
- * name.
563
+ * Rotate a named region about the Z axis by a multiple of 90 degrees.
526
564
  */
527
565
  rotateRegionZ(regionName: string, degrees: number): void;
528
566
 
567
+ /**
568
+ * Move one named region without affecting its siblings.
569
+ */
570
+ translateRegion(regionName: string, dx: number, dy: number, dz: number): void;
571
+
572
+ /**
573
+ * Rotate every region as one rigid schematic around the shared bounds.
574
+ */
575
+ rotateSchematicX(degrees: number): void;
576
+
577
+ /**
578
+ * Rotate every region as one rigid schematic around the shared bounds.
579
+ */
580
+ rotateSchematicY(degrees: number): void;
581
+
582
+ /**
583
+ * Rotate every region as one rigid schematic around the shared bounds.
584
+ */
585
+ rotateSchematicZ(degrees: number): void;
586
+
587
+ /**
588
+ * Mirror every region across the shared schematic X bounds.
589
+ */
590
+ flipSchematicX(): void;
591
+
592
+ /**
593
+ * Mirror every region across the shared schematic Y bounds.
594
+ */
595
+ flipSchematicY(): void;
596
+
597
+ /**
598
+ * Mirror every region across the shared schematic Z bounds.
599
+ */
600
+ flipSchematicZ(): void;
601
+
602
+ /**
603
+ * Move every region by the same delta, preserving their relative layout.
604
+ */
605
+ translateSchematic(dx: number, dy: number, dz: number): void;
606
+
529
607
  /**
530
608
  * Fill a cuboid with a block.
531
609
  */
@@ -565,6 +643,26 @@ export class Schematic {
565
643
  */
566
644
  setBlockInRegion(regionName: string, x: number, y: number, z: number, blockName: string): void;
567
645
 
646
+ /**
647
+ * Whether a default or named schematic region exists.
648
+ */
649
+ hasRegion(regionName: string): boolean;
650
+
651
+ /**
652
+ * Create an empty named region. Its first block anchors its bounds.
653
+ */
654
+ createRegion(regionName: string): void;
655
+
656
+ /**
657
+ * Remove a named region. The default region cannot be removed.
658
+ */
659
+ removeRegion(regionName: string): void;
660
+
661
+ /**
662
+ * Rename a named region. The default region cannot be renamed.
663
+ */
664
+ renameRegion(oldName: string, newName: string): void;
665
+
568
666
  /**
569
667
  * The schematic bounding box as a JSON array
570
668
  * `[min_x, min_y, min_z, max_x, max_y, max_z]`.