Add clay pieces, masking, and topology editing to sculpt

Add pastel presets, piece selection and colors, mask brushes, subdivision and conservative decimation with bounded worker operations and mixed undo history.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0b4b4-202c-73f1-984d-9a55c88f9c83
Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
Amp
2026-10-01 07:55:48 +00:00
co-authored by heaust
parent d930d8172f
commit d279ec4123
21 changed files with 2564 additions and 131 deletions
+16 -4
View File
@@ -2,7 +2,7 @@ import { Mailbox } from "./mailbox.js";
import { pressureValue } from "./engine.js";
export class StrokeClient {
constructor(row, level, onError) {
constructor(row, mesh, onError) {
this.mailbox = new Mailbox(row.share());
this.worker = new Worker(new URL("./stroke-worker.js", import.meta.url), {
type: "module",
@@ -22,7 +22,19 @@ export class StrokeClient {
this.worker.onerror = () => this.fail(new Error("Sculpt worker stopped"));
this.worker.onmessageerror = () =>
this.fail(new Error("Sculpt worker message failed"));
this.worker.postMessage({ type: "init", row: row.share(), level });
const topology =
typeof mesh === "number"
? { level: mesh }
: {
mesh: {
level: mesh.level,
positions: mesh.positions.slice(),
indices: mesh.indices.slice(),
masks: mesh.masks.slice(),
pieces: structuredClone(mesh.pieces),
},
};
this.worker.postMessage({ type: "init", row: row.share(), ...topology });
}
begin(data, apply) {
if (this.job || this.disposed)
@@ -34,7 +46,7 @@ export class StrokeClient {
this.write(data.sample);
this.worker.postMessage(
{ type: "begin", ...data, id, version: this.version },
[data.positions.buffer],
[data.positions.buffer, ...(data.masks ? [data.masks.buffer] : [])],
);
return promise;
}
@@ -92,7 +104,7 @@ export class StrokeClient {
return;
}
const j = this.job;
if (data.type === "geometry") {
if (data.type === "geometry" || data.type === "mask") {
if (j?.id === data.id && !j.canceling) j.apply(data);
this.worker.postMessage({ type: "ack", packet: data.packet });
} else if (