nucleation 0.3.8 → 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/Brush.d.ts +9 -0
- package/Brush.mjs +20 -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/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/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
|