nucleation 0.3.7 → 0.3.9
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/Blocks.d.ts +8 -0
- package/Blocks.mjs +29 -0
- package/Brush.d.ts +9 -0
- package/Brush.mjs +20 -0
- package/PaletteBuilder.d.ts +18 -0
- package/PaletteBuilder.mjs +69 -0
- package/Shape.d.ts +17 -0
- package/Shape.mjs +63 -0
- package/Voxelizer.d.ts +56 -0
- package/Voxelizer.mjs +155 -0
- package/index.d.ts +2 -0
- package/index.mjs +2 -0
- package/nucleation.wasm +0 -0
- package/package.json +1 -1
package/Blocks.d.ts
CHANGED
|
@@ -38,6 +38,14 @@ export class Blocks {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Ids of every block carrying the vanilla block tag, as a sorted
|
|
41
|
+
* Blocks whose measured texture color is within `max_distance`
|
|
42
|
+
* (Oklab; ~0.05 = same color family, ~0.15 = generous) of the given
|
|
43
|
+
* RGB, as a JSON array of `{"id", "color": [r,g,b], "distance"}`
|
|
44
|
+
* sorted nearest-first. Blocks without color data never match.
|
|
45
|
+
*/
|
|
46
|
+
static byColorJson(r: number, g: number, b: number, maxDistance: number): string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
41
49
|
* JSON array string (`[]` for unknown tags). Accepts
|
|
42
50
|
* `minecraft:wool` and short `wool` forms, including nested paths
|
|
43
51
|
* like `mineable/pickaxe`.
|
package/Blocks.mjs
CHANGED
|
@@ -102,6 +102,35 @@ export class Blocks {
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Ids of every block carrying the vanilla block tag, as a sorted
|
|
105
|
+
* Blocks whose measured texture color is within `max_distance`
|
|
106
|
+
* (Oklab; ~0.05 = same color family, ~0.15 = generous) of the given
|
|
107
|
+
* RGB, as a JSON array of `{"id", "color": [r,g,b], "distance"}`
|
|
108
|
+
* sorted nearest-first. Blocks without color data never match.
|
|
109
|
+
*/
|
|
110
|
+
static byColorJson(r, g, b, maxDistance) {
|
|
111
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
112
|
+
|
|
113
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const result = wasm.Blocks_by_color_json(diplomatReceive.buffer, r, g, b, maxDistance, write.buffer);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
if (!diplomatReceive.resultFlag) {
|
|
120
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
121
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
122
|
+
}
|
|
123
|
+
return write.readString8();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
finally {
|
|
127
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
128
|
+
diplomatReceive.free();
|
|
129
|
+
write.free();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
105
134
|
* JSON array string (`[]` for unknown tags). Accepts
|
|
106
135
|
* `minecraft:wool` and short `wool` forms, including nested paths
|
|
107
136
|
* like `mineable/pickaxe`.
|
package/Brush.d.ts
CHANGED
|
@@ -51,6 +51,15 @@ export class Brush {
|
|
|
51
51
|
*/
|
|
52
52
|
static pointGradient(positions: Array<number>, colors: Array<number>, falloff: number, space: InterpolationSpace): Brush;
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Spotlight-lit base color (`r`, `g`, `b`): Lambert shading toward a
|
|
56
|
+
* cone light at (`px`, `py`, `pz`) aimed along (`dx`, `dy`, `dz`).
|
|
57
|
+
* Full intensity inside 0.7 × `cone_angle_deg`, smoothstep falloff
|
|
58
|
+
* to zero at the cone edge; surfaces facing away or outside the cone
|
|
59
|
+
* drop to a 4% ambient floor.
|
|
60
|
+
*/
|
|
61
|
+
static spotlight(px: number, py: number, pz: number, dx: number, dy: number, dz: number, coneAngleDeg: number, r: number, g: number, b: number): Brush;
|
|
62
|
+
|
|
54
63
|
/**
|
|
55
64
|
* Use `palette` for this brush's color→block snapping instead of the
|
|
56
65
|
* default all-blocks palette. No-op for `solid` brushes, which place
|
package/Brush.mjs
CHANGED
|
@@ -167,6 +167,26 @@ export class Brush {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Spotlight-lit base color (`r`, `g`, `b`): Lambert shading toward a
|
|
172
|
+
* cone light at (`px`, `py`, `pz`) aimed along (`dx`, `dy`, `dz`).
|
|
173
|
+
* Full intensity inside 0.7 × `cone_angle_deg`, smoothstep falloff
|
|
174
|
+
* to zero at the cone edge; surfaces facing away or outside the cone
|
|
175
|
+
* drop to a 4% ambient floor.
|
|
176
|
+
*/
|
|
177
|
+
static spotlight(px, py, pz, dx, dy, dz, coneAngleDeg, r, g, b) {
|
|
178
|
+
|
|
179
|
+
const result = wasm.Brush_spotlight(px, py, pz, dx, dy, dz, coneAngleDeg, r, g, b);
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
return new Brush(diplomatRuntime.internalConstructor, result, []);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
finally {
|
|
186
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
170
190
|
/**
|
|
171
191
|
* Use `palette` for this brush's color→block snapping instead of the
|
|
172
192
|
* default all-blocks palette. No-op for `solid` brushes, which place
|
package/PaletteBuilder.d.ts
CHANGED
|
@@ -94,6 +94,24 @@ export class PaletteBuilder {
|
|
|
94
94
|
*/
|
|
95
95
|
kind(k: string): void;
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Keep only blocks whose measured Oklab lightness L is within
|
|
99
|
+
* `[min, max]` (0.0 = black, 1.0 = white).
|
|
100
|
+
*/
|
|
101
|
+
lightnessBetween(min: number, max: number): void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Keep only near-neutral blocks: measured Oklab chroma at most
|
|
105
|
+
* `max` (the grayscale preset uses 0.022).
|
|
106
|
+
*/
|
|
107
|
+
chromaBelow(max: number): void;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Keep only blocks whose measured color is within `max_distance`
|
|
111
|
+
* (Oklab; ~0.05 = same family, ~0.15 = generous) of the RGB color.
|
|
112
|
+
*/
|
|
113
|
+
colorNear(r: number, g: number, b: number, maxDistance: number): void;
|
|
114
|
+
|
|
97
115
|
/**
|
|
98
116
|
* Build the palette; consumes the builder.
|
|
99
117
|
*/
|
package/PaletteBuilder.mjs
CHANGED
|
@@ -359,6 +359,75 @@ export class PaletteBuilder {
|
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Keep only blocks whose measured Oklab lightness L is within
|
|
364
|
+
* `[min, max]` (0.0 = black, 1.0 = white).
|
|
365
|
+
*/
|
|
366
|
+
lightnessBetween(min, max) {
|
|
367
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
const result = wasm.PaletteBuilder_lightness_between(diplomatReceive.buffer, this.ffiValue, min, max);
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
if (!diplomatReceive.resultFlag) {
|
|
374
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
375
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
finally {
|
|
380
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
381
|
+
diplomatReceive.free();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Keep only near-neutral blocks: measured Oklab chroma at most
|
|
387
|
+
* `max` (the grayscale preset uses 0.022).
|
|
388
|
+
*/
|
|
389
|
+
chromaBelow(max) {
|
|
390
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
const result = wasm.PaletteBuilder_chroma_below(diplomatReceive.buffer, this.ffiValue, max);
|
|
394
|
+
|
|
395
|
+
try {
|
|
396
|
+
if (!diplomatReceive.resultFlag) {
|
|
397
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
398
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
finally {
|
|
403
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
404
|
+
diplomatReceive.free();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Keep only blocks whose measured color is within `max_distance`
|
|
410
|
+
* (Oklab; ~0.05 = same family, ~0.15 = generous) of the RGB color.
|
|
411
|
+
*/
|
|
412
|
+
colorNear(r, g, b, maxDistance) {
|
|
413
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
const result = wasm.PaletteBuilder_color_near(diplomatReceive.buffer, this.ffiValue, r, g, b, maxDistance);
|
|
417
|
+
|
|
418
|
+
try {
|
|
419
|
+
if (!diplomatReceive.resultFlag) {
|
|
420
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
421
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
finally {
|
|
426
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
427
|
+
diplomatReceive.free();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
362
431
|
/**
|
|
363
432
|
* Build the palette; consumes the builder.
|
|
364
433
|
*/
|
package/Shape.d.ts
CHANGED
|
@@ -85,6 +85,23 @@ export class Shape {
|
|
|
85
85
|
*/
|
|
86
86
|
static bezier(controlPoints: Array<number>, thickness: number, resolution: number): Shape;
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Any SDF tree as a Shape: the same JSON the terrain sampler takes
|
|
90
|
+
* (primitives, smooth booleans, noise — see the SDF guide) becomes
|
|
91
|
+
* fillable with every brush, combinable with other shapes, and
|
|
92
|
+
* usable in masked fills. Normals come from the field gradient, so
|
|
93
|
+
* the shaded brush shades smooth blends smoothly. Errors with
|
|
94
|
+
* `Parse` on invalid JSON and `InvalidArgument` for unbounded trees
|
|
95
|
+
* (use `sdf_bounded`).
|
|
96
|
+
*/
|
|
97
|
+
static sdf(sdfJson: string): Shape;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Like `sdf`, with explicit sampling bounds (inclusive block
|
|
101
|
+
* coordinates) for unbounded trees such as planes.
|
|
102
|
+
*/
|
|
103
|
+
static sdfBounded(sdfJson: string, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): Shape;
|
|
104
|
+
|
|
88
105
|
/**
|
|
89
106
|
* Hollowed-out copy of this shape with the given wall thickness (clones the
|
|
90
107
|
* input, like the old `shape_hollow`).
|
package/Shape.mjs
CHANGED
|
@@ -265,6 +265,69 @@ export class Shape {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Any SDF tree as a Shape: the same JSON the terrain sampler takes
|
|
270
|
+
* (primitives, smooth booleans, noise — see the SDF guide) becomes
|
|
271
|
+
* fillable with every brush, combinable with other shapes, and
|
|
272
|
+
* usable in masked fills. Normals come from the field gradient, so
|
|
273
|
+
* the shaded brush shades smooth blends smoothly. Errors with
|
|
274
|
+
* `Parse` on invalid JSON and `InvalidArgument` for unbounded trees
|
|
275
|
+
* (use `sdf_bounded`).
|
|
276
|
+
*/
|
|
277
|
+
static sdf(sdfJson) {
|
|
278
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
279
|
+
|
|
280
|
+
const sdfJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sdfJson)));
|
|
281
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
const result = wasm.Shape_sdf(diplomatReceive.buffer, sdfJsonSlice.ptr);
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
if (!diplomatReceive.resultFlag) {
|
|
288
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
289
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
290
|
+
}
|
|
291
|
+
return new Shape(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
finally {
|
|
295
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
296
|
+
functionCleanupArena.free();
|
|
297
|
+
|
|
298
|
+
diplomatReceive.free();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Like `sdf`, with explicit sampling bounds (inclusive block
|
|
304
|
+
* coordinates) for unbounded trees such as planes.
|
|
305
|
+
*/
|
|
306
|
+
static sdfBounded(sdfJson, minX, minY, minZ, maxX, maxY, maxZ) {
|
|
307
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
308
|
+
|
|
309
|
+
const sdfJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sdfJson)));
|
|
310
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
const result = wasm.Shape_sdf_bounded(diplomatReceive.buffer, sdfJsonSlice.ptr, minX, minY, minZ, maxX, maxY, maxZ);
|
|
314
|
+
|
|
315
|
+
try {
|
|
316
|
+
if (!diplomatReceive.resultFlag) {
|
|
317
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
318
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
319
|
+
}
|
|
320
|
+
return new Shape(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
finally {
|
|
324
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
325
|
+
functionCleanupArena.free();
|
|
326
|
+
|
|
327
|
+
diplomatReceive.free();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
268
331
|
/**
|
|
269
332
|
* Hollowed-out copy of this shape with the given wall thickness (clones the
|
|
270
333
|
* input, like the old `shape_hollow`).
|
package/Voxelizer.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { NucleationError } from "./NucleationError"
|
|
3
|
+
import type { Palette } from "./Palette"
|
|
4
|
+
import type { Schematic } from "./Schematic"
|
|
5
|
+
import type { Shape } from "./Shape"
|
|
6
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Namespace for the mesh-voxelization entry points (GLB/OBJ → shapes
|
|
12
|
+
* and textured schematics).
|
|
13
|
+
*/
|
|
14
|
+
export class Voxelizer {
|
|
15
|
+
/** @internal */
|
|
16
|
+
get ffiValue(): pointer;
|
|
17
|
+
/** @internal */
|
|
18
|
+
constructor();
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Load a binary glTF (`.glb`, embedded buffers/images) and voxelize
|
|
23
|
+
* it into a fillable Shape: the model is uniformly scaled so its
|
|
24
|
+
* largest dimension equals `target_size` voxels, centered on x/z
|
|
25
|
+
* with its base resting at y = 0. Solidity is a parity test at each
|
|
26
|
+
* voxel center (robust on closed meshes), plus — when `shell` > 0 —
|
|
27
|
+
* every voxel whose center is within `shell` blocks of the surface,
|
|
28
|
+
* which rescues thin walls and hollow vessels (0.7–1.0 closes
|
|
29
|
+
* single-voxel shells; 0 = pure parity). Errors with `Parse` on
|
|
30
|
+
* malformed/triangle-less GLB and `InvalidArgument` on a
|
|
31
|
+
* non-positive `target_size`.
|
|
32
|
+
*/
|
|
33
|
+
static shapeFromGlb(data: Array<number>, targetSize: number, shell: number): Shape;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Load a Wavefront OBJ (`v`/`vt`/`f` lines; polygon faces are
|
|
37
|
+
* fan-triangulated, negative indices supported, materials ignored)
|
|
38
|
+
* and voxelize it into a fillable Shape, fitted and shelled exactly
|
|
39
|
+
* like `shape_from_glb`. Errors with `Parse` on malformed/triangle-less
|
|
40
|
+
* OBJ and `InvalidArgument` on invalid UTF-8 or a non-positive
|
|
41
|
+
* `target_size`.
|
|
42
|
+
*/
|
|
43
|
+
static shapeFromObj(text: string, targetSize: number, shell: number): Shape;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Load a binary glTF and voxelize it directly into a textured
|
|
47
|
+
* schematic named `name`: every solid voxel becomes the `palette`
|
|
48
|
+
* block closest to its nearest-surface texture color (interior
|
|
49
|
+
* voxels inherit the nearest surface color; voxels without texture
|
|
50
|
+
* info snap to mid-gray). `shell` behaves as in `shape_from_glb` —
|
|
51
|
+
* use ~0.7 for thin-walled models. Errors with `Parse` on malformed GLB and
|
|
52
|
+
* `InvalidArgument` on invalid UTF-8 or a non-positive
|
|
53
|
+
* `target_size`.
|
|
54
|
+
*/
|
|
55
|
+
static schematicFromGlbTextured(data: Array<number>, targetSize: number, shell: number, palette: Palette, name: string): Schematic;
|
|
56
|
+
}
|
package/Voxelizer.mjs
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
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 { Shape } from "./Shape.mjs"
|
|
6
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
7
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
8
|
+
|
|
9
|
+
const Voxelizer_box_destroy_registry = new FinalizationRegistry((ptr) => {
|
|
10
|
+
wasm.Voxelizer_destroy(ptr);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Namespace for the mesh-voxelization entry points (GLB/OBJ → shapes
|
|
15
|
+
* and textured schematics).
|
|
16
|
+
*/
|
|
17
|
+
export class Voxelizer {
|
|
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("Voxelizer 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
|
+
Voxelizer_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
|
+
* Load a binary glTF (`.glb`, embedded buffers/images) and voxelize
|
|
48
|
+
* it into a fillable Shape: the model is uniformly scaled so its
|
|
49
|
+
* largest dimension equals `target_size` voxels, centered on x/z
|
|
50
|
+
* with its base resting at y = 0. Solidity is a parity test at each
|
|
51
|
+
* voxel center (robust on closed meshes), plus — when `shell` > 0 —
|
|
52
|
+
* every voxel whose center is within `shell` blocks of the surface,
|
|
53
|
+
* which rescues thin walls and hollow vessels (0.7–1.0 closes
|
|
54
|
+
* single-voxel shells; 0 = pure parity). Errors with `Parse` on
|
|
55
|
+
* malformed/triangle-less GLB and `InvalidArgument` on a
|
|
56
|
+
* non-positive `target_size`.
|
|
57
|
+
*/
|
|
58
|
+
static shapeFromGlb(data, targetSize, shell) {
|
|
59
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
60
|
+
|
|
61
|
+
const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
|
|
62
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const result = wasm.Voxelizer_shape_from_glb(diplomatReceive.buffer, dataSlice.ptr, targetSize, shell);
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
if (!diplomatReceive.resultFlag) {
|
|
69
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
70
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
71
|
+
}
|
|
72
|
+
return new Shape(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
finally {
|
|
76
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
77
|
+
functionCleanupArena.free();
|
|
78
|
+
|
|
79
|
+
diplomatReceive.free();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Load a Wavefront OBJ (`v`/`vt`/`f` lines; polygon faces are
|
|
85
|
+
* fan-triangulated, negative indices supported, materials ignored)
|
|
86
|
+
* and voxelize it into a fillable Shape, fitted and shelled exactly
|
|
87
|
+
* like `shape_from_glb`. Errors with `Parse` on malformed/triangle-less
|
|
88
|
+
* OBJ and `InvalidArgument` on invalid UTF-8 or a non-positive
|
|
89
|
+
* `target_size`.
|
|
90
|
+
*/
|
|
91
|
+
static shapeFromObj(text, targetSize, shell) {
|
|
92
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
93
|
+
|
|
94
|
+
const textSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, text)));
|
|
95
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const result = wasm.Voxelizer_shape_from_obj(diplomatReceive.buffer, textSlice.ptr, targetSize, shell);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
if (!diplomatReceive.resultFlag) {
|
|
102
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
103
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
104
|
+
}
|
|
105
|
+
return new Shape(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
finally {
|
|
109
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
110
|
+
functionCleanupArena.free();
|
|
111
|
+
|
|
112
|
+
diplomatReceive.free();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Load a binary glTF and voxelize it directly into a textured
|
|
118
|
+
* schematic named `name`: every solid voxel becomes the `palette`
|
|
119
|
+
* block closest to its nearest-surface texture color (interior
|
|
120
|
+
* voxels inherit the nearest surface color; voxels without texture
|
|
121
|
+
* info snap to mid-gray). `shell` behaves as in `shape_from_glb` —
|
|
122
|
+
* use ~0.7 for thin-walled models. Errors with `Parse` on malformed GLB and
|
|
123
|
+
* `InvalidArgument` on invalid UTF-8 or a non-positive
|
|
124
|
+
* `target_size`.
|
|
125
|
+
*/
|
|
126
|
+
static schematicFromGlbTextured(data, targetSize, shell, palette, name) {
|
|
127
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
128
|
+
|
|
129
|
+
const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
|
|
130
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
131
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
const result = wasm.Voxelizer_schematic_from_glb_textured(diplomatReceive.buffer, dataSlice.ptr, targetSize, shell, palette.ffiValue, nameSlice.ptr);
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
if (!diplomatReceive.resultFlag) {
|
|
138
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
139
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
140
|
+
}
|
|
141
|
+
return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
finally {
|
|
145
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
146
|
+
functionCleanupArena.free();
|
|
147
|
+
|
|
148
|
+
diplomatReceive.free();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
constructor(symbol, ptr, selfEdge) {
|
|
153
|
+
return this.#internalConstructor(...arguments)
|
|
154
|
+
}
|
|
155
|
+
}
|
package/index.d.ts
CHANGED
package/index.mjs
CHANGED
package/nucleation.wasm
CHANGED
|
Binary file
|