nucleation 0.3.17 → 0.3.18
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/DistanceField.d.ts +39 -0
- package/DistanceField.mjs +114 -0
- package/index.d.ts +2 -0
- package/index.mjs +2 -0
- package/nucleation.wasm +0 -0
- package/package.json +1 -1
|
@@ -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/index.d.ts
CHANGED
package/index.mjs
CHANGED
package/nucleation.wasm
CHANGED
|
Binary file
|