chore:模型调整
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""Compare dimensions of new GLB assets with matching project FBX assets."""
|
||||
|
||||
from pathlib import Path
|
||||
import csv
|
||||
import bpy
|
||||
from mathutils import Vector
|
||||
|
||||
|
||||
PROJECT = Path(__file__).resolve().parent.parent
|
||||
ASSET_ROOT = PROJECT / "docs" / "asset"
|
||||
NEW_ROOT = next(path for path in ASSET_ROOT.iterdir() if path.is_dir() and any(path.rglob("*.glb")))
|
||||
REFERENCE_ROOT = PROJECT / "assets" / "Models"
|
||||
OUTPUT = PROJECT / "tools" / "new_model_scale_comparison.csv"
|
||||
|
||||
|
||||
def clear_scene():
|
||||
bpy.ops.object.select_all(action="SELECT")
|
||||
bpy.ops.object.delete(use_global=False)
|
||||
|
||||
|
||||
def dimensions(path: Path, extension: str):
|
||||
clear_scene()
|
||||
if extension == ".glb":
|
||||
bpy.ops.import_scene.gltf(filepath=str(path))
|
||||
else:
|
||||
bpy.ops.import_scene.fbx(filepath=str(path))
|
||||
points = []
|
||||
for obj in bpy.context.scene.objects:
|
||||
if obj.type == "MESH":
|
||||
points.extend(obj.matrix_world @ Vector(corner) for corner in obj.bound_box)
|
||||
low = [min(point[i] for point in points) for i in range(3)]
|
||||
high = [max(point[i] for point in points) for i in range(3)]
|
||||
return tuple(round(high[i] - low[i], 5) for i in range(3))
|
||||
|
||||
|
||||
references = {path.stem: path for path in REFERENCE_ROOT.rglob("*.fbx")}
|
||||
rows = []
|
||||
for glb in sorted(NEW_ROOT.rglob("*.glb")):
|
||||
reference = references.get(glb.stem)
|
||||
if reference is None:
|
||||
continue
|
||||
glb_size = dimensions(glb, ".glb")
|
||||
fbx_size = dimensions(reference, ".fbx")
|
||||
ratios = [fbx_size[i] / glb_size[i] for i in range(3) if glb_size[i] > 0 and fbx_size[i] > 0]
|
||||
rows.append((glb.stem, *glb_size, *fbx_size, round(sum(ratios) / len(ratios), 5)))
|
||||
|
||||
with OUTPUT.open("w", newline="", encoding="utf-8-sig") as file:
|
||||
writer = csv.writer(file)
|
||||
writer.writerow(("model", "glb_x", "glb_y", "glb_z", "project_fbx_x", "project_fbx_y", "project_fbx_z", "project_to_new_ratio"))
|
||||
writer.writerows(rows)
|
||||
print(f"Wrote {len(rows)} comparisons to {OUTPUT}")
|
||||
Reference in New Issue
Block a user