nucleation 0.2.18 → 0.3.1

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 (129) 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 +68 -0
  8. package/Brush.mjs +220 -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/Palette.d.ts +84 -0
  66. package/Palette.mjs +269 -0
  67. package/PaletteBuilder.d.ts +76 -0
  68. package/PaletteBuilder.mjs +297 -0
  69. package/README.md +28 -197
  70. package/RawMeshExport.d.ts +74 -0
  71. package/RawMeshExport.mjs +243 -0
  72. package/RedstoneGraph.d.ts +58 -0
  73. package/RedstoneGraph.mjs +242 -0
  74. package/RegionBounds.d.ts +41 -0
  75. package/RegionBounds.mjs +181 -0
  76. package/RenderConfig.d.ts +66 -0
  77. package/RenderConfig.mjs +170 -0
  78. package/Renderer.d.ts +35 -0
  79. package/Renderer.mjs +139 -0
  80. package/ResourcePack.d.ts +105 -0
  81. package/ResourcePack.mjs +447 -0
  82. package/ResourcePackList.d.ts +32 -0
  83. package/ResourcePackList.mjs +96 -0
  84. package/Schematic.d.ts +655 -0
  85. package/Schematic.mjs +2647 -0
  86. package/SchematicBuilder.d.ts +103 -0
  87. package/SchematicBuilder.mjs +401 -0
  88. package/SchematicRegions.d.ts +93 -0
  89. package/SchematicRegions.mjs +411 -0
  90. package/Scripting.d.ts +40 -0
  91. package/Scripting.mjs +138 -0
  92. package/Sdf.d.ts +31 -0
  93. package/Sdf.mjs +107 -0
  94. package/Shape.d.ts +108 -0
  95. package/Shape.mjs +336 -0
  96. package/SortStrategy.d.ts +86 -0
  97. package/SortStrategy.mjs +272 -0
  98. package/Store.d.ts +83 -0
  99. package/Store.mjs +369 -0
  100. package/StoreIo.d.ts +71 -0
  101. package/StoreIo.mjs +292 -0
  102. package/TextureAtlas.d.ts +40 -0
  103. package/TextureAtlas.mjs +122 -0
  104. package/TextureInfo.d.ts +34 -0
  105. package/TextureInfo.mjs +148 -0
  106. package/TypedCircuitExecutor.d.ts +101 -0
  107. package/TypedCircuitExecutor.mjs +378 -0
  108. package/Value.d.ts +73 -0
  109. package/Value.mjs +275 -0
  110. package/WorldChunkView.d.ts +63 -0
  111. package/WorldChunkView.mjs +201 -0
  112. package/WorldSink.d.ts +50 -0
  113. package/WorldSink.mjs +177 -0
  114. package/WorldStream.d.ts +45 -0
  115. package/WorldStream.mjs +184 -0
  116. package/diplomat-runtime.d.ts +15 -0
  117. package/diplomat-runtime.mjs +774 -0
  118. package/diplomat-wasm.mjs +52 -0
  119. package/diplomat.config.mjs +6 -0
  120. package/index.d.ts +117 -0
  121. package/index.mjs +120 -0
  122. package/{nucleation_bg.wasm → nucleation.wasm} +0 -0
  123. package/package.json +19 -41
  124. package/LICENSE +0 -21
  125. package/api.js +0 -608
  126. package/nucleation-cdn-loader.js +0 -15
  127. package/nucleation-original.js +0 -8383
  128. package/nucleation.d.ts +0 -2947
  129. package/nucleation.js +0 -36
