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.

fix(look): a hidden guide still works, opacity 0 hides its bones, a faint layer has a real box

yhh555ac22784ca
diff --git a/desktop b/desktop
index 0468ce72d..de685bc9d 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 0468ce72dc21b6901344e0ce7da6e6d1d932033f
+Subproject commit de685bc9d670746bdc4127e7ad141280d9d5b8d3
diff --git a/pipeline/src/image/imageRaster.ts b/pipeline/src/image/imageRaster.ts
index 56ad49ff8..4418e8802 100644
--- a/pipeline/src/image/imageRaster.ts
+++ b/pipeline/src/image/imageRaster.ts
@@ -604,13 +604,24 @@ function boxOf(w: number, h: number, covers: (i: number) => boolean): ImageBox |
function noteBox(drawn: Drawn, id: string | undefined, mask: Float32Array, w: number, h: number): void {
if (!id) return;
- const box = boxOf(w, h, (i) => mask[i]! >= 0.5);
+ // Half of what it reaches: a faint layer is still somewhere, and half of full coverage would miss it.
+ let peak = 0;
+ for (let i = 0; i < mask.length; i++) if (mask[i]! > peak) peak = mask[i]!;
+ if (peak <= 0.004) return;
+ const box = boxOf(w, h, (i) => mask[i]! >= Math.min(0.5, peak / 2));
if (box) drawn.bounds.set(id, box);
}
function drawLayer(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn): void {
- if (layer.visible === false) return;
const { w, h } = c;
+ if (layer.visible === false) {
+ // A guide hidden from sight is still what others are clipped to and lit by. Anything else hidden is simply not there.
+ if (layer.guide ?? (layer.shape === 'figure' || layer.shape === 'image')) {
+ const { visible: _v, ...shown } = layer;
+ drawLayer(new Canvas(w, h), { ...shown, guide: false }, parent, drawn);
+ }
+ return;
+ }
// What a guide masks is still wanted when it is not seen, so it draws somewhere that is thrown away.
if (!drawn.showGuides && (layer.guide ?? (layer.shape === 'figure' || layer.shape === 'image'))) {
drawLayer(new Canvas(w, h), { ...layer, guide: false }, parent, drawn);
@@ -1273,15 +1284,15 @@ function drawFigure(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn,
if (a <= 0) continue;
const lit = 0.25 + 0.7 * Math.max(0, 0.5 + 0.5 * (figure.normals[i * 3]! * lx + figure.normals[i * 3 + 1]! * ly + figure.normals[i * 3 + 2]! * lz));
const line = 1 - figure.contour[i]! * 0.85;
- put(c, i, lit * line * 0.92, lit * line * 0.94, lit * line, a * (layer.opacity ?? opacity) * (clip ? clip[i]! : 1), blend);
+ put(c, i, lit * line * 0.92, lit * line * 0.94, lit * line, a * opacity * (clip ? clip[i]! : 1), blend);
}
const bones = strokeMask(figure.lines.map((points) => ({ closed: false, points })), 1.5, w, h);
- for (let i = 0; i < bones.length; i++) put(c, i, 0.95, 0.35, 0.3, bones[i]! * 0.8, 'normal');
+ for (let i = 0; i < bones.length; i++) put(c, i, 0.95, 0.35, 0.3, bones[i]! * 0.8 * opacity, 'normal');
for (const [x, y] of Object.values(figure.joints)) {
for (let dy = -2; dy <= 2; dy++) {
for (let dx = -2; dx <= 2; dx++) {
if (x + dx < 0 || y + dy < 0 || x + dx >= w || y + dy >= h || dx * dx + dy * dy > 5) continue;
- put(c, (y + dy) * w + x + dx, 0.95, 0.2, 0.25, 0.85, 'normal');
+ put(c, (y + dy) * w + x + dx, 0.95, 0.2, 0.25, 0.85 * opacity, 'normal');
}
}
}
diff --git a/pipeline/tests/image-raster.test.ts b/pipeline/tests/image-raster.test.ts
index 78ffe3d16..ce51ee113 100644
--- a/pipeline/tests/image-raster.test.ts
+++ b/pipeline/tests/image-raster.test.ts
@@ -1117,6 +1117,43 @@ describe('a picture to draw over', () => {
});
});
+describe('what the third trial tripped on', () => {
+ const person = { id: 'f', shape: 'figure', at: [128, 240], height: 220 } as ImageLayer;
+ const looking = (layers: object[]): ReturnType<typeof renderImage> => renderImage(validateImageSource({ size: 256, layers }), { guides: true });
+
+ it('a figure at opacity 0 shows nothing at all, bones and joints included', () => {
+ const img = looking([{ ...person, opacity: 0 }]);
+ for (let i = 3; i < img.rgba.length; i += 4) expect(img.rgba[i]).toBe(0);
+ });
+
+ it('a figure hidden from sight still clips and lights what uses it, without a warning', () => {
+ const uses = { shape: 'rect', at: [0, 0], size: [256, 256], clip: 'f', fill: { type: 'form', figure: 'f', light: [-1, 0, 0.2], stops: [[0, '#000000'], [1, '#ffffff']] } };
+ const hidden = looking([{ ...person, visible: false }, uses]);
+ const shown = renderImage(validateImageSource({ size: 256, layers: [person, uses] as never }));
+ expect(hidden.notes).toEqual([]);
+ expect(hidden.rgba).toEqual(shown.rgba);
+ });
+
+ it('anything else hidden is simply not there', () => {
+ const img = draw([{ id: 'a', shape: 'rect', at: [0, 0], size: [8, 8], fill: RED, visible: false }, { shape: 'rect', at: [0, 0], size: [64, 64], fill: BLUE, clip: 'a' }]);
+ expect(img.notes.join()).toMatch(/names no layer/);
+ });
+
+ it('a faint layer is still reported where it is', () => {
+ const img = draw([{ id: 'faint', shape: 'paint', strokes: [{ points: [[10, 20], [50, 20]], color: RED, size: 8, opacity: 0.3, hardness: 1 }] } as never]);
+ const box = img.layerBounds.faint!;
+ expect(box[2]).toBeGreaterThan(30);
+ expect(box[3]).toBeGreaterThan(5);
+ });
+
+ it('a sparse spray of large dabs shows as separate discs', () => {
+ const img = draw([{ shape: 'paint', strokes: [{ points: [[0, 64], [256, 64]], color: '#ffffff', size: 80, dab: 0.25, scatter: 0.8, spacing: 2.5, hardness: 0.85, opacity: 0.6, seed: 2 }] } as never], [256, 128]);
+ let runs = 0, on = false;
+ for (let x = 0; x < 256; x++) { const lit = [40, 64, 90].some((y) => px(img, x, y)[3]! > 60); if (lit && !on) runs++; on = lit; }
+ expect(runs).toBeGreaterThan(3);
+ });
+});
+
describe('what the second trial tripped on', () => {
const halves: ImageLayer[] = [{ id: 'a', shape: 'rect', at: [0, 0], size: [32, 64], fill: BLUE }];
it('takes a clip with @ as well, and a clip of nothing draws nothing', () => {