Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

refactor(image): the noise, colour and path helpers live in their own modules, so no two image or modeling modules import each other

yhhda682185cf69
diff --git a/desktop b/desktop
index 0be668267..e6b39a6b3 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 0be6682676608a475ed6d27e5b69723b15bc3fac
+Subproject commit e6b39a6b38f1a462a9d2c8dd28c82cc7ce2029f9
diff --git a/pipeline/src/image/imageAdjust.ts b/pipeline/src/image/imageAdjust.ts
index 273315319..210e12de6 100644
--- a/pipeline/src/image/imageAdjust.ts
+++ b/pipeline/src/image/imageAdjust.ts
@@ -7,7 +7,7 @@
* Each is one operation with numbers to turn, and the layer it sits on says where it applies and how much. Which to use, and how far, is the model's.
* Pixels here are stored as the canvas stores them, colour already times alpha.
*/
-import { blurMask, fractalNoise, parseColor } from './imageRaster';
+import { blurMask, fractalNoise, parseColor } from './imageNoise';
import type { ImageAdjust, ImageFilterName } from './imageSource';
const clamp01 = (v: number): number => Math.max(0, Math.min(1, v));
diff --git a/pipeline/src/image/imageNoise.ts b/pipeline/src/image/imageNoise.ts
new file mode 100644
index 000000000..944a8c01f
--- /dev/null
+++ b/pipeline/src/image/imageNoise.ts
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+export type Rgba = readonly [number, number, number, number];
+
+export function parseColor(text: string): Rgba {
+ const h = /^#([0-9a-fA-F]+)$/.exec(text)?.[1];
+ if (!h || ![3, 4, 6, 8].includes(h.length)) throw new Error(`color ${JSON.stringify(text)} must be #rgb, #rgba, #rrggbb or #rrggbbaa`);
+ const full = h.length <= 4 ? [...h].map((c) => c + c).join('') : h;
+ const at = (i: number): number => parseInt(full.slice(i, i + 2), 16) / 255;
+ return [at(0), at(2), at(4), full.length === 8 ? at(6) : 1];
+}
+
+export function blurMask(src: Float32Array, w: number, h: number, sigma: number): Float32Array {
+ if (sigma <= 0) return src;
+ const r = Math.max(1, Math.round(sigma * 1.2));
+ let cur = src;
+ for (let pass = 0; pass < 3; pass++) {
+ const a = new Float32Array(w * h);
+ for (let y = 0; y < h; y++) {
+ let sum = 0;
+ for (let x = -r; x <= r; x++) sum += cur[y * w + Math.max(0, Math.min(w - 1, x))]!;
+ for (let x = 0; x < w; x++) {
+ a[y * w + x] = sum / (2 * r + 1);
+ sum += cur[y * w + Math.min(w - 1, x + r + 1)]! - cur[y * w + Math.max(0, x - r)]!;
+ }
+ }
+ const b = new Float32Array(w * h);
+ for (let x = 0; x < w; x++) {
+ let sum = 0;
+ for (let y = -r; y <= r; y++) sum += a[Math.max(0, Math.min(h - 1, y)) * w + x]!;
+ for (let y = 0; y < h; y++) {
+ b[y * w + x] = sum / (2 * r + 1);
+ sum += a[Math.min(h - 1, y + r + 1) * w + x]! - a[Math.max(0, y - r) * w + x]!;
+ }
+ }
+ cur = b;
+ }
+ return cur;
+}
+
+export const NOISE_DIRECTIONS: readonly (readonly [number, number])[] = [
+ [1, 0], [0.9239, 0.3827], [0.7071, 0.7071], [0.3827, 0.9239], [0, 1], [-0.3827, 0.9239], [-0.7071, 0.7071], [-0.9239, 0.3827],
+ [-1, 0], [-0.9239, -0.3827], [-0.7071, -0.7071], [-0.3827, -0.9239], [0, -1], [0.3827, -0.9239], [0.7071, -0.7071], [0.9239, -0.3827],
+];
+
+export function cornerLift(ix: number, iy: number, seed: number, dx: number, dy: number): number {
+ let h = Math.imul(ix, 374761393) + Math.imul(iy, 668265263) + Math.imul(seed, 1442968193);
+ h = Math.imul(h ^ (h >>> 13), 1274126177);
+ h = Math.imul(h ^ (h >>> 16), 2246822519);
+ const d = NOISE_DIRECTIONS[((h ^ (h >>> 16)) >>> 0) % NOISE_DIRECTIONS.length]!;
+ return d[0] * dx + d[1] * dy;
+}
+
+export const fade = (t: number): number => t * t * t * (t * (t * 6 - 15) + 10);
+
+export function gradientNoise(x: number, y: number, seed: number): number {
+ const [ix, iy] = [Math.floor(x), Math.floor(y)];
+ const [fx, fy] = [x - ix, y - iy];
+ const [sx, sy] = [fade(fx), fade(fy)];
+ const top = cornerLift(ix, iy, seed, fx, fy) * (1 - sx) + cornerLift(ix + 1, iy, seed, fx - 1, fy) * sx;
+ const bottom = cornerLift(ix, iy + 1, seed, fx, fy - 1) * (1 - sx) + cornerLift(ix + 1, iy + 1, seed, fx - 1, fy - 1) * sx;
+ return top * (1 - sy) + bottom * sy;
+}
+
+export const NOISE_CONTRAST = [1.15, 1.3, 1.4, 1.45, 1.45, 1.45, 1.45, 1.45];
+
+export function fractalNoise(x: number, y: number, octaves: number, seed: number): number {
+ let [sum, weight, amplitude, frequency] = [0, 0, 1, 1];
+ for (let i = 0; i < octaves; i++) {
+ // Off the lattice, where this noise is always nothing.
+ sum += gradientNoise(x * frequency + 0.37, y * frequency + 0.61, seed + i * 101) * amplitude;
+ weight += amplitude;
+ amplitude *= 0.5;
+ frequency *= 2;
+ }
+ return Math.max(0, Math.min(1, 0.5 + (sum / weight) * NOISE_CONTRAST[octaves - 1]!));
+}
diff --git a/pipeline/src/image/imagePath.ts b/pipeline/src/image/imagePath.ts
new file mode 100644
index 000000000..0750b54da
--- /dev/null
+++ b/pipeline/src/image/imagePath.ts
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+export type Pt = readonly [number, number];
+
+export const CURVE_STEPS = 20;
+
+export function parsePath(d: string): { points: Pt[]; closed: boolean }[] {
+ const tokens = d.match(/[a-zA-Z]|-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g) ?? [];
+ const runs: { points: Pt[]; closed: boolean }[] = [];
+ let run: Pt[] | null = null;
+ let [x, y, sx, sy, lastCx, lastCy] = [0, 0, 0, 0, 0, 0];
+ let cmd = '', prev = '', i = 0;
+ const num = (): number => {
+ const t = tokens[i++];
+ if (t === undefined || /[a-zA-Z]/.test(t)) throw new Error(`path ${JSON.stringify(d.slice(0, 60))}: command ${cmd} is short of numbers`);
+ return Number(t);
+ };
+ const start = (): void => {
+ if (!run) { run = [[x, y]]; runs.push({ points: run, closed: false }); }
+ };
+ const curve = (f: (t: number) => Pt): void => {
+ start();
+ for (let s = 1; s <= CURVE_STEPS; s++) run!.push(f(s / CURVE_STEPS));
+ };
+ while (i < tokens.length) {
+ if (/[a-zA-Z]/.test(tokens[i]!)) cmd = tokens[i++]!;
+ else if (!cmd) throw new Error(`path ${JSON.stringify(d.slice(0, 60))} must start with a command`);
+ const rel = cmd === cmd.toLowerCase();
+ const [ox, oy] = rel ? [x, y] : [0, 0];
+ switch (cmd.toUpperCase()) {
+ case 'M':
+ x = ox + num(); y = oy + num(); sx = x; sy = y;
+ run = [[x, y]];
+ runs.push({ points: run, closed: false });
+ cmd = rel ? 'l' : 'L';
+ break;
+ case 'L': x = ox + num(); y = oy + num(); start(); run!.push([x, y]); break;
+ case 'H': x = ox + num(); start(); run!.push([x, y]); break;
+ case 'V': y = oy + num(); start(); run!.push([x, y]); break;
+ case 'C': case 'S': {
+ const smooth = cmd.toUpperCase() === 'S';
+ const [c1x, c1y] = smooth ? (prev === 'C' || prev === 'S' ? [2 * x - lastCx, 2 * y - lastCy] : [x, y]) : [ox + num(), oy + num()];
+ const [c2x, c2y, ex, ey] = [ox + num(), oy + num(), ox + num(), oy + num()];
+ const [x0, y0] = [x, y];
+ curve((t) => {
+ const u = 1 - t;
+ return [u * u * u * x0 + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * ex, u * u * u * y0 + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * ey];
+ });
+ [x, y, lastCx, lastCy] = [ex, ey, c2x, c2y];
+ break;
+ }
+ case 'Q': case 'T': {
+ const smooth = cmd.toUpperCase() === 'T';
+ const [cx, cy] = smooth ? (prev === 'Q' || prev === 'T' ? [2 * x - lastCx, 2 * y - lastCy] : [x, y]) : [ox + num(), oy + num()];
+ const [ex, ey] = [ox + num(), oy + num()];
+ const [x0, y0] = [x, y];
+ curve((t) => {
+ const u = 1 - t;
+ return [u * u * x0 + 2 * u * t * cx + t * t * ex, u * u * y0 + 2 * u * t * cy + t * t * ey];
+ });
+ [x, y, lastCx, lastCy] = [ex, ey, cx, cy];
+ break;
+ }
+ case 'Z':
+ if (runs.length) runs[runs.length - 1]!.closed = true;
+ x = sx; y = sy; run = null;
+ cmd = '';
+ break;
+ default:
+ throw new Error(`path command ${cmd} is not one this draws; there are M L H V C S Q T Z`);
+ }
+ prev = cmd.toUpperCase() === 'L' && prev === 'M' ? 'L' : cmd.toUpperCase();
+ }
+ return runs;
+}
diff --git a/pipeline/src/image/imageRaster.ts b/pipeline/src/image/imageRaster.ts
index b9e7514c2..f53e6524f 100644
--- a/pipeline/src/image/imageRaster.ts
+++ b/pipeline/src/image/imageRaster.ts
@@ -11,24 +11,14 @@ import { applyAdjust, applyFilter, lightnessOf } from './imageAdjust';
import { figureLight, flattenFigure, type FlatFigure } from './imageFigure';
import { IMAGE_BRUSHES, isGuideLayer, MAX_MARK_STROKES } from './imageSource';
import type { ImageFill, ImageLayer, ImageSource, ImageAlong, ImageBrushSettings, ImageEffect, ImageField, ImageMark, ImageStroke, ImageSweep, ImageTransform } from './imageSource';
+import { type Pt, parsePath } from './imagePath';
+import { type Rgba, blurMask, fractalNoise, gradientNoise, parseColor } from './imageNoise';
export interface RgbaBitmap { width: number; height: number; rgba: Uint8Array }
-
-type Rgba = readonly [number, number, number, number];
-type Pt = readonly [number, number];
type Matrix = readonly [number, number, number, number, number, number];
const IDENTITY: Matrix = [1, 0, 0, 1, 0, 0];
const SUBSCANS = 8;
-const CURVE_STEPS = 20;
-
-export function parseColor(text: string): Rgba {
- const h = /^#([0-9a-fA-F]+)$/.exec(text)?.[1];
- if (!h || ![3, 4, 6, 8].includes(h.length)) throw new Error(`color ${JSON.stringify(text)} must be #rgb, #rgba, #rrggbb or #rrggbbaa`);
- const full = h.length <= 4 ? [...h].map((c) => c + c).join('') : h;
- const at = (i: number): number => parseInt(full.slice(i, i + 2), 16) / 255;
- return [at(0), at(2), at(4), full.length === 8 ? at(6) : 1];
-}
const times = (a: Matrix, b: Matrix): Matrix => [
a[0] * b[0] + a[2] * b[1], a[1] * b[0] + a[3] * b[1],
@@ -80,77 +70,6 @@ function roundedRect(x: number, y: number, w: number, h: number, radius: number
return out;
}
-/** An SVG path's closed and open runs: M L H V C S Q T Z, either case. */
-export function parsePath(d: string): { points: Pt[]; closed: boolean }[] {
- const tokens = d.match(/[a-zA-Z]|-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g) ?? [];
- const runs: { points: Pt[]; closed: boolean }[] = [];
- let run: Pt[] | null = null;
- let [x, y, sx, sy, lastCx, lastCy] = [0, 0, 0, 0, 0, 0];
- let cmd = '', prev = '', i = 0;
- const num = (): number => {
- const t = tokens[i++];
- if (t === undefined || /[a-zA-Z]/.test(t)) throw new Error(`path ${JSON.stringify(d.slice(0, 60))}: command ${cmd} is short of numbers`);
- return Number(t);
- };
- const start = (): void => {
- if (!run) { run = [[x, y]]; runs.push({ points: run, closed: false }); }
- };
- const curve = (f: (t: number) => Pt): void => {
- start();
- for (let s = 1; s <= CURVE_STEPS; s++) run!.push(f(s / CURVE_STEPS));
- };
- while (i < tokens.length) {
- if (/[a-zA-Z]/.test(tokens[i]!)) cmd = tokens[i++]!;
- else if (!cmd) throw new Error(`path ${JSON.stringify(d.slice(0, 60))} must start with a command`);
- const rel = cmd === cmd.toLowerCase();
- const [ox, oy] = rel ? [x, y] : [0, 0];
- switch (cmd.toUpperCase()) {
- case 'M':
- x = ox + num(); y = oy + num(); sx = x; sy = y;
- run = [[x, y]];
- runs.push({ points: run, closed: false });
- cmd = rel ? 'l' : 'L';
- break;
- case 'L': x = ox + num(); y = oy + num(); start(); run!.push([x, y]); break;
- case 'H': x = ox + num(); start(); run!.push([x, y]); break;
- case 'V': y = oy + num(); start(); run!.push([x, y]); break;
- case 'C': case 'S': {
- const smooth = cmd.toUpperCase() === 'S';
- const [c1x, c1y] = smooth ? (prev === 'C' || prev === 'S' ? [2 * x - lastCx, 2 * y - lastCy] : [x, y]) : [ox + num(), oy + num()];
- const [c2x, c2y, ex, ey] = [ox + num(), oy + num(), ox + num(), oy + num()];
- const [x0, y0] = [x, y];
- curve((t) => {
- const u = 1 - t;
- return [u * u * u * x0 + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * ex, u * u * u * y0 + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * ey];
- });
- [x, y, lastCx, lastCy] = [ex, ey, c2x, c2y];
- break;
- }
- case 'Q': case 'T': {
- const smooth = cmd.toUpperCase() === 'T';
- const [cx, cy] = smooth ? (prev === 'Q' || prev === 'T' ? [2 * x - lastCx, 2 * y - lastCy] : [x, y]) : [ox + num(), oy + num()];
- const [ex, ey] = [ox + num(), oy + num()];
- const [x0, y0] = [x, y];
- curve((t) => {
- const u = 1 - t;
- return [u * u * x0 + 2 * u * t * cx + t * t * ex, u * u * y0 + 2 * u * t * cy + t * t * ey];
- });
- [x, y, lastCx, lastCy] = [ex, ey, cx, cy];
- break;
- }
- case 'Z':
- if (runs.length) runs[runs.length - 1]!.closed = true;
- x = sx; y = sy; run = null;
- cmd = '';
- break;
- default:
- throw new Error(`path command ${cmd} is not one this draws; there are M L H V C S Q T Z`);
- }
- prev = cmd.toUpperCase() === 'L' && prev === 'M' ? 'L' : cmd.toUpperCase();
- }
- return runs;
-}
-
/** A layer's outlines in its own coordinates. */
function outlinesOf(layer: ImageLayer): { runs: { points: Pt[]; closed: boolean }[]; middle: Pt } {
const closed = (points: Pt[]): { points: Pt[]; closed: boolean }[] => [{ points, closed: true }];
@@ -372,35 +291,6 @@ function strokeMask(runs: readonly { points: readonly Pt[]; closed: boolean }[],
return mask;
}
-/** Three box blurs, which is a gaussian to the eye at a cost that does not grow with the radius. */
-export function blurMask(src: Float32Array, w: number, h: number, sigma: number): Float32Array {
- if (sigma <= 0) return src;
- const r = Math.max(1, Math.round(sigma * 1.2));
- let cur = src;
- for (let pass = 0; pass < 3; pass++) {
- const a = new Float32Array(w * h);
- for (let y = 0; y < h; y++) {
- let sum = 0;
- for (let x = -r; x <= r; x++) sum += cur[y * w + Math.max(0, Math.min(w - 1, x))]!;
- for (let x = 0; x < w; x++) {
- a[y * w + x] = sum / (2 * r + 1);
- sum += cur[y * w + Math.min(w - 1, x + r + 1)]! - cur[y * w + Math.max(0, x - r)]!;
- }
- }
- const b = new Float32Array(w * h);
- for (let x = 0; x < w; x++) {
- let sum = 0;
- for (let y = -r; y <= r; y++) sum += a[Math.max(0, Math.min(h - 1, y)) * w + x]!;
- for (let y = 0; y < h; y++) {
- b[y * w + x] = sum / (2 * r + 1);
- sum += a[Math.min(h - 1, y + r + 1) * w + x]! - a[Math.max(0, y - r) * w + x]!;
- }
- }
- cur = b;
- }
- return cur;
-}
-
function shifted(src: Float32Array, w: number, h: number, dx: number, dy: number): Float32Array {
const [ix, iy] = [Math.round(dx), Math.round(dy)];
if (ix === 0 && iy === 0) return src;
@@ -416,51 +306,6 @@ function shifted(src: Float32Array, w: number, h: number, dx: number, dy: number
return out;
}
-// ---- Paint ----------------------------------------------------------------------
-
-/** A fill as a function of a pixel. Its coordinates go with its layer's, turned and all. */
-/** Written out, not computed by cos and sin, whose last bits are the engine's to choose. */
-const NOISE_DIRECTIONS: readonly (readonly [number, number])[] = [
- [1, 0], [0.9239, 0.3827], [0.7071, 0.7071], [0.3827, 0.9239], [0, 1], [-0.3827, 0.9239], [-0.7071, 0.7071], [-0.9239, 0.3827],
- [-1, 0], [-0.9239, -0.3827], [-0.7071, -0.7071], [-0.3827, -0.9239], [0, -1], [0.3827, -0.9239], [0.7071, -0.7071], [0.9239, -0.3827],
-];
-
-/** How much a corner of the lattice lifts the point @p dx, @p dy away. Integer hashing, so it is the same on every machine. */
-function cornerLift(ix: number, iy: number, seed: number, dx: number, dy: number): number {
- let h = Math.imul(ix, 374761393) + Math.imul(iy, 668265263) + Math.imul(seed, 1442968193);
- h = Math.imul(h ^ (h >>> 13), 1274126177);
- h = Math.imul(h ^ (h >>> 16), 2246822519);
- const d = NOISE_DIRECTIONS[((h ^ (h >>> 16)) >>> 0) % NOISE_DIRECTIONS.length]!;
- return d[0] * dx + d[1] * dy;
-}
-
-const fade = (t: number): number => t * t * t * (t * (t * 6 - 15) + 10);
-
-/** Gradient noise, about -0.7..0.7: a value on a lattice alone shows the lattice, as boxes in a large soft cloud. */
-function gradientNoise(x: number, y: number, seed: number): number {
- const [ix, iy] = [Math.floor(x), Math.floor(y)];
- const [fx, fy] = [x - ix, y - iy];
- const [sx, sy] = [fade(fx), fade(fy)];
- const top = cornerLift(ix, iy, seed, fx, fy) * (1 - sx) + cornerLift(ix + 1, iy, seed, fx - 1, fy) * sx;
- const bottom = cornerLift(ix, iy + 1, seed, fx, fy - 1) * (1 - sx) + cornerLift(ix + 1, iy + 1, seed, fx - 1, fy - 1) * sx;
- return top * (1 - sy) + bottom * sy;
-}
-
-/** Spread out to 0..1, so that the stops at the ends are reached. */
-const NOISE_CONTRAST = [1.15, 1.3, 1.4, 1.45, 1.45, 1.45, 1.45, 1.45];
-
-export function fractalNoise(x: number, y: number, octaves: number, seed: number): number {
- let [sum, weight, amplitude, frequency] = [0, 0, 1, 1];
- for (let i = 0; i < octaves; i++) {
- // Off the lattice, where this noise is always nothing.
- sum += gradientNoise(x * frequency + 0.37, y * frequency + 0.61, seed + i * 101) * amplitude;
- weight += amplitude;
- amplitude *= 0.5;
- frequency *= 2;
- }
- return Math.max(0, Math.min(1, 0.5 + (sum / weight) * NOISE_CONTRAST[octaves - 1]!));
-}
-
/** From a place in the picture to where it lies on four corners, 0..1 each way; null when the corners cannot be solved. */
function quadToUnit(q: readonly (readonly number[])[]): ((x: number, y: number) => readonly [number, number]) | null {
const [[x0, y0], [x1, y1], [x2, y2], [x3, y3]] = q as unknown as [[number, number], [number, number], [number, number], [number, number]];
diff --git a/pipeline/src/image/imageSource.ts b/pipeline/src/image/imageSource.ts
index 97f9b3418..0d1e99490 100644
--- a/pipeline/src/image/imageSource.ts
+++ b/pipeline/src/image/imageSource.ts
@@ -3,7 +3,7 @@
/**
* @file imageSource.ts — `.esimage`: a picture as a list of layers, what a model writes and edits, and what is wrong with one.
*/
-import { parsePath } from './imageRaster';
+import { parsePath } from './imagePath';
export const IMAGE_BLENDS = [
'normal', 'multiply', 'screen', 'overlay', 'add', 'softLight', 'hardLight', 'vividLight', 'linearLight', 'pinLight', 'colorDodge', 'colorBurn', 'linearBurn',
diff --git a/pipeline/src/modeling/displace.ts b/pipeline/src/modeling/displace.ts
index 558e2a071..827e89b53 100644
--- a/pipeline/src/modeling/displace.ts
+++ b/pipeline/src/modeling/displace.ts
@@ -10,7 +10,7 @@
* `decimate` and a `normalBake` afterwards exist to pay back.
*/
import { boundsOf, compact, dot, faceArea, faceNormal, normalize, selectFaces, type Face, type FaceSelector, type PolyMesh, type Vec3 } from './polyMesh';
-import { hash3 } from './organic';
+import { hash3 } from './hash';
import { triangulateFace } from './triangulate';
export const DISPLACE_PATTERNS = ['bumps', 'wrinkles', 'cracks', 'scales', 'pores', 'ribs', 'weave', 'scratches', 'pleats', 'folds'] as const;
diff --git a/pipeline/src/modeling/hair.ts b/pipeline/src/modeling/hair.ts
index 44eed3fd9..c556dc048 100644
--- a/pipeline/src/modeling/hair.ts
+++ b/pipeline/src/modeling/hair.ts
@@ -11,7 +11,7 @@
*/
import { TriangleTree, trianglesOf } from './triangleTree';
import { triangulateFace } from './triangulate';
-import { hash3 } from './organic';
+import { hash3 } from './hash';
import { add, boundsOf, compact, cross, dot, faceNormal, normalize, scale, selectFaces, sub, type Face, type FaceSelector, type PolyMesh, type Vec3 } from './polyMesh';
import type { RigJoint, SkinWeights } from './rig';
diff --git a/pipeline/src/modeling/hash.ts b/pipeline/src/modeling/hash.ts
new file mode 100644
index 000000000..07acd69d9
--- /dev/null
+++ b/pipeline/src/modeling/hash.ts
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+export function hash3(x: number, y: number, z: number, seed: number): number {
+ let h = Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(z, 2147483647 - 1274126177) + Math.imul(seed, 1442695041);
+ h = Math.imul(h ^ (h >>> 13), 1274126177);
+ h ^= h >>> 16;
+ return ((h >>> 0) / 4294967295) * 2 - 1;
+}
diff --git a/pipeline/src/modeling/organic.ts b/pipeline/src/modeling/organic.ts
index 9a8c64b2f..0f71177b0 100644
--- a/pipeline/src/modeling/organic.ts
+++ b/pipeline/src/modeling/organic.ts
@@ -18,6 +18,7 @@
import { refine } from './displace';
import { add, type Face, type PolyMesh, type Vec3 } from './polyMesh';
import { curveThrough } from './surfaces';
+import { hash3 } from './hash';
export type OrganicShape = 'sphere' | 'ellipsoid' | 'box' | 'torus' | 'chain' | 'outline' | 'limb';
@@ -104,13 +105,6 @@ type Eval = (x: number, y: number, z: number) => number;
// ---- Noise: value noise, seeded and platform-independent, so a bake is the same everywhere ----
-export function hash3(x: number, y: number, z: number, seed: number): number {
- let h = Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(z, 2147483647 - 1274126177) + Math.imul(seed, 1442695041);
- h = Math.imul(h ^ (h >>> 13), 1274126177);
- h ^= h >>> 16;
- return ((h >>> 0) / 4294967295) * 2 - 1;
-}
-
const fade = (t: number): number => t * t * t * (t * (t * 6 - 15) + 10);
const mix = (a: number, b: number, t: number): number => a + (b - a) * t;
diff --git a/pipeline/src/modeling/scatter.ts b/pipeline/src/modeling/scatter.ts
index cd8a1672b..bb9841e7b 100644
--- a/pipeline/src/modeling/scatter.ts
+++ b/pipeline/src/modeling/scatter.ts
@@ -6,7 +6,7 @@
* Feathers along a limb, rivets on a plate, the lights of a far city: each is one small shape and a rule for where
* the rest go, where writing them out step by step would run to hundreds. The same seed lays them out the same way.
*/
-import { hash3 } from './organic';
+import { hash3 } from './hash';
import { triangulateFace } from './triangulate';
import { add, boundsOf, compact, cross, dot, faceNormal, length, normalize, scale, selectFaces, sub, type Face, type FaceSelector, type PolyMesh, type Vec3 } from './polyMesh';
diff --git a/pipeline/tests/image-raster.test.ts b/pipeline/tests/image-raster.test.ts
index 1b9c81797..1887de085 100644
--- a/pipeline/tests/image-raster.test.ts
+++ b/pipeline/tests/image-raster.test.ts
@@ -2,7 +2,9 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/** A picture from layers: each draws what it says and where, edges are antialiased, and what is wrong with a source is said before anything is drawn. */
import { describe, expect, it } from 'vitest';
-import { imageCacheStats, imageSheet, parseColor, parsePath, pickColors, renderImage, setSheet, valuesImage, zoomImage } from '../src/image/imageRaster';
+import { imageCacheStats, imageSheet, pickColors, renderImage, setSheet, valuesImage, zoomImage } from '../src/image/imageRaster';
+import { parseColor } from '../src/image/imageNoise';
+import { parsePath } from '../src/image/imagePath';
import { applyImageEdits, IMAGE_BLENDS, IMAGE_BRUSHES, IMAGE_FILTERS, strokeWidths, validateImageSource, type ImageLayer } from '../src/image/imageSource';
const draw = (layers: unknown[], size: number | [number, number] = 64, background?: string): ReturnType<typeof renderImage> => renderImage(validateImageSource({ size, layers, ...(background ? { background } : {}) }));
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index b03269c95..771551f2b 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -4102,4 +4102,8 @@ export const NOTED = {
{"note": "A prefab made over MCP is in `list_assets` at once."},
"fix(docs): the CompositeBatch entry of the component reference quotes its apostrophe, which stopped the site building":
{"internal": "The docs site did not build, so v0.99.0 was not deployed to it; no package changes."},
+ "refactor(image): a text mask draws in the canvas's own default colour, since only its alpha is read":
+ {"internal": "Two assignments of the colour a fresh canvas already has; the mask read back is the same."},
+ "refactor(image): the noise, colour and path helpers live in their own modules, so no two image or modeling modules import each other":
+ {"internal": "Declarations moved between files unchanged; every image and modeling test draws and builds the same."},
};