package/Brush.mjs ADDED
@@ -0,0 +1,220 @@
1
+ // generated by diplomat-tool
2
+ import { InterpolationSpace } from "./InterpolationSpace.mjs"
3
+ import { NucleationError } from "./NucleationError.mjs"
4
+ import { Palette } from "./Palette.mjs"
5
+ import wasm from "./diplomat-wasm.mjs";
6
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
+
8
+ const Brush_box_destroy_registry = new FinalizationRegistry((ptr) => {
9
+ wasm.Brush_destroy(ptr);
10
+ });
11
+
12
+ /**
13
+ * Decides which block goes at each point of a filled shape. Wraps `BrushEnum`.
14
+ */
15
+ export class Brush {
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("Brush 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
+ Brush_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
+ * Every point becomes `block_name` (a block-state string).
46
+ */
47
+ static solid(blockName) {
48
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
49
+
50
+ const blockNameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, blockName)));
51
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
52
+
53
+
54
+ const result = wasm.Brush_solid(diplomatReceive.buffer, blockNameSlice.ptr);
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 Brush(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
+ /**
73
+ * Nearest-block-to-RGB-color brush.
74
+ */
75
+ static color(r, g, b) {
76
+
77
+ const result = wasm.Brush_color(r, g, b);
78
+
79
+ try {
80
+ return new Brush(diplomatRuntime.internalConstructor, result, []);
81
+ }
82
+
83
+ finally {
84
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Linear color gradient between two anchored points.
90
+ */
91
+ static linearGradient(x1, y1, z1, r1, g1, b1, x2, y2, z2, r2, g2, b2, space) {
92
+
93
+ const result = wasm.Brush_linear_gradient(x1, y1, z1, r1, g1, b1, x2, y2, z2, r2, g2, b2, space.ffiValue);
94
+
95
+ try {
96
+ return new Brush(diplomatRuntime.internalConstructor, result, []);
97
+ }
98
+
99
+ finally {
100
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Base color shaded by surface normal against light direction
106
+ * (`lx`, `ly`, `lz`).
107
+ */
108
+ static shaded(r, g, b, lx, ly, lz) {
109
+
110
+ const result = wasm.Brush_shaded(r, g, b, lx, ly, lz);
111
+
112
+ try {
113
+ return new Brush(diplomatRuntime.internalConstructor, result, []);
114
+ }
115
+
116
+ finally {
117
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Bilinear gradient over the patch `origin + s*u + t*v` with corner colors
123
+ * c00/c10/c01/c11.
124
+ */
125
+ static bilinearGradient(ox, oy, oz, ux, uy, uz, vx, vy, vz, r00, g00, b00, r10, g10, b10, r01, g01, b01, r11, g11, b11, space) {
126
+
127
+ const result = wasm.Brush_bilinear_gradient(ox, oy, oz, ux, uy, uz, vx, vy, vz, r00, g00, b00, r10, g10, b10, r01, g01, b01, r11, g11, b11, space.ffiValue);
128
+
129
+ try {
130
+ return new Brush(diplomatRuntime.internalConstructor, result, []);
131
+ }
132
+
133
+ finally {
134
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Inverse-distance-weighted gradient between colored anchor points.
140
+ * `positions` is flat `[x0, y0, z0, x1, …]` and `colors` is flat
141
+ * `[r0, g0, b0, r1, …]`; both must describe the same non-zero number of
142
+ * points (`positions.len() == colors.len()`, a multiple of 3).
143
+ */
144
+ static pointGradient(positions, colors, falloff, space) {
145
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
146
+
147
+ const positionsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, positions, "i32")));
148
+ const colorsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, colors, "u8")));
149
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
150
+
151
+
152
+ const result = wasm.Brush_point_gradient(diplomatReceive.buffer, positionsSlice.ptr, colorsSlice.ptr, falloff, space.ffiValue);
153
+
154
+ try {
155
+ if (!diplomatReceive.resultFlag) {
156
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
157
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
158
+ }
159
+ return new Brush(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
160
+ }
161
+
162
+ finally {
163
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
164
+ functionCleanupArena.free();
165
+
166
+ diplomatReceive.free();
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Use `palette` for this brush's color→block snapping instead of the
172
+ * default all-blocks palette. No-op for `solid` brushes, which place
173
+ * a fixed block state. Set it before filling; the palette is shared,
174
+ * not copied.
175
+ */
176
+ setPalette(palette) {
177
+ wasm.Brush_set_palette(this.ffiValue, palette.ffiValue);
178
+
179
+ try {}
180
+
181
+ finally {
182
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Gradient along a parametric curve: `stops` holds the curve parameters in
188
+ * `[0, 1]` and `colors` the matching flat RGB triples
189
+ * (`colors.len() == stops.len() * 3`, `stops` non-empty).
190
+ */
191
+ static curveGradient(stops, colors, space) {
192
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
193
+
194
+ const stopsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, stops, "f32")));
195
+ const colorsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, colors, "u8")));
196
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
197
+
198
+
199
+ const result = wasm.Brush_curve_gradient(diplomatReceive.buffer, stopsSlice.ptr, colorsSlice.ptr, space.ffiValue);
200
+
201
+ try {
202
+ if (!diplomatReceive.resultFlag) {
203
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
204
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
205
+ }
206
+ return new Brush(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
207
+ }
208
+
209
+ finally {
210
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
211
+ functionCleanupArena.free();
212
+
213
+ diplomatReceive.free();
214
+ }
215
+ }
216
+
217
+ constructor(symbol, ptr, selfEdge) {
218
+ return this.#internalConstructor(...arguments)
219
+ }
220
+ }
@@ -0,0 +1,29 @@
1
+ // generated by diplomat-tool
2
+ import type { Brush } from "./Brush"
3
+ import type { Schematic } from "./Schematic"
4
+ import type { Shape } from "./Shape"
5
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
6
+
7
+
8
+
9
+ /**
10
+ * Namespace for the fill operations that combine a schematic, a shape and a
11
+ * brush (the old `buildingtool_*` free functions).
12
+ */
13
+ export class BuildingTool {
14
+ /** @internal */
15
+ get ffiValue(): pointer;
16
+ /** @internal */
17
+ constructor();
18
+
19
+
20
+ /**
21
+ * Fill `shape` into `schematic` using `brush`.
22
+ */
23
+ static fill(schematic: Schematic, shape: Shape, brush: Brush): void;
24
+
25
+ /**
26
+ * Fill `count` copies of `shape`, each offset by `offset * i`.
27
+ */
28
+ static rstack(schematic: Schematic, shape: Shape, brush: Brush, count: number, offsetX: number, offsetY: number, offsetZ: number): void;
29
+ }
@@ -0,0 +1,74 @@
1
+ // generated by diplomat-tool
2
+ import { Brush } from "./Brush.mjs"
3
+ import { Schematic } from "./Schematic.mjs"
4
+ import { Shape } from "./Shape.mjs"
5
+ import wasm from "./diplomat-wasm.mjs";
6
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
+
8
+ const BuildingTool_box_destroy_registry = new FinalizationRegistry((ptr) => {
9
+ wasm.BuildingTool_destroy(ptr);
10
+ });
11
+
12
+ /**
13
+ * Namespace for the fill operations that combine a schematic, a shape and a
14
+ * brush (the old `buildingtool_*` free functions).
15
+ */
16
+ export class BuildingTool {
17
+ // Internal ptr reference:
18
+ #ptr = null;
19
+
20
+ // Lifetimes are only to keep dependencies alive.
21
+ // Since JS won't garbage collect until there are no incoming edges.
22
+ #selfEdge = [];
23
+
24
+ #internalConstructor(symbol, ptr, selfEdge) {
25
+ if (symbol !== diplomatRuntime.internalConstructor) {
26
+ console.error("BuildingTool is an Opaque type. You cannot call its constructor.");
27
+ return;
28
+ }
29
+ this.#ptr = ptr;
30
+ this.#selfEdge = selfEdge;
31
+
32
+ // Are we being borrowed? If not, we can register.
33
+ if (this.#selfEdge.length === 0) {
34
+ BuildingTool_box_destroy_registry.register(this, this.#ptr);
35
+ }
36
+
37
+ return this;
38
+ }
39
+ /** @internal */
40
+ get ffiValue() {
41
+ return this.#ptr;
42
+ }
43
+
44
+
45
+ /**
46
+ * Fill `shape` into `schematic` using `brush`.
47
+ */
48
+ static fill(schematic, shape, brush) {
49
+ wasm.BuildingTool_fill(schematic.ffiValue, shape.ffiValue, brush.ffiValue);
50
+
51
+ try {}
52
+
53
+ finally {
54
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Fill `count` copies of `shape`, each offset by `offset * i`.
60
+ */
61
+ static rstack(schematic, shape, brush, count, offsetX, offsetY, offsetZ) {
62
+ wasm.BuildingTool_rstack(schematic.ffiValue, shape.ffiValue, brush.ffiValue, count, offsetX, offsetY, offsetZ);
63
+
64
+ try {}
65
+
66
+ finally {
67
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
68
+ }
69
+ }
70
+
71
+ constructor(symbol, ptr, selfEdge) {
72
+ return this.#internalConstructor(...arguments)
73
+ }
74
+ }
@@ -0,0 +1,75 @@
1
+ // generated by diplomat-tool
2
+ import type { BlockPos } from "./BlockPos"
3
+ import type { MeshConfig } from "./MeshConfig"
4
+ import type { MeshResult } from "./MeshResult"
5
+ import type { NucleationError } from "./NucleationError"
6
+ import type { ResourcePack } from "./ResourcePack"
7
+ import type { Schematic } from "./Schematic"
8
+ import type { TextureAtlas } from "./TextureAtlas"
9
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
10
+
11
+
12
+
13
+ /**
14
+ * Per-chunk mesh results. Wraps {@link crate::meshing::ChunkMeshResult}.
15
+ */
16
+ export class ChunkMeshResult {
17
+ /** @internal */
18
+ get ffiValue(): pointer;
19
+ /** @internal */
20
+ constructor();
21
+
22
+
23
+ /**
24
+ * Mesh with the default chunk size (old ABI: `schematic_mesh_by_chunk`).
25
+ */
26
+ static create(schematic: Schematic, pack: ResourcePack, config: MeshConfig): ChunkMeshResult;
27
+
28
+ /**
29
+ * Mesh with an explicit chunk size (old ABI: `schematic_mesh_by_chunk_size`).
30
+ */
31
+ static createWithSize(schematic: Schematic, pack: ResourcePack, config: MeshConfig, chunkSize: number): ChunkMeshResult;
32
+
33
+ /**
34
+ * Mesh chunks against a pre-built shared atlas, synchronously
35
+ * (old ABI: `schematic_mesh_chunks_with_atlas`). For progress
36
+ * reporting use {@link MeshJob::start} instead.
37
+ */
38
+ static createWithAtlas(schematic: Schematic, pack: ResourcePack, config: MeshConfig, chunkSize: number, atlas: TextureAtlas): ChunkMeshResult;
39
+
40
+ /**
41
+ * Number of chunk meshes.
42
+ */
43
+ chunkCount(): number;
44
+
45
+ /**
46
+ * Coordinate of the `index`-th chunk (old ABI:
47
+ * `chunkmeshresult_chunk_coordinates` returned all of them flat).
48
+ */
49
+ chunkCoordinateAt(index: number): BlockPos;
50
+
51
+ /**
52
+ * The mesh for one chunk coordinate (cloned).
53
+ */
54
+ getMesh(cx: number, cy: number, cz: number): MeshResult;
55
+
56
+ /**
57
+ * Total vertex count across all chunk meshes.
58
+ */
59
+ totalVertexCount(): number;
60
+
61
+ /**
62
+ * Total triangle count across all chunk meshes.
63
+ */
64
+ totalTriangleCount(): number;
65
+
66
+ /**
67
+ * All chunk meshes serialized in the NUCM cache format, base64-encoded.
68
+ */
69
+ nucmDataB64(): string;
70
+
71
+ /**
72
+ * NUCM v2 with a shared atlas, base64-encoded.
73
+ */
74
+ nucmDataWithAtlasB64(atlas: TextureAtlas): string;
75
+ }
@@ -0,0 +1,253 @@
1
+ // generated by diplomat-tool
2
+ import { BlockPos } from "./BlockPos.mjs"
3
+ import { MeshConfig } from "./MeshConfig.mjs"
4
+ import { MeshResult } from "./MeshResult.mjs"
5
+ import { NucleationError } from "./NucleationError.mjs"
6
+ import { ResourcePack } from "./ResourcePack.mjs"
7
+ import { Schematic } from "./Schematic.mjs"
8
+ import { TextureAtlas } from "./TextureAtlas.mjs"
9
+ import wasm from "./diplomat-wasm.mjs";
10
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
11
+
12
+ const ChunkMeshResult_box_destroy_registry = new FinalizationRegistry((ptr) => {
13
+ wasm.ChunkMeshResult_destroy(ptr);
14
+ });
15
+
16
+ /**
17
+ * Per-chunk mesh results. Wraps {@link crate::meshing::ChunkMeshResult}.
18
+ */
19
+ export class ChunkMeshResult {
20
+ // Internal ptr reference:
21
+ #ptr = null;
22
+
23
+ // Lifetimes are only to keep dependencies alive.
24
+ // Since JS won't garbage collect until there are no incoming edges.
25
+ #selfEdge = [];
26
+
27
+ #internalConstructor(symbol, ptr, selfEdge) {
28
+ if (symbol !== diplomatRuntime.internalConstructor) {
29
+ console.error("ChunkMeshResult is an Opaque type. You cannot call its constructor.");
30
+ return;
31
+ }
32
+ this.#ptr = ptr;
33
+ this.#selfEdge = selfEdge;
34
+
35
+ // Are we being borrowed? If not, we can register.
36
+ if (this.#selfEdge.length === 0) {
37
+ ChunkMeshResult_box_destroy_registry.register(this, this.#ptr);
38
+ }
39
+
40
+ return this;
41
+ }
42
+ /** @internal */
43
+ get ffiValue() {
44
+ return this.#ptr;
45
+ }
46
+
47
+
48
+ /**
49
+ * Mesh with the default chunk size (old ABI: `schematic_mesh_by_chunk`).
50
+ */
51
+ static create(schematic, pack, config) {
52
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
53
+
54
+
55
+ const result = wasm.ChunkMeshResult_create(diplomatReceive.buffer, schematic.ffiValue, pack.ffiValue, config.ffiValue);
56
+
57
+ try {
58
+ if (!diplomatReceive.resultFlag) {
59
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
60
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
61
+ }
62
+ return new ChunkMeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
63
+ }
64
+
65
+ finally {
66
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
67
+ diplomatReceive.free();
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Mesh with an explicit chunk size (old ABI: `schematic_mesh_by_chunk_size`).
73
+ */
74
+ static createWithSize(schematic, pack, config, chunkSize) {
75
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
76
+
77
+
78
+ const result = wasm.ChunkMeshResult_create_with_size(diplomatReceive.buffer, schematic.ffiValue, pack.ffiValue, config.ffiValue, chunkSize);
79
+
80
+ try {
81
+ if (!diplomatReceive.resultFlag) {
82
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
83
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
84
+ }
85
+ return new ChunkMeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
86
+ }
87
+
88
+ finally {
89
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
90
+ diplomatReceive.free();
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Mesh chunks against a pre-built shared atlas, synchronously
96
+ * (old ABI: `schematic_mesh_chunks_with_atlas`). For progress
97
+ * reporting use {@link MeshJob::start} instead.
98
+ */
99
+ static createWithAtlas(schematic, pack, config, chunkSize, atlas) {
100
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
101
+
102
+
103
+ const result = wasm.ChunkMeshResult_create_with_atlas(diplomatReceive.buffer, schematic.ffiValue, pack.ffiValue, config.ffiValue, chunkSize, atlas.ffiValue);
104
+
105
+ try {
106
+ if (!diplomatReceive.resultFlag) {
107
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
108
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
109
+ }
110
+ return new ChunkMeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
111
+ }
112
+
113
+ finally {
114
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
115
+ diplomatReceive.free();
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Number of chunk meshes.
121
+ */
122
+ chunkCount() {
123
+
124
+ const result = wasm.ChunkMeshResult_chunk_count(this.ffiValue);
125
+
126
+ try {
127
+ return result;
128
+ }
129
+
130
+ finally {
131
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Coordinate of the `index`-th chunk (old ABI:
137
+ * `chunkmeshresult_chunk_coordinates` returned all of them flat).
138
+ */
139
+ chunkCoordinateAt(index) {
140
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 13, 4, true);
141
+
142
+
143
+ const result = wasm.ChunkMeshResult_chunk_coordinate_at(diplomatReceive.buffer, this.ffiValue, index);
144
+
145
+ try {
146
+ if (!diplomatReceive.resultFlag) {
147
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
148
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
149
+ }
150
+ return BlockPos._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
151
+ }
152
+
153
+ finally {
154
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
155
+ diplomatReceive.free();
156
+ }
157
+ }
158
+
159
+ /**
160
+ * The mesh for one chunk coordinate (cloned).
161
+ */
162
+ getMesh(cx, cy, cz) {
163
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
164
+
165
+
166
+ const result = wasm.ChunkMeshResult_get_mesh(diplomatReceive.buffer, this.ffiValue, cx, cy, cz);
167
+
168
+ try {
169
+ if (!diplomatReceive.resultFlag) {
170
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
171
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
172
+ }
173
+ return new MeshResult(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
174
+ }
175
+
176
+ finally {
177
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
178
+ diplomatReceive.free();
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Total vertex count across all chunk meshes.
184
+ */
185
+ totalVertexCount() {
186
+
187
+ const result = wasm.ChunkMeshResult_total_vertex_count(this.ffiValue);
188
+
189
+ try {
190
+ return result;
191
+ }
192
+
193
+ finally {
194
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Total triangle count across all chunk meshes.
200
+ */
201
+ totalTriangleCount() {
202
+
203
+ const result = wasm.ChunkMeshResult_total_triangle_count(this.ffiValue);
204
+
205
+ try {
206
+ return result;
207
+ }
208
+
209
+ finally {
210
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
211
+ }
212
+ }
213
+
214
+ /**
215
+ * All chunk meshes serialized in the NUCM cache format, base64-encoded.
216
+ */
217
+ nucmDataB64() {
218
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
219
+
220
+ wasm.ChunkMeshResult_nucm_data_b64(this.ffiValue, write.buffer);
221
+
222
+ try {
223
+ return write.readString8();
224
+ }
225
+
226
+ finally {
227
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
228
+ write.free();
229
+ }
230
+ }
231
+
232
+ /**
233
+ * NUCM v2 with a shared atlas, base64-encoded.
234
+ */
235
+ nucmDataWithAtlasB64(atlas) {
236
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
237
+
238
+ wasm.ChunkMeshResult_nucm_data_with_atlas_b64(this.ffiValue, atlas.ffiValue, write.buffer);
239
+
240
+ try {
241
+ return write.readString8();
242
+ }
243
+
244
+ finally {
245
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
246
+ write.free();
247
+ }
248
+ }
249
+
250
+ constructor(symbol, ptr, selfEdge) {
251
+ return this.#internalConstructor(...arguments)
252
+ }
253
+ }