Environment lighting: - ship all eight desktop studiolights/world datasets (WBENV1 float32) and a shared loader used by both the main viewport and the offscreen worker - add the N-panel "studio 环境" selector - rotate the world background together with the environment (backgroundRotation/backgroundIntensity), so camera view and offscreen renders match the desktop Mapping-node behaviour Verification (Chromium, OPFS, NOT_CLAIMED): - environment lighting + 8 world pixel identity - camera-view rotation correspondence (camera matrices, 207 samples) - offscreen vs on-screen background parity after hiding geometry (1305 samples) - metals case extended with material-field OPFS roundtrip - material Principled edits and rename undo/redo - eight studio worlds: pairwise frame differences + luminance rank correlation - undo history depth capped at 64 steps and undo across OPFS save/reopen Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
200 lines
7.8 KiB
Python
200 lines
7.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate small COLLADA 1.4.1 fixtures for the Web Blender COLLADA import case.
|
|
|
|
Run: python3 tools/web/generate-collada-fixtures.py
|
|
|
|
Writes `web/tests/fixtures/collada/<name>.dae` plus `expected.json`, which records the
|
|
values the import path is expected to reproduce (objects, triangles, raw bounds, unit
|
|
scale). The fixtures are generated, deterministic and independent of YT2.dae.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import pathlib
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
OUT = ROOT / "web" / "tests" / "fixtures" / "collada"
|
|
|
|
|
|
def source(geometry_id: str, positions: list[tuple[float, float, float]]) -> str:
|
|
flat = " ".join(f"{value:g}" for point in positions for value in point)
|
|
return f""" <source id="{geometry_id}-positions">
|
|
<float_array id="{geometry_id}-positions-array" count="{len(positions) * 3}">{flat}</float_array>
|
|
<technique_common>
|
|
<accessor source="#{geometry_id}-positions-array" count="{len(positions)}" stride="3">
|
|
<param name="X" type="float"/><param name="Y" type="float"/><param name="Z" type="float"/>
|
|
</accessor>
|
|
</technique_common>
|
|
</source>
|
|
"""
|
|
|
|
|
|
def geometry(geometry_id: str, positions: list[tuple[float, float, float]], triangles: list[tuple[int, int, int]]) -> str:
|
|
index_list = " ".join(str(index) for triangle in triangles for index in triangle)
|
|
return f""" <geometry id="{geometry_id}" name="{geometry_id}">
|
|
<mesh>
|
|
{source(geometry_id, positions)} <vertices id="{geometry_id}-vertices">
|
|
<input semantic="POSITION" source="#{geometry_id}-positions"/>
|
|
</vertices>
|
|
<triangles count="{len(triangles)}">
|
|
<input semantic="VERTEX" source="#{geometry_id}-vertices" offset="0"/>
|
|
<p>{index_list}</p>
|
|
</triangles>
|
|
</mesh>
|
|
</geometry>
|
|
"""
|
|
|
|
|
|
def effect(effect_id: str, color: str) -> str:
|
|
return f""" <effect id="{effect_id}">
|
|
<profile_COMMON>
|
|
<technique sid="common">
|
|
<lambert><diffuse><color>{color}</color></diffuse></lambert>
|
|
</technique>
|
|
</profile_COMMON>
|
|
</effect>
|
|
"""
|
|
|
|
|
|
def material(material_id: str, name: str, effect_id: str) -> str:
|
|
return f""" <material id="{material_id}" name="{name}">
|
|
<instance_effect url="#{effect_id}"/>
|
|
</material>
|
|
"""
|
|
|
|
|
|
def instance(geometry_id: str, material_symbol: str | None = None, material_id: str | None = None) -> str:
|
|
if material_symbol and material_id:
|
|
bind = f"""<bind_material><technique_common>
|
|
<instance_material symbol="{material_symbol}" target="#{material_id}"/>
|
|
</technique_common></bind_material>"""
|
|
else:
|
|
bind = ""
|
|
return f' <instance_geometry url="#{geometry_id}">{bind}</instance_geometry>\n'
|
|
|
|
|
|
def collada(geometries: str, effects: str, materials: str, scene: str, unit_meter: float, unit_name: str, up_axis: str) -> str:
|
|
return f"""<?xml version="1.0" encoding="utf-8"?>
|
|
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
|
|
<asset>
|
|
<contributor><author>WebBlender fixtures</author></contributor>
|
|
<created>2026-11-21T00:00:00Z</created>
|
|
<modified>2026-11-21T00:00:00Z</modified>
|
|
<unit meter="{unit_meter:g}" name="{unit_name}"/>
|
|
<up_axis>{up_axis}</up_axis>
|
|
</asset>
|
|
<library_geometries>
|
|
{geometries} </library_geometries>
|
|
<library_effects>
|
|
{effects} </library_effects>
|
|
<library_materials>
|
|
{materials} </library_materials>
|
|
<library_visual_scenes>
|
|
<visual_scene id="Scene" name="Scene">
|
|
{scene} </visual_scene>
|
|
</library_visual_scenes>
|
|
<scene><instance_visual_scene url="#Scene"/></scene>
|
|
</COLLADA>
|
|
"""
|
|
|
|
|
|
def bounds(positions: list[tuple[float, float, float]]) -> tuple[list[float], list[float]]:
|
|
minimum = [min(point[axis] for point in positions) for axis in range(3)]
|
|
maximum = [max(point[axis] for point in positions) for axis in range(3)]
|
|
return minimum, maximum
|
|
|
|
|
|
def write(name: str, text: str, expected: dict) -> None:
|
|
OUT.mkdir(parents=True, exist_ok=True)
|
|
(OUT / f"{name}.dae").write_text(text, encoding="utf-8")
|
|
expected.setdefault("file", f"{name}.dae")
|
|
print(f"wrote {name}.dae")
|
|
|
|
|
|
def main() -> None:
|
|
manifest: dict[str, dict] = {}
|
|
|
|
# 1. Minimal triangle, meters, Z-up.
|
|
tri = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 2.0, 0.0)]
|
|
text = collada(
|
|
geometry("MinimalTriangle", tri, [(0, 1, 2)]),
|
|
"", "", ' <node id="Root" name="Root">\n' + instance("MinimalTriangle") + " </node>\n",
|
|
1.0, "meter", "Z_UP")
|
|
write("triangle_minimal", text, {
|
|
"objects": 1, "triangles": 1, "vertices": 3, "materials": 0,
|
|
"raw_min": [0, 0, 0], "raw_max": [1, 2, 0], "unit_meter": 1.0,
|
|
})
|
|
manifest["triangle_minimal"] = {"objects": 1, "triangles": 1}
|
|
|
|
# 2. Nested hierarchy: parent translate, child rotate+scale, two geometries.
|
|
quad = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0)]
|
|
quad_tris = [(0, 1, 2), (0, 2, 3)]
|
|
marker = [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.0, 0.5, 0.0)]
|
|
scene = (
|
|
' <node id="Root" name="Root">\n'
|
|
' <translate sid="location">0 0 2</translate>\n'
|
|
+ instance("Marker")
|
|
+ ' <node id="Child" name="Child">\n'
|
|
' <rotate sid="rotationZ">0 0 1 90</rotate>\n'
|
|
' <scale sid="scale">2 2 2</scale>\n'
|
|
+ instance("Panel")
|
|
+ ' </node>\n'
|
|
' </node>\n'
|
|
)
|
|
text = collada(
|
|
geometry("Marker", marker, [(0, 1, 2)]) + geometry("Panel", quad, quad_tris),
|
|
"", "", scene, 1.0, "meter", "Z_UP")
|
|
write("nested_hierarchy", text, {
|
|
"objects": 2, "triangles": 3, "vertices": 7, "materials": 0,
|
|
"unit_meter": 1.0, "parent_translate": [0, 0, 2], "child_scale": [2, 2, 2],
|
|
})
|
|
manifest["nested_hierarchy"] = {"objects": 2, "triangles": 3}
|
|
|
|
# 3. Two materials bound per instance.
|
|
left = [(-1.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 1.0, 0.0)]
|
|
right = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)]
|
|
scene = (
|
|
' <node id="Root" name="Root">\n'
|
|
+ instance("Left", "MatRed", "Red")
|
|
+ instance("Right", "MatGreen", "Green")
|
|
+ ' </node>\n'
|
|
)
|
|
text = collada(
|
|
geometry("Left", left, [(0, 1, 2)]) + geometry("Right", right, [(0, 1, 2)]),
|
|
effect("FxRed", "1 0 0 1") + effect("FxGreen", "0 1 0 1"),
|
|
material("Red", "Red", "FxRed") + material("Green", "Green", "FxGreen"),
|
|
scene, 1.0, "meter", "Z_UP")
|
|
write("two_materials", text, {
|
|
"objects": 2, "triangles": 2, "vertices": 6, "materials": 2,
|
|
"unit_meter": 1.0, "material_colors": {"Red": [1, 0, 0, 1], "Green": [0, 1, 0, 1]},
|
|
})
|
|
manifest["two_materials"] = {"objects": 2, "triangles": 2, "materials": 2}
|
|
|
|
# 4. Millimeter units with Y-up: 1000 mm cube becomes 1 m after import.
|
|
cube_vertices = [
|
|
(0, 0, 0), (1000, 0, 0), (1000, 1000, 0), (0, 1000, 0),
|
|
(0, 0, 1000), (1000, 0, 1000), (1000, 1000, 1000), (0, 1000, 1000),
|
|
]
|
|
cube_faces = [
|
|
(0, 1, 2), (0, 2, 3), (4, 6, 5), (4, 7, 6),
|
|
(0, 4, 5), (0, 5, 1), (1, 5, 6), (1, 6, 2),
|
|
(2, 6, 7), (2, 7, 3), (3, 7, 4), (3, 4, 0),
|
|
]
|
|
text = collada(
|
|
geometry("Cube", cube_vertices, cube_faces),
|
|
"", "", ' <node id="Root" name="Root">\n' + instance("Cube") + " </node>\n",
|
|
0.001, "millimeter", "Y_UP")
|
|
write("millimeter_yup", text, {
|
|
"objects": 1, "triangles": 12, "vertices": 8, "materials": 0,
|
|
"raw_min": [0, 0, 0], "raw_max": [1000, 1000, 1000], "unit_meter": 0.001,
|
|
"expected_size_m": [1, 1, 1],
|
|
})
|
|
manifest["millimeter_yup"] = {"objects": 1, "triangles": 12, "size_m": [1, 1, 1]}
|
|
|
|
(OUT / "expected.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
print(f"wrote expected.json ({len(manifest)} fixtures) -> {OUT}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|