Files
PerfectCoffee/model_assets/validate_low_poly_consumables.py
Yanchen 0f9e127162 feat: track remaining production assets, playtest scenes and references
Close the gaps left open after the LFS migration: 177 files that were
sitting untracked now enter version control, with every binary going
through Git LFS.

- labels: milk and orange-juice wrap artwork (SVG/PNG), Seedream sources,
  prompts and Dreamina job records
- orange juice 2L: bottle, cap, empty state and three label variants
  (blend + glb each)
- cup contents: desktop and mobile-optimised variants plus 3 textures
- milk 2L: empty and packaged variants with their glb exports
- milk frother: low-poly assembly and split base/jug parts
- tamper: model, glb and fit test
- juicer: seven assembly-part review scenes and their export scripts
- playtests: extraction animation scene and grinding/tamping whitebox
- reference: Minex page candidates, user review screenshots, sequence
  analysis frames and tamper STLs
- docs: item design draft, bean research notes, region reference and the
  model-asset audit report

Re-renderable preview/check frames stay untracked on purpose.
2026-11-22 10:26:53 +08:00

160 lines
6.9 KiB
Python

import bpy
import bmesh
import json
from pathlib import Path
from mathutils import Vector
ROOT = Path(__file__).resolve().parent
LIMIT = 1000
def meshes():
return [obj for obj in bpy.context.scene.objects if obj.type == "MESH" and not obj.name.startswith("Studio_")]
def triangles(objects):
total = 0
for obj in objects:
obj.data.calc_loop_triangles()
total += len(obj.data.loop_triangles)
return total
def bounds(objects):
bpy.context.view_layer.update()
points = [obj.matrix_world @ vertex.co for obj in objects for vertex in obj.data.vertices]
return [max(point[axis] for point in points) - min(point[axis] for point in points) for axis in range(3)]
def volume_ml(obj):
bm = bmesh.new()
bm.from_mesh(obj.data)
result = abs(bm.calc_volume(signed=True)) * 1000000
bm.free()
return result
def close_dimensions(first, second):
return all(abs(a - b) < 0.0001 for a, b in zip(first, second))
def import_glb(path):
bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.gltf(filepath=str(path))
objects = meshes()
return triangles(objects), bounds(objects), [obj.name for obj in bpy.context.scene.objects]
manifest = json.loads((ROOT / "low_poly_consumables_manifest.json").read_text())
summary = []
for entry in manifest["assets"]:
directory = ROOT / entry["directory"]
report_path = directory / "validation.json"
report = json.loads(report_path.read_text())
bpy.ops.wm.open_mainfile(filepath=str(directory / entry["blend"]))
native_objects = meshes()
native_triangles = triangles(native_objects)
native_dimensions = bounds(native_objects)
reference_images = [image for image in bpy.data.images if image.name.startswith("REFERENCE_")]
packed_references = bool(reference_images) and all(image.packed_file for image in reference_images)
image_texture_nodes = [
(material.name, node.name)
for material in bpy.data.materials if material.use_nodes
for node in material.node_tree.nodes if node.type == "TEX_IMAGE"
]
generic_orange_label = (
report["asset"] == "OrangeJuice2L_Root"
and len(image_texture_nodes) == 1
and image_texture_nodes[0][0] == "OrangeJuice_Label"
)
texture_check = not image_texture_nodes or generic_orange_label
cap_check = None
liquid_check = None
assembly_check = None
if report["asset"] == "Milk2L_Root":
assembly = json.loads((directory / "assembly_test" / "validation.json").read_text())
assembly_check = assembly["passed"] and assembly["assembled_triangles"] == native_triangles
size_check = max(native_dimensions) < 0.5 and min(native_dimensions) > 0.01
if report.get("cap_mesh"):
cap = bpy.data.objects[report["cap_mesh"]]
pivot = cap.parent
old_location = pivot.location.copy()
old_cap_z = cap.matrix_world.translation.z
pivot.location.z += 0.01
bpy.context.view_layer.update()
moved_distance = cap.matrix_world.translation.z - old_cap_z
cap_check = cap.parent != bpy.data.objects.get(report["asset"]) and abs(moved_distance - 0.01) < 0.00001
pivot.location = old_location
if report["asset"] == "OrangeJuice2L_Root":
liquid_check = abs(volume_ml(bpy.data.objects["OrangeJuice_Juice_Fill"]) - 2000) < 0.5
glb_triangles, glb_dimensions, imported_names = import_glb(directory / entry["glb"])
glb_clean = not any(name.startswith("Studio_") for name in imported_names)
transparent_pet_check = None
if report["asset"] == "OrangeJuice2L_Root":
pet = bpy.data.materials.get("OrangeJuice_ClearPET")
transparent_pet_check = pet is not None and pet.node_tree.nodes["Principled BSDF"].inputs["Alpha"].default_value < 0.1
native_ok = native_triangles == report["triangles"] and close_dimensions(native_dimensions, report["dimensions_m"])
glb_ok = glb_triangles == report["triangles"] and close_dimensions(glb_dimensions, native_dimensions)
cap_files_ok = None
if cap_check is not None:
cap_blend = directory / report["cap_files"][0]
cap_glb = directory / report["cap_files"][1]
bpy.ops.wm.open_mainfile(filepath=str(cap_blend))
cap_native_triangles = triangles(meshes())
cap_glb_triangles, _, _ = import_glb(cap_glb)
cap_files_ok = cap_native_triangles == report["cap_triangles"] and cap_glb_triangles == report["cap_triangles"]
report.update({
"native_reopen_passed": native_ok,
"native_triangles": native_triangles,
"native_dimensions_m": native_dimensions,
"reference_images_packed": packed_references,
"no_image_textures_or_labels": not image_texture_nodes,
"cap_detach_parenting_passed": cap_check,
"cap_assembly_test_passed": assembly_check,
"cap_blend_and_glb_passed": cap_files_ok,
"liquid_volume_2000ml_passed": liquid_check,
"plausible_dimensions_passed": size_check,
"transparent_pet_passed": transparent_pet_check,
"glb_reimport_passed": glb_ok,
"glb_triangles": glb_triangles,
"glb_dimensions_m": glb_dimensions,
"studio_excluded_from_glb": glb_clean,
})
checks = [
native_ok, glb_ok, native_triangles <= LIMIT, glb_triangles <= LIMIT,
packed_references, texture_check, glb_clean, size_check,
]
if transparent_pet_check is not None:
checks.append(transparent_pet_check)
if cap_check is not None:
checks.extend([cap_check, cap_files_ok])
if assembly_check is not None:
checks.append(assembly_check)
if liquid_check is not None:
checks.append(liquid_check)
report["technical_validation_passed"] = all(checks)
report["passed"] = all(checks) and report.get("visual_review_passed", False)
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
entry["triangles"] = native_triangles
summary.append({
"directory": entry["directory"],
"native_triangles": native_triangles,
"glb_triangles": glb_triangles,
"triangle_limit": LIMIT,
"cap_files_verified": cap_files_ok,
"reference_images_packed": packed_references,
"technical_validation_passed": all(checks),
"visual_review_passed": report.get("visual_review_passed", False),
"passed": report["passed"],
})
print("VALIDATED", entry["directory"], native_triangles, glb_triangles, all(checks), flush=True)
(ROOT / "low_poly_consumables_manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n")
(ROOT / "low_poly_consumables_validation.json").write_text(json.dumps({
"triangle_limit_per_asset": LIMIT,
"all_technical_checks_passed": all(item["technical_validation_passed"] for item in summary),
"all_visual_reviews_passed": all(item["visual_review_passed"] for item in summary),
"assets": summary,
}, ensure_ascii=False, indent=2) + "\n")
assert all(item["technical_validation_passed"] for item in summary), "Technical validation failed"