nucleation 0.2.18 → 0.3.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 (125) hide show
  1. package/Autostack.d.ts +43 -0
  2. package/Autostack.mjs +134 -0
  3. package/BlockPos.d.ts +28 -0
  4. package/BlockPos.mjs +129 -0
  5. package/BlockState.d.ts +39 -0
  6. package/BlockState.mjs +134 -0
  7. package/Brush.d.ts +59 -0
  8. package/Brush.mjs +203 -0
  9. package/BuildingTool.d.ts +29 -0
  10. package/BuildingTool.mjs +74 -0
  11. package/ChunkMeshResult.d.ts +75 -0
  12. package/ChunkMeshResult.mjs +253 -0
  13. package/CircuitBuilder.d.ts +118 -0
  14. package/CircuitBuilder.mjs +516 -0
  15. package/DefinitionRegion.d.ts +274 -0
  16. package/DefinitionRegion.mjs +973 -0
  17. package/Diff.d.ts +88 -0
  18. package/Diff.mjs +316 -0
  19. package/Dimensions.d.ts +28 -0
  20. package/Dimensions.mjs +129 -0
  21. package/ExecutionMode.d.ts +42 -0
  22. package/ExecutionMode.mjs +127 -0
  23. package/Fingerprint.d.ts +44 -0
  24. package/Fingerprint.mjs +197 -0
  25. package/InterpolationSpace.d.ts +25 -0
  26. package/InterpolationSpace.mjs +73 -0
  27. package/IoLayout.d.ts +26 -0
  28. package/IoLayout.mjs +81 -0
  29. package/IoLayoutBuilder.d.ts +73 -0
  30. package/IoLayoutBuilder.mjs +315 -0
  31. package/IoType.d.ts +41 -0
  32. package/IoType.mjs +125 -0
  33. package/ItemModelConfig.d.ts +65 -0
  34. package/ItemModelConfig.mjs +223 -0
  35. package/ItemModelPackBuilder.d.ts +32 -0
  36. package/ItemModelPackBuilder.mjs +104 -0
  37. package/ItemModelResult.d.ts +72 -0
  38. package/ItemModelResult.mjs +268 -0
  39. package/ItemScale.d.ts +31 -0
  40. package/ItemScale.mjs +132 -0
  41. package/LayoutFunction.d.ts +52 -0
  42. package/LayoutFunction.mjs +159 -0
  43. package/MchprsWorld.d.ts +131 -0
  44. package/MchprsWorld.mjs +423 -0
  45. package/MeshBounds.d.ts +40 -0
  46. package/MeshBounds.mjs +180 -0
  47. package/MeshConfig.d.ts +101 -0
  48. package/MeshConfig.mjs +306 -0
  49. package/MeshJob.d.ts +44 -0
  50. package/MeshJob.mjs +116 -0
  51. package/MeshPhase.d.ts +38 -0
  52. package/MeshPhase.mjs +90 -0
  53. package/MeshProgress.d.ts +32 -0
  54. package/MeshProgress.mjs +133 -0
  55. package/MeshResult.d.ts +60 -0
  56. package/MeshResult.mjs +206 -0
  57. package/MultiMeshResult.d.ts +50 -0
  58. package/MultiMeshResult.mjs +166 -0
  59. package/Nbt.d.ts +50 -0
  60. package/Nbt.mjs +161 -0
  61. package/NucleationError.d.ts +36 -0
  62. package/NucleationError.mjs +104 -0
  63. package/OutputCondition.d.ts +45 -0
  64. package/OutputCondition.mjs +129 -0
  65. package/README.md +28 -197
  66. package/RawMeshExport.d.ts +74 -0
  67. package/RawMeshExport.mjs +243 -0
  68. package/RedstoneGraph.d.ts +58 -0
  69. package/RedstoneGraph.mjs +242 -0
  70. package/RegionBounds.d.ts +41 -0
  71. package/RegionBounds.mjs +181 -0
  72. package/RenderConfig.d.ts +66 -0
  73. package/RenderConfig.mjs +170 -0
  74. package/Renderer.d.ts +35 -0
  75. package/Renderer.mjs +139 -0
  76. package/ResourcePack.d.ts +105 -0
  77. package/ResourcePack.mjs +447 -0
  78. package/ResourcePackList.d.ts +32 -0
  79. package/ResourcePackList.mjs +96 -0
  80. package/Schematic.d.ts +655 -0
  81. package/Schematic.mjs +2647 -0
  82. package/SchematicBuilder.d.ts +103 -0
  83. package/SchematicBuilder.mjs +401 -0
  84. package/SchematicRegions.d.ts +93 -0
  85. package/SchematicRegions.mjs +411 -0
  86. package/Scripting.d.ts +40 -0
  87. package/Scripting.mjs +138 -0
  88. package/Sdf.d.ts +31 -0
  89. package/Sdf.mjs +107 -0
  90. package/Shape.d.ts +108 -0
  91. package/Shape.mjs +336 -0
  92. package/SortStrategy.d.ts +86 -0
  93. package/SortStrategy.mjs +272 -0
  94. package/Store.d.ts +83 -0
  95. package/Store.mjs +369 -0
  96. package/StoreIo.d.ts +71 -0
  97. package/StoreIo.mjs +292 -0
  98. package/TextureAtlas.d.ts +40 -0
  99. package/TextureAtlas.mjs +122 -0
  100. package/TextureInfo.d.ts +34 -0
  101. package/TextureInfo.mjs +148 -0
  102. package/TypedCircuitExecutor.d.ts +101 -0
  103. package/TypedCircuitExecutor.mjs +378 -0
  104. package/Value.d.ts +73 -0
  105. package/Value.mjs +275 -0
  106. package/WorldChunkView.d.ts +63 -0
  107. package/WorldChunkView.mjs +201 -0
  108. package/WorldSink.d.ts +50 -0
  109. package/WorldSink.mjs +177 -0
  110. package/WorldStream.d.ts +45 -0
  111. package/WorldStream.mjs +184 -0
  112. package/diplomat-runtime.d.ts +15 -0
  113. package/diplomat-runtime.mjs +774 -0
  114. package/diplomat-wasm.mjs +52 -0
  115. package/diplomat.config.mjs +6 -0
  116. package/index.d.ts +113 -0
  117. package/index.mjs +116 -0
  118. package/{nucleation_bg.wasm → nucleation.wasm} +0 -0
  119. package/package.json +19 -41
  120. package/LICENSE +0 -21
  121. package/api.js +0 -608
  122. package/nucleation-cdn-loader.js +0 -15
  123. package/nucleation-original.js +0 -8383
  124. package/nucleation.d.ts +0 -2947
  125. package/nucleation.js +0 -36
@@ -0,0 +1,32 @@
1
+ // generated by diplomat-tool
2
+ import type { MeshPhase } from "./MeshPhase"
3
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
4
+
5
+ export type MeshProgress_obj = {
6
+ phase: MeshPhase;
7
+ current: number;
8
+ total: number;
9
+ };
10
+
11
+
12
+
13
+ /**
14
+ * Snapshot of a {@link MeshJob}'s progress.
15
+ */
16
+ export class MeshProgress {
17
+ get phase(): MeshPhase;
18
+ set phase(value: MeshPhase);
19
+ get current(): number;
20
+ set current(value: number);
21
+ get total(): number;
22
+ set total(value: number);
23
+ /** @internal */
24
+ static fromFields(structObj : MeshProgress_obj) : MeshProgress;
25
+
26
+ /**
27
+ * Create `MeshProgress` from an object that contains all of `MeshProgress`s fields.
28
+ * Optional fields do not need to be included in the provided object.
29
+ */
30
+ constructor(structObj: MeshProgress_obj);
31
+
32
+ }
@@ -0,0 +1,133 @@
1
+ // generated by diplomat-tool
2
+ import { MeshPhase } from "./MeshPhase.mjs"
3
+ import wasm from "./diplomat-wasm.mjs";
4
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
+
6
+
7
+
8
+ /**
9
+ * Snapshot of a {@link MeshJob}'s progress.
10
+ */
11
+ export class MeshProgress {
12
+ #phase;
13
+ get phase() {
14
+ return this.#phase;
15
+ }
16
+ set phase(value){
17
+ this.#phase = value;
18
+ }
19
+ #current;
20
+ get current() {
21
+ return this.#current;
22
+ }
23
+ set current(value){
24
+ this.#current = value;
25
+ }
26
+ #total;
27
+ get total() {
28
+ return this.#total;
29
+ }
30
+ set total(value){
31
+ this.#total = value;
32
+ }
33
+ /** @internal */
34
+ static fromFields(structObj) {
35
+ return new MeshProgress(structObj);
36
+ }
37
+
38
+ #internalConstructor(structObj) {
39
+ if (typeof structObj !== "object") {
40
+ throw new Error("MeshProgress's constructor takes an object of MeshProgress's fields.");
41
+ }
42
+
43
+ if ("phase" in structObj) {
44
+ this.#phase = structObj.phase;
45
+ } else {
46
+ throw new Error("Missing required field phase.");
47
+ }
48
+
49
+ if ("current" in structObj) {
50
+ this.#current = structObj.current;
51
+ } else {
52
+ throw new Error("Missing required field current.");
53
+ }
54
+
55
+ if ("total" in structObj) {
56
+ this.#total = structObj.total;
57
+ } else {
58
+ throw new Error("Missing required field total.");
59
+ }
60
+
61
+ return this;
62
+ }
63
+
64
+ // Return this struct in FFI function friendly format.
65
+ // Returns an array that can be expanded with spread syntax (...)
66
+ _intoFFI(
67
+ dst,
68
+ functionCleanupArena,
69
+ appendArrayMap
70
+ ) {
71
+
72
+ this._writeToArrayBuffer(wasm.memory.buffer, dst, functionCleanupArena, appendArrayMap);
73
+
74
+ return dst;
75
+ }
76
+
77
+ static get _sizeBytes() {
78
+ return 12;
79
+ }
80
+
81
+ /// Currently unused, we may want to use later on though:
82
+ static get _sizeAlign() {
83
+ return 4;
84
+ }
85
+
86
+ static _fromSuppliedValue(internalConstructor, obj) {
87
+ if (internalConstructor !== diplomatRuntime.internalConstructor) {
88
+ throw new Error("_fromSuppliedValue cannot be called externally.");
89
+ }
90
+
91
+ if (obj instanceof MeshProgress) {
92
+ return obj;
93
+ }
94
+
95
+ return MeshProgress.fromFields(obj);
96
+ }
97
+
98
+ _writeToArrayBuffer(
99
+ arrayBuffer,
100
+ offset,
101
+ functionCleanupArena,
102
+ appendArrayMap
103
+ ) {
104
+ diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#phase.ffiValue, Int32Array);
105
+ diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#current, Uint32Array);
106
+ diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#total, Uint32Array);
107
+ }
108
+
109
+ // This struct contains borrowed fields, so this takes in a list of
110
+ // "edges" corresponding to where each lifetime's data may have been borrowed from
111
+ // and passes it down to individual fields containing the borrow.
112
+ // This method does not attempt to handle any dependencies between lifetimes, the caller
113
+ // should handle this when constructing edge arrays.
114
+ static _fromFFI(internalConstructor, ptr) {
115
+ if (internalConstructor !== diplomatRuntime.internalConstructor) {
116
+ throw new Error("MeshProgress._fromFFI is not meant to be called externally. Please use the default constructor.");
117
+ }
118
+ let structObj = {};
119
+ const phaseDeref = diplomatRuntime.enumDiscriminant(wasm, ptr);
120
+ structObj.phase = new MeshPhase(diplomatRuntime.internalConstructor, phaseDeref);
121
+ const currentDeref = (new Uint32Array(wasm.memory.buffer, ptr + 4, 1))[0];
122
+ structObj.current = currentDeref;
123
+ const totalDeref = (new Uint32Array(wasm.memory.buffer, ptr + 8, 1))[0];
124
+ structObj.total = totalDeref;
125
+
126
+ return new MeshProgress(structObj);
127
+ }
128
+
129
+
130
+ constructor(structObj) {
131
+ return this.#internalConstructor(...arguments)
132
+ }
133
+ }
@@ -0,0 +1,60 @@
1
+ // generated by diplomat-tool
2
+ import type { MeshBounds } from "./MeshBounds"
3
+ import type { MeshConfig } from "./MeshConfig"
4
+ import type { NucleationError } from "./NucleationError"
5
+ import type { ResourcePack } from "./ResourcePack"
6
+ import type { Schematic } from "./Schematic"
7
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
8
+
9
+
10
+
11
+ /**
12
+ * A single mesh output. Wraps {@link crate::meshing::MeshResult}.
13
+ */
14
+ export class MeshResult {
15
+ /** @internal */
16
+ get ffiValue(): pointer;
17
+ /** @internal */
18
+ constructor();
19
+
20
+
21
+ /**
22
+ * Mesh an entire schematic in one pass (old ABI: `schematic_to_mesh`).
23
+ */
24
+ static create(schematic: Schematic, pack: ResourcePack, config: MeshConfig): MeshResult;
25
+
26
+ /**
27
+ * Mesh a schematic with USDZ-compatible output (old ABI: `schematic_to_usdz`).
28
+ */
29
+ static createUsdz(schematic: Schematic, pack: ResourcePack, config: MeshConfig): MeshResult;
30
+
31
+ /**
32
+ * The mesh as a binary GLB, base64-encoded.
33
+ */
34
+ glbDataB64(): string;
35
+
36
+ /**
37
+ * The mesh serialized in the NUCM cache format, base64-encoded.
38
+ */
39
+ nucmDataB64(): string;
40
+
41
+ /**
42
+ * Total number of vertices in the mesh.
43
+ */
44
+ vertexCount(): number;
45
+
46
+ /**
47
+ * Total number of triangles in the mesh.
48
+ */
49
+ triangleCount(): number;
50
+
51
+ /**
52
+ * Whether the mesh contains any transparent or translucent geometry.
53
+ */
54
+ hasTransparency(): boolean;
55
+
56
+ /**
57
+ * Axis-aligned bounding box of the mesh, in world units.
58
+ */
59
+ bounds(): MeshBounds;
60
+ }
package/MeshResult.mjs ADDED
@@ -0,0 +1,206 @@
1
+ // generated by diplomat-tool
2
+ import { MeshBounds } from "./MeshBounds.mjs"
3
+ import { MeshConfig } from "./MeshConfig.mjs"
4
+ import { NucleationError } from "./NucleationError.mjs"
5
+ import { ResourcePack } from "./ResourcePack.mjs"
6
+ import { Schematic } from "./Schematic.mjs"
7
+ import wasm from "./diplomat-wasm.mjs";
8
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
9
+
10
+ const MeshResult_box_destroy_registry = new FinalizationRegistry((ptr) => {
11
+ wasm.MeshResult_destroy(ptr);
12
+ });
13
+
14
+ /**
15
+ * A single mesh output. Wraps {@link crate::meshing::MeshResult}.
16
+ */
17
+ export class MeshResult {
18
+ // Internal ptr reference:
19
+ #ptr = null;
20
+
21
+ // Lifetimes are only to keep dependencies alive.
22
+ // Since JS won't garbage collect until there are no incoming edges.
23
+ #selfEdge = [];
24
+
25
+ #internalConstructor(symbol, ptr, selfEdge) {
26
+ if (symbol !== diplomatRuntime.internalConstructor) {
27
+ console.error("MeshResult is an Opaque type. You cannot call its constructor.");
28
+ return;
29
+ }
30
+ this.#ptr = ptr;
31
+ this.#selfEdge = selfEdge;
32
+
33
+ // Are we being borrowed? If not, we can register.
34
+ if (this.#selfEdge.length === 0) {
35
+ MeshResult_box_destroy_registry.register(this, this.#ptr);
36
+ }
37
+
38
+ return this;
39
+ }
40
+ /** @internal */
41
+ get ffiValue() {
42
+ return this.#ptr;
43
+ }
44
+
45
+
46
+ /**
47
+ * Mesh an entire schematic in one pass (old ABI: `schematic_to_mesh`).
48
+ */
49
+ static create(schematic, pack, config) {
50
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
51
+
52
+
53
+ const result = wasm.MeshResult_create(diplomatReceive.buffer, schematic.ffiValue, pack.ffiValue, config.ffiValue);
54
+
55
+ try {
56
+ if (!diplomatReceive.resultFlag) {
57
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
58
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
59
+ }
60
+ return new MeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
61
+ }
62
+
63
+ finally {
64
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
65
+ diplomatReceive.free();
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Mesh a schematic with USDZ-compatible output (old ABI: `schematic_to_usdz`).
71
+ */
72
+ static createUsdz(schematic, pack, config) {
73
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
74
+
75
+
76
+ const result = wasm.MeshResult_create_usdz(diplomatReceive.buffer, schematic.ffiValue, pack.ffiValue, config.ffiValue);
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 MeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
84
+ }
85
+
86
+ finally {
87
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
88
+ diplomatReceive.free();
89
+ }
90
+ }
91
+
92
+ /**
93
+ * The mesh as a binary GLB, base64-encoded.
94
+ */
95
+ glbDataB64() {
96
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
97
+
98
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
99
+
100
+
101
+ const result = wasm.MeshResult_glb_data_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
102
+
103
+ try {
104
+ if (!diplomatReceive.resultFlag) {
105
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
106
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
107
+ }
108
+ return write.readString8();
109
+ }
110
+
111
+ finally {
112
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
113
+ diplomatReceive.free();
114
+ write.free();
115
+ }
116
+ }
117
+
118
+ /**
119
+ * The mesh serialized in the NUCM cache format, base64-encoded.
120
+ */
121
+ nucmDataB64() {
122
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
123
+
124
+ wasm.MeshResult_nucm_data_b64(this.ffiValue, write.buffer);
125
+
126
+ try {
127
+ return write.readString8();
128
+ }
129
+
130
+ finally {
131
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
132
+ write.free();
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Total number of vertices in the mesh.
138
+ */
139
+ vertexCount() {
140
+
141
+ const result = wasm.MeshResult_vertex_count(this.ffiValue);
142
+
143
+ try {
144
+ return result;
145
+ }
146
+
147
+ finally {
148
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Total number of triangles in the mesh.
154
+ */
155
+ triangleCount() {
156
+
157
+ const result = wasm.MeshResult_triangle_count(this.ffiValue);
158
+
159
+ try {
160
+ return result;
161
+ }
162
+
163
+ finally {
164
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Whether the mesh contains any transparent or translucent geometry.
170
+ */
171
+ hasTransparency() {
172
+
173
+ const result = wasm.MeshResult_has_transparency(this.ffiValue);
174
+
175
+ try {
176
+ return result;
177
+ }
178
+
179
+ finally {
180
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Axis-aligned bounding box of the mesh, in world units.
186
+ */
187
+ bounds() {
188
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 24, 4, false);
189
+
190
+
191
+ const result = wasm.MeshResult_bounds(diplomatReceive.buffer, this.ffiValue);
192
+
193
+ try {
194
+ return MeshBounds._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
195
+ }
196
+
197
+ finally {
198
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
199
+ diplomatReceive.free();
200
+ }
201
+ }
202
+
203
+ constructor(symbol, ptr, selfEdge) {
204
+ return this.#internalConstructor(...arguments)
205
+ }
206
+ }
@@ -0,0 +1,50 @@
1
+ // generated by diplomat-tool
2
+ import type { MeshConfig } from "./MeshConfig"
3
+ import type { MeshResult } from "./MeshResult"
4
+ import type { NucleationError } from "./NucleationError"
5
+ import type { ResourcePack } from "./ResourcePack"
6
+ import type { Schematic } from "./Schematic"
7
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
8
+
9
+
10
+
11
+ /**
12
+ * Per-region mesh results. Wraps {@link crate::meshing::MultiMeshResult}.
13
+ */
14
+ export class MultiMeshResult {
15
+ /** @internal */
16
+ get ffiValue(): pointer;
17
+ /** @internal */
18
+ constructor();
19
+
20
+
21
+ /**
22
+ * Mesh each region separately (old ABI: `schematic_mesh_by_region`).
23
+ */
24
+ static create(schematic: Schematic, pack: ResourcePack, config: MeshConfig): MultiMeshResult;
25
+
26
+ /**
27
+ * Region names, as a JSON array string.
28
+ */
29
+ regionNamesJson(): string;
30
+
31
+ /**
32
+ * The mesh for one region (cloned).
33
+ */
34
+ getMesh(regionName: string): MeshResult;
35
+
36
+ /**
37
+ * Total vertex count across all region meshes.
38
+ */
39
+ totalVertexCount(): number;
40
+
41
+ /**
42
+ * Total triangle count across all region meshes.
43
+ */
44
+ totalTriangleCount(): number;
45
+
46
+ /**
47
+ * Number of region meshes.
48
+ */
49
+ meshCount(): number;
50
+ }
@@ -0,0 +1,166 @@
1
+ // generated by diplomat-tool
2
+ import { MeshConfig } from "./MeshConfig.mjs"
3
+ import { MeshResult } from "./MeshResult.mjs"
4
+ import { NucleationError } from "./NucleationError.mjs"
5
+ import { ResourcePack } from "./ResourcePack.mjs"
6
+ import { Schematic } from "./Schematic.mjs"
7
+ import wasm from "./diplomat-wasm.mjs";
8
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
9
+
10
+ const MultiMeshResult_box_destroy_registry = new FinalizationRegistry((ptr) => {
11
+ wasm.MultiMeshResult_destroy(ptr);
12
+ });
13
+
14
+ /**
15
+ * Per-region mesh results. Wraps {@link crate::meshing::MultiMeshResult}.
16
+ */
17
+ export class MultiMeshResult {
18
+ // Internal ptr reference:
19
+ #ptr = null;
20
+
21
+ // Lifetimes are only to keep dependencies alive.
22
+ // Since JS won't garbage collect until there are no incoming edges.
23
+ #selfEdge = [];
24
+
25
+ #internalConstructor(symbol, ptr, selfEdge) {
26
+ if (symbol !== diplomatRuntime.internalConstructor) {
27
+ console.error("MultiMeshResult is an Opaque type. You cannot call its constructor.");
28
+ return;
29
+ }
30
+ this.#ptr = ptr;
31
+ this.#selfEdge = selfEdge;
32
+
33
+ // Are we being borrowed? If not, we can register.
34
+ if (this.#selfEdge.length === 0) {
35
+ MultiMeshResult_box_destroy_registry.register(this, this.#ptr);
36
+ }
37
+
38
+ return this;
39
+ }
40
+ /** @internal */
41
+ get ffiValue() {
42
+ return this.#ptr;
43
+ }
44
+
45
+
46
+ /**
47
+ * Mesh each region separately (old ABI: `schematic_mesh_by_region`).
48
+ */
49
+ static create(schematic, pack, config) {
50
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
51
+
52
+
53
+ const result = wasm.MultiMeshResult_create(diplomatReceive.buffer, schematic.ffiValue, pack.ffiValue, config.ffiValue);
54
+
55
+ try {
56
+ if (!diplomatReceive.resultFlag) {
57
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
58
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
59
+ }
60
+ return new MultiMeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
61
+ }
62
+
63
+ finally {
64
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
65
+ diplomatReceive.free();
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Region names, as a JSON array string.
71
+ */
72
+ regionNamesJson() {
73
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
74
+
75
+ wasm.MultiMeshResult_region_names_json(this.ffiValue, write.buffer);
76
+
77
+ try {
78
+ return write.readString8();
79
+ }
80
+
81
+ finally {
82
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
83
+ write.free();
84
+ }
85
+ }
86
+
87
+ /**
88
+ * The mesh for one region (cloned).
89
+ */
90
+ getMesh(regionName) {
91
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
92
+
93
+ const regionNameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, regionName)));
94
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
95
+
96
+
97
+ const result = wasm.MultiMeshResult_get_mesh(diplomatReceive.buffer, this.ffiValue, regionNameSlice.ptr);
98
+
99
+ try {
100
+ if (!diplomatReceive.resultFlag) {
101
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
102
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
103
+ }
104
+ return new MeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
105
+ }
106
+
107
+ finally {
108
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
109
+ functionCleanupArena.free();
110
+
111
+ diplomatReceive.free();
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Total vertex count across all region meshes.
117
+ */
118
+ totalVertexCount() {
119
+
120
+ const result = wasm.MultiMeshResult_total_vertex_count(this.ffiValue);
121
+
122
+ try {
123
+ return result;
124
+ }
125
+
126
+ finally {
127
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Total triangle count across all region meshes.
133
+ */
134
+ totalTriangleCount() {
135
+
136
+ const result = wasm.MultiMeshResult_total_triangle_count(this.ffiValue);
137
+
138
+ try {
139
+ return result;
140
+ }
141
+
142
+ finally {
143
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Number of region meshes.
149
+ */
150
+ meshCount() {
151
+
152
+ const result = wasm.MultiMeshResult_mesh_count(this.ffiValue);
153
+
154
+ try {
155
+ return result;
156
+ }
157
+
158
+ finally {
159
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
160
+ }
161
+ }
162
+
163
+ constructor(symbol, ptr, selfEdge) {
164
+ return this.#internalConstructor(...arguments)
165
+ }
166
+ }
package/Nbt.d.ts ADDED
@@ -0,0 +1,50 @@
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
+ * Namespace type for the free-standing NBT builder helpers (the old
9
+ * `nbt_text_build` / `nbt_chest_build` / `nbt_sign_build`), following the
10
+ * static-methods-on-a-dummy-opaque pattern.
11
+ */
12
+ export class Nbt {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Build a Minecraft JSON text-component string.
21
+ *
22
+ * `color` may be empty (no color). `bold` and `italic` use `-1` for
23
+ * unset, `0` for false, nonzero for true.
24
+ */
25
+ static textBuild(s: string, color: string, bold: number, italic: number): string;
26
+
27
+ /**
28
+ * Build a chest-NBT SNBT string for use as the `{...}` portion of a block
29
+ * string.
30
+ *
31
+ * `items_json` is a JSON array of `{"id": string, "count"?: int,
32
+ * "slot"?: int}` entries (may be empty or `[]`); a missing/non-positive
33
+ * `count` defaults to 1, a missing/negative `slot` auto-assigns
34
+ * positionally. `name` is an optional plain-text custom name (empty = no
35
+ * `CustomName`); it is wrapped in a JSON text component automatically
36
+ * unless it already starts with `{`.
37
+ */
38
+ static chestBuild(itemsJson: string, name: string): string;
39
+
40
+ /**
41
+ * Build a modern (1.20+) sign-NBT SNBT string.
42
+ *
43
+ * `front_json` and `back_json` are JSON arrays of up to 4 line strings
44
+ * (either may be empty or `[]`). Each line may be a plain string
45
+ * (auto-wrapped via `text_build`) or an already-built JSON component
46
+ * (starts with `{`). `color` is the dye color string (empty defaults to
47
+ * `"black"`).
48
+ */
49
+ static signBuild(frontJson: string, backJson: string, color: string, glowing: boolean, waxed: boolean): string;
50
+ }