feat: configure outdoor texture scale and rotation per area

This commit is contained in:
jhartworks committed 2026-11-16 13:57:52 +01:00
1 parent d8cf076019
commit c56f1a5ba9
26 files changed
+1958 -1778

No files matched your search

@@ -2,7 +2,7 @@
import { html, nothing, type TemplateResult } from "lit";
import { formatNumber, type I18nKey } from "../../../i18n.ts";
import { bounds, cutsOut, isAxisRect, uid, type FenceGate, type FreeWall, OUTDOOR_TOP, OUTDOOR_TYPES, outdoorStanding, SLOPE_DIRS, type Direction, type OutdoorArea, type OutdoorType, type SlopeDir, type Vec2 } from "../../../model.ts";
import { bounds, cutsOut, isAxisRect, uid, type FenceGate, type FreeWall, OUTDOOR_TOP, OUTDOOR_TYPES, outdoorStanding, outdoorTextureSettings, SLOPE_DIRS, type Direction, type OutdoorArea, type OutdoorType, type SlopeDir, type Vec2 } from "../../../model.ts";
import { checkField, entityField, hint, numberField, selectField, toThousandths } from "../fields.ts";
import { entityOptions } from "../entities.ts";
import type { EditorHost } from "../host.ts";
@@ -24,12 +24,22 @@ export function renderOutdoorForm(host: EditorHost, area: OutdoorArea, actions:
const t = host.t;
const set = (patch: Partial<OutdoorArea>) => actions.update(patch);
const box = bounds(area.points);
const texture = outdoorTextureSettings(area);
const types = OUTDOOR_TYPES.map((type): [OutdoorType, string] => [type, t(`out_${type}` as I18nKey)]);
const slopeDirs = SLOPE_DIRS.map((d): [SlopeDir, string] => [d, t(`slope_${d.replace("-", "n")}` as I18nKey)]);
return html`<section>
<div class="nf-h3row"><h3>${t("outdoor")}</h3>${actions.lockButton}</div>
<div class="nf-form">
${selectField(host, t("outdoor_type"), area.type, types, (type) => set({ type }), { wide: true })}
${numberField(host, t("outdoor_texture_scale"), texture.scale * 100, (v) => {
const { scale } = outdoorTextureSettings({ texture_scale: v / 100 });
set({ texture_scale: scale === 1 ? null : scale });
}, 5, 5)}
${numberField(host, t("outdoor_texture_rotation"), texture.rotation, (v) => {
const { rotation } = outdoorTextureSettings({ texture_rotation: v });
set({ texture_rotation: rotation || null });
}, 5)}
${hint(t("outdoor_texture_hint"))}
${selectField(host, t("area"), area.area_id ?? "", [["", t("no_area")], ...Object.values(host.hass?.areas ?? {}).sort((a, b) => a.name.localeCompare(b.name)).map((a): [string, string] => [a.area_id, a.name])], (id) => set({ area_id: id || null }), { wide: true, title: t("outdoor_area_hint") })}
${area.type === "pool" || area.type === "wild" || area.type === "bed"
? html`${entityField(host, t("pool_temp"), area.temp_entity ?? null, undefined, entityOptions(host.hass, (id) => id.startsWith("sensor.") && host.hass?.states[id]?.attributes.device_class === "temperature"), (v) => set({ temp_entity: v && v !== "none" ? v : null }))}
@@ -31,6 +31,11 @@ test("a floor opening is the drawn rectangle, and an outdoor area its outline; c
assert.equal(area.type, "lawn");
assert.equal(area.points[2][1], 1.235);
assert.deepEqual(copyOfOutdoorArea(area).points[0], [0.5, 0.5]);
const textured = { ...area, texture_scale: 2.5, texture_rotation: 45 };
const copy = copyOfOutdoorArea(textured);
assert.equal(copy.texture_scale, 2.5);
assert.equal(copy.texture_rotation, 45);
assert.notEqual(copy.id, textured.id);
});
test("new furniture has its type's size, and stairs reach to the floor above", () => {
+6
View File
@@ -1134,6 +1134,9 @@ const DE = {
out_path: "Weg",
out_driveway: "Einfahrt",
out_street: "Straße",
outdoor_texture_scale: "Texturmaßstab (%)",
outdoor_texture_rotation: "Texturdrehung (°)",
outdoor_texture_hint: "100 % ist die Originalgröße. 200 % macht das Muster doppelt so groß, 50 % halb so groß (5–2000 %). Die Drehung verändert nur die Textur dieser Fläche. Standard: 100 % und 0°.",
out_sidewalk: "Gehweg",
out_gravel: "Schotterfläche",
out_river: "Fluss",
@@ -3204,6 +3207,9 @@ const EN: Record<Key, string> = {
out_path: "Path",
out_driveway: "Driveway",
out_street: "Street",
outdoor_texture_scale: "Texture scale (%)",
outdoor_texture_rotation: "Texture rotation (°)",
outdoor_texture_hint: "100% is the original size. 200% doubles the pattern size, 50% halves it (5–2000%). Rotation changes only this area's texture. Defaults: 100% and 0°.",
out_sidewalk: "Sidewalk",
out_gravel: "Gravel",
out_river: "River",
+11
View File
@@ -1024,6 +1024,10 @@ export interface OutdoorArea {
gates?: FenceGate[];
/** How opaque the area is drawn, 0.1 … 1 (null = fully): a driveway above a cellar can be seen through. The outline stays. */
opacity?: number | null;
/** Size of the outdoor texture pattern (1 = original, 2 = twice as large). */
texture_scale?: number | null;
/** Clockwise texture rotation in degrees; independent of the outline. */
texture_rotation?: number | null;
}
/** A gate in a fence: a gap in one edge of its outline with a garden gate (one leaf), a double gate or a sliding gate. */
@@ -1044,6 +1048,13 @@ export interface FenceGate {
/** Whether an area leaves a hole in the areas around it: water areas default to on. */
export const cutsOut = (a: OutdoorArea): boolean => a.cut ?? (a.type === "pool" || a.type === "river" || a.type === "stream");
/** Valid texture settings for old plans and imported data as well as editor inputs. */
export function outdoorTextureSettings(a: Pick<OutdoorArea, "texture_scale" | "texture_rotation">): { scale: number; rotation: number } {
const scale = Number.isFinite(a.texture_scale) ? Math.max(0.05, Math.min(20, a.texture_scale!)) : 1;
const rotation = Number.isFinite(a.texture_rotation) ? ((a.texture_rotation! % 360) + 360) % 360 : 0;
return { scale, rotation };
}
/** Energy flow: meter position and power sensors (W). Grid positive = import, battery positive = discharging. */
export interface EnergySettings {
meter: { floor_id: string; x: number; z: number } | null;
+1
View File
@@ -42,6 +42,7 @@ export function flipWinding(buf: GeoBuffer, from: number): void {
swapped(buf.uv, tri * 6, 2);
swapped(buf.tile, tri * 6, 2);
swapped(buf.surface, tri * 3, 1);
swapped(buf.surfaceTransform, tri * 6, 2);
}
}
+4
View File
@@ -28,6 +28,8 @@ export class GeoBuffer {
tile: number[] | null;
/** Outdoor material IDs, allocated only for buffers that contain outdoor geometry. */
surface: number[] | null = null;
/** Outdoor texture scale and rotation (radians), two numbers per vertex. */
surfaceTransform: number[] | null = null;
constructor(uvs = false, tiles = false) {
this.uv = uvs ? [] : null;
@@ -42,6 +44,7 @@ export class GeoBuffer {
this.uv?.push(...(uv ?? [0.5, 0.5, 0.5, 0.5, 0.5, 0.5]));
this.tile?.push(...tile, ...tile, ...tile);
this.surface?.push(0, 0, 0);
this.surfaceTransform?.push(1, 0, 1, 0, 1, 0);
}
/** The number of triangles. */
@@ -57,6 +60,7 @@ export class GeoBuffer {
if (this.uv) geometry.setAttribute("uv", attribute(this.uv, 2));
if (this.tile) geometry.setAttribute("tile", attribute(this.tile, 2));
if (this.surface) geometry.setAttribute("surface", attribute(this.surface, 1));
if (this.surfaceTransform) geometry.setAttribute("surfaceTransform", attribute(this.surfaceTransform, 2));
geometry.computeBoundingSphere();
return geometry;
}
+5 -1
View File
@@ -11,6 +11,7 @@ interface Vertex {
uv: number[] | null;
tile: number[] | null;
surface: number;
surfaceTransform: number[] | null;
}
const blend = (a: number[], b: number[], t: number) => a.map((x, i) => x + (b[i] - x) * t);
@@ -18,7 +19,7 @@ const blend = (a: number[], b: number[], t: number) => a.map((x, i) => x + (b[i]
/** The point where an edge crosses the height `cut`; colours and uvs are interpolated. */
function crossing(a: Vertex, b: Vertex, cut: number): Vertex {
const t = (cut - a.p[1]) / (b.p[1] - a.p[1]);
return { p: blend(a.p, b.p, t), c: blend(a.c, b.c, t), uv: a.uv && b.uv ? blend(a.uv, b.uv, t) : null, tile: a.tile, surface: a.surface };
return { p: blend(a.p, b.p, t), c: blend(a.c, b.c, t), uv: a.uv && b.uv ? blend(a.uv, b.uv, t) : null, tile: a.tile, surface: a.surface, surfaceTransform: a.surfaceTransform };
}
function readVertex(buf: GeoBuffer, v: number): Vertex {
@@ -28,6 +29,7 @@ function readVertex(buf: GeoBuffer, v: number): Vertex {
uv: buf.uv ? buf.uv.slice(v * 2, v * 2 + 2) : null,
tile: buf.tile ? buf.tile.slice(v * 2, v * 2 + 2) : null,
surface: buf.surface?.[v] ?? 0,
surfaceTransform: buf.surfaceTransform?.slice(v * 2, v * 2 + 2) ?? null,
};
}
@@ -40,6 +42,7 @@ function overwriteTriangle(buf: GeoBuffer, tri: number, corners: Vertex[], fold:
if (buf.tile && corner.tile) corner.tile.forEach((x, i) => (buf.tile![v * 2 + i] = x));
buf.f[v] = fold;
if (buf.surface) buf.surface[v] = corner.surface;
if (buf.surfaceTransform && corner.surfaceTransform) corner.surfaceTransform.forEach((x, i) => (buf.surfaceTransform![v * 2 + i] = x));
});
}
@@ -51,6 +54,7 @@ function appendTriangle(buf: GeoBuffer, corners: Vertex[], fold: number): void {
buf.uv?.push(...(corner.uv ?? [0.5, 0.5]));
buf.tile?.push(...(corner.tile ?? [0, 1]));
buf.surface?.push(corner.surface);
buf.surfaceTransform?.push(...(corner.surfaceTransform ?? [1, 0]));
}
}
+7
View File
@@ -82,16 +82,23 @@ test("cutAbove keeps colours and uvs along the new edge", () => {
test("cutting geometry retains outdoor surface IDs and appending furniture uses a neutral material", () => {
const buf = new GeoBuffer();
buf.surface = [];
buf.surfaceTransform = [];
buf.tri([0, 0, 0], [1, 2, 0], [0, 0, 1], grey);
buf.surface.fill(12);
buf.surfaceTransform = [2, 0.5, 2, 0.5, 2, 0.5];
cutAbove(buf, 0, 1, FURN_OFFSET);
assert.equal(buf.surface.length, buf.p.length / 3);
assert.ok(buf.surface.every((id) => id === 12));
assert.equal(buf.surfaceTransform.length, buf.p.length / 3 * 2);
assert.ok(buf.surfaceTransform.every((value, i) => value === (i % 2 === 0 ? 2 : 0.5)));
buf.tri([4, 0, 0], [5, 2, 0], [4, 0, 1], grey);
assert.deepEqual(buf.surface.slice(-3), [0, 0, 0]);
assert.deepEqual(buf.surfaceTransform.slice(-6), [1, 0, 1, 0, 1, 0]);
cutAbove(buf, buf.count - 1, 1, FURN_OFFSET);
assert.equal(buf.surface.length, buf.p.length / 3);
assert.deepEqual(buf.surface.slice(-6), [0, 0, 0, 0, 0, 0]);
assert.equal(buf.surfaceTransform.length, buf.p.length / 3 * 2);
assert.deepEqual(buf.surfaceTransform.slice(-12), [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]);
});
test("cutAbove only touches triangles from the given one on", () => {
+26 -1
View File
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { newFloor, OUTDOOR_TOP, OUTDOOR_TYPES, type Floor, type OutdoorArea, type Vec2 } from "../../model.ts";
import { newFloor, OUTDOOR_TOP, OUTDOOR_TYPES, outdoorTextureSettings, type Floor, type OutdoorArea, type Vec2 } from "../../model.ts";
import { GeoBuffer, LineBuffer } from "../geo.ts";
import { counterClockwise, pushBeam, pushPost } from "./beams.ts";
import { outdoorHoles, outdoorOpacity, outdoorSurface, pushOutdoor } from "./outdoor.ts";
@@ -54,10 +54,35 @@ test("every outdoor type has a texture ID; later furniture stays untextured and
assert.ok(buf.surface!.slice(-30).every((id) => id === 0), "later geometry never inherits the outdoor texture");
const g = buf.geometry();
assert.equal(g.getAttribute("surface").count, g.getAttribute("position").count);
assert.equal(g.getAttribute("surfaceTransform").count, g.getAttribute("position").count);
g.dispose();
}
});
test("texture settings default old plans, bound pattern size and wrap rotations", () => {
assert.deepEqual(outdoorTextureSettings({}), { scale: 1, rotation: 0 });
assert.deepEqual(outdoorTextureSettings({ texture_scale: null, texture_rotation: null }), { scale: 1, rotation: 0 });
assert.deepEqual(outdoorTextureSettings({ texture_scale: 2.5, texture_rotation: -90 }), { scale: 2.5, rotation: 270 });
assert.deepEqual(outdoorTextureSettings({ texture_scale: 0, texture_rotation: 720 }), { scale: 0.05, rotation: 0 });
assert.equal(outdoorTextureSettings({ texture_scale: 100 }).scale, 20);
assert.deepEqual(outdoorTextureSettings({ texture_scale: NaN, texture_rotation: Infinity }), { scale: 1, rotation: 0 });
});
test("scale and rotation stay per area, preserve geometry and reach transparent sloped surfaces", () => {
const plain = area("terrace", square(0, 0, 4, 3));
const changed = { ...plain, texture_scale: 2.5, texture_rotation: 45 };
assert.deepEqual(build(plain).buf.p, build(changed).buf.p, "the outline and all mesh coordinates stay unchanged");
const solid = new GeoBuffer(), ghosts = new Map<number, GeoBuffer>();
pushOutdoor(solid, new LineBuffer(), floorWith(plain, area("sidewalk", square(5, 0, 9, 3), { texture_scale: 0.5, texture_rotation: 90 }), { ...changed, opacity: 0.4, slope: 0.3 }), ghosts, () => new GeoBuffer());
for (let v = 0; v < solid.surface!.length; v++) {
const id = solid.surface![v];
assert.deepEqual(solid.surfaceTransform!.slice(v * 2, v * 2 + 2), id === OUTDOOR_MATERIAL.terrace ? [1, 0] : [0.5, Math.PI / 2]);
}
const ghost = ghosts.get(0.4)!;
assert.equal(ghost.surfaceTransform!.length, ghost.p.length / 3 * 2);
for (let v = 0; v < ghost.p.length / 3; v++) assert.deepEqual(ghost.surfaceTransform!.slice(v * 2, v * 2 + 2), [2.5, Math.PI / 4]);
});
test("river and stream cut through a surrounding lawn, can be sloped, and preserve transparency", () => {
for (const type of ["river", "stream"] as const) {
const water = area(type, square(1, 1, 3, 2), { slope: 0.3, offset: 0.2, opacity: 0.4 });
+8 -1
View File
@@ -5,7 +5,7 @@
// patches cut out of it.
import { Color } from "three";
import { bounds, cutsOut, groundLevel, isAxisRect, OUTDOOR_TOP, outdoorDrop, outdoorStanding, pointInPolygon, type Floor, type OutdoorArea, type Vec2 } from "../../model.ts";
import { bounds, cutsOut, groundLevel, isAxisRect, OUTDOOR_TOP, outdoorDrop, outdoorStanding, outdoorTextureSettings, pointInPolygon, type Floor, type OutdoorArea, type Vec2 } from "../../model.ts";
import { ALWAYS, pushPrism, shade, triangulate, type GeoBuffer, type LineBuffer } from "../geo.ts";
import { counterClockwise, pushBeam, pushPost } from "./beams.ts";
import { gateLayout, gatesOnEdge } from "./gates.ts";
@@ -194,6 +194,7 @@ export function outdoorOpacity(area: OutdoorArea): number {
export function pushOutdoor(buf: GeoBuffer, lines: LineBuffer, floor: Floor, ghosts?: Map<number, GeoBuffer>, makeBuffer?: () => GeoBuffer): void {
// The shared wall shader also serves floors without outdoor areas: supply a neutral ID there.
buf.surface ??= Array(buf.p.length / 3).fill(0);
buf.surfaceTransform ??= Array.from({ length: (buf.p.length / 3) * 2 }, (_, i) => i % 2 === 0 ? 1 : 0);
const ground = groundLevel(floor);
const areas = floor.outdoor ?? [];
areas.forEach((area, index) => {
@@ -209,6 +210,7 @@ export function pushOutdoor(buf: GeoBuffer, lines: LineBuffer, floor: Floor, gho
target = ghosts.get(opacity)!;
}
target.surface ??= Array(target.p.length / 3).fill(0);
target.surfaceTransform ??= Array.from({ length: (target.p.length / 3) * 2 }, (_, i) => i % 2 === 0 ? 1 : 0);
const firstVertex = target.p.length / 3;
const context: Context = {
buf: target,
@@ -229,5 +231,10 @@ export function pushOutdoor(buf: GeoBuffer, lines: LineBuffer, floor: Floor, gho
else if (area.type === "pergola") buildPergola(context);
else buildBlock(context, areas, index);
target.surface.fill(OUTDOOR_MATERIAL[area.type], firstVertex);
const texture = outdoorTextureSettings(area);
for (let v = firstVertex; v < target.p.length / 3; v++) {
target.surfaceTransform[v * 2] = texture.scale;
target.surfaceTransform[v * 2 + 1] = texture.rotation * Math.PI / 180;
}
});
}
+8 -3
View File
@@ -10,6 +10,7 @@ export const OUTDOOR_MATERIAL: Record<OutdoorType, number> = {
const TEXTURE = /* glsl */ `
varying vec3 vNfGround;
varying float vNfSurface;
varying vec2 vNfSurfaceTransform;
float nfGrain(vec2 p) {
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
}
@@ -59,6 +60,10 @@ vec3 nfOutdoorTexture(vec3 position, float kind) {
// Project onto the dominant face, so raised beds, hedge sides and timber have texture too.
vec3 n = abs(cross(dFdx(position), dFdy(position)));
vec2 p = n.y >= max(n.x, n.z) ? position.xz : (n.x > n.z ? position.zy : position.xy);
// Sample with the inverse transform: increasing scale enlarges the visible pattern.
float angle = vNfSurfaceTransform.y;
float c = cos(angle), s = sin(angle);
p = vec2(c * p.x + s * p.y, -s * p.x + c * p.y) / max(vNfSurfaceTransform.x, 0.05);
float broad = nfNoise(p * 1.7);
if (kind < 1.5 || (kind > 6.5 && kind < 8.5)) {
if (kind > 7.5) return nfPebbles(p * 14.0, true);
@@ -107,8 +112,8 @@ export function outdoorTextured<T extends Material>(material: T): T {
material.onBeforeCompile = (shader, renderer) => {
previous(shader, renderer);
shader.vertexShader = shader.vertexShader
.replace("#include <common>", "#include <common>\nattribute float surface;\nvarying vec3 vNfGround;\nvarying float vNfSurface;")
.replace("#include <begin_vertex>", "#include <begin_vertex>\nvNfGround = position;\nvNfSurface = surface;");
.replace("#include <common>", "#include <common>\nattribute float surface;\nattribute vec2 surfaceTransform;\nvarying vec3 vNfGround;\nvarying float vNfSurface;\nvarying vec2 vNfSurfaceTransform;")
.replace("#include <begin_vertex>", "#include <begin_vertex>\nvNfGround = position;\nvNfSurface = surface;\nvNfSurfaceTransform = surfaceTransform;");
shader.fragmentShader = shader.fragmentShader.replace("#include <common>", `#include <common>\n${TEXTURE}`)
.replace("#include <opaque_fragment>", `if (vNfSurface > 0.5) {
if (uTheme == 2) outgoingLight = nfOutdoorDay(vNfSurface) * (0.7 + dot(outgoingLight, vec3(0.299, 0.587, 0.114)) * 0.4);
@@ -116,6 +121,6 @@ export function outdoorTextured<T extends Material>(material: T): T {
}
#include <opaque_fragment>`);
};
material.customProgramCacheKey = () => `${previousKey()}-outdoor-textures-1`;
material.customProgramCacheKey = () => `${previousKey()}-outdoor-textures-2`;
return material;
}
+38 -5
View File
@@ -76,13 +76,33 @@ try {
}, { type, label, id: drawn.id });
assert.equal(stored, type);
}
const textureEdit = await page.evaluate(async (id) => {
const e = window.outdoorEditor;
const setNumber = async (label, value) => {
const field = [...e.shadowRoot.querySelectorAll("label.nf-field")].find((l) => l.textContent.trim().startsWith(label));
const input = field?.querySelector("input"); if (!input) throw new Error(`Missing ${label}`);
input.value = String(value); input.dispatchEvent(new Event("change", { bubbles: true })); await e.updateComplete;
};
await setNumber("Texturmaßstab", 250); await setNumber("Texturdrehung", -90);
let a = e._doc.floors[0].outdoor.find((a) => a.id === id);
const custom = [a.texture_scale, a.texture_rotation];
await setNumber("Texturmaßstab", 0); const minimum = e._doc.floors[0].outdoor.find((a) => a.id === id).texture_scale;
await setNumber("Texturmaßstab", 100); await setNumber("Texturdrehung", 360);
a = e._doc.floors[0].outdoor.find((a) => a.id === id);
const reset = [a.texture_scale, a.texture_rotation];
await setNumber("Texturmaßstab", 250); await setNumber("Texturdrehung", 45);
const doc = JSON.parse(JSON.stringify(e._doc)); e.setDoc(doc); await e.updateComplete;
const saved = doc.floors[0].outdoor.find((a) => a.id === id);
return { custom, minimum, reset, saved: [saved.texture_scale, saved.texture_rotation], neighbor: doc.floors[0].outdoor.find((a) => a.id === "neighbor").texture_scale ?? null };
}, drawn.id);
assert.deepEqual(textureEdit, { custom: [2.5, 270], minimum: 0.05, reset: [null, null], saved: [2.5, 45], neighbor: null });
await page.screenshot({ path: join(out, "symcon-outdoor-editor.png") });
await page.evaluate(async () => {
const p = window.nfPanel, b = structuredClone(window.outdoorEditor._doc), f = b.floors[0];
const types = ["lawn", "terrace", "path", "driveway", "street", "sidewalk", "gravel", "river", "stream", "pool", "bed", "wild", "hedge", "fence", "pergola"];
f.outdoor = types.map((type, i) => {
const x = (i % 5) * 5, z = Math.floor(i / 5) * 4;
return { id: type, type, points: [[x, z], [x + 4, z], [x + 4, z + 3], [x, z + 3]], ...(type === "sidewalk" ? { slope: 0.25 } : {}), ...(type === "stream" ? { opacity: 0.6 } : {}) };
return { id: type, type, points: [[x, z], [x + 4, z], [x + 4, z + 3], [x, z + 3]], ...(type === "terrace" ? { texture_scale: 2.5, texture_rotation: 45 } : {}), ...(type === "sidewalk" ? { slope: 0.25, texture_scale: 0.5, texture_rotation: 90 } : {}), ...(type === "stream" ? { opacity: 0.6, texture_scale: 1.5, texture_rotation: 330 } : {}) };
});
f.rooms = [{ id: "reference", name: "Referenz", points: [[-2, -2], [-1, -2], [-1, -1], [-2, -1]], area_id: null, floor_material: "plain" }];
f.furniture = []; p.data.edit(b); await p.updateComplete;
@@ -101,7 +121,7 @@ try {
await page.evaluate(() => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done))));
await page.screenshot({ path: join(out, `symcon-outdoor-${theme}.png`) });
}
for (const [name, x, z] of [["street", 22, 1.5], ["gravel", 7, 5.5], ["lawn", 2, 1.5]]) {
for (const [name, x, z] of [["street", 22, 1.5], ["gravel", 7, 5.5], ["lawn", 2, 1.5], ["terrace", 7, 1.5]]) {
await page.evaluate(({ x, z }) => {
const v = window.outdoorView.viewer; v.setTheme("day"); v.showView({ target: { x, y: 0, z }, radius: 5, phi: 0.65, theta: 0.1 }, 0);
}, { x, z });
@@ -111,14 +131,27 @@ try {
const gpu = await page.evaluate(() => {
const v = window.outdoorView.viewer;
let textured = 0, neutral = 0;
const transforms = {};
v.scene.traverse((o) => {
const ids = o.geometry?.getAttribute("surface");
if (ids) { for (const kind of ids.array) kind > 0 ? textured++ : neutral++; }
if (ids) {
const settings = o.geometry.getAttribute("surfaceTransform");
if (!settings || settings.count !== ids.count) throw new Error("Outdoor texture transform buffer mismatch");
for (let i = 0; i < ids.count; i++) {
const kind = ids.getX(i); kind > 0 ? textured++ : neutral++;
if (kind > 0) (transforms[kind] ??= []).push([settings.getX(i), settings.getY(i)]);
}
}
});
return { textured, neutral, programs: v.renderer.info.programs.map((p) => p.diagnostics?.runnable !== false) };
return { textured, neutral, transforms, programs: v.renderer.info.programs.map((p) => p.diagnostics?.runnable !== false) };
});
for (const [id, scale, rotation] of [[2, 2.5, Math.PI / 4], [11, 0.5, Math.PI / 2], [14, 1.5, 330 * Math.PI / 180]]) {
assert.ok(gpu.transforms[id]?.length > 0);
assert.ok(gpu.transforms[id].every(([s, r]) => s === scale && Math.abs(r - rotation) < 1e-6));
}
assert.ok(gpu.textured > 0); assert.ok(gpu.programs.every(Boolean)); assert.deepEqual(errors, []);
console.log("OK: pointer drawing/moving/corner snapping, Alt bypass, five persisted surface types, metre-scaled textures compiled in all three themes, sloped and transparent surfaces", gpu);
delete gpu.transforms;
console.log("OK: outdoor snapping, surface types, per-area texture size/rotation/reset/persistence, independent GPU transforms in all three themes including sloped and transparent surfaces", gpu);
} finally {
await browser?.close(); await new Promise((done) => server.close(done));
}