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.
This commit is contained in:
Yanchen
2026-11-22 10:26:53 +08:00
parent e8f6f34e15
commit 0f9e127162
177 changed files with 10053 additions and 0 deletions
@@ -0,0 +1,525 @@
import bpy
import bmesh
import hashlib
import json
import math
from pathlib import Path
from mathutils import Vector
OUT = Path(__file__).resolve().parent
SOURCE = OUT / 'PerfectCoffee_MilkFrother.blend'
LOW = OUT / 'PerfectCoffee_MilkFrother_LowPoly.blend'
GLB = OUT / 'PerfectCoffee_MilkFrother_LowPoly.glb'
BASE_BLEND = OUT / 'PerfectCoffee_MilkFrother_Base_LowPoly.blend'
JUG_BLEND = OUT / 'PerfectCoffee_MilkFrother_Jug_LowPoly.blend'
BASE_GLB = OUT / 'PerfectCoffee_MilkFrother_Base_LowPoly.glb'
JUG_GLB = OUT / 'PerfectCoffee_MilkFrother_Jug_LowPoly.glb'
REPORT = OUT / 'low_poly_validation.json'
TARGET_MIN = 5000
TARGET_MAX = 10000
source_hash = hashlib.sha256(SOURCE.read_bytes()).hexdigest()
bpy.ops.wm.open_mainfile(filepath=str(SOURCE))
bpy.context.preferences.filepaths.save_version = 0
scene = bpy.context.scene
model_collection = bpy.data.collections['MF_MilkFrother_Model']
root = bpy.data.objects['MilkFrother_Root']
base_root = bpy.data.objects['MF_Base_Assembly']
jug_root = bpy.data.objects['MF_Jug_Assembly']
def mesh_objects():
return [obj for obj in model_collection.all_objects if obj.type == 'MESH']
def evaluated_triangles(obj, depsgraph):
evaluated = obj.evaluated_get(depsgraph)
mesh = evaluated.to_mesh()
mesh.calc_loop_triangles()
count = len(mesh.loop_triangles)
evaluated.to_mesh_clear()
return count
def total_triangles():
depsgraph = bpy.context.evaluated_depsgraph_get()
return sum(evaluated_triangles(obj, depsgraph) for obj in mesh_objects())
def bounds(objects):
bpy.context.view_layer.update()
points = [obj.matrix_world @ Vector(corner) for obj in objects for corner in obj.bound_box]
minimum = [min(point[axis] for point in points) for axis in range(3)]
maximum = [max(point[axis] for point in points) for axis in range(3)]
return minimum, maximum
def dimensions(objects):
minimum, maximum = bounds(objects)
return [maximum[axis] - minimum[axis] for axis in range(3)]
source_triangles = total_triangles()
source_dimensions = dimensions(mesh_objects())
def replace_mesh(obj, mesh):
materials = list(obj.data.materials)
for material in materials:
mesh.materials.append(material)
old = obj.data
obj.data = mesh
if old.users == 0:
bpy.data.meshes.remove(old)
mesh.update()
def replace_torus(name, major_segments, minor_segments, major_radius, minor_radius):
obj = bpy.data.objects[name]
vertices = []
faces = []
for major_index in range(major_segments):
major_angle = major_index * math.tau / major_segments
for minor_index in range(minor_segments):
minor_angle = minor_index * math.tau / minor_segments
radius = major_radius + minor_radius * math.cos(minor_angle)
vertices.append((radius * math.cos(major_angle), radius * math.sin(major_angle), minor_radius * math.sin(minor_angle)))
for major_index in range(major_segments):
next_major = (major_index + 1) % major_segments
for minor_index in range(minor_segments):
next_minor = (minor_index + 1) % minor_segments
faces.append((
major_index * minor_segments + minor_index,
next_major * minor_segments + minor_index,
next_major * minor_segments + next_minor,
major_index * minor_segments + next_minor,
))
mesh = bpy.data.meshes.new(name + '_LowMesh')
mesh.from_pydata(vertices, [], faces)
for polygon in mesh.polygons:
polygon.use_smooth = True
replace_mesh(obj, mesh)
return obj
def extract_lathe_profile(obj, original_segments=192):
vertices = obj.data.vertices
profile = []
cursor = 0
while cursor < len(vertices):
point = vertices[cursor].co
radius = math.hypot(point.x, point.y)
profile.append((0.0 if radius <= 1e-9 else radius, point.z))
cursor += 1 if radius <= 1e-9 else original_segments
assert cursor == len(vertices), (obj.name, cursor, len(vertices))
return profile
def replace_lathe(name, segments, close_profile=True):
obj = bpy.data.objects[name]
profile = extract_lathe_profile(obj)
vertices = []
rings = []
for radius, height in profile:
if radius <= 1e-9:
rings.append([len(vertices)])
vertices.append((0.0, 0.0, height))
else:
ring = []
for index in range(segments):
angle = index * math.tau / segments
ring.append(len(vertices))
vertices.append((radius * math.cos(angle), radius * math.sin(angle), height))
rings.append(ring)
faces = []
for ring_index in range(len(rings) if close_profile else len(rings) - 1):
first = rings[ring_index]
second = rings[(ring_index + 1) % len(rings)]
if len(first) == 1 and len(second) == 1:
continue
for index in range(segments):
next_index = (index + 1) % segments
if len(first) == 1:
faces.append((first[0], second[next_index], second[index]))
elif len(second) == 1:
faces.append((first[index], first[next_index], second[0]))
else:
faces.append((first[index], first[next_index], second[next_index], second[index]))
mesh = bpy.data.meshes.new(name + '_LowMesh')
mesh.from_pydata(vertices, [], faces)
bm = bmesh.new()
bm.from_mesh(mesh)
bmesh.ops.recalc_face_normals(bm, faces=list(bm.faces))
bm.to_mesh(mesh)
bm.free()
for polygon in mesh.polygons:
polygon.use_smooth = True
replace_mesh(obj, mesh)
return obj
def replace_cylinder(name, segments, bevel_segments=1):
obj = bpy.data.objects[name]
radius = max(math.hypot(vertex.co.x, vertex.co.y) for vertex in obj.data.vertices)
depth = max(vertex.co.z for vertex in obj.data.vertices) - min(vertex.co.z for vertex in obj.data.vertices)
vertices = []
for z in (-depth / 2, depth / 2):
for index in range(segments):
angle = index * math.tau / segments
vertices.append((radius * math.cos(angle), radius * math.sin(angle), z))
faces = [tuple(reversed(range(segments))), tuple(range(segments, 2 * segments))]
for index in range(segments):
next_index = (index + 1) % segments
faces.append((index, next_index, next_index + segments, index + segments))
mesh = bpy.data.meshes.new(name + '_LowMesh')
mesh.from_pydata(vertices, [], faces)
for polygon in mesh.polygons:
polygon.use_smooth = len(polygon.vertices) == 4
replace_mesh(obj, mesh)
for modifier in list(obj.modifiers):
if modifier.type == 'BEVEL':
if bevel_segments:
modifier.segments = bevel_segments
else:
obj.modifiers.remove(modifier)
return obj
def stretch_spout(obj):
bpy.context.view_layer.update()
matrix = obj.matrix_world.copy()
inverse = matrix.inverted()
maximum_extension = 0.0
for vertex in obj.data.vertices:
point = matrix @ vertex.co
if point.z < 0.202 or math.hypot(point.x, point.y) < 0.02:
continue
angle = math.atan2(point.y, point.x)
delta = math.atan2(math.sin(angle + math.pi / 2), math.cos(angle + math.pi / 2))
angular = max(0.0, 1.0 - abs(delta) / 0.42) ** 1.25
vertical = min(1.0, max(0.0, (point.z - 0.202) / 0.027)) ** 2
weight = angular * vertical
extension = 0.012 * weight
point.y -= extension
point.z += 0.004 * weight
vertex.co = inverse @ point
maximum_extension = max(maximum_extension, extension)
obj.data.update()
return maximum_extension
for name, segments in [
('MF_Jug_Outer', 48),
('MF_White_Housing', 48),
('MF_Neck_Collar', 32),
('MF_Chrome_Base', 48),
('MF_Base_Seam', 24),
('MF_Whisk_Disk', 24),
]:
replace_lathe(name, segments, close_profile=name != 'MF_Jug_Outer')
replace_torus('MF_Jug_Rolled_Rim', 48, 8, 0.0551, 0.00115)
replace_torus('MF_Lid_Clear_Rim', 32, 8, 0.0565, 0.0013)
replace_torus('MF_Measuring_Cap_Rim', 24, 8, 0.017, 0.0016)
replace_torus('MF_Whisk_Notched_Ring', 24, 8, 0.0125, 0.0020)
spout_extension = max(
stretch_spout(bpy.data.objects['MF_Jug_Outer']),
stretch_spout(bpy.data.objects['MF_Jug_Rolled_Rim']),
)
replace_cylinder('MF_Lid_Clear_Disk', 48)
replace_cylinder('MF_Measuring_Cap', 32)
replace_cylinder('MF_Start_Bezel', 32)
replace_cylinder('MF_Start_Button', 32)
replace_cylinder('MF_Base_Support_Pad', 24, 0)
replace_cylinder('MF_Whisk_Central_Pin', 24, 0)
for obj in mesh_objects():
if obj.name.startswith('MF_Whisk_Tooth_') or obj.name in {
'MF_Base_Foot_01', 'MF_Base_Foot_02', 'MF_Base_Foot_03', 'MF_Base_Foot_04',
'MF_Handle_Mount_Upper', 'MF_Measuring_Cap_Grip', 'MF_Lid_Tab_Left', 'MF_Lid_Tab_Right',
}:
obj.modifiers.clear()
handle = bpy.data.objects['MF_Handle_Frame']
handle_bevel = handle.modifiers.get('MF_Soft_Edges')
handle_bevel.segments = 1
handle_bevel_segments = 1
teeth = [obj for obj in mesh_objects() if obj.name.startswith('MF_Whisk_Tooth_')]
bpy.ops.object.select_all(action='DESELECT')
for obj in teeth:
obj.select_set(True)
bpy.context.view_layer.objects.active = teeth[0]
bpy.ops.object.join()
joined_teeth = bpy.context.object
joined_teeth.name = 'MF_Whisk_Teeth'
joined_teeth.data.name = 'MF_Whisk_Teeth_LowMesh'
bpy.ops.object.select_all(action='DESELECT')
low_triangles = total_triangles()
if low_triangles > TARGET_MAX:
handle.modifiers.remove(handle_bevel)
handle_bevel_segments = 0
low_triangles = total_triangles()
assert TARGET_MIN <= low_triangles <= TARGET_MAX, low_triangles
root['lod'] = 'low'
root['source_model'] = SOURCE.name
root['target_triangle_range'] = [TARGET_MIN, TARGET_MAX]
scene['lod'] = 'low'
scene['source_model'] = SOURCE.name
scene['source_sha256'] = source_hash
about = bpy.data.texts.get('ABOUT_MilkFrother')
about.clear()
about.write(
'Independent low-poly milk frother derived from the preserved high-detail source.\n'
'Front: +Y. Up: +Z. Units: meters.\n'
'Base, jug, lid, handle, whisk and controls retain their original assembled coordinates.\n'
'The jug retains its single-wall glass thickness and continuously modeled pouring lip.\n'
'Fill marks remain Minimum, Half, Maximum, readable normally from the -Y exterior.\n'
'Blender glass matches the high-detail source; GLB uses compatible Principled transmission glass.\n'
f'Evaluated triangles: {low_triangles}; target range: {TARGET_MIN} to {TARGET_MAX}.\n'
)
export_glass = bpy.data.materials.new('MF_GLTF_Clear_Glass')
export_glass.use_nodes = True
export_shader = export_glass.node_tree.nodes.get('Principled BSDF')
export_shader.inputs['Base Color'].default_value = (0.98, 0.99, 1.0, 1.0)
export_shader.inputs['Roughness'].default_value = 0.005
export_shader.inputs['Transmission Weight'].default_value = 1.0
export_shader.inputs['IOR'].default_value = 1.46
glass = bpy.data.materials['MF_Clear_Single_Wall_Glass']
glass_export_slots = []
for obj in mesh_objects():
for slot in obj.material_slots:
if slot.material == glass:
glass_export_slots.append(slot)
slot.material = export_glass
glass.name = 'MF_Clear_Single_Wall_Glass_Blender'
export_glass.name = 'MF_Clear_Single_Wall_Glass'
bpy.ops.object.select_all(action='DESELECT')
for obj in model_collection.all_objects:
obj.select_set(True)
bpy.context.view_layer.objects.active = root
bpy.ops.export_scene.gltf(
filepath=str(GLB),
export_format='GLB',
use_selection=True,
export_apply=True,
export_animations=False,
export_extras=True,
)
def export_assembly(assembly, filename):
bpy.ops.object.select_all(action='DESELECT')
assembly.select_set(True)
for obj in assembly.children_recursive:
obj.select_set(True)
bpy.context.view_layer.objects.active = assembly
bpy.ops.export_scene.gltf(
filepath=str(OUT / filename),
export_format='GLB',
use_selection=True,
export_apply=True,
export_animations=False,
export_extras=True,
)
export_assembly(base_root, BASE_GLB.name)
export_assembly(jug_root, JUG_GLB.name)
for slot in glass_export_slots:
slot.material = glass
export_glass.name = 'MF_GLTF_Clear_Glass'
glass.name = 'MF_Clear_Single_Wall_Glass'
bpy.data.materials.remove(export_glass)
bpy.ops.object.select_all(action='DESELECT')
scene.camera = bpy.data.objects['MF_Preview_Three_Quarter']
scene.render.resolution_x = 1200
scene.render.resolution_y = 1200
scene.render.resolution_percentage = 100
scene.cycles.samples = 64
scene.render.filepath = str(OUT / 'preview_low_poly.png')
bpy.ops.render.render(write_still=True)
scene.render.filepath = '//preview_low_poly.png'
mesh_items = mesh_objects()
minimum, maximum = bounds(mesh_items)
low_dimensions = [maximum[axis] - minimum[axis] for axis in range(3)]
non_manifold = {}
depsgraph = bpy.context.evaluated_depsgraph_get()
for name in ['MF_White_Housing', 'MF_Jug_Outer', 'MF_Handle_Frame', 'MF_Start_Button', 'MF_Lid_Clear_Disk', 'MF_Whisk_Teeth']:
obj = bpy.data.objects[name]
evaluated = obj.evaluated_get(depsgraph)
mesh = evaluated.to_mesh()
bm = bmesh.new()
bm.from_mesh(mesh)
non_manifold[name] = sum(not edge.is_manifold for edge in bm.edges)
bm.free()
evaluated.to_mesh_clear()
support_min, support_max = bounds([bpy.data.objects['MF_Base_Support_Pad']])
jug_min, jug_max = bounds([bpy.data.objects['MF_Jug_Outer']])
label = bpy.data.objects['MF_Fill_Text_Maximum_0.211']
rotation = label.matrix_world.to_quaternion()
report = {
'source_blend': SOURCE.name,
'source_sha256': source_hash,
'source_unchanged': hashlib.sha256(SOURCE.read_bytes()).hexdigest() == source_hash,
'source_triangles': source_triangles,
'low_blend': LOW.name,
'low_glb': GLB.name,
'target_triangle_range': [TARGET_MIN, TARGET_MAX],
'evaluated_triangles': low_triangles,
'triangle_reduction_percent': (1.0 - low_triangles / source_triangles) * 100.0,
'mesh_objects': len(mesh_items),
'source_mesh_objects': 64,
'dimensions_m': low_dimensions,
'source_dimensions_m': source_dimensions,
'bounds_min_m': minimum,
'bounds_max_m': maximum,
'handle_bevel_segments': handle_bevel_segments,
'spout_integrated': True,
'spout_max_extension_m': spout_extension,
'separate_spout_patch_present': bpy.data.objects.get('MF_Pour_Spout') is not None,
'jug_seat_z_m': jug_min[2],
'base_support_top_z_m': support_max[2],
'assembly_contact_gap_m': jug_min[2] - support_max[2],
'fill_level_labels_bottom_to_top': ['Minimum', 'Half', 'Maximum'],
'fill_text_screen_right_vector': list(rotation @ Vector((1, 0, 0))),
'fill_text_up_vector': list(rotation @ Vector((0, 1, 0))),
'fill_text_outward_normal': list(rotation @ Vector((0, 0, 1))),
'handle_open_bottom': bpy.data.objects.get('MF_Handle_Mount_Lower') is None,
'handle_and_button_on_positive_y': bpy.data.objects['MF_Start_Button'].location.y > 0,
'component_files': {
'base': [BASE_BLEND.name, BASE_GLB.name],
'jug': [JUG_BLEND.name, JUG_GLB.name],
'shared_assembled_coordinates': True,
'lid_and_handle_follow_jug': bpy.data.objects['MF_Lid_Assembly'].parent == jug_root and handle.parent == jug_root,
},
'required_parts': {
name: bpy.data.objects.get(name) is not None for name in [
'MF_White_Housing', 'MF_Chrome_Base', 'MF_Neck_Collar', 'MF_Jug_Outer',
'MF_Handle_Frame', 'MF_Start_Button', 'MF_Lid_Clear_Disk',
'MF_Measuring_Cap', 'MF_Whisk_Notched_Ring', 'MF_Whisk_Teeth', 'MF_Base_Support_Pad',
]
},
'key_part_non_manifold_edges': non_manifold,
'studio_ground_present': bpy.data.objects.get('MF_Studio_Ground') is not None,
'preview': 'preview_low_poly.png',
'comparison_views': [
'comparison_three_quarter.png', 'comparison_front.png', 'comparison_back.png',
'comparison_side.png', 'comparison_open.png', 'comparison_separated.png', 'comparison_measurements.png',
],
'comparison_layout': 'High detail left; low poly right',
}
report['passed'] = (
report['source_unchanged']
and TARGET_MIN <= low_triangles <= TARGET_MAX
and all(report['required_parts'].values())
and all(math.isclose(a, b, abs_tol=1e-6) for a, b in zip(low_dimensions, source_dimensions))
and spout_extension > 0.009
and not report['separate_spout_patch_present']
and abs(report['assembly_contact_gap_m']) < 1e-6
and report['handle_open_bottom']
and report['handle_and_button_on_positive_y']
and report['component_files']['lid_and_handle_follow_jug']
and (Vector(report['fill_text_screen_right_vector']) - Vector((1, 0, 0))).length < 1e-6
and (Vector(report['fill_text_up_vector']) - Vector((0, 0, 1))).length < 1e-6
and (Vector(report['fill_text_outward_normal']) - Vector((0, -1, 0))).length < 1e-6
and all(value == 0 for value in non_manifold.values())
and not report['studio_ground_present']
)
assert report['passed']
REPORT.write_text(json.dumps(report, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
bpy.ops.wm.save_as_mainfile(filepath=str(LOW), compress=True)
def save_component(excluded_assembly, filename):
bpy.ops.wm.open_mainfile(filepath=str(LOW))
excluded = bpy.data.objects[excluded_assembly]
for obj in list(excluded.children_recursive) + [excluded]:
bpy.data.objects.remove(obj, do_unlink=True)
bpy.ops.wm.save_as_mainfile(filepath=str(OUT / filename), compress=True)
save_component('MF_Jug_Assembly', BASE_BLEND.name)
save_component('MF_Base_Assembly', JUG_BLEND.name)
bpy.ops.wm.open_mainfile(filepath=str(LOW))
scene = bpy.context.scene
low_root = bpy.data.objects['MilkFrother_Root']
with bpy.data.libraries.load(str(SOURCE), link=False) as (source, destination):
destination.collections = ['MF_MilkFrother_Model']
high_collection = destination.collections[0]
scene.collection.children.link(high_collection)
def high_object(name):
return next(obj for obj in high_collection.all_objects if obj.name == name or obj.name.startswith(name + '.'))
high_root = high_object('MilkFrother_Root')
comparison_camera = bpy.data.objects['MF_Preview_Three_Quarter']
scene.camera = comparison_camera
scene.render.resolution_x = 1600
scene.render.resolution_y = 1000
scene.cycles.samples = 64
def reset_pair(camera_location, target, spacing):
direction = (Vector(target) - Vector(camera_location)).normalized()
right = direction.cross(Vector((0, 0, 1))).normalized()
high_root.location = -right * spacing
low_root.location = right * spacing
for current_root in (low_root, high_root):
current_root.location.z = 0
for name in ('MF_Jug_Assembly', 'MF_Lid_Assembly'):
bpy.data.objects[name].location = (0, 0, 0)
high_object(name).location = (0, 0, 0)
bpy.context.view_layer.update()
def render_comparison(filename, camera_location, target, ortho, state='assembled', spacing=0.17):
reset_pair(camera_location, target, spacing)
if state == 'open':
for name in ('MF_Lid_Assembly',):
bpy.data.objects[name].location = (-0.105, 0, 0.078)
high_object(name).location = (-0.105, 0, 0.078)
elif state == 'separated':
for name in ('MF_Jug_Assembly',):
bpy.data.objects[name].location.z = 0.090
high_object(name).location.z = 0.090
elif state == 'measurements':
for name in ('MF_Lid_Assembly',):
for obj in bpy.data.objects[name].children_recursive:
obj.hide_render = True
for obj in high_object(name).children_recursive:
obj.hide_render = True
bpy.context.view_layer.update()
comparison_camera.location = camera_location
comparison_camera.rotation_euler = (Vector(target) - comparison_camera.location).to_track_quat('-Z', 'Y').to_euler()
comparison_camera.data.ortho_scale = ortho
scene.render.filepath = str(OUT / filename)
bpy.ops.render.render(write_still=True)
render_comparison('comparison_three_quarter.png', (0.30, 0.48, 0.32), (0, 0, 0.122), 0.56)
render_comparison('comparison_front.png', (0, 0.60, 0.145), (0, 0, 0.122), 0.54)
render_comparison('comparison_back.png', (0, -0.60, 0.145), (0, 0, 0.122), 0.54)
render_comparison('comparison_side.png', (-0.60, 0.04, 0.160), (0, 0, 0.122), 0.64)
render_comparison('comparison_open.png', (0.16, 0.20, 0.50), (0, 0, 0.155), 0.62, 'open')
render_comparison('comparison_separated.png', (0.30, 0.48, 0.36), (0, 0, 0.170), 0.62, 'separated')
scene.render.resolution_y = 700
render_comparison('comparison_measurements.png', (0.13, -0.20, 0.245), (0, -0.052, 0.193), 0.42, 'measurements', 0.13)
print('LOW_POLY_BUILD_COMPLETE', json.dumps({
'triangles': low_triangles,
'mesh_objects': report['mesh_objects'],
'reduction_percent': report['triangle_reduction_percent'],
'dimensions_m': low_dimensions,
'comparison_views': report['comparison_views'],
}, ensure_ascii=False), flush=True)