Files
PerfectCoffee/model_assets/orange_juice_2l/create_empty_bottle.py
T
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

128 lines
4.7 KiB
Python

import hashlib
import json
from pathlib import Path
import bpy
from mathutils import Vector
OUT = Path(__file__).resolve().parent
SOURCE = OUT / "PerfectCoffee_orange_juice_2l.blend"
BLEND = OUT / "PerfectCoffee_orange_juice_2l_Empty.blend"
GLB = OUT / "PerfectCoffee_orange_juice_2l_Empty.glb"
ALPHA = 0.18
def sha256(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def mesh_objects():
return [obj for obj in bpy.context.scene.objects if obj.type == "MESH" and not obj.name.startswith("Studio_")]
def triangle_count(objects):
total = 0
for obj in objects:
obj.data.calc_loop_triangles()
total += len(obj.data.loop_triangles)
return total
source_hash = sha256(SOURCE)
cap_hashes = {
name: sha256(OUT / name)
for name in ("PerfectCoffee_orange_juice_2l_Cap.blend", "PerfectCoffee_orange_juice_2l_Cap.glb")
}
bpy.ops.wm.open_mainfile(filepath=str(SOURCE))
bpy.context.preferences.filepaths.save_version = 0
liquid = bpy.data.objects.get("OrangeJuice_Juice_Fill")
assert liquid is not None, "Source must contain the liquid object"
source_triangles = triangle_count(mesh_objects())
liquid_triangles = triangle_count([liquid])
bpy.data.objects.remove(liquid, do_unlink=True)
body = bpy.data.objects["OrangeJuice_Bottle_Body"]
original_material = body.data.materials[0]
material = original_material.copy()
material.name = "OrangeJuice_ClearPET_Study"
material.diffuse_color = (*material.diffuse_color[:3], ALPHA)
material.use_nodes = True
shader = material.node_tree.nodes.get("Principled BSDF")
shader.inputs["Alpha"].default_value = ALPHA
body.data.materials.clear()
body.data.materials.append(material)
for polygon in body.data.polygons:
polygon.material_index = 0
root = bpy.data.objects["OrangeJuice2L_Root"]
root.name = "OrangeJuice2L_Empty_Root"
root["empty_observation_variant"] = True
root["modeled_liquid_ml"] = 0.0
root["pet_opacity"] = ALPHA
root["source_model"] = SOURCE.name
collection = bpy.data.collections["Model"]
bpy.ops.object.select_all(action="DESELECT")
for obj in collection.all_objects:
obj.select_set(True)
bpy.context.view_layer.objects.active = body
bpy.ops.export_scene.gltf(
filepath=str(GLB), export_format="GLB", use_selection=True,
export_yup=True, export_apply=True, export_cameras=False, export_lights=False,
)
scene = bpy.context.scene
scene.render.filepath = str(OUT / "preview_empty.png")
bpy.ops.render.render(write_still=True)
pivot = bpy.data.objects["OrangeJuice_Cap_Pivot"]
location = pivot.location.copy()
pivot.location += Vector((0.045, 0, 0.055))
scene.render.filepath = str(OUT / "preview_empty_cap_removed.png")
bpy.ops.render.render(write_still=True)
pivot.location = location
scene.render.filepath = str(OUT / "preview_empty.png")
bpy.ops.wm.save_as_mainfile(filepath=str(BLEND), compress=True)
assert sha256(SOURCE) == source_hash
for name, old_hash in cap_hashes.items():
assert sha256(OUT / name) == old_hash
bpy.ops.wm.open_mainfile(filepath=str(BLEND))
native_triangles = triangle_count(mesh_objects())
native_shader = bpy.data.materials["OrangeJuice_ClearPET_Study"].node_tree.nodes["Principled BSDF"]
native_ok = (
bpy.data.objects.get("OrangeJuice_Juice_Fill") is None
and native_triangles == source_triangles - liquid_triangles
and abs(native_shader.inputs["Alpha"].default_value - ALPHA) < 0.00001
)
bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.gltf(filepath=str(GLB))
imported_objects = mesh_objects()
imported_shader = bpy.data.materials["OrangeJuice_ClearPET_Study"].node_tree.nodes["Principled BSDF"]
glb_ok = (
bpy.data.objects.get("OrangeJuice_Juice_Fill") is None
and triangle_count(imported_objects) == source_triangles - liquid_triangles
and abs(imported_shader.inputs["Alpha"].default_value - ALPHA) < 0.00001
)
assert native_ok and glb_ok, "Empty bottle validation failed"
report = {
"asset": "OrangeJuice2L_Empty_Root",
"source_model": SOURCE.name,
"source_unchanged": True,
"empty_liquid_object_removed": True,
"source_triangles": source_triangles,
"liquid_triangles_removed": liquid_triangles,
"native_triangles": native_triangles,
"glb_triangles": triangle_count(imported_objects),
"triangle_limit": 1000,
"pet_opacity": ALPHA,
"source_pet_opacity": 0.055,
"cap_files_untouched": True,
"native_reopen_passed": native_ok,
"glb_reimport_passed": glb_ok,
"technical_validation_passed": True,
"visual_review_passed": False,
"passed": False,
"blend": BLEND.name,
"glb": GLB.name,
"preview": "preview_empty.png",
"preview_cap_removed": "preview_empty_cap_removed.png",
}
(OUT / "validation_empty.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
print(json.dumps(report, ensure_ascii=False, indent=2))