[change] src/app/App.tsx [change] src/assets/starter-environment-assets.ts [change] src/document/migrate-scene-document.ts [change] src/document/scene-document-validation.ts [change] src/document/scene-document.ts [change] src/document/world-settings.ts [change] src/rendering/world-background-renderer.ts [change] src/rendering/world-shader-sky.ts [change] src/runtime-three/runtime-host.ts [change] src/runtime-three/runtime-project-time.ts [change] src/shared-ui/world-background-style.ts [change] src/viewport-three/ViewportCanvas.tsx [change] src/viewport-three/viewport-host.ts [change] tests/domain/runtime-project-time.test.ts [change] tests/domain/scene-document-validation.test.ts [change] tests/domain/world-settings.test.ts [change] tests/serialization/project-document-json.test.ts [change] tests/serialization/scene-document-json.test.ts [change] tests/unit/world-shader-sky.test.ts
177 lines
4.7 KiB
TypeScript
177 lines
4.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { createDefaultProjectTimeSettings } from "../../src/document/project-time-settings";
|
|
import { createDefaultWorldSettings } from "../../src/document/world-settings";
|
|
import { resolveWorldShaderSkyRenderState } from "../../src/rendering/world-shader-sky";
|
|
import {
|
|
resolveRuntimeDayNightWorldState,
|
|
resolveRuntimeTimeState
|
|
} from "../../src/runtime-three/runtime-project-time";
|
|
|
|
describe("resolveWorldShaderSkyRenderState", () => {
|
|
it("blends authored day, dawn, dusk, and night color bases continuously", () => {
|
|
const world = createDefaultWorldSettings();
|
|
const time = createDefaultProjectTimeSettings();
|
|
world.background = {
|
|
mode: "shader"
|
|
};
|
|
world.showCelestialBodies = true;
|
|
world.shaderSky.dayTopColorHex = "#88ccff";
|
|
world.shaderSky.dayBottomColorHex = "#dff3ff";
|
|
world.timeOfDay.dawn.background = {
|
|
mode: "verticalGradient",
|
|
topColorHex: "#ff8855",
|
|
bottomColorHex: "#ffd4a8"
|
|
};
|
|
world.timeOfDay.dusk.background = {
|
|
mode: "verticalGradient",
|
|
topColorHex: "#5e62c8",
|
|
bottomColorHex: "#ff9966"
|
|
};
|
|
world.timeOfDay.night.background = {
|
|
mode: "verticalGradient",
|
|
topColorHex: "#04101d",
|
|
bottomColorHex: "#17263b"
|
|
};
|
|
time.sunriseTimeOfDayHours = 7;
|
|
time.sunsetTimeOfDayHours = 20;
|
|
time.dawnDurationHours = 2;
|
|
time.duskDurationHours = 2;
|
|
|
|
const dawnTime = resolveRuntimeTimeState(time, {
|
|
timeOfDayHours: 6.5,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
});
|
|
const dawnWorld = resolveRuntimeDayNightWorldState(
|
|
world,
|
|
time,
|
|
{
|
|
timeOfDayHours: 6.5,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
},
|
|
dawnTime
|
|
);
|
|
const noonTime = resolveRuntimeTimeState(time, {
|
|
timeOfDayHours: 12,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
});
|
|
const noonWorld = resolveRuntimeDayNightWorldState(
|
|
world,
|
|
time,
|
|
{
|
|
timeOfDayHours: 12,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
},
|
|
noonTime
|
|
);
|
|
const midnightTime = resolveRuntimeTimeState(time, {
|
|
timeOfDayHours: 0,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
});
|
|
const midnightWorld = resolveRuntimeDayNightWorldState(
|
|
world,
|
|
time,
|
|
{
|
|
timeOfDayHours: 0,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
},
|
|
midnightTime
|
|
);
|
|
|
|
const dawnSky = resolveWorldShaderSkyRenderState(
|
|
world,
|
|
dawnWorld,
|
|
dawnTime,
|
|
time
|
|
);
|
|
const noonSky = resolveWorldShaderSkyRenderState(
|
|
world,
|
|
noonWorld,
|
|
noonTime,
|
|
time
|
|
);
|
|
const midnightSky = resolveWorldShaderSkyRenderState(
|
|
world,
|
|
midnightWorld,
|
|
midnightTime,
|
|
time
|
|
);
|
|
|
|
expect(dawnSky).not.toBeNull();
|
|
expect(noonSky?.sky.topColorHex).toBe("#88ccff");
|
|
expect(noonSky?.sky.bottomColorHex).toBe("#dff3ff");
|
|
expect(dawnSky?.sky.topColorHex).not.toBe(noonSky?.sky.topColorHex);
|
|
expect(dawnSky?.sky.topColorHex).not.toBe(midnightSky?.sky.topColorHex);
|
|
expect(midnightSky?.stars.visibility ?? 0).toBeGreaterThan(
|
|
dawnSky?.stars.visibility ?? 0
|
|
);
|
|
expect(dawnSky?.stars.visibility ?? 0).toBeGreaterThan(0);
|
|
expect(noonSky?.stars.visibility ?? 1).toBe(0);
|
|
});
|
|
|
|
it("keeps shader sky drift and celestial visibility coherent across days", () => {
|
|
const world = createDefaultWorldSettings();
|
|
const time = createDefaultProjectTimeSettings();
|
|
world.background = {
|
|
mode: "shader"
|
|
};
|
|
world.showCelestialBodies = true;
|
|
|
|
const firstNightTime = resolveRuntimeTimeState(time, {
|
|
timeOfDayHours: 0,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
});
|
|
const firstNightWorld = resolveRuntimeDayNightWorldState(
|
|
world,
|
|
time,
|
|
{
|
|
timeOfDayHours: 0,
|
|
dayCount: 0,
|
|
dayLengthMinutes: 24
|
|
},
|
|
firstNightTime
|
|
);
|
|
const secondNightTime = resolveRuntimeTimeState(time, {
|
|
timeOfDayHours: 0,
|
|
dayCount: 1,
|
|
dayLengthMinutes: 24
|
|
});
|
|
const secondNightWorld = resolveRuntimeDayNightWorldState(
|
|
world,
|
|
time,
|
|
{
|
|
timeOfDayHours: 0,
|
|
dayCount: 1,
|
|
dayLengthMinutes: 24
|
|
},
|
|
secondNightTime
|
|
);
|
|
|
|
const firstNightSky = resolveWorldShaderSkyRenderState(
|
|
world,
|
|
firstNightWorld,
|
|
firstNightTime,
|
|
time
|
|
);
|
|
const secondNightSky = resolveWorldShaderSkyRenderState(
|
|
world,
|
|
secondNightWorld,
|
|
secondNightTime,
|
|
time
|
|
);
|
|
|
|
expect(firstNightSky?.celestial.sunVisible).toBe(false);
|
|
expect(firstNightSky?.celestial.moonVisible).toBe(true);
|
|
expect(secondNightSky?.clouds.driftOffset.x).not.toBeCloseTo(
|
|
firstNightSky?.clouds.driftOffset.x ?? 0
|
|
);
|
|
});
|
|
});
|