nucleation 0.3.15 → 0.3.17

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 CHANGED
@@ -74,4 +74,17 @@ export class Brush {
74
74
  * (`colors.len() == stops.len() * 3`, `stops` non-empty).
75
75
  */
76
76
  static curveGradient(stops: Array<number>, colors: Array<number>, space: InterpolationSpace): Brush;
77
+
78
+ /**
79
+ * A field brush: color every voxel by evaluating a scalar field at its
80
+ * center, remapping `[lo, hi]` to `[0, 1]`, and reading a multi-stop
81
+ * gradient (`stops` in `[0, 1]`, `colors` as flat RGB triples). The
82
+ * field is any SDF JSON — the same language that builds geometry — so a
83
+ * `cells` node paints a Voronoi mosaic (`mode: value`) or cracks
84
+ * (`mode: f2MinusF1`), an fbm field a marble, a coordinate expression a
85
+ * stripe. Call `set_palette` to choose the block set. Errors with
86
+ * `Parse` on bad field JSON and `InvalidArgument` on a stops/colors
87
+ * length mismatch.
88
+ */
89
+ static field(fieldJson: string, stops: Array<number>, colors: Array<number>, lo: number, hi: number, space: InterpolationSpace): Brush;
77
90
  }
package/Brush.mjs CHANGED
@@ -234,6 +234,44 @@ export class Brush {
234
234
  }
235
235
  }
236
236
 
237
+ /**
238
+ * A field brush: color every voxel by evaluating a scalar field at its
239
+ * center, remapping `[lo, hi]` to `[0, 1]`, and reading a multi-stop
240
+ * gradient (`stops` in `[0, 1]`, `colors` as flat RGB triples). The
241
+ * field is any SDF JSON — the same language that builds geometry — so a
242
+ * `cells` node paints a Voronoi mosaic (`mode: value`) or cracks
243
+ * (`mode: f2MinusF1`), an fbm field a marble, a coordinate expression a
244
+ * stripe. Call `set_palette` to choose the block set. Errors with
245
+ * `Parse` on bad field JSON and `InvalidArgument` on a stops/colors
246
+ * length mismatch.
247
+ */
248
+ static field(fieldJson, stops, colors, lo, hi, space) {
249
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
250
+
251
+ const fieldJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, fieldJson)));
252
+ const stopsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, stops, "f32")));
253
+ const colorsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, colors, "u8")));
254
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
255
+
256
+
257
+ const result = wasm.Brush_field(diplomatReceive.buffer, fieldJsonSlice.ptr, stopsSlice.ptr, colorsSlice.ptr, lo, hi, space.ffiValue);
258
+
259
+ try {
260
+ if (!diplomatReceive.resultFlag) {
261
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
262
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
263
+ }
264
+ return new Brush(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
265
+ }
266
+
267
+ finally {
268
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
269
+ functionCleanupArena.free();
270
+
271
+ diplomatReceive.free();
272
+ }
273
+ }
274
+
237
275
  constructor(symbol, ptr, selfEdge) {
238
276
  return this.#internalConstructor(...arguments)
239
277
  }
@@ -39,6 +39,18 @@ export class WorldChunkView {
39
39
  */
40
40
  toSchematic(): Schematic;
41
41
 
42
+ /**
43
+ * Build a chunk view at (`cx`, `cz`) from a schematic — every non-air
44
+ * block whose world (x, z) falls in this chunk is copied in, the rest
45
+ * ignored. The write-side twin of `to_schematic`: this is how the
46
+ * schematic building tools become a *world generator*. Fill a schematic
47
+ * with any shape, SDF, brush, or footprint (intersect it with the
48
+ * chunk's cuboid to keep memory flat), then hand it here per chunk and
49
+ * `WorldSink.write_chunk` it. Also the transform step of a world filter:
50
+ * `to_schematic` a streamed chunk, edit it, rebuild with this.
51
+ */
52
+ static fromSchematic(schematic: Schematic, cx: number, cz: number): WorldChunkView;
53
+
42
54
  /**
43
55
  * Set a block at absolute world coordinates inside this chunk view.
44
56
  * `block_name` must be a valid Minecraft block identifier (e.g.
@@ -108,6 +108,29 @@ export class WorldChunkView {
108
108
  }
109
109
  }
110
110
 
111
+ /**
112
+ * Build a chunk view at (`cx`, `cz`) from a schematic — every non-air
113
+ * block whose world (x, z) falls in this chunk is copied in, the rest
114
+ * ignored. The write-side twin of `to_schematic`: this is how the
115
+ * schematic building tools become a *world generator*. Fill a schematic
116
+ * with any shape, SDF, brush, or footprint (intersect it with the
117
+ * chunk's cuboid to keep memory flat), then hand it here per chunk and
118
+ * `WorldSink.write_chunk` it. Also the transform step of a world filter:
119
+ * `to_schematic` a streamed chunk, edit it, rebuild with this.
120
+ */
121
+ static fromSchematic(schematic, cx, cz) {
122
+
123
+ const result = wasm.WorldChunkView_from_schematic(schematic.ffiValue, cx, cz);
124
+
125
+ try {
126
+ return new WorldChunkView(diplomatRuntime.internalConstructor, result, []);
127
+ }
128
+
129
+ finally {
130
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
131
+ }
132
+ }
133
+
111
134
  /**
112
135
  * Set a block at absolute world coordinates inside this chunk view.
113
136
  * `block_name` must be a valid Minecraft block identifier (e.g.
package/nucleation.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nucleation",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "A high-performance Minecraft schematic parser and utility library",
5
5
  "type": "module",
6
6
  "main": "index.mjs",