Files
Spellcast3d/code/tests/web/omnitexture.test.mjs

1252 lines
64 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The Omni-Texture stage on a fake page, with a stand-in viewer and graphics card (standin_viewer3d.mjs,
// standin_card.mjs): its tools - Projection's marker and clone stamp, its own mask marker at the column's foot - and
// the hand paint they leave, which is in its files before the page has the hub make the steps again (Render Masked, a
// fade, a picture taken off, a job): the hub takes no paint while that is under way. A mask stroke is never saved, and
// the mask outlives a model made again. The view moves while the mask marker is up; "Render Masked" (the side
// panel's button while something is masked) sends the view as it is at the press.
// node --test code/tests/web/omnitexture.test.mjs
import assert from 'node:assert/strict';
import { registerHooks } from 'node:module';
import { test } from 'node:test';
import { strokeAt } from './standin_card.mjs';
// ---- a page, as far as these modules use one: elements with a parent, attributes, children, classes, text ----
class FakeNode {}
class FakeEl extends FakeNode {
constructor(tag) {
super();
this.tagName = tag.toUpperCase();
this.children = [];
this.attrs = {};
this.className = '';
this.style = { setProperty(k, v) { this[k] = v; } };
this.dataset = {};
this.listeners = {};
this.hidden = false;
this.disabled = false;
this.parentNode = null;
this.offsetWidth = this.offsetHeight = 0;
}
setAttribute(k, v) { this.attrs[k] = String(v); }
getAttribute(k) { return this.attrs[k] ?? null; }
removeAttribute(k) { delete this.attrs[k]; }
addEventListener(type, fn) { (this.listeners[type] ||= []).push(fn); }
removeEventListener(type, fn) { this.listeners[type] = (this.listeners[type] || []).filter((f) => f !== fn); }
fire(type, event = {}) { for (const fn of this.listeners[type] || []) fn({ preventDefault() {}, stopPropagation() {}, target: this, ...event }); }
click() { this.fire('click'); }
showModal() { this.open = true; } // (a <dialog>, as far as the page's windows use one)
close() { this.open = false; this.fire('close'); }
remove() {
const siblings = this.parentNode?.children;
if (siblings) siblings.splice(siblings.indexOf(this), 1);
this.parentNode = null;
}
adopt(node) {
if (node instanceof FakeEl) {
node.remove();
node.parentNode = this;
}
return node;
}
append(...nodes) { for (const n of nodes) this.children.push(this.adopt(n)); }
prepend(...nodes) { this.children.unshift(...nodes.map((n) => this.adopt(n))); }
replaceChildren(...nodes) {
for (const c of [...this.children]) if (c instanceof FakeEl) c.remove();
this.children = [];
this.append(...nodes);
}
replaceWith(node) {
const parent = this.parentNode;
if (!parent) return;
parent.children.splice(parent.children.indexOf(this), 1, parent.adopt(node));
this.parentNode = null;
}
get firstChild() { return this.children[0] ?? null; }
get isConnected() { return true; }
get textContent() { return this.children.map((c) => (typeof c === 'string' ? c : c.textContent)).join(''); }
set textContent(v) { this.replaceChildren(String(v)); }
get title() { return this.attrs.title ?? ''; }
set title(v) { this.attrs.title = String(v); }
get classList() {
const el = this;
const list = () => el.className.split(/\s+/).filter(Boolean);
return {
contains: (c) => list().includes(c),
add: (c) => { if (!list().includes(c)) el.className = [...list(), c].join(' '); },
remove: (c) => { el.className = list().filter((x) => x !== c).join(' '); },
toggle: (c, on = !list().includes(c)) => {
el.className = on ? [...new Set([...list(), c])].join(' ') : list().filter((x) => x !== c).join(' ');
return on;
},
};
}
animate() { return { finished: Promise.resolve(), playState: 'finished', cancel() {}, finish() {} }; }
getBoundingClientRect() { return { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 }; }
focus() {}
blur() {}
matches() { return false; }
// (a canvas, as far as the mask's picture is made on one)
getContext() { return { createImageData: (w, h) => ({ data: new Uint8ClampedArray(w * h * 4) }), putImageData() {} }; }
toBlob(done) { done({ arrayBuffer: async () => new ArrayBuffer(8) }); }
/** Every element in it (itself first) that `pick` accepts. */
all(pick) {
const out = pick(this) ? [this] : [];
for (const c of this.children) if (c instanceof FakeEl) out.push(...c.all(pick));
return out;
}
byClass(name) { return this.all((e) => e.classList.contains(name)); }
querySelectorAll(sel) {
const classes = sel.trim().split(/\s+/).at(-1).split('.').filter(Boolean);
return this.all((e) => e !== this && classes.every((c) => e.classList.contains(c)));
}
querySelector(sel) { return this.querySelectorAll(sel)[0] ?? null; }
}
class FakeTemplate extends FakeEl {
set innerHTML(html) { this.html = html; }
get content() { return { firstChild: new FakeEl('svg') }; }
}
const pageKeys = [];
globalThis.Node = FakeNode;
globalThis.addEventListener ??= () => {};
globalThis.document = {
addEventListener: (type, fn) => { if (type === 'keydown') pageKeys.push(fn); },
removeEventListener: (type, fn) => { if (pageKeys.includes(fn)) pageKeys.splice(pageKeys.indexOf(fn), 1); },
hidden: false, activeElement: null, documentElement: { dataset: {} }, body: new FakeEl('body'),
querySelector: () => null,
getElementById: () => new FakeEl('div'),
createElement: (tag) => (tag === 'template' ? new FakeTemplate(tag) : new FakeEl(tag)),
createElementNS: (ns, tag) => new FakeEl(tag),
};
// The page's polls and toasts wait a second or more: here they never come.
const realTimeout = globalThis.setTimeout;
globalThis.setTimeout = (fn, ms, ...rest) => (ms >= 1000 ? 0 : realTimeout(fn, ms, ...rest));
/** A key pressed on the page, as far as its listeners let it go. */
function keyDown(key, mods = {}) {
let stopped = false;
const e = { type: 'keydown', key, ...mods, preventDefault() {}, stopImmediatePropagation() { stopped = true; } };
for (const fn of [...pageKeys]) {
if (stopped) break;
fn(e);
}
}
// viewer3d.js is the stand-in viewer here.
const VIEWER = new URL('./standin_viewer3d.mjs', import.meta.url).href;
registerHooks({
resolve: (specifier, context, next) => {
const found = next(specifier, context);
return found.url.endsWith('/static/js/viewer3d.js') ? { url: VIEWER, shortCircuit: true } : found;
},
});
const { viewer } = await import(VIEWER);
const load = (path) => import(new URL(`../../spellcast/static/js/${path}`, import.meta.url));
const { store } = await load('store.js');
const { undoList, undoStamp } = await load('undo.js');
const { flushSettings } = await load('actions.js');
const { default: OMNI } = await load('stages/omnitexture.js');
const { hubJob } = await import('./hub_job.mjs');
// ---- a prop with an Omni-Texture and one repaint on it, and a hub that holds the hand paint's saves ----------------
const RESULT = 'omnitexture/ot_001/omnitexture.glb';
const REPAINT = 'omnitexture/ot_001/retouch_001/omnitexture.glb';
const MADE_AGAIN = 'omnitexture/ot_001/remove_001/omnitexture.glb';
const API = '/api/projects/Props/props/p_1';
const prop = (glb = REPAINT, steps = [RESULT, REPAINT]) => ({
id: 'p_1', name: 'Barrel', images: { chosen: 'images/0001.png', candidates: ['images/0001.png'], views: [] },
mesh: { glb: 'mesh/mesh.glb', settings: {} },
omnitexture: {
settings: { chosen: true }, glb, steps, source_mesh: 'mesh/mesh.glb', stats: {},
views: ['omnitexture/ot_001/views/0-front/painted.png', 'omnitexture/ot_001/views/1-back/painted.png'],
repaints: [{ glb: REPAINT, picture: 'omnitexture/ot_001/retouch_001/picture.png', under: RESULT, fade: 1 }],
},
retopo: { obj: null, settings: {} },
});
/** The prop with a second, newer repaint on its model (older: the first one hidden or not). */
const NEWER = 'omnitexture/ot_001/retouch_002/omnitexture.glb';
const twice = (olderHidden = false) => {
const p = prop(NEWER, [RESULT, REPAINT, NEWER]);
p.omnitexture.repaints = [
{ glb: REPAINT, picture: 'omnitexture/ot_001/retouch_001/picture.png', under: RESULT, fade: 1, hidden: olderHidden },
{ glb: NEWER, picture: 'omnitexture/ot_001/retouch_002/picture.png', under: REPAINT, fade: 1 }];
return p;
};
/** A second prop, chosen and waiting for its Omni-Texture: "Omni-Texture the chosen" has it to paint. */
const waiting = () => ({
id: 'p_2', name: 'Crate', images: { chosen: 'images/0001.png', candidates: ['images/0001.png'], views: [] },
mesh: { glb: 'mesh/mesh.glb', settings: {} }, omnitexture: { settings: { chosen: true } }, retopo: { obj: null, settings: {} },
});
/** A prop the artist never OmniTextured (and has not chosen): its 3D model alone. */
const plain = () => ({
id: 'p_1', name: 'Guy', images: { chosen: 'images/0001.png', candidates: ['images/0001.png'], views: [] },
mesh: { glb: 'mesh/mesh.glb', settings: {} }, omnitexture: { settings: { chosen: false } }, retopo: { obj: null, settings: {} },
});
/** ... and with the result of its own texture the hub begins for it: no views, no steps yet. */
const begun = () => ({
...plain(),
omnitexture: { settings: { chosen: false }, glb: RESULT, steps: [], source_mesh: 'mesh/mesh.glb', stats: null, views: [], repaints: [] },
});
// job: what the newest job was asked with; asked: the newest change of any kind
const hub = { calls: [], hold: null, answer: null, job: null, asked: null };
const answer = (body) => ({ status: 200, text: async () => JSON.stringify(body) });
globalThis.fetch = async (path, init = {}) => {
const method = init.method || 'GET';
const body = typeof init.body === 'string' ? JSON.parse(init.body) : null;
hub.calls.push(`${method} ${path.split('?')[0]}${body?.prepare ? ' (prepare)' : ''}`);
if (method !== 'GET') hub.asked = body;
if (path.startsWith('/api/jobs')) {
if (method === 'POST') hub.job = body;
return answer(method === 'POST' ? { id: 'j_1', stage: 'omnitexture', status: 'queued', prop_ids: body.prop_ids, props: {} } : []);
}
if (path.includes('/omnitexture/paint')) {
await hub.hold;
return answer(null);
}
if (path.includes('/omnitexture/mask')) return answer({ mask: 'omnitexture/masks/0001.png' });
if (path.includes('/omnitexture/')) return answer(await (hub.answer ? hub.answer(path, body) : { prop: store.project.props[0], renamed: {} }));
return answer({});
};
/** What the page asked the hub to change, in order (its reads and a fade's readying left out). */
const changes = () => hub.calls.filter((c) => !c.startsWith('GET') && !c.endsWith('(prepare)'));
const settle = async () => { for (let i = 0; i < 8; i++) await new Promise((resolve) => realTimeout(resolve, 0)); };
let opened = 0;
/** The stage on the first prop, its result on screen with the tools bound, no tool up; the hand paint's saves held. */
async function mount(props = [prop()]) {
OMNI.unmount();
store.connected = true;
store.jobs = [];
store.jobErrors = {};
store.status = {
tools: { qwen: { state: 'stopped', installed: true, supported: true, uses_gpu: true } },
stage_tools: { images: ['qwen'], omnitexture: ['qwen'] }, install: { running: false, components: {} },
};
store.project = { id: 'Props', name: 'Props', props, ui: {} };
store.bust = {};
store.openStamp = ++opened; // a model of its own for each test
hub.calls = [];
hub.answer = null;
hub.job = null;
lookFrom(FRONT);
let release;
hub.hold = new Promise((resolve) => { release = resolve; });
const host = new FakeEl('div');
const ctx = { selectedId: 'p_1', stageId: 'omnitexture', project: store.project, select() {}, goto() {}, moving: false };
OMNI.mount(host, ctx);
await settle();
const label = (node) => node.getAttribute('aria-label');
const tools = host.byClass('pt-tools')[0];
// The column's buttons, top to bottom (the stage's own tool stands with the x that wipes it, its lens with the
// glass of its slider).
const buttons = () => tools.children.flatMap((b) => (b.className === 'pt-own' ? b.children : [b]))
.filter((b) => b.tagName !== 'SPAN');
const tool = (name) => buttons().find((b) => label(b) === name);
tool('Orbit').click(); // (the brush is the page's: a tool may still be up from the view before)
// (... and the view is the stage's: it keeps the one the artist, or a tool of theirs, picked last)
host.all((e) => e.tagName === 'BUTTON' && e.textContent === 'All')[0]?.click();
/** The side panel's button pressed: "Render Masked" while something is masked. */
const render = () => host.byClass('sv-wide')[0].click();
return { host, ctx, release, tools, buttons, tool, label, render, update: () => OMNI.update(ctx) };
}
// Where the artist looks from (the stand-in camera's place): as every test begins, and after going round the model.
const FRONT = [0, 0, 2];
const SIDE = [2, 0.5, 0];
function lookFrom(place) {
viewer.camera.position.fromArray(place);
viewer.camera.updateMatrixWorld();
}
const lookingFrom = () => viewer.camera.position.toArray();
/** A stroke of the marker on the base colour, its save due. */
function paintBase(stage, rect = { x: 8, y: 8, w: 4, h: 4 }) {
stage.tool('Marker of any colour').click();
strokeAt(viewer, rect);
}
/** The step-making call `then` waits for the paint's save: none of it is asked for until that is in the files. */
async function waitsForThePaint(stage, then) {
await settle();
assert.deepEqual(changes(), [`PUT ${API}/omnitexture/paint`], 'the hand paint goes first ...');
stage.release();
await settle();
assert.deepEqual(changes(), [`PUT ${API}/omnitexture/paint`, ...then], '... and only once it is in the files, the rest');
}
test('the Omni-Texture result has Projection\'s tools in the column, Orbit on top, its mask marker at the foot with the x that discards the mask, the hint left of the glass', async () => {
const stage = await mount();
const WIPE = 'Discard the mask (Ctrl+Z brings it back)';
assert.deepEqual(stage.buttons().map(stage.label),
['Orbit', 'Clone stamp', 'Marker of any colour', WIPE, 'Mask marker', 'Inverse perspective']);
// The mask marker is a tool like the stamp above it, with an icon of its own: not one more disc of colour.
const [stamp, mask] = [stage.tool('Clone stamp'), stage.tool('Mask marker')];
assert.deepEqual([mask.className, mask.children.length], [stamp.className, 1]);
const [hint, glass] = stage.host.byClass('pt-row')[0].children;
assert.equal(hint.className, 'pt-hint');
assert.equal(glass.className, 'pt-bar');
const cover = stage.host.byClass('mk-cover')[0];
assert.equal(cover.children.length, 1, 'the square alone lies on the viewport: the words are asked in the side panel');
assert.equal(stage.tool(WIPE).hidden, true);
stage.tool('Mask marker').click();
assert.equal(cover.hidden, false, 'the black outside the square Render Masked sends');
assert.equal(stage.tool(WIPE).hidden, false, 'the x beside the marker while it is up');
// Masked: the x discards the mask.
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
stage.tool(WIPE).click();
assert.equal(await viewer.current.userData.paint.readOverlay().then((read) => Math.max(...read.data)), 0);
// Masked again, then the marker put down: the black goes, and the x with it.
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
stage.tool('Orbit').click();
assert.deepEqual([cover.hidden, stage.tool(WIPE).hidden], [true, true]);
OMNI.unmount();
});
test('the side panel\'s field takes words of the artist\'s own, if any: they go with the mask, and Enter renders', async () => {
const stage = await mount();
stage.release();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
const [field] = stage.host.byClass('ot-mask-words')[0].byClass('mk-ask-input');
stage.render();
await settle();
assert.equal('words' in hub.job.params.retouch, false, 'none typed: none sent');
store.jobs = []; // (the repaint done)
stage.update();
await settle();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
field.value = ' rusty bolts along the edge ';
field.fire('input');
field.fire('keydown', { key: 'Enter', shiftKey: false, isComposing: false });
await settle();
assert.equal(hub.job.params.retouch.words, 'rusty bolts along the edge');
OMNI.unmount();
});
test('a mask stroke is never saved, and a stroke of the marker leaves the mask as it was', async () => {
let stage = await mount();
stage.release();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
assert.equal(stage.host.byClass('sv-wide')[0].textContent, 'Render Masked', 'something masked: the panel renders it');
OMNI.unmount(); // what is left to save goes as the view goes
await settle();
assert.deepEqual(changes(), [], 'nothing saved of the mask');
stage = await mount();
stage.release();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
const session = viewer.current.userData.paint;
const mask = (await session.readOverlay()).data;
paintBase(stage, { x: 10, y: 10, w: 8, h: 8 });
assert.deepEqual((await session.readOverlay()).data, mask, 'the mask as it was');
stage.tool('Mask marker').click();
await settle();
assert.equal(stage.host.byClass('sv-wide')[0].textContent, 'Render Masked');
OMNI.unmount();
await settle();
assert.deepEqual(changes(), [`PUT ${API}/omnitexture/paint`], 'the marker\'s stroke');
});
test('a picture taken off waits until the hand paint is in the files; the mask on the model comes back with it', async () => {
const stage = await mount();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
const mask = (await viewer.current.userData.paint.readOverlay()).data;
paintBase(stage);
const shownFirst = viewer.shown.at(-1);
hub.answer = (path) => (path.endsWith('/remove') ? { prop: (store.project.props[0] = prop(MADE_AGAIN, [RESULT, REPAINT, MADE_AGAIN])) }
: store.project.props[0] = prop());
stage.host.byClass('ot-x')[0].click();
await waitsForThePaint(stage, [`POST ${API}/omnitexture/remove`]);
stage.update(); // the prop shows the model made again ...
await settle();
assert.notEqual(viewer.shown.at(-1), shownFirst);
viewer.forget(shownFirst); // ... the viewer lets go of the one before ...
keyDown('z', { ctrlKey: true }); // ... and Ctrl+Z shows it again
await settle();
assert.deepEqual(changes().at(-1), `POST ${API}/omnitexture/step`);
stage.update();
await settle();
assert.equal(viewer.shown.at(-1), shownFirst);
assert.deepEqual((await viewer.current.userData.paint.readOverlay()).data, mask, 'its mask, stroke by stroke');
OMNI.unmount();
});
test('a prop that was never OmniTextured has the tools on its 3D model: the first one taken up begins a result of its own texture, a model of its own that alone is painted', async () => {
const stage = await mount([plain()]);
const onScreen = viewer.shown.at(-1);
assert.ok(onScreen.includes('mesh/mesh.glb'), onScreen);
assert.equal(stage.host.byClass('pt-layer')[0].hidden, false, 'the tools are there, though the prop is not chosen');
assert.deepEqual(changes(), [], 'looking at it asks the hub for nothing');
const marker = stage.tool('Marker of any colour');
hub.answer = (path) => (path.endsWith('/own') ? { prop: begun() } : { prop: store.project.props[0] });
marker.click();
assert.equal(marker.classList.contains('on'), false, 'not up before the model is the result\'s to paint');
await settle();
assert.deepEqual(changes(), [`POST ${API}/omnitexture/own`]);
stage.update(); // the prop has its result now
await settle();
const step = viewer.shown.at(-1);
assert.ok(step.includes(RESULT), 'the step is shown as its own model, never the 3D model\'s under another name');
assert.equal(marker.classList.contains('on'), true, 'the tool asked for is up');
assert.equal(stage.host.all((e) => e.tagName === 'BUTTON' && e.textContent === 'Painted').length, 1,
'the switch names what the result is');
// From here on it is painted and masked like any result: the hand paint goes into the new step.
strokeAt(viewer, { x: 8, y: 8, w: 4, h: 4 });
stage.release();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 20, y: 20, w: 6, h: 6 });
stage.render();
await settle();
assert.deepEqual(changes().slice(1), [`PUT ${API}/omnitexture/paint`, `PUT ${API}/omnitexture/mask`, 'POST /api/jobs']);
// "Original" shows the model the 3D stage made: nothing of the paint or of the mask is on it.
stage.host.all((e) => e.tagName === 'BUTTON' && e.textContent === 'Original')[0].click();
await settle();
assert.equal(viewer.shown.at(-1), onScreen);
assert.equal(viewer.current.userData.paint?.painted('base') ?? false, false);
assert.equal(viewer.current.userData.paint?.painted('overlay') ?? false, false);
OMNI.unmount();
});
test('a tool taken up in "All" moves the view to Base colour, and the repaint\'s model comes up there too - not in "All" again', async () => {
const stage = await mount();
stage.release();
assert.equal(viewer.view, 'all');
stage.tool('Mask marker').click();
assert.equal(viewer.view, 'basecolor', 'what the brushes paint, flat');
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
stage.render(); // "Render Masked": the marker goes down, the job paints ...
await settle();
const NEXT = 'omnitexture/ot_001/retouch_002/omnitexture.glb';
store.jobs = []; // ... and ends with the prop on its next step
store.project.props[0] = prop(NEXT, [RESULT, REPAINT, NEXT]);
stage.update();
await settle();
assert.ok(viewer.shown.at(-1).includes(NEXT), 'the repaint\'s model is on screen');
assert.equal(viewer.view, 'basecolor', 'in the view the artist was working in');
OMNI.unmount();
});
test('a result of the prop\'s own texture on a 3D model made again since shows nowhere: not in the viewport, not among the painted views', async () => {
const stale = () => ({ ...begun(), omnitexture: {
...begun().omnitexture, stale: true, steps: [RESULT, REPAINT], glb: REPAINT,
repaints: [{ glb: REPAINT, picture: 'omnitexture/ot_001/retouch_001/picture.png', under: RESULT, fade: 1 }] } });
const stage = await mount([stale()]);
assert.ok(viewer.shown.at(-1).includes('mesh/mesh.glb'), 'the 3D model the prop has now');
assert.deepEqual(stage.host.byClass('ot-repaint'), [], 'no repaint of the old model to point at or take off');
assert.deepEqual(stage.host.byClass('ot-x').filter((x) => !x.hidden), [], 'no × is offered');
// The tools are there, on the 3D model: the first one taken up begins anew.
hub.answer = (path) => (path.endsWith('/own') ? { prop: begun() } : { prop: store.project.props[0] });
stage.tool('Marker of any colour').click();
await settle();
assert.deepEqual(changes(), [`POST ${API}/omnitexture/own`]);
OMNI.unmount();
});
test('the hub refusing to begin the result puts the brush down and says why', async () => {
const stage = await mount([plain()]);
const said = [];
const warn = console.warn;
console.warn = (e) => said.push(e?.message || String(e));
const real = globalThis.fetch;
globalThis.fetch = async (path, init) => (String(path).endsWith('/own')
? { status: 409, text: async () => JSON.stringify({ detail: 'This prop is being OmniTextured. Wait until it is done.' }) }
: real(path, init));
try {
const marker = stage.tool('Marker of any colour');
marker.click();
await settle();
assert.equal(marker.classList.contains('on'), false);
assert.equal(stage.tool('Orbit').classList.contains('on'), true);
assert.deepEqual(said, ['This prop is being OmniTextured. Wait until it is done.']);
marker.click(); // asked again: the hub is asked again
await settle();
assert.equal(said.length, 2);
} finally {
globalThis.fetch = real;
console.warn = warn;
}
OMNI.unmount();
});
test('a tile\'s box chooses the prop for Omni-Texture; a click on the tile no longer does', async () => {
await mount([plain()]);
const box = () => OMNI.tileCheck(store.project.props[0]);
assert.deepEqual(box(), { on: false, title: 'Choose it for Omni-Texture' });
assert.equal(OMNI.pickTile, undefined, 'a click on the tile only opens the prop');
assert.equal(OMNI.tileMark, undefined, 'no golden outline');
// A tick rings the button it is for, once ("Omni-Texture the chosen"); taking the tick away rings nothing.
const rung = [];
const { animate } = FakeEl.prototype;
FakeEl.prototype.animate = function (frames, timing) { rung.push([this.classList.contains('ot-go'), timing?.iterations]); return animate.call(this); };
OMNI.checkTile('p_1');
assert.equal(store.project.props[0].omnitexture.settings.chosen, true);
assert.deepEqual(box(), { on: true, title: 'Chosen for Omni-Texture: click to leave it out' });
assert.deepEqual(rung, [[true, 1]]);
OMNI.checkTile('p_1');
assert.equal(box().on, false);
assert.equal(rung.length, 1);
FakeEl.prototype.animate = animate;
// A prop whose Omni-Texture is being made stays chosen; Omni-Texture that can't run here offers no box.
OMNI.checkTile('p_1');
store.jobs = [hubJob({ id: 'j_1', stage: 'omnitexture', status: 'running', prop_ids: ['p_1'], progress: { fraction: 0.2, message: '' }, errors: {} })];
OMNI.checkTile('p_1');
assert.equal(box().on, true);
store.jobs = [];
// A tileable texture has no 3D model to paint: no box for it.
const [object] = store.project.props;
assert.equal(OMNI.tileCheck({ ...object, images: { ...object.images, settings: { tileable: true } } }), null);
assert.notEqual(OMNI.tileCheck(object), null);
store.status.stage_tools.omnitexture = [];
assert.equal(OMNI.tileCheck(store.project.props[0]), null);
await new Promise((resolve) => realTimeout(resolve, 650));
assert.deepEqual(changes(), [`PATCH ${API}`], 'saved like any setting, a moment later');
OMNI.unmount();
});
test('while a whole Omni-Texture is painted no prop\'s model shows - the progress in its place, whichever prop is clicked -; beside a masked repaint the models show', async () => {
const stage = await mount();
const busy = () => stage.host.byClass('sv-busy')[0];
const job = (retouch) => hubJob({ id: 'j_5', stage: 'omnitexture', status: 'running', prop_ids: ['p_2'], retouch,
progress: { fraction: 0.2, message: 'Painting the views' }, errors: {} });
const shown = viewer.shown.length;
assert.equal(busy().hidden, true);
store.jobs = [job(false)];
stage.update();
assert.equal(busy().hidden, false);
assert.match(busy().byClass('sv-busy-text')[0].textContent, /^The models show once the Omni-Texture is done/);
assert.equal(stage.host.byClass('mk-cover')[0].hidden, true, 'nothing to paint on meanwhile');
// A masked repaint of another prop: this one's model shows beside it.
store.jobs = [job(true)];
stage.update();
await settle();
assert.deepEqual([busy().hidden, viewer.shown.length], [true, shown + 1]);
store.jobs = [];
stage.update();
OMNI.unmount();
});
test('taking up the mask marker has the hub ready its worker for the repaint that follows, once while the artist masks', async () => {
(await mount([begun()])).tool('Discard the mask (Ctrl+Z brings it back)').click(); // (the tests' before)
await settle();
const stage = await mount([begun()]);
hub.calls.length = 0;
const readied = () => hub.calls.filter((c) => c.endsWith('(prepare)'));
stage.update();
await settle();
assert.deepEqual(readied(), [], 'a result without repaints on screen, nothing masked: nothing to ready');
stage.tool('Mask marker').click();
await settle();
assert.deepEqual(readied(), [`POST ${API}/omnitexture/fade (prepare)`]);
assert.deepEqual(hub.asked, { mask: true, prepare: true });
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
stage.tool('Mask marker').click();
stage.tool('Mask marker').click();
await settle();
assert.equal(readied().length, 1, 'asked once: the worker stays while the artist goes on');
assert.deepEqual(changes(), [], 'nothing changed by it');
// A minute on, still masking: asked again (the hub lets an unused worker go after two). A hub that says a job
// is at work is asked again a few seconds later; one that only says no, not before the minute is over.
const now = Date.now;
let clock = now();
Date.now = () => clock;
try {
const again = async (later) => {
clock += later;
stage.update();
await settle();
return readied().length;
};
assert.equal(await again(59_000), 1);
hub.answer = () => ({ ready: false, busy: true });
assert.equal(await again(2_000), 2);
assert.deepEqual([await again(4_000), await again(2_000)], [2, 3], 'a job was at work: asked again soon');
hub.answer = () => ({ ready: false });
assert.deepEqual([await again(6_000), await again(6_000), await again(56_000)], [4, 4, 5], 'no: a minute');
// Nothing is asked while a job of the prop waits or runs, nor with the 3D model itself on screen.
store.jobs = [hubJob({ id: 'j_9', stage: 'omnitexture', status: 'running', prop_ids: ['p_1'], retouch: true,
progress: { fraction: 0.2, message: 'Painting what you masked' }, errors: {} })];
assert.equal(await again(120_000), 5, 'its own job at work: the worker is the job\'s');
store.jobs = [];
stage.host.all((e) => e.tagName === 'BUTTON' && e.textContent === 'Original')[0].click();
await settle();
assert.equal(await again(120_000), 5, 'the 3D model on screen: nothing of the result to repaint');
} finally {
Date.now = now;
hub.answer = null;
store.jobs = [];
}
(await mount([begun()])).tool('Discard the mask (Ctrl+Z brings it back)').click(); // (for the tests after)
await settle();
OMNI.unmount();
});
test('a result with repaints on screen has the hub ready its worker at once, and the newest repaint is the edge fade\'s until another is clicked', async () => {
const stage = await mount();
const readied = () => hub.calls.filter((c) => c.startsWith('POST'));
assert.deepEqual(readied(), [`POST ${API}/omnitexture/fade (prepare)`]);
assert.deepEqual(hub.asked, { prepare: true }, 'the model is shown: no repaint named');
const [repaint] = stage.host.byClass('ot-repaint');
assert.equal(repaint.classList.contains('picked'), true);
assert.equal(stage.host.byClass('ot-fade-range')[0].disabled, false, 'the slider is its');
// The pointer at the pictures: ready for a click on any of them - asked once, whichever picture it then points
// at - and at the slider, for that repaint's other fades.
stage.host.byClass('ot-views')[0].fire('pointerenter');
stage.host.byClass('ot-tile')[2].fire('pointerenter');
await settle();
assert.deepEqual([readied().length, hub.asked], [2, { all: true, prepare: true }]);
stage.host.byClass('ot-fade')[0].fire('pointerenter');
await settle();
assert.deepEqual([readied().length, hub.asked], [3, { glb: REPAINT, prepare: true }]);
assert.deepEqual(changes(), [], 'nothing changed by any of it');
OMNI.unmount();
// None clicked and the newest hidden: the slider is for the newest that shows.
const two = twice();
two.omnitexture.repaints[1].hidden = true;
const older = await mount([two]);
assert.deepEqual(older.host.byClass('ot-repaint').map((node) => node.classList.contains('picked')), [true, false]);
assert.equal(older.host.byClass('ot-fade-range')[0].disabled, false);
OMNI.unmount();
// A prop's 3D model alone has no repaints to ready.
await mount([plain()]);
assert.deepEqual(hub.calls.filter((c) => c.startsWith('POST')), []);
OMNI.unmount();
});
test('the edge fade follows the repaint clicked last: hidden by that click it has nothing to fade, shown again it is that one\'s', async () => {
const stage = await mount([twice()]);
const ringed = () => stage.host.byClass('ot-repaint').map((node) => node.classList.contains('picked'));
const slider = () => stage.host.byClass('ot-fade-range')[0];
const clickOlder = async (hiddenAfter) => {
hub.answer = () => ({ prop: (store.project.props[0] = twice(hiddenAfter)), renamed: {} });
stage.host.byClass('ot-tile')[2].fire('click', { altKey: false });
await settle();
stage.update();
await settle();
};
assert.deepEqual(ringed(), [false, true], 'none clicked: the newest');
await clickOlder(true);
assert.deepEqual([ringed(), slider().disabled], [[false, false], true], 'the one clicked is hidden: nothing to fade');
await clickOlder(false);
assert.deepEqual([ringed(), slider().disabled], [[true, false], false], 'shown again: the slider is its');
OMNI.unmount();
});
test('a click on a picture does nothing while another change of the pictures is under way: no change, and the edge fade stays the clicked one\'s', async () => {
const stage = await mount([twice()]);
let release;
const held = new Promise((resolve) => { release = resolve; });
hub.answer = () => held.then(() => ({ prop: (store.project.props[0] = twice(true)), renamed: {} }));
const tiles = stage.host.byClass('ot-tile');
tiles[2].fire('click', { altKey: false }); // the older repaint: hidden, once the hub answers
await settle();
tiles[0].fire('click', { altKey: false }); // meanwhile: the painted views' eye, and the newer repaint
tiles[3].fire('click', { altKey: false });
await settle();
assert.deepEqual(changes(), [`POST ${API}/omnitexture/hide`], 'the one change asked, no other beside it');
release();
await settle();
stage.update();
await settle();
assert.equal(stage.host.byClass('ot-fade-range')[0].disabled, true, 'still the older one\'s, which is hidden now');
OMNI.unmount();
});
test('Alt + click on a painted view or on a repaint shows what Qwen-Image was given, and hides nothing', async () => {
const stage = await mount();
const asked = () => hub.calls.filter((c) => c.includes('request.json'));
const [view] = stage.host.byClass('ot-view');
const [repaint] = stage.host.byClass('ot-repaint');
const [viewTile, , repaintTile] = stage.host.byClass('ot-tile');
assert.ok(view.title.endsWith('Alt + click: what Qwen-Image was given for it.') && repaint.title.endsWith('Alt + click: what Qwen-Image was given for it.'));
const real = globalThis.fetch;
const record = { prompt: 'restore the image', pictures: ['picture 1: 1-viewport.png', 'picture 2: 2-depth.png', 'picture 3: 3-example.png'],
seed: 7, steps: 8, strength: 0.9, model: 'turbo',
retouch: { example: 'front', tries: [{ seed: 6, left: 30 }, { seed: 7, left: 2 }] } };
globalThis.fetch = async (path, init = {}) => {
hub.calls.push(`${init.method || 'GET'} ${String(path).split('?')[0]}`);
return String(path).includes('request.json') ? { ok: true, status: 200, json: async () => record } : { ok: true, status: 200 };
};
try {
repaintTile.fire('click', { altKey: true });
await settle();
assert.deepEqual(asked(), ['GET /files/Props/props/p_1/omnitexture/ot_001/retouch_001/request.json'], 'the repaint\'s own folder');
assert.deepEqual(changes(), [], 'nothing hidden');
const [shown] = document.body.all((e) => e.classList.contains('ot-inputs'));
const said = shown.all((e) => e.tagName === 'FIGCAPTION').map((e) => e.textContent);
assert.deepEqual(said, [
'Picture 1, also what it starts from: your view of the model, what you masked in magenta',
'Picture 2: the depth map from there',
'Picture 3, the example: the prop’s own picture of its front',
'Qwen-Image’s painting', 'Its lighting taken off', 'What went onto the model']);
assert.ok(shown.all((e) => e.classList.contains('hint')).some((e) => e.textContent.includes('the second picture')), 'it says a picture was made again');
viewTile.fire('click', { altKey: true });
await settle();
assert.equal(asked().length, 2, 'a painted view\'s record too');
// Masked from behind the side its picture shows: the picture went mirrored, and the caption says so. Older
// records: the example was the model from the nearest camera around it, and before that your own view.
for (const [retouch, said] of [[{ example: 'front', mirrored: true }, 'the prop’s own picture of its front, mirrored: you look from behind it'],
[{ example: 'front', mirrored: false }, 'the prop’s own picture of its front'],
[{ example_view: 'front left' }, 'the model from the front left, the nearest camera around it'],
[{}, 'the model without the mask']]) {
record.retouch = { ...retouch, tries: [] };
repaintTile.fire('click', { altKey: true });
await settle();
const older = document.body.all((e) => e.classList.contains('ot-inputs')).at(-1);
assert.ok(older.all((e) => e.tagName === 'FIGCAPTION').some((e) => e.textContent === `Picture 3, the example: ${said}`), said);
}
// A repaint of today is drawn anew where the view is masked and held to the view elsewhere (its record's
// "redrawn"): picture 1 is worded so, and what was drawn anew is shown after the pictures it saw.
record.redrawn = 'redrawn.png';
repaintTile.fire('click', { altKey: true });
await settle();
const held = document.body.all((e) => e.classList.contains('ot-inputs')).at(-1)
.all((e) => e.tagName === 'FIGCAPTION').map((e) => e.textContent);
assert.equal(held[0], 'Picture 1, also what it is held to outside the mask: your view of the model, what you masked in magenta');
assert.equal(held[3], 'Not a picture it sees: what it draws anew (white); everywhere else its painting is held to picture 1');
delete record.redrawn;
// A painted view of today: the depth map, then the prop's own picture of its front as the example. A sheet
// starts from the model with its own texture, which is no picture Qwen-Image sees: listed after them.
Object.assign(record, { pictures: ['picture 1: 1-render.png', 'picture 2: prop: mesh/views/0_front.png'],
shown: 'depth', example: 'front', start_image: '1-render.png', painted_where: '2-mask.png' });
const captions = async () => {
viewTile.fire('click', { altKey: true });
await settle();
return document.body.all((e) => e.classList.contains('ot-inputs')).at(-1)
.all((e) => e.tagName === 'FIGCAPTION').map((e) => e.textContent);
};
let told = await captions();
assert.ok(told[0].startsWith('Picture 1, also what it starts from: the depth map'));
assert.equal(told[1], 'Picture 2, the example: the prop’s own picture of its front');
assert.ok(!told.some((text) => text.startsWith('Not a picture it sees')));
record.start_image = 'model.png';
record.ref_sides = [1152, 512]; // a sheet: how large Qwen-Image's own copy of each picture is
told = await captions();
assert.ok(told[0].startsWith('Picture 1: the depth map') && told[0].endsWith('(Qwen-Image sees it at 1152 px)'));
assert.equal(told[1], 'Picture 2, the example: the prop’s own picture of its front (Qwen-Image sees it at 512 px)');
assert.ok(told[2].startsWith('Not a picture it sees: what the painting starts from, one step in'));
} finally {
globalThis.fetch = real;
}
OMNI.unmount();
});
test('a click anywhere on a picture hides it on the model and shows it again, the eye in its middle says which: a repaint alone, the painted views all together; Alt + click there is the picture\'s own', async () => {
const stage = await mount();
stage.release();
const eyes = () => stage.host.byClass('ot-eye');
const off = () => stage.host.byClass('ot-tile').map((tile) => tile.classList.contains('off'));
const shown = (omnitexture) => ({ prop: (store.project.props[0] = { ...prop(), omnitexture: { ...prop().omnitexture, ...omnitexture } }),
renamed: { [REPAINT]: MADE_AGAIN } });
const repaint = (hidden) => ({ glb: MADE_AGAIN, picture: 'omnitexture/ot_001/remove_001/picture.png', under: RESULT, fade: 1, hidden });
assert.deepEqual(off(), [false, false, false], 'two views and a repaint, all on the model');
assert.ok(eyes().slice(0, 2).every((eye) => stage.label(eye).startsWith('Hide the painted views - all of them')));
assert.equal(stage.label(eyes()[2]), 'Hide this repaint: the model shows what is under it');
// A click on the repaint's picture, wherever: it alone is asked hidden; its tile stays, dim under the crossed
// eye, and the edge fade has nothing to fade.
hub.answer = () => shown({ glb: MADE_AGAIN, steps: [RESULT, MADE_AGAIN], repaints: [repaint(true)] });
stage.host.byClass('ot-tile')[2].fire('click', { altKey: false });
await settle();
assert.deepEqual([changes(), hub.asked], [[`POST ${API}/omnitexture/hide`], { glb: REPAINT, repaint: REPAINT, hidden: true }]);
stage.update();
await settle();
assert.deepEqual(off(), [false, false, true]);
assert.equal(stage.label(eyes()[2]), 'Show this repaint on the model again');
const [picture] = stage.host.byClass('ot-repaint');
assert.equal(picture.classList.contains('picked'), false, 'no edge to fade while it is hidden');
assert.equal(stage.host.byClass('ot-fade-range')[0].disabled, true);
assert.ok(picture.title.includes('hidden: it is not on the model'));
hub.answer = () => shown({ glb: MADE_AGAIN, steps: [RESULT, MADE_AGAIN], repaints: [repaint(false)] });
eyes()[2].fire('click', { altKey: false }); // (the eye itself is as good a place to click)
await settle();
assert.deepEqual(hub.asked, { glb: MADE_AGAIN, repaint: MADE_AGAIN, hidden: false }, 'shown again');
// A view's eye: all of them, whichever is clicked - and no view is taken off while they are hidden.
const base = { glb: MADE_AGAIN, steps: [MADE_AGAIN], repaints: [] };
const views = prop().omnitexture.views.map((view) => ({ folder: view.slice(0, view.lastIndexOf('/')), picture: view, layer: null }));
hub.answer = () => shown({ ...base, bases: [{ glb: MADE_AGAIN, views, hidden: true, shown: RESULT }] });
eyes()[1].fire('click', { altKey: false });
await settle();
assert.deepEqual(hub.asked, { glb: MADE_AGAIN, views: true, hidden: true });
stage.update();
await settle();
assert.deepEqual(off(), [true, true]);
assert.ok(eyes().every((eye) => stage.label(eye) === 'Show the painted views on the model again'));
assert.deepEqual(stage.host.byClass('ot-tile').flatMap((tile) => tile.byClass('ot-x')), [], 'no × on a hidden view');
eyes()[0].fire('click', { altKey: false });
await settle();
assert.deepEqual(hub.asked, { glb: MADE_AGAIN, views: true, hidden: false });
// Alt + click on an eye hides nothing: it shows what Qwen-Image was given, as on the picture around it.
const asked = changes().length;
const real = globalThis.fetch;
globalThis.fetch = async (path) => {
hub.calls.push(`GET ${String(path).split('?')[0]}`);
return { ok: true, status: 200, json: async () => ({ prompt: '', pictures: [] }) };
};
try {
eyes()[0].fire('click', { altKey: true });
await settle();
} finally {
globalThis.fetch = real;
}
assert.equal(changes().length, asked, 'nothing asked of the hub');
assert.ok(hub.calls.at(-1).endsWith('/omnitexture/ot_001/views/0-front/request.json'));
OMNI.unmount();
});
test('a picture\'s share shows on the model while the pointer is anywhere on its tile, its eye and its × too', async () => {
const stage = await mount([{ ...prop(), omnitexture: { ...prop().omnitexture,
layers: ['omnitexture/ot_001/views/0-front/layer.webp'] } }]);
const [front, back] = stage.host.byClass('ot-tile');
const layers = [];
const setLayer = viewer.setLayer;
viewer.setLayer = (url) => layers.push(url && url.split('?')[0]);
try {
front.fire('pointerenter');
front.fire('pointerleave');
back.fire('pointerenter'); // (a view without a layer of its own: nothing to show)
back.fire('pointerleave');
} finally {
viewer.setLayer = setLayer;
}
assert.deepEqual(layers, ['/files/Props/props/p_1/omnitexture/ot_001/views/0-front/layer.webp', null]);
OMNI.unmount();
});
test('a fade waits until the hand paint is in the files', async () => {
const stage = await mount();
paintBase(stage);
const range = stage.host.byClass('ot-fade-range')[0]; // (the newest repaint's)
range.value = 2;
range.fire('change');
await waitsForThePaint(stage, [`POST ${API}/omnitexture/fade`]);
OMNI.unmount();
});
test('"OmniTex it again" and "Omni-Texture the chosen" wait until the hand paint is in the files', async () => {
let stage = await mount();
paintBase(stage);
stage.host.all((e) => e.tagName === 'BUTTON' && e.textContent === 'OmniTex it again')[0].click();
await waitsForThePaint(stage, ['POST /api/jobs']);
OMNI.unmount();
stage = await mount([prop(), waiting()]);
paintBase(stage);
stage.host.byClass('ot-go')[0].click();
await waitsForThePaint(stage, ['POST /api/jobs']);
OMNI.unmount();
});
test('"Render Masked" sends the mask once the hand paint is in the files', async () => {
const stage = await mount();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
paintBase(stage);
stage.render();
await waitsForThePaint(stage, [`PUT ${API}/omnitexture/mask`, 'POST /api/jobs']);
assert.equal(stage.host.byClass('mk-cover')[0].hidden, true, 'the mask marker put down');
OMNI.unmount();
});
test('the × beside "Painted views" takes the whole Omni-Texture off: the prop shows its 3D model, Ctrl+Z brings the result back and Ctrl+Y takes it off again', async () => {
const stage = await mount();
stage.release();
const steps = [RESULT, REPAINT, ''];
const whole = stage.host.all((e) => stage.label(e) === 'Take the whole Omni-Texture off this model')[0];
assert.equal(whole.hidden, false, 'beside the heading of the painted views');
hub.answer = (path, body) => (path.endsWith('/remove') ? { prop: (store.project.props[0] = prop('', steps)) }
: (store.project.props[0] = prop(body.glb, steps)));
whole.click();
await settle();
assert.deepEqual([changes(), hub.asked], [[`POST ${API}/omnitexture/remove`], { glb: REPAINT, whole: true }]);
stage.update();
await settle();
assert.ok(viewer.shown.at(-1).includes('mesh/mesh.glb'), 'the 3D model with its own texture');
assert.deepEqual([stage.host.byClass('ot-view').length, whole.hidden], [0, true], 'nothing painted is listed any more');
keyDown('z', { ctrlKey: true });
await settle();
assert.deepEqual([changes().at(-1), hub.asked], [`POST ${API}/omnitexture/step`, { glb: REPAINT }]);
stage.update();
await settle();
assert.ok(viewer.shown.at(-1).includes(REPAINT), 'the result again, as it was');
assert.equal(whole.hidden, false);
// Taken off once more, after a change elsewhere on the page: it is the newest change again, Ctrl+Z's first.
const elsewhere = undoStamp();
const forget = undoList(() => elsewhere);
whole.click();
await settle();
stage.update();
await settle();
assert.ok(viewer.shown.at(-1).includes('mesh/mesh.glb'));
keyDown('z', { ctrlKey: true });
await settle();
assert.deepEqual([changes().at(-1), hub.asked], [`POST ${API}/omnitexture/step`, { glb: REPAINT }]);
forget();
stage.update();
await settle();
keyDown('y', { ctrlKey: true });
await settle();
assert.deepEqual([changes().at(-1), hub.asked], [`POST ${API}/omnitexture/step`, { glb: '' }]);
OMNI.unmount();
});
test('the mask marker\'s hint says where "Render Masked" is and how the view moves, as with any tool', async () => {
const stage = await mount();
stage.release();
stage.tool('Mask marker').click();
const [first, keys] = stage.host.byClass('pt-hint')[0].children.map((line) => line.textContent);
assert.ok(first.startsWith('Mask marker: paint over what to make again') && first.includes('on the right')
&& keys.includes('orbit'), `${first} / ${keys}`);
stage.tool('Orbit').click();
OMNI.unmount();
});
test('a tool taken up in the lit view shows the base colour; "Render Masked" puts the marker down', async () => {
const stage = await mount();
stage.release();
assert.equal(viewer.view, 'all');
stage.tool('Mask marker').click();
assert.equal(viewer.view, 'basecolor', 'the mask marker too: what is painted over shows flat');
// A job takes the prop (one started elsewhere): the tools go until it is through.
store.jobs = [hubJob({ id: 'j_2', stage: 'omnitexture', status: 'running', prop_ids: ['p_1'], progress: { fraction: 0.2, message: '' }, errors: {} })];
stage.update();
store.jobs = [];
stage.update();
await settle();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
stage.render();
await settle();
assert.equal(stage.tool('Mask marker').classList.contains('on'), false);
assert.equal(viewer.view, 'basecolor', 'the view stays where the tool left it');
OMNI.unmount();
});
test('the side panel\'s "Render Masked" has the mask\'s words above it and "No Facets" on its left, and as "OmniTex it again" neither; "No Facets" stays as it was set', async () => {
const stage = await mount();
stage.release();
stage.tool('Discard the mask (Ctrl+Z brings it back)').click(); // (the mask the test before left on the model)
await settle();
const [again] = stage.host.byClass('sv-wide');
const [row] = stage.host.byClass('ot-again');
const [above] = stage.host.byClass('ot-mask-words');
const [facets] = stage.host.byClass('ot-facets');
const [sideField] = above.byClass('mk-ask-input');
assert.deepEqual(row.children.slice(0, 2), [facets, again], '"No Facets" on the left part, the button on the rest');
const { children } = stage.host.byClass('sv-foot')[0];
assert.equal(children.indexOf(above), children.indexOf(row) - 1, 'right above the button\'s row');
assert.deepEqual([again.textContent, above.hidden, facets.hidden], ['OmniTex it again', true, true]);
// Masked: the button is "Render Masked", the words above it and "No Facets" beside it.
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
assert.deepEqual([again.textContent, above.hidden, facets.hidden], ['Render Masked', false, false]);
assert.match(above.textContent, /Explain: \(optional\)/);
assert.deepEqual([sideField.getAttribute('rows'), facets.textContent], ['2', 'No Facets']);
// "No Facets" off: the depth map as the model is.
assert.equal(facets.getAttribute('aria-pressed'), 'false');
again.click();
await settle();
assert.equal('smooth' in hub.job.params.retouch, false);
store.jobs = [];
stage.update();
await settle();
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
sideField.value = 'rusty bolts along the edge';
sideField.fire('input');
facets.click();
assert.equal(facets.getAttribute('aria-pressed'), 'true');
// Still masked with the marker put down: Enter in the field renders, with the words and without the facets.
stage.tool('Orbit').click();
assert.deepEqual([above.hidden, facets.hidden], [false, false]);
sideField.fire('keydown', { key: 'Enter', shiftKey: false, isComposing: false });
await settle();
assert.deepEqual([hub.job.params.retouch.words, hub.job.params.retouch.smooth], ['rusty bolts along the edge', true]);
// Its job under way: the button is gone, and the words with it.
store.jobs = [hubJob({ id: 'j_3', stage: 'omnitexture', status: 'running', prop_ids: ['p_1'], progress: { fraction: 0.2, message: '' }, errors: {} })];
stage.update();
assert.deepEqual([row.hidden, above.hidden], [true, true]);
store.jobs = [];
stage.update();
// The artist's setting, as the lens is: the next view of the stage has it on still.
OMNI.unmount();
const next = (await mount()).host.byClass('ot-facets')[0];
assert.equal(next.getAttribute('aria-pressed'), 'true');
next.click(); // (off again for the tests that follow)
OMNI.unmount();
});
test('beside "OmniTex it again": the prop\'s Detail given to the texture the 3D stage made, Qwen-Image left out; none while Detail is Original', async () => {
const p = prop(RESULT, [RESULT]);
p.omnitexture.repaints = [];
p.omnitexture.settings.detail = 'original';
const stage = await mount([p]);
stage.release();
const [row] = stage.host.byClass('ot-again');
const [, again, own] = row.children;
assert.deepEqual([again.textContent, again.hidden, own.hidden], ['OmniTex it again', false, true]);
store.status.omnitexture_details = [{ kind: 'upscaled', ready: true }, { kind: 'detailed', ready: false }];
store.project.props[0].omnitexture.settings.detail = 'upscaled';
stage.update();
assert.deepEqual([own.textContent, own.hidden, own.disabled], ['Upscale its original', false, false]);
store.project.props[0].omnitexture.settings.detail = 'detailed';
stage.update();
assert.deepEqual([own.textContent, own.disabled], ['Detail its original', true], 'its network is not here yet');
assert.match(own.title, /SeedVR2.*not on this PC yet/s);
store.status.omnitexture_details[1].ready = true;
stage.update();
assert.equal(own.disabled, false);
// While something is masked the row is the mask's alone.
stage.tool('Mask marker').click();
assert.deepEqual([again.textContent, own.hidden], ['Render Masked', true]);
stage.tool('Orbit').click();
assert.deepEqual([again.textContent, own.hidden], ['OmniTex it again', false]);
own.click();
await settle();
assert.deepEqual(hub.job.params, { from_model: true }, 'the job takes the model\'s own texture as its painting');
OMNI.unmount();
});
test('a prop that was never OmniTextured, and is not chosen, still has "Render Masked" in the side panel while something on it is masked', async () => {
const stage = await mount([begun()]);
stage.release();
const [row] = stage.host.byClass('ot-again');
const [, again] = row.children;
assert.equal(row.hidden, true, 'nothing to paint again, nothing masked');
stage.tool('Mask marker').click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
await settle();
assert.deepEqual([row.hidden, again.hidden, again.textContent], [false, false, 'Render Masked']);
assert.equal(stage.host.byClass('ot-mask-words')[0].hidden, false, 'with the field for its words');
stage.tool('Discard the mask (Ctrl+Z brings it back)').click();
stage.tool('Orbit').click();
assert.equal(row.hidden, true);
OMNI.unmount();
});
test('"Inverse perspective" under the mask marker bends the view, its slider says how far, "Render Masked" sends that lens, and it goes with the view', async () => {
const stage = await mount();
stage.release();
const bend = stage.tool('Inverse perspective');
const [glass] = stage.host.byClass('mk-lens');
const [slider] = glass.children;
assert.deepEqual([viewer.camera.perspective, bend.getAttribute('aria-pressed'), glass.hidden], [1, 'false', true]);
bend.click();
assert.deepEqual([viewer.camera.perspective, bend.getAttribute('aria-pressed'), glass.hidden], [-1, 'true', false],
'half way along its slider: as inverse as a camera is perspective');
slider.value = 25;
slider.fire('input');
assert.equal(viewer.camera.perspective, 0, 'a quarter of the way: no perspective left');
slider.value = 100;
slider.fire('input');
assert.equal(viewer.camera.perspective, -3);
// The lens stays the artist's while the mask marker is up.
stage.tool('Mask marker').click();
assert.deepEqual([bend.disabled, slider.disabled], [false, false]);
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
stage.render();
await settle();
const { tan, wide } = hub.job.params.retouch;
const half = Math.tan((viewer.camera.fov * Math.PI) / 360);
assert.ok(Math.abs(tan + 3 * half) < 1e-12 && Math.abs(wide - half * 2 * 4) < 1e-12, 'the bent lens goes with the camera');
store.jobs = []; // (the repaint done)
stage.update();
await settle();
assert.equal(bend.disabled, false, 'the repaint done: the lens is the artist\'s again');
// Off again: a camera's own view.
bend.click();
assert.deepEqual([viewer.camera.perspective, glass.hidden], [1, true]);
bend.click();
assert.equal(viewer.camera.perspective, -3, 'on again: as far as it was');
// Another prop's view, or another stage's, starts from the usual view; the setting stays for the next visit here.
OMNI.unmount();
assert.equal(viewer.camera.perspective, 1);
const again = await mount();
assert.equal(viewer.camera.perspective, -3, 'back in the stage: the lens as the artist left it');
again.tool('Inverse perspective').click();
OMNI.unmount();
});
test('"Render Masked" sends the view as it is at the press, wherever the mask was painted from; taking the marker up again leaves the view where it is', async () => {
const stage = await mount();
stage.release();
const mask = stage.tool('Mask marker');
mask.click();
strokeAt(viewer, { x: 8, y: 8, w: 6, h: 6 });
stage.tool('Orbit').click();
lookFrom(SIDE); // the marker down, the artist goes round the model
mask.click();
assert.deepEqual(lookingFrom(), SIDE, 'the marker up again: the view stays where it is');
stage.tool('Orbit').click();
stage.render();
await settle();
assert.deepEqual(hub.job.params.retouch.eye, SIDE, 'the camera Qwen-Image paints for is the one at the press');
assert.deepEqual(lookingFrom(), SIDE);
OMNI.unmount();
});
test('the side panel\'s Detail is the project\'s: Detailed until another is picked, then every prop\'s; what the hub cannot make is dimmed, and a result says what it was made with', async () => {
const p = prop(RESULT, [RESULT]);
p.omnitexture.repaints = [];
const other = { ...prop(RESULT, [RESULT]), id: 'p_2', name: 'Crate' };
other.omnitexture.settings.chosen = false;
const stage = await mount([p, other]);
const box = stage.host.byClass('ot-detail')[0];
const buttons = () => box.all((e) => e.tagName === 'BUTTON');
const picked = () => buttons().filter((b) => b.getAttribute('aria-checked') === 'true').map((b) => b.textContent);
assert.deepEqual(buttons().map((b) => b.textContent), ['Original', 'Upscaled(Better)', 'Detailed(Best)']);
assert.deepEqual(picked(), ['Detailed(Best)'], 'a project that never said');
store.project.props[0].omnitexture.settings.detail = 'original';
stage.update();
assert.deepEqual(picked(), ['Original']);
// The hub has not said which it can make: only Original. Then: the upscaler is here, the third kind is not.
assert.deepEqual(buttons().map((b) => b.disabled), [false, true, true]);
store.status.omnitexture_details = [{ kind: 'original', ready: true }, { kind: 'upscaled', ready: true }, { kind: 'detailed', ready: false }];
stage.update();
assert.deepEqual(buttons().map((b) => b.disabled), [false, false, true]);
assert.match(buttons()[2].title, /SeedVR2.*not on this PC yet: Spellcast3D downloads it at its next start\.$/s);
assert.doesNotMatch(buttons()[1].title, /not on this PC/);
buttons()[1].click();
assert.deepEqual(store.project.props.map((each) => each.omnitexture.settings.detail), ['upscaled', 'upscaled'],
'picked on one prop: every prop of the project has it');
await flushSettings();
assert.deepEqual([hub.calls.filter((call) => call.startsWith('PATCH')), hub.asked],
[['PATCH /api/projects/Props/props/p_1'], { omnitexture: { settings: { detail: 'upscaled' } } }],
'saved through the prop shown: the hub gives it to the others');
stage.update();
assert.deepEqual(picked(), ['Upscaled(Better)']);
assert.equal(box.hidden, false);
// The result as painted says nothing of it; composed from larger pictures, what with and how long that took.
const row = () => {
const cells = stage.host.byClass('sv-stats')[0]?.children || [];
const at = cells.findIndex((cell) => cell.tagName === 'DT' && cell.textContent === 'Detail');
return at < 0 ? null : cells[at + 1].textContent;
};
assert.equal(row(), null);
const larger = 'omnitexture/ot_002/omnitexture.glb';
Object.assign(store.project.props[0].omnitexture, {
glb: larger, steps: [RESULT, larger], stats: { seconds: 150, detail_seconds: 42 },
bases: [{ glb: larger, detail: 'upscaled', views: [] }],
});
stage.update();
assert.equal(row(), 'Upscaled, 42 s more');
// Under it while it is "Detailed": how boldly SeedVR2 redraws, the prop's own too: 0 .. 50 %, 25 % unless set.
const [boldRow] = box.byClass('ot-fade');
const [slider] = boldRow.all((e) => e.tagName === 'INPUT');
assert.equal(boldRow.hidden, true, 'nothing to set for Upscaled');
store.status.omnitexture_details[2].ready = true;
store.project.props[0].omnitexture.settings.detail = 'detailed';
stage.update();
assert.deepEqual([boldRow.hidden, slider.value, slider.getAttribute('max'), boldRow.textContent],
[false, 25, '50', 'Boldness25 %']);
slider.value = 50;
slider.fire('input');
assert.equal(boldRow.textContent, 'Boldness50 %');
slider.fire('change');
assert.deepEqual(store.project.props.map((each) => each.omnitexture.settings.detail_boldness), [0.5, 0.5]);
stage.update();
assert.equal(slider.value, 50);
store.project.props[0].omnitexture.settings.detail_boldness = 1; // (an older page's 100 %)
stage.update();
assert.equal(slider.value, 50, 'no bolder than 50 %');
// Under a heading of their own, apart from the result: the settings the next painting takes.
const [general] = stage.host.byClass('ot-general');
assert.ok(general.textContent.startsWith('General Render SettingsUsed the next time props are painted'));
assert.ok(general.byClass('ot-detail')[0] === box && general.byClass('ot-faster').length === 1);
assert.doesNotMatch(general.textContent, /Ctrl\+Z/);
// There for a prop that is not chosen too: they are the project's.
store.project.props[0].omnitexture.settings.chosen = false;
stage.update();
assert.deepEqual([box.hidden, general.hidden], [false, false]);
await flushSettings(); // (its saves land here, not in the test after it)
OMNI.unmount();
});
test('a result with its Detail has a switch in its Detail row to show it as painted; Ctrl+Z and Ctrl+Y do not go between them', async () => {
const larger = 'omnitexture/ot_002/omnitexture.glb';
const made = (glb) => {
const p = prop(glb, [RESULT, larger]);
p.omnitexture.repaints = [];
p.omnitexture.bases = [{ glb: larger, detail: 'upscaled', views: [] }];
p.omnitexture.stats = { detail_seconds: 42 };
return p;
};
const stage = await mount([made(larger)]);
stage.release();
hub.answer = (path, body) => ({ prop: (store.project.props[0] = made(body.glb)) });
const detailRow = () => {
const cells = stage.host.byClass('sv-stats')[0].children;
return cells[cells.findIndex((cell) => cell.tagName === 'DT' && cell.textContent === 'Detail') + 1];
};
const switchOf = () => detailRow().all((e) => e.tagName === 'INPUT')[0];
assert.deepEqual([detailRow().textContent, switchOf().checked], ['Upscaled, 42 s more', true]);
hub.calls = [];
keyDown('z', { ctrlKey: true });
await settle();
assert.deepEqual(changes(), [], 'Ctrl+Z leaves the Detail on');
switchOf().checked = false;
switchOf().fire('change');
await settle();
assert.deepEqual([changes().at(-1), hub.asked], [`POST ${API}/omnitexture/step`, { glb: RESULT }]);
stage.update();
await settle();
assert.ok(viewer.shown.at(-1).includes('ot_001'), 'the result as Qwen-Image painted it');
assert.deepEqual([detailRow().textContent, !!switchOf().checked], ['Upscaled: off', false]);
hub.calls = [];
keyDown('y', { ctrlKey: true });
await settle();
assert.deepEqual(changes(), [], 'nor Ctrl+Y the Detail');
switchOf().checked = true;
switchOf().fire('change');
await settle();
assert.deepEqual([changes().at(-1), hub.asked], [`POST ${API}/omnitexture/step`, { glb: larger }]);
stage.update();
await settle();
hub.calls = [];
keyDown('z', { ctrlKey: true });
await settle();
assert.deepEqual(changes(), [], 'switched on again: still none of Ctrl+Z\'s');
OMNI.unmount();
// A result composed again without larger pictures (a view taken off on another visit) stays as before: not this
// visit's change, so Ctrl+Z leaves it.
const other = 'omnitexture/ot_003/omnitexture.glb'; // (the page remembers the stamps of models it showed)
const plainBase = prop(other, [RESULT, other]);
plainBase.omnitexture.repaints = [];
plainBase.omnitexture.bases = [{ glb: other, views: [] }];
await mount([plainBase]);
hub.calls = [];
keyDown('z', { ctrlKey: true });
await settle();
assert.deepEqual(changes(), [], 'nothing asked');
OMNI.unmount();
});