nucleation 0.3.16 → 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
  }
package/nucleation.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nucleation",
3
- "version": "0.3.16",
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",