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.

feat(environment): six cube faces import as an environment, and an import reports what it clipped

yhhf79d06e8d08c
diff --git a/pipeline/src/assets/environmentCube.ts b/pipeline/src/assets/environmentCube.ts
new file mode 100644
index 000000000..d0a896f71
--- /dev/null
+++ b/pipeline/src/assets/environmentCube.ts
@@ -0,0 +1,158 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file Six square images → the panorama an environment import takes.
+ *
+ * A skybox set is the other common way artists hand over a sky. The engine loads no
+ * cube map, so the six faces are resampled into one equirectangular panorama and
+ * then go through the same import as a `.hdr`: one atlas, nine coefficients, and a
+ * sky drawn from the panorama.
+ *
+ * Each face is read as a viewer standing inside the box sees it — facing +Z, right
+ * is -X, which is also how `panoramaDirection` reads a panorama — so a face with
+ * text on it shows the text unmirrored. A set authored with another convention is
+ * fixed per face with `rotate` and `flip`, never by editing the images.
+ */
+import type { Panorama } from './environmentImport';
+
+export const CUBE_FACE_NAMES = ['px', 'nx', 'py', 'ny', 'pz', 'nz'] as const;
+export type CubeFaceName = typeof CUBE_FACE_NAMES[number];
+
+/** The axis each face looks along, for messages an author reads. */
+export const CUBE_FACE_LABELS: Record<CubeFaceName, string> = {
+ px: '+X', nx: '-X', py: '+Y', ny: '-Y', pz: '+Z', nz: '-Z',
+};
+
+/** The widest face an import takes: six of them at this size are 6 x 4096² x 4 bytes. */
+export const CUBE_MAX_FACE = 4096;
+
+export interface CubeFace {
+ width: number;
+ height: number;
+ /** RGBA8, row 0 = top. */
+ rgba: Uint8Array;
+ /** Turn the image clockwise by this many degrees. Default 0. */
+ rotate?: 0 | 90 | 180 | 270;
+ /** Mirror the image left to right, before it is turned. */
+ flip?: boolean;
+}
+
+export type CubeFaceSet = Partial<Record<CubeFaceName, CubeFace>>;
+
+/** A face set that cannot be imported, naming the face it is about when it has one. */
+export class CubeImportError extends Error {
+ constructor(message: string, readonly face?: CubeFaceName) {
+ super(message);
+ this.name = 'CubeImportError';
+ }
+}
+
+/** Check a set is six matching squares. Never fills a face in: a black face would
+ * import cleanly and light the scene wrongly. */
+export function validateCubeFaces(faces: CubeFaceSet): void {
+ const missing = CUBE_FACE_NAMES.filter((n) => !faces[n]);
+ if (missing.length > 0) {
+ throw new CubeImportError(`missing face${missing.length > 1 ? 's' : ''} ${missing.map((n) => CUBE_FACE_LABELS[n]).join(', ')}`,
+ missing[0]);
+ }
+ for (const n of CUBE_FACE_NAMES) {
+ const f = faces[n]!;
+ if (f.width !== f.height) {
+ throw new CubeImportError(`face ${CUBE_FACE_LABELS[n]} is ${f.width}x${f.height}, not square`, n);
+ }
+ if (f.width < 1 || f.width > CUBE_MAX_FACE) {
+ throw new CubeImportError(`face ${CUBE_FACE_LABELS[n]} is ${f.width}px wide; faces must be 1 to ${CUBE_MAX_FACE}`, n);
+ }
+ if (f.rgba.length !== f.width * f.height * 4) {
+ throw new CubeImportError(`face ${CUBE_FACE_LABELS[n]} holds ${f.rgba.length} bytes, not ${f.width * f.height * 4}`, n);
+ }
+ }
+ const size = faces.px!.width;
+ for (const n of CUBE_FACE_NAMES) {
+ if (faces[n]!.width !== size) {
+ throw new CubeImportError(`face ${CUBE_FACE_LABELS[n]} is ${faces[n]!.width}px but +X is ${size}px; all six must match`, n);
+ }
+ }
+}
+
+const SRGB_TO_LINEAR = (() => {
+ const lut = new Float32Array(256);
+ for (let i = 0; i < 256; i++) {
+ const c = i / 255;
+ lut[i] = c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
+ }
+ return lut;
+})();
+
+/** A direction → the face it leaves through and where on it, in [0, 1]² of the face as
+ * seen from inside, before any rotate or flip. */
+function faceOf(x: number, y: number, z: number): { face: CubeFaceName; a: number; b: number } {
+ const ax = Math.abs(x), ay = Math.abs(y), az = Math.abs(z);
+ let face: CubeFaceName, sc: number, tc: number, ma: number;
+ if (ax >= ay && ax >= az) {
+ ma = ax;
+ if (x > 0) { face = 'px'; sc = z; tc = -y; } else { face = 'nx'; sc = -z; tc = -y; }
+ } else if (ay >= az) {
+ ma = ay;
+ if (y > 0) { face = 'py'; sc = x; tc = z; } else { face = 'ny'; sc = -x; tc = -z; }
+ } else {
+ ma = az;
+ if (z > 0) { face = 'pz'; sc = -x; tc = -y; } else { face = 'nz'; sc = x; tc = -y; }
+ }
+ return { face, a: (sc / ma + 1) / 2, b: (tc / ma + 1) / 2 };
+}
+
+/** Where the displayed point (a, b) sits in the source image, once the face's own
+ * rotate and flip are undone. */
+function sourcePoint(face: CubeFace, a: number, b: number): [number, number] {
+ let x: number, y: number;
+ switch (face.rotate ?? 0) {
+ case 90: x = b; y = 1 - a; break;
+ case 180: x = 1 - a; y = 1 - b; break;
+ case 270: x = 1 - b; y = a; break;
+ default: x = a; y = b;
+ }
+ return [face.flip ? 1 - x : x, y];
+}
+
+/**
+ * Resample six faces into a linear equirectangular panorama, 4n by 2n for faces of n.
+ *
+ * @param colorSpace How the 8-bit faces are encoded. `srgb` is what a PNG or JPEG is,
+ * and is linearized; this is a low-dynamic-range source, so nothing here
+ * brightens it past 1 — a sun in a JPEG is as bright as white.
+ */
+export function cubeFacesToPanorama(faces: CubeFaceSet, colorSpace: 'srgb' | 'linear' = 'srgb'): Panorama {
+ validateCubeFaces(faces);
+ const n = faces.px!.width;
+ const width = n * 4, height = n * 2;
+ const rgb = new Float32Array(width * height * 3);
+ const lut = colorSpace === 'srgb' ? SRGB_TO_LINEAR : null;
+ const read = (f: CubeFace, ix: number, iy: number, c: number): number => {
+ const cx = Math.max(0, Math.min(n - 1, ix)), cy = Math.max(0, Math.min(n - 1, iy));
+ const v = f.rgba[(cy * n + cx) * 4 + c]!;
+ return lut ? lut[v]! : v / 255;
+ };
+ for (let y = 0; y < height; y++) {
+ const v = (y + 0.5) / height;
+ const theta = v * Math.PI;
+ const s = Math.sin(theta), cy = Math.cos(theta);
+ for (let x = 0; x < width; x++) {
+ const phi = ((x + 0.5) / width - 0.5) * 2 * Math.PI;
+ const dx = -s * Math.sin(phi), dz = s * Math.cos(phi);
+ const hit = faceOf(dx, cy, dz);
+ const face = faces[hit.face]!;
+ const [u, w] = sourcePoint(face, hit.a, hit.b);
+ const fx = u * n - 0.5, fy = w * n - 0.5;
+ const x0 = Math.floor(fx), y0 = Math.floor(fy);
+ const tx = fx - x0, ty = fy - y0;
+ const o = (y * width + x) * 3;
+ for (let c = 0; c < 3; c++) {
+ const top = read(face, x0, y0, c) * (1 - tx) + read(face, x0 + 1, y0, c) * tx;
+ const bottom = read(face, x0, y0 + 1, c) * (1 - tx) + read(face, x0 + 1, y0 + 1, c) * tx;
+ rgb[o + c] = top * (1 - ty) + bottom * ty;
+ }
+ }
+ }
+ return { width, height, rgb };
+}
diff --git a/pipeline/src/assets/environmentImport.ts b/pipeline/src/assets/environmentImport.ts
index 71049967e..8d0800d46 100644
--- a/pipeline/src/assets/environmentImport.ts
+++ b/pipeline/src/assets/environmentImport.ts
@@ -556,7 +556,28 @@ export function separateSun(env: Panorama): EnvironmentSun | null {
};
}
-/** Everything a `.hdr` becomes, less the reference the caller has to resolve. */
+/** What an import measured about itself — the numbers an author weighs quality against. */
+export interface EnvironmentImportReport {
+ sourceWidth: number;
+ sourceHeight: number;
+ /** Mip 0's face edge, in texels, and how many mips follow it. */
+ faceSize: number;
+ mipCount: number;
+ /** The sky texture's size; 0 when none was written. */
+ skyWidth: number;
+ skyHeight: number;
+ atlasBytes: number;
+ skyBytes: number;
+ /** The radiance the RGBM encoding tops out at. */
+ maxRange: number;
+ /** The share of source texels with a channel above {@link maxRange}: what the sky and the
+ * reflections clip, which a diffuse term (summed from the unclipped source) does not. */
+ clippedFraction: number;
+ /** The brightest channel in the source, so a clip can be told apart from a dim exposure. */
+ peak: number;
+}
+
+/** Everything a panorama becomes, less the reference the caller has to resolve. */
export interface ImportedEnvironment {
/** `<stem>_env.png` — the octahedral atlas. */
atlasName: string;
@@ -568,37 +589,91 @@ export interface ImportedEnvironment {
document: EnvironmentAssetData;
/** What the source says that this import had to reinterpret. */
warnings: string[];
+ report: EnvironmentImportReport;
+}
+
+/** Named quality settings: what an author picks between import time and image bytes. */
+export const ENV_QUALITY_PRESETS = {
+ low: { faceSize: 64, skyWidth: 1024 },
+ standard: { faceSize: ENV_FACE_SIZE, skyWidth: ENV_SKY_MAX_WIDTH },
+ high: { faceSize: 256, skyWidth: 4096 },
+} as const;
+export type EnvironmentQuality = keyof typeof ENV_QUALITY_PRESETS;
+
+/** The most an import is allowed to ask for: past these the memory and time are not a
+ * quality setting but a way to run out of both. */
+export const ENV_MAX_FACE_SIZE = 1024;
+export const ENV_MAX_SKY_WIDTH = 8192;
+
+export interface EnvironmentImportOptions {
+ faceSize?: number;
+ mipCount?: number;
+ skyWidth?: number;
+ /** A named preset; an explicit `faceSize` or `skyWidth` wins over it. */
+ quality?: EnvironmentQuality;
+}
+
+/** Turn a Radiance panorama into the assets a scene can reference. */
+export function importEnvironment(bytes: Uint8Array, stem: string,
+ options: EnvironmentImportOptions = {}): ImportedEnvironment {
+ return importEnvironmentFromPanorama(decodeRadianceHdr(bytes), stem, options);
}
/**
- * Turn a Radiance panorama into the assets a scene can reference.
+ * Turn a panorama in linear light into the assets a scene can reference.
*
* @param faceSize Mip 0's face size; smaller is faster and is what tests use.
* @param skyWidth The sky texture's widest edge; 0 writes none.
*/
-export function importEnvironment(bytes: Uint8Array, stem: string,
- options: { faceSize?: number; mipCount?: number; skyWidth?: number } = {}):
- ImportedEnvironment {
- const faceSize = options.faceSize ?? ENV_FACE_SIZE;
- const mipCount = mipCountFor(faceSize, options.mipCount ?? ENV_MIP_COUNT);
- const panorama = decodeRadianceHdr(bytes);
+export function importEnvironmentFromPanorama(panorama: Panorama, stem: string,
+ options: EnvironmentImportOptions = {}): ImportedEnvironment {
+ const preset = ENV_QUALITY_PRESETS[options.quality ?? 'standard'];
const warnings: string[] = [];
+ let faceSize = options.faceSize ?? preset.faceSize;
+ if (faceSize > ENV_MAX_FACE_SIZE) {
+ warnings.push(`faceSize ${faceSize} is past the ${ENV_MAX_FACE_SIZE} an import allows; it was imported at ${ENV_MAX_FACE_SIZE}`);
+ faceSize = ENV_MAX_FACE_SIZE;
+ }
+ let skyWidth = options.skyWidth ?? preset.skyWidth;
+ if (skyWidth > ENV_MAX_SKY_WIDTH) {
+ warnings.push(`skyWidth ${skyWidth} is past the ${ENV_MAX_SKY_WIDTH} an import allows; it was imported at ${ENV_MAX_SKY_WIDTH}`);
+ skyWidth = ENV_MAX_SKY_WIDTH;
+ }
+ const mipCount = mipCountFor(faceSize, options.mipCount ?? ENV_MIP_COUNT);
// Equirectangular is 2:1 by construction. Another ratio still bakes, but the
// sphere it wraps onto is not the one the file draws — said, not guessed at.
if (Math.abs(panorama.width - panorama.height * 2) > 1) {
warnings.push(`the panorama is ${panorama.width}x${panorama.height}, not the 2:1 an`
+ ' equirectangular projection is; it was wrapped as if it were');
}
+ let clipped = 0, peak = 0;
+ for (let i = 0; i < panorama.rgb.length; i += 3) {
+ const m = Math.max(panorama.rgb[i]!, panorama.rgb[i + 1]!, panorama.rgb[i + 2]!);
+ if (m > peak) peak = m;
+ if (m > ENV_MAX_RANGE) clipped++;
+ }
+ const clippedFraction = clipped / Math.max(1, panorama.rgb.length / 3);
+ if (clipped > 0) {
+ warnings.push(`${(clippedFraction * 100).toFixed(2)}% of the source is brighter than the ${ENV_MAX_RANGE}`
+ + ` the sky and reflections store (peak ${peak.toFixed(1)}); those texels clip there, and the diffuse light does not`);
+ }
const irradiance = projectIrradianceSH(panorama);
const sun = separateSun(panorama);
const atlas = prefilterOctahedral(panorama, faceSize, mipCount, ENV_MAX_RANGE);
- const skyWidth = options.skyWidth ?? ENV_SKY_MAX_WIDTH;
const sky = skyWidth > 0 ? encodeSkyPanorama(panorama, skyWidth, ENV_MAX_RANGE) : null;
+ const atlasBytes = encodeRgbaPng(atlas.width, atlas.height, atlas.rgba);
+ const skyBytes = sky ? encodeRgbaPng(sky.width, sky.height, sky.rgba) : null;
return {
atlasName: `${stem}_env.png`,
- atlasBytes: encodeRgbaPng(atlas.width, atlas.height, atlas.rgba),
- sky: sky ? { name: `${stem}_sky.png`, bytes: encodeRgbaPng(sky.width, sky.height, sky.rgba) } : null,
+ atlasBytes,
+ sky: sky && skyBytes ? { name: `${stem}_sky.png`, bytes: skyBytes } : null,
warnings,
+ report: {
+ sourceWidth: panorama.width, sourceHeight: panorama.height, faceSize, mipCount,
+ skyWidth: sky?.width ?? 0, skyHeight: sky?.height ?? 0,
+ atlasBytes: atlasBytes.length, skyBytes: skyBytes?.length ?? 0,
+ maxRange: ENV_MAX_RANGE, clippedFraction, peak,
+ },
document: {
version: ENVIRONMENT_FORMAT_VERSION,
irradiance: Array.from(irradiance),
diff --git a/pipeline/tests/environment-cube.test.ts b/pipeline/tests/environment-cube.test.ts
new file mode 100644
index 000000000..b1b68f6e0
--- /dev/null
+++ b/pipeline/tests/environment-cube.test.ts
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * Six square images become a panorama that points every face the way a viewer standing
+ * inside the box sees it, and a set that cannot be read says which face is wrong.
+ */
+import { describe, it, expect } from 'vitest';
+import {
+ cubeFacesToPanorama, validateCubeFaces, CubeImportError, CUBE_FACE_NAMES,
+ type CubeFace, type CubeFaceSet, type CubeFaceName,
+} from '../src/assets/environmentCube';
+import {
+ samplePanorama, importEnvironmentFromPanorama, ENV_MAX_FACE_SIZE, ENV_QUALITY_PRESETS, type Panorama,
+} from '../src/assets/environmentImport';
+
+const N = 32;
+
+function face(fill: [number, number, number], mark?: (x: number, y: number) => boolean, extra: Partial<CubeFace> = {}): CubeFace {
+ const rgba = new Uint8Array(N * N * 4);
+ for (let y = 0; y < N; y++) {
+ for (let x = 0; x < N; x++) {
+ const on = mark?.(x, y) ?? false;
+ const o = (y * N + x) * 4;
+ rgba[o] = on ? 255 : fill[0]; rgba[o + 1] = on ? 255 : fill[1]; rgba[o + 2] = on ? 255 : fill[2]; rgba[o + 3] = 255;
+ }
+ }
+ return { width: N, height: N, rgba, ...extra };
+}
+
+const FILLS: Record<CubeFaceName, [number, number, number]> = {
+ px: [200, 0, 0], nx: [100, 0, 0], py: [0, 200, 0], ny: [0, 100, 0], pz: [0, 0, 200], nz: [0, 0, 100],
+};
+const solid = (): CubeFaceSet => Object.fromEntries(CUBE_FACE_NAMES.map((n) => [n, face(FILLS[n])])) as CubeFaceSet;
+const topRight = (x: number, y: number): boolean => x >= N - 6 && y < 6;
+
+function at(p: Panorama, x: number, y: number, z: number): number[] {
+ const l = Math.hypot(x, y, z);
+ const out = new Float32Array(3);
+ samplePanorama(p, x / l, y / l, z / l, out);
+ return [...out];
+}
+const bright = (c: number[]): boolean => c[0]! > 0.9 && c[1]! > 0.9 && c[2]! > 0.9;
+
+describe('six faces as a panorama', () => {
+ it('puts each face on the axis it is named for', () => {
+ const p = cubeFacesToPanorama(solid());
+ expect(p.width).toBe(N * 4);
+ expect(p.height).toBe(N * 2);
+ const dominant = (c: number[]): number => c.indexOf(Math.max(...c));
+ expect(dominant(at(p, 1, 0, 0))).toBe(0);
+ expect(dominant(at(p, 0, 1, 0))).toBe(1);
+ expect(dominant(at(p, 0, 0, 1))).toBe(2);
+ // +X is the brighter red (200 against 100), and likewise for the other two axes.
+ expect(at(p, 1, 0, 0)[0]!).toBeGreaterThan(at(p, -1, 0, 0)[0]!);
+ expect(at(p, 0, 1, 0)[1]!).toBeGreaterThan(at(p, 0, -1, 0)[1]!);
+ expect(at(p, 0, 0, 1)[2]!).toBeGreaterThan(at(p, 0, 0, -1)[2]!);
+ });
+
+ it('linearizes sRGB faces, and leaves linear ones alone', () => {
+ const s = cubeFacesToPanorama(solid(), 'srgb');
+ const l = cubeFacesToPanorama(solid(), 'linear');
+ expect(at(s, 1, 0, 0)[0]!).toBeCloseTo(Math.pow((200 / 255 + 0.055) / 1.055, 2.4), 2);
+ expect(at(l, 1, 0, 0)[0]!).toBeCloseTo(200 / 255, 2);
+ });
+
+ it('reads a face as a viewer inside the box does: facing +Z, right is -X', () => {
+ const faces = solid();
+ faces.pz = face(FILLS.pz, topRight);
+ const p = cubeFacesToPanorama(faces);
+ expect(bright(at(p, -0.7, 0.7, 1))).toBe(true);
+ expect(bright(at(p, 0.7, 0.7, 1))).toBe(false);
+ expect(bright(at(p, -0.7, -0.7, 1))).toBe(false);
+ });
+
+ it('reads the side faces and a pole with their tops toward the sky and the front', () => {
+ const faces = solid();
+ faces.nz = face(FILLS.nz, topRight); // facing -Z: right is +X
+ faces.px = face(FILLS.px, topRight); // facing +X: right is +Z
+ faces.py = face(FILLS.py, topRight); // looking up, top toward -Z, right is +X
+ const p = cubeFacesToPanorama(faces);
+ expect(bright(at(p, 0.7, 0.7, -1))).toBe(true);
+ expect(bright(at(p, -0.7, 0.7, -1))).toBe(false);
+ expect(bright(at(p, 1, 0.7, 0.7))).toBe(true);
+ expect(bright(at(p, 1, 0.7, -0.7))).toBe(false);
+ expect(bright(at(p, 0.7, 1, -0.7))).toBe(true);
+ expect(bright(at(p, 0.7, 1, 0.7))).toBe(false);
+ });
+
+ it('turns and mirrors one face without touching the others', () => {
+ const turned = solid(); turned.pz = face(FILLS.pz, topRight, { rotate: 90 });
+ const mirrored = solid(); mirrored.pz = face(FILLS.pz, topRight, { flip: true });
+ // Top right turned clockwise lands bottom right; mirrored it lands top left.
+ const t = cubeFacesToPanorama(turned);
+ expect(bright(at(t, -0.7, -0.7, 1))).toBe(true);
+ expect(bright(at(t, -0.7, 0.7, 1))).toBe(false);
+ const m = cubeFacesToPanorama(mirrored);
+ expect(bright(at(m, 0.7, 0.7, 1))).toBe(true);
+ expect(bright(at(m, -0.7, 0.7, 1))).toBe(false);
+ expect(at(m, 0, 0, -1)[2]!).toBeGreaterThan(0);
+ });
+});
+
+describe('a face set that cannot be imported', () => {
+ const fails = (faces: CubeFaceSet): CubeImportError => {
+ try { validateCubeFaces(faces); } catch (e) { return e as CubeImportError; }
+ throw new Error('expected the set to be refused');
+ };
+
+ it('names every missing face rather than filling one with black', () => {
+ const faces = solid(); delete faces.ny; delete faces.nz;
+ const e = fails(faces);
+ expect(e.message).toBe('missing faces -Y, -Z');
+ expect(e.face).toBe('ny');
+ });
+
+ it('names a face that is not square', () => {
+ const faces = solid();
+ faces.py = { width: 32, height: 16, rgba: new Uint8Array(32 * 16 * 4) };
+ const e = fails(faces);
+ expect(e.message).toContain('+Y');
+ expect(e.message).toContain('not square');
+ expect(e.face).toBe('py');
+ });
+
+ it('names the face whose size differs from the rest', () => {
+ const faces = solid();
+ faces.nx = { width: 16, height: 16, rgba: new Uint8Array(16 * 16 * 4) };
+ const e = fails(faces);
+ expect(e.face).toBe('nx');
+ expect(e.message).toMatch(/-X is 16px but \+X is 32px/);
+ });
+
+ it('refuses a face whose bytes are not its size', () => {
+ const faces = solid();
+ faces.pz = { width: 32, height: 32, rgba: new Uint8Array(10) };
+ expect(fails(faces).face).toBe('pz');
+ });
+});
+
+describe('an imported panorama reports what it cost and what it clipped', () => {
+ const flat = (value: number): Panorama => {
+ const width = 64, height = 32;
+ return { width, height, rgb: new Float32Array(width * height * 3).fill(value) };
+ };
+
+ it('says nothing is clipped for a source inside the stored range', () => {
+ const r = importEnvironmentFromPanorama(flat(0.5), 'dim', { faceSize: 16, skyWidth: 64 });
+ expect(r.report.clippedFraction).toBe(0);
+ expect(r.warnings).toEqual([]);
+ expect(r.report.faceSize).toBe(16);
+ expect(r.report.skyWidth).toBe(64);
+ expect(r.report.atlasBytes).toBe(r.atlasBytes.length);
+ expect(r.report.skyBytes).toBe(r.sky!.bytes.length);
+ });
+
+ it('measures the share of texels past the range, and the peak, apart from a dim exposure', () => {
+ const p = flat(0.5);
+ for (let i = 0; i < 64 * 4; i++) p.rgb[i * 3] = 50; // 4 of the 32 rows are far over the range
+ const r = importEnvironmentFromPanorama(p, 'hot', { faceSize: 16, skyWidth: 0 });
+ expect(r.report.peak).toBe(50);
+ expect(r.report.clippedFraction).toBeCloseTo(4 / 32, 5);
+ expect(r.warnings.join(' ')).toMatch(/brighter than the 8/);
+ expect(r.sky).toBeNull();
+ expect(r.report.skyBytes).toBe(0);
+ });
+
+ it('takes a named quality and lets an explicit size win', () => {
+ const low = importEnvironmentFromPanorama(flat(0.5), 'q', { quality: 'low', skyWidth: 64 });
+ expect(low.report.faceSize).toBe(ENV_QUALITY_PRESETS.low.faceSize);
+ const own = importEnvironmentFromPanorama(flat(0.5), 'q', { quality: 'low', faceSize: 32, skyWidth: 64 });
+ expect(own.report.faceSize).toBe(32);
+ });
+
+ it('refuses to be asked for more than an import allows, and says so', () => {
+ const r = importEnvironmentFromPanorama(flat(0.5), 'huge', { faceSize: ENV_MAX_FACE_SIZE * 4, mipCount: 1, skyWidth: 0 });
+ expect(r.report.faceSize).toBe(ENV_MAX_FACE_SIZE);
+ expect(r.warnings.join(' ')).toMatch(/past the 1024/);
+ }, 120000);
+});