github-actions[bot] commited on
Commit
dfec6e1
·
1 Parent(s): 49c7907

Automated Deploy: 481de343009e6b4c65440fc24152da9baba359bc

Browse files
frontend/viz2d-demo/e2e/lighting-preservation.spec.ts ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { expect, test, type Page } from "@playwright/test";
2
+
3
+ const WIDTH = 120;
4
+ const HEIGHT = 72;
5
+ const SHADE_MIN = 0.15;
6
+ const SHADE_MAX = 1.10;
7
+
8
+ for (const renderer of ["webgl", "canvas"] as const) {
9
+ test(`automatically transfers room shadows to light and dark tiles in ${renderer}`, async ({ page }) => {
10
+ if (renderer === "canvas") await disableWebGl(page);
11
+
12
+ const lightTile = await renderLightingBundle(page, "Light Marble", 0.70);
13
+ const darkTile = await renderLightingBundle(page, "Dark Marble", 0.70);
14
+
15
+ expect(lightTile.dark).toBeLessThan(lightTile.neutral * 0.78);
16
+ expect(darkTile.dark).toBeLessThan(darkTile.neutral * 0.82);
17
+ expect(lightTile.bright).toBeGreaterThan(lightTile.neutral);
18
+ expect(darkTile.bright).toBeGreaterThan(darkTile.neutral);
19
+ });
20
+
21
+ test(`uses bundle shadow strength in ${renderer}`, async ({ page }) => {
22
+ if (renderer === "canvas") await disableWebGl(page);
23
+
24
+ const subtle = await renderLightingBundle(page, "Light Marble", 0.35);
25
+ const natural = await renderLightingBundle(page, "Light Marble", 0.70);
26
+
27
+ expect(natural.dark).toBeLessThan(subtle.dark - 5);
28
+ expect(natural.neutral).toBeCloseTo(subtle.neutral, 0);
29
+ });
30
+ }
31
+
32
+ function buildLightingBundle(shadingStrength: number) {
33
+ const pixelCount = WIDTH * HEIGHT;
34
+ const pixels = new Uint8Array(pixelCount * 4);
35
+ const mask = new Uint32Array(pixelCount);
36
+ const shadeMap = new Uint8Array(pixelCount);
37
+
38
+ for (let index = 0; index < pixelCount; index += 1) {
39
+ const x = index % WIDTH;
40
+ const sourceValue = x < 40 ? 70 : x >= 80 ? 210 : 145;
41
+ const shade = x < 40 ? 0.30 : x >= 80 ? 1.08 : 1;
42
+ const pixelIndex = index * 4;
43
+ pixels[pixelIndex] = sourceValue;
44
+ pixels[pixelIndex + 1] = sourceValue;
45
+ pixels[pixelIndex + 2] = sourceValue;
46
+ pixels[pixelIndex + 3] = 255;
47
+ mask[index] = index;
48
+ shadeMap[index] = Math.round(((shade - SHADE_MIN) / (SHADE_MAX - SHADE_MIN)) * 255);
49
+ }
50
+
51
+ return {
52
+ format: "baetes-vizbundle",
53
+ bundleVersion: 3,
54
+ width: WIDTH,
55
+ height: HEIGHT,
56
+ pixels: Buffer.from(pixels).toString("base64"),
57
+ segments: [
58
+ {
59
+ id: 0,
60
+ className: "floor",
61
+ mask: Buffer.from(mask.buffer).toString("base64"),
62
+ homography: null,
63
+ plane: null,
64
+ shadeMap: Buffer.from(shadeMap).toString("base64"),
65
+ showroomShadeMap: null,
66
+ reflectionMap: null,
67
+ metadata: {
68
+ lightingSource: "luminance",
69
+ lightingTransferVersion: 4,
70
+ shadeMapEncoding: "linear-relative",
71
+ shadeMapRange: [SHADE_MIN, SHADE_MAX],
72
+ renderPresetDefaults: {
73
+ preset: "realistic",
74
+ shadingStrength,
75
+ },
76
+ },
77
+ },
78
+ ],
79
+ };
80
+ }
81
+
82
+ async function renderLightingBundle(page: Page, textureName: string, shadingStrength: number) {
83
+ await page.goto("/visualizer");
84
+ await page.getByTestId("room-file-input").setInputFiles({
85
+ name: `lighting-${textureName}-${shadingStrength}.vizbundle.json`,
86
+ mimeType: "application/json",
87
+ buffer: Buffer.from(JSON.stringify(buildLightingBundle(shadingStrength))),
88
+ });
89
+ await expect(page.getByTestId("visualizer-editor")).toBeVisible();
90
+ await page.getByTestId("surface-card").click();
91
+ await expect(page.getByTestId("texture-selector")).toBeVisible();
92
+ await page.getByTestId("texture-card").filter({ hasText: textureName }).first().click();
93
+ await expect(page.getByTestId("texture-selector")).toBeHidden();
94
+ await expect(page.getByTestId("surface-card").filter({ hasText: textureName })).toBeVisible();
95
+ await page.mouse.move(4, 4);
96
+ return readLightingRegions(page);
97
+ }
98
+
99
+ async function readLightingRegions(page: Page) {
100
+ return page.getByTestId("visualizer-canvas").evaluate((node) => {
101
+ const canvas = node as HTMLCanvasElement;
102
+ const context = canvas.getContext("2d", { willReadFrequently: true });
103
+ if (!context) throw new Error("Canvas does not expose a 2D context.");
104
+ const image = context.getImageData(0, 0, canvas.width, canvas.height);
105
+
106
+ const meanLuminance = (startX: number, endX: number) => {
107
+ let total = 0;
108
+ let count = 0;
109
+ for (let y = 8; y < canvas.height - 8; y += 1) {
110
+ for (let x = startX; x < endX; x += 1) {
111
+ const index = (y * canvas.width + x) * 4;
112
+ total += (
113
+ image.data[index] * 0.2126
114
+ + image.data[index + 1] * 0.7152
115
+ + image.data[index + 2] * 0.0722
116
+ );
117
+ count += 1;
118
+ }
119
+ }
120
+ return total / Math.max(count, 1);
121
+ };
122
+
123
+ return {
124
+ dark: meanLuminance(8, 32),
125
+ neutral: meanLuminance(48, 72),
126
+ bright: meanLuminance(88, 112),
127
+ };
128
+ });
129
+ }
130
+
131
+ async function disableWebGl(page: Page) {
132
+ await page.addInitScript(() => {
133
+ const originalGetContext = HTMLCanvasElement.prototype.getContext;
134
+ HTMLCanvasElement.prototype.getContext = function getContext(
135
+ this: HTMLCanvasElement,
136
+ contextId: string,
137
+ ...args: unknown[]
138
+ ) {
139
+ if (contextId === "webgl2") return null;
140
+ return originalGetContext.call(this, contextId as "2d", ...args as []);
141
+ } as typeof HTMLCanvasElement.prototype.getContext;
142
+ });
143
+ }
frontend/viz2d-demo/playwright.config.ts ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { defineConfig, devices } from "@playwright/test";
2
+
3
+ const port = Number(process.env.PLAYWRIGHT_PORT ?? 4173);
4
+ const baseURL = process.env.PLAYWRIGHT_BASE_URL ?? `http://127.0.0.1:${port}`;
5
+
6
+ export default defineConfig({
7
+ testDir: "./e2e",
8
+ timeout: 60_000,
9
+ expect: {
10
+ timeout: 15_000,
11
+ },
12
+ fullyParallel: false,
13
+ workers: 1,
14
+ retries: process.env.CI ? 1 : 0,
15
+ reporter: [["list"], ["html", { open: "never", outputFolder: "playwright-report" }]],
16
+ use: {
17
+ baseURL,
18
+ actionTimeout: 15_000,
19
+ navigationTimeout: 30_000,
20
+ screenshot: "only-on-failure",
21
+ trace: "retain-on-failure",
22
+ viewport: {
23
+ width: 1440,
24
+ height: 1000,
25
+ },
26
+ },
27
+ projects: [
28
+ {
29
+ name: "chromium",
30
+ use: { ...devices["Desktop Chrome"] },
31
+ },
32
+ ],
33
+ ...(process.env.PLAYWRIGHT_BASE_URL
34
+ ? {}
35
+ : {
36
+ webServer: {
37
+ command: `pnpm exec vite --host 127.0.0.1 --port ${port}`,
38
+ reuseExistingServer: !process.env.CI,
39
+ timeout: 120_000,
40
+ url: baseURL,
41
+ },
42
+ }),
43
+ });
services/pipeline/bundle_assembly.py CHANGED
@@ -109,7 +109,7 @@ def build_floor_segment(
109
  "showroomShadeMapRange": [SHOWROOM_SHADE_MAP_MIN, SHOWROOM_SHADE_MAP_MAX],
110
  "renderPresetDefaults": {
111
  "preset": "realistic",
112
- "shadingStrength": 0.30,
113
  "reflectionTransfer": True,
114
  "edgeFeatherPixels": 2,
115
  },
 
109
  "showroomShadeMapRange": [SHOWROOM_SHADE_MAP_MIN, SHOWROOM_SHADE_MAP_MAX],
110
  "renderPresetDefaults": {
111
  "preset": "realistic",
112
+ "shadingStrength": 0.70,
113
  "reflectionTransfer": True,
114
  "edgeFeatherPixels": 2,
115
  },
test_lighting_transfer.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ import numpy as np
4
+
5
+ from config.lighting import SHADE_MAP_MAX, SHADE_MAP_MIN
6
+ from services.lighting.luminance import decode_relative_map
7
+ from services.lighting.shading import build_luminance_lighting_maps
8
+
9
+
10
+ class LuminanceLightingTransferTests(unittest.TestCase):
11
+ def test_preserves_cast_shadow_and_broad_room_light(self):
12
+ height, width = 180, 240
13
+ image = np.full((height, width, 3), 150, dtype=np.uint8)
14
+ image[:, :80, :] = 60
15
+ image[:, 170:, :] = 215
16
+ surface_mask = np.ones((height, width), dtype=np.uint8)
17
+
18
+ maps = build_luminance_lighting_maps(image, surface_mask)
19
+
20
+ self.assertIsNotNone(maps)
21
+ shade = decode_relative_map(maps["shadeMap"], SHADE_MAP_MIN, SHADE_MAP_MAX)
22
+ dark = float(np.median(shade[:, 20:60]))
23
+ neutral = float(np.median(shade[:, 105:135]))
24
+ bright = float(np.median(shade[:, 190:225]))
25
+ self.assertLess(dark, neutral * 0.60)
26
+ self.assertGreater(bright, neutral * 1.03)
27
+
28
+ def test_rejects_high_frequency_source_floor_pattern(self):
29
+ height, width = 180, 240
30
+ image = np.full((height, width, 3), 165, dtype=np.uint8)
31
+ image[:, :90, :] = 78
32
+ for x in range(0, width, 8):
33
+ image[:, x:x + 2, :] = np.clip(
34
+ image[:, x:x + 2, :].astype(np.int16) - 35,
35
+ 0,
36
+ 255,
37
+ ).astype(np.uint8)
38
+ surface_mask = np.ones((height, width), dtype=np.uint8)
39
+
40
+ maps = build_luminance_lighting_maps(image, surface_mask)
41
+
42
+ self.assertIsNotNone(maps)
43
+ shade = decode_relative_map(maps["shadeMap"], SHADE_MAP_MIN, SHADE_MAP_MAX)
44
+ broad_shadow_contrast = float(
45
+ np.median(shade[:, 120:180]) - np.median(shade[:, 20:70])
46
+ )
47
+ pattern_contrast = float(np.mean(np.abs(np.diff(shade[:, 120:180], axis=1))))
48
+ self.assertGreater(broad_shadow_contrast, 0.20)
49
+ self.assertLess(pattern_contrast, 0.04)
50
+
51
+ def test_replaced_rug_appearance_is_inpainted(self):
52
+ height, width = 180, 240
53
+ image = np.full((height, width, 3), 160, dtype=np.uint8)
54
+ image[65:145, 75:175, :] = 45
55
+ surface_mask = np.ones((height, width), dtype=np.uint8)
56
+ rug_mask = np.zeros((height, width), dtype=np.uint8)
57
+ rug_mask[65:145, 75:175] = 1
58
+
59
+ maps = build_luminance_lighting_maps(image, surface_mask, rug_mask)
60
+
61
+ self.assertIsNotNone(maps)
62
+ shade = decode_relative_map(maps["shadeMap"], SHADE_MAP_MIN, SHADE_MAP_MAX)
63
+ rug_value = float(np.median(shade[rug_mask > 0]))
64
+ surrounding_value = float(np.median(shade[rug_mask == 0]))
65
+ self.assertAlmostEqual(rug_value, surrounding_value, delta=0.12)
66
+
67
+
68
+ if __name__ == "__main__":
69
+ unittest.main()
visualizer.gpu.toml CHANGED
@@ -19,7 +19,7 @@ enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
  enable_wall_segments = false
21
  enable_intrinsic_shading = false
22
- enable_shading_transfer = false
23
  enable_sam_refinement = false
24
  enable_floor_mask_cleanup = true
25
  warm_start_models = true
 
19
  enable_multi_plane_surfaces = true
20
  enable_wall_segments = false
21
  enable_intrinsic_shading = false
22
+ enable_shading_transfer = true
23
  enable_sam_refinement = false
24
  enable_floor_mask_cleanup = true
25
  warm_start_models = true
visualizer.hf.toml CHANGED
@@ -19,7 +19,7 @@ enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
  enable_wall_segments = false
21
  enable_intrinsic_shading = false
22
- enable_shading_transfer = false
23
  enable_sam_refinement = false
24
  enable_floor_mask_cleanup = true
25
  debug_artifacts_enabled = false
 
19
  enable_multi_plane_surfaces = true
20
  enable_wall_segments = false
21
  enable_intrinsic_shading = false
22
+ enable_shading_transfer = true
23
  enable_sam_refinement = false
24
  enable_floor_mask_cleanup = true
25
  debug_artifacts_enabled = false