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:
Binary file not shown.
@@ -0,0 +1,765 @@
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
|
||||
import bmesh
|
||||
import bpy
|
||||
from mathutils import Vector
|
||||
from mathutils.bvhtree import BVHTree
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
PROJECT_ROOT = ROOT.parent.parent
|
||||
MACHINE_SOURCE = PROJECT_ROOT / 'model_assets' / 'coffee_machine' / 'PerfectCoffee_CoffeeMachine.blend'
|
||||
CUP_SOURCE = PROJECT_ROOT / 'model_assets' / 'coffee_cup' / 'PerfectCoffee_CupContents.blend'
|
||||
BLEND_OUT = ROOT / 'PerfectCoffee_Extraction_AnimationTest.blend'
|
||||
FPS = 30
|
||||
FRAME_END = 1350
|
||||
Q_MAX = 30.0
|
||||
LEVER_OPEN = 0.30
|
||||
FLOW = Q_MAX * LEVER_OPEN
|
||||
SATURATION_ML = 60.0
|
||||
T_START = 2.0
|
||||
T_SATURATED = (T_START * FPS + round(SATURATION_ML / FLOW * FPS)) / FPS
|
||||
T_CLOSE = 42.0
|
||||
T_CLOSED = 42.25
|
||||
BREW_Y = -0.237
|
||||
TRAY_Z = 0.098
|
||||
SPOUT_Z = 0.224034
|
||||
SPOUTS = [(-0.014, 'Left'), (0.014, 'Right')]
|
||||
CUP_PARK_X = 0.145
|
||||
CUP_INNER_RIM = 0.0405
|
||||
STREAM_RADIUS = 0.00135
|
||||
LIQUID_BOTTOM = 0.0022
|
||||
LIQUID_TOP = 0.1038
|
||||
LIQUID_BOTTOM_RADIUS = 0.0278
|
||||
LIQUID_TOP_RADIUS = 0.0392
|
||||
|
||||
source_hashes = {
|
||||
'machine': hashlib.sha256(MACHINE_SOURCE.read_bytes()).hexdigest(),
|
||||
'cup_contents': hashlib.sha256(CUP_SOURCE.read_bytes()).hexdigest(),
|
||||
}
|
||||
|
||||
bpy.ops.wm.open_mainfile(filepath=str(MACHINE_SOURCE))
|
||||
bpy.context.preferences.filepaths.save_version = 0
|
||||
scene = bpy.context.scene
|
||||
scene.name = 'PerfectCoffee_Extraction_AnimationTest'
|
||||
scene.render.fps = FPS
|
||||
scene.frame_start = 1
|
||||
scene.frame_end = FRAME_END
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.length_unit = 'METERS'
|
||||
scene.unit_settings.scale_length = 1.0
|
||||
|
||||
for obj in list(bpy.data.objects):
|
||||
if obj.type == 'CAMERA':
|
||||
bpy.data.objects.remove(obj, do_unlink=True)
|
||||
|
||||
rigs = bpy.data.collections.new('AT_01_Godot_Anchors')
|
||||
visuals = bpy.data.collections.new('AT_02_TestOnly_Cutaway_And_Liquid')
|
||||
hud = bpy.data.collections.new('AT_03_TestOnly_HUD')
|
||||
for collection in [rigs, visuals, hud]:
|
||||
scene.collection.children.link(collection)
|
||||
|
||||
machine = bpy.data.objects['CM_CoffeeMachine']
|
||||
portafilter = bpy.data.objects['CM_Portafilter']
|
||||
controller = bpy.data.objects['CM_ControlState']
|
||||
controller['temperature_c'] = 92.0
|
||||
controller['hot_water_open'] = 0.60
|
||||
controller['brew_flow'] = 0.0
|
||||
|
||||
|
||||
def link_object(obj, collection):
|
||||
for old in list(obj.users_collection):
|
||||
old.objects.unlink(obj)
|
||||
collection.objects.link(obj)
|
||||
return obj
|
||||
|
||||
|
||||
def parent_keep(obj, parent):
|
||||
bpy.context.view_layer.update()
|
||||
matrix = obj.matrix_world.copy()
|
||||
obj.parent = parent
|
||||
obj.matrix_world = matrix
|
||||
|
||||
|
||||
def material(name, color, roughness=0.4, metallic=0.0, emission=False):
|
||||
mat = bpy.data.materials.new(name)
|
||||
mat.use_nodes = True
|
||||
mat.diffuse_color = (*color, 1.0)
|
||||
nodes = mat.node_tree.nodes
|
||||
nodes.clear()
|
||||
output = nodes.new('ShaderNodeOutputMaterial')
|
||||
if emission:
|
||||
shader = nodes.new('ShaderNodeEmission')
|
||||
shader.inputs['Color'].default_value = (*color, 1.0)
|
||||
shader.inputs['Strength'].default_value = 1.0
|
||||
else:
|
||||
shader = nodes.new('ShaderNodeBsdfPrincipled')
|
||||
shader.inputs['Base Color'].default_value = (*color, 1.0)
|
||||
shader.inputs['Roughness'].default_value = roughness
|
||||
shader.inputs['Metallic'].default_value = metallic
|
||||
mat.node_tree.links.new(shader.outputs[0], output.inputs['Surface'])
|
||||
return mat
|
||||
|
||||
|
||||
coffee_mat = material('AT_Coffee_Stream', (0.030, 0.0075, 0.0020), 0.24)
|
||||
coffee_side_mat = material('AT_Coffee_Volume', (0.014, 0.0038, 0.0012), 0.28)
|
||||
crema_mat = material('AT_Crema_Surface', (0.095, 0.031, 0.0065), 0.34)
|
||||
water_mat = material('AT_Preinfusion_Water', (0.08, 0.38, 0.52), 0.18, emission=True)
|
||||
puck_mat = material('AT_Puck_Wetness', (0.20, 0.068, 0.018), 0.88)
|
||||
ripple_mat = material('AT_Ripple', (0.18, 0.065, 0.014), 0.32)
|
||||
white_hud = material('AT_HUD_White', (0.91, 0.95, 0.91), emission=True)
|
||||
muted_hud = material('AT_HUD_Muted', (0.61, 0.72, 0.68), emission=True)
|
||||
accent_hud = material('AT_HUD_Accent', (0.62, 0.88, 0.67), emission=True)
|
||||
dark_hud = material('AT_HUD_Backdrop', (0.014, 0.025, 0.022), emission=True)
|
||||
|
||||
|
||||
def smooth(value):
|
||||
value = max(0.0, min(1.0, value))
|
||||
return value * value * (3.0 - 2.0 * value)
|
||||
|
||||
|
||||
def cup_x_at(t):
|
||||
if t < 1.2:
|
||||
return CUP_PARK_X
|
||||
if t < 1.8:
|
||||
return CUP_PARK_X * (1.0 - smooth((t - 1.2) / 0.6))
|
||||
if t < 15.0:
|
||||
return 0.0
|
||||
if t < 15.5:
|
||||
return CUP_PARK_X * smooth((t - 15.0) / 0.5)
|
||||
if t < 18.0:
|
||||
return CUP_PARK_X
|
||||
if t < 18.5:
|
||||
return CUP_PARK_X * (1.0 - smooth((t - 18.0) / 0.5))
|
||||
if t < 42.25:
|
||||
return 0.0
|
||||
if t < 42.85:
|
||||
return CUP_PARK_X * smooth((t - 42.25) / 0.6)
|
||||
return CUP_PARK_X
|
||||
|
||||
|
||||
def lever_at(t):
|
||||
if t < 1.70:
|
||||
return 0.0
|
||||
if t < T_START:
|
||||
return LEVER_OPEN * (t - 1.70) / (T_START - 1.70)
|
||||
if t <= T_CLOSE:
|
||||
return LEVER_OPEN
|
||||
if t < T_CLOSED:
|
||||
return LEVER_OPEN * (T_CLOSED - t) / (T_CLOSED - T_CLOSE)
|
||||
return 0.0
|
||||
|
||||
|
||||
def machine_flow_at(t):
|
||||
if t < T_START:
|
||||
return 0.0
|
||||
return Q_MAX * lever_at(t)
|
||||
|
||||
|
||||
def machine_volume_at(t):
|
||||
if t <= T_SATURATED:
|
||||
return 0.0
|
||||
if t <= T_CLOSE:
|
||||
return (t - T_SATURATED) * FLOW
|
||||
full = (T_CLOSE - T_SATURATED) * FLOW
|
||||
if t >= T_CLOSED:
|
||||
return full + FLOW * (T_CLOSED - T_CLOSE) / 2.0
|
||||
dt = t - T_CLOSE
|
||||
duration = T_CLOSED - T_CLOSE
|
||||
return full + FLOW * (dt - dt * dt / (2.0 * duration))
|
||||
|
||||
|
||||
def catches_at(t):
|
||||
x = cup_x_at(t)
|
||||
result = []
|
||||
for spout_x, _ in SPOUTS:
|
||||
distance = math.hypot(spout_x - x, 0.0)
|
||||
result.append(distance <= CUP_INNER_RIM - STREAM_RADIUS)
|
||||
return result
|
||||
|
||||
|
||||
def frustum_ml(factor):
|
||||
factor = max(0.0, min(1.0, factor))
|
||||
height = (LIQUID_TOP - LIQUID_BOTTOM) * factor
|
||||
radius = LIQUID_BOTTOM_RADIUS + (LIQUID_TOP_RADIUS - LIQUID_BOTTOM_RADIUS) * factor
|
||||
return math.pi * height * (radius * radius + radius * LIQUID_BOTTOM_RADIUS + LIQUID_BOTTOM_RADIUS * LIQUID_BOTTOM_RADIUS) / 3.0 * 1e6
|
||||
|
||||
|
||||
CUP_MAX_ML = frustum_ml(1.0)
|
||||
|
||||
|
||||
def fill_factor(volume_ml):
|
||||
if volume_ml <= 0.0:
|
||||
return 0.0
|
||||
low = 0.0
|
||||
high = 1.0
|
||||
for _ in range(32):
|
||||
middle = (low + high) / 2.0
|
||||
if frustum_ml(middle) < volume_ml:
|
||||
low = middle
|
||||
else:
|
||||
high = middle
|
||||
return (low + high) / 2.0
|
||||
|
||||
|
||||
states = {}
|
||||
cup_volume = 0.0
|
||||
for frame in range(1, FRAME_END + 1):
|
||||
t = (frame - 1) / FPS
|
||||
if frame > 1:
|
||||
middle_t = t - 0.5 / FPS
|
||||
middle_q = machine_flow_at(middle_t) if middle_t > T_SATURATED else 0.0
|
||||
middle_catches = catches_at(middle_t)
|
||||
cup_volume += middle_q * sum(middle_catches) / 2.0 / FPS
|
||||
preinfusion = min(max(0.0, t - T_START), T_SATURATED - T_START)
|
||||
absorbed = min(SATURATION_ML, max(0.0, t - T_START) * FLOW)
|
||||
catches = catches_at(t)
|
||||
q = machine_flow_at(t)
|
||||
states[frame] = {
|
||||
'time': t,
|
||||
'cup_x': cup_x_at(t),
|
||||
'lever': lever_at(t),
|
||||
'flow': q,
|
||||
'absorbed': absorbed,
|
||||
'preinfusion': preinfusion,
|
||||
'machine_volume': machine_volume_at(t),
|
||||
'cup_volume': cup_volume,
|
||||
'catches': catches,
|
||||
'fill': fill_factor(cup_volume),
|
||||
'extraction': t >= T_SATURATED,
|
||||
}
|
||||
|
||||
cup_rig = bpy.data.objects.new('AT_CupRig', None)
|
||||
rigs.objects.link(cup_rig)
|
||||
cup_rig.empty_display_type = 'PLAIN_AXES'
|
||||
cup_rig.empty_display_size = 0.025
|
||||
cup_rig['purpose'] = 'Move this transform in Godot; bottom remains on the drip tray.'
|
||||
cup_rig['support_z_m'] = TRAY_Z
|
||||
cup_rig['collection_rule'] = 'Each spout integrates flow only while its vertical projection is inside the cup opening.'
|
||||
|
||||
with bpy.data.libraries.load(str(CUP_SOURCE), link=False) as (data_from, data_to):
|
||||
data_to.objects = ['CC_Cup_Body']
|
||||
cup_proxy = data_to.objects[0]
|
||||
visuals.objects.link(cup_proxy)
|
||||
cup_proxy.name = 'AT_Cup_CollisionProxy_Full'
|
||||
cup_proxy.parent = cup_rig
|
||||
cup_proxy.location = (0.0, 0.0, 0.0)
|
||||
cup_proxy.rotation_euler = (0.0, 0.0, 0.0)
|
||||
cup_proxy.scale = (1.0, 1.0, 1.0)
|
||||
cup_proxy.hide_render = True
|
||||
cup_proxy.display_type = 'WIRE'
|
||||
cup_proxy.hide_set(True)
|
||||
|
||||
|
||||
def cut_front(obj, plane_y):
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(obj.data)
|
||||
bmesh.ops.bisect_plane(
|
||||
bm,
|
||||
geom=list(bm.verts) + list(bm.edges) + list(bm.faces),
|
||||
dist=0.0000001,
|
||||
plane_co=(0.0, plane_y, 0.0),
|
||||
plane_no=(0.0, 1.0, 0.0),
|
||||
clear_inner=True,
|
||||
clear_outer=False,
|
||||
)
|
||||
cut_edges = [
|
||||
edge for edge in bm.edges
|
||||
if edge.is_boundary and all(abs(vertex.co.y - plane_y) < 0.00001 for vertex in edge.verts)
|
||||
]
|
||||
if cut_edges:
|
||||
bmesh.ops.holes_fill(bm, edges=cut_edges, sides=0)
|
||||
bmesh.ops.recalc_face_normals(bm, faces=list(bm.faces))
|
||||
bm.to_mesh(obj.data)
|
||||
bm.free()
|
||||
obj.data.update()
|
||||
obj['test_only_cutaway'] = True
|
||||
|
||||
|
||||
cup_cutaway = bpy.data.objects.new('AT_Cup_Cutaway', cup_proxy.data.copy())
|
||||
visuals.objects.link(cup_cutaway)
|
||||
cup_cutaway.parent = cup_rig
|
||||
cut_front(cup_cutaway, 0.0)
|
||||
assert min(vertex.co.y for vertex in cup_cutaway.data.vertices) > -0.00001, 'Cup cutaway kept the wrong half.'
|
||||
|
||||
for name in [
|
||||
'CM_Portafilter_Bowl',
|
||||
'CM_GroupHead_Bell',
|
||||
'CM_GroupHead_SealingSeat',
|
||||
'CM_GroupHead_Gasket',
|
||||
'CM_GroupHead_ShowerScreen',
|
||||
]:
|
||||
obj = bpy.data.objects[name]
|
||||
obj.data = obj.data.copy()
|
||||
cut_front(obj, BREW_Y)
|
||||
|
||||
|
||||
def half_frustum(name, bottom_z, top_z, bottom_radius, top_radius, collection, materials):
|
||||
count = 20
|
||||
angles = [math.pi * index / count for index in range(count + 1)]
|
||||
vertices = []
|
||||
for radius, z in [(bottom_radius, bottom_z), (bottom_radius, bottom_z)]:
|
||||
vertices.extend((radius * math.cos(angle), radius * math.sin(angle), z) for angle in angles)
|
||||
vertices.extend([(0.0, 0.0, bottom_z), (0.0, 0.0, bottom_z)])
|
||||
bottom_center = len(vertices) - 2
|
||||
top_center = len(vertices) - 1
|
||||
top_offset = count + 1
|
||||
faces = []
|
||||
material_indices = []
|
||||
for index in range(count):
|
||||
faces.append((index, index + 1, top_offset + index + 1, top_offset + index))
|
||||
material_indices.append(0)
|
||||
faces.append((top_center, top_offset + index, top_offset + index + 1))
|
||||
material_indices.append(min(1, len(materials) - 1))
|
||||
faces.append((bottom_center, index + 1, index))
|
||||
material_indices.append(0)
|
||||
faces.extend([
|
||||
(bottom_center, 0, top_offset, top_center),
|
||||
(bottom_center, top_center, top_offset + count, count),
|
||||
])
|
||||
material_indices.extend([0, 0])
|
||||
mesh = bpy.data.meshes.new(name + '_Mesh')
|
||||
mesh.from_pydata(vertices, [], faces)
|
||||
mesh.update()
|
||||
for mat in materials:
|
||||
mesh.materials.append(mat)
|
||||
for polygon, material_index in zip(mesh.polygons, material_indices):
|
||||
polygon.material_index = material_index
|
||||
polygon.use_smooth = len(polygon.vertices) == 4 and polygon.index < count * 3 and polygon.index % 3 == 0
|
||||
obj = bpy.data.objects.new(name, mesh)
|
||||
collection.objects.link(obj)
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(mesh)
|
||||
bmesh.ops.recalc_face_normals(bm, faces=list(bm.faces))
|
||||
bm.to_mesh(mesh)
|
||||
bm.free()
|
||||
obj.shape_key_add(name='Basis')
|
||||
full = obj.shape_key_add(name='Full')
|
||||
for index, angle in enumerate(angles):
|
||||
full.data[top_offset + index].co = (top_radius * math.cos(angle), top_radius * math.sin(angle), top_z)
|
||||
full.data[top_center].co = (0.0, 0.0, top_z)
|
||||
full.value = 1.0
|
||||
return obj, full
|
||||
|
||||
|
||||
liquid, liquid_fill = half_frustum(
|
||||
'AT_CupLiquid_Cutaway', LIQUID_BOTTOM, LIQUID_TOP,
|
||||
LIQUID_BOTTOM_RADIUS, LIQUID_TOP_RADIUS, visuals,
|
||||
[coffee_side_mat, crema_mat],
|
||||
)
|
||||
liquid.parent = cup_rig
|
||||
liquid['volume_to_shape'] = 'Solve frustum volume; Full.value is geometric fill, not extraction time.'
|
||||
liquid['maximum_visual_volume_ml'] = CUP_MAX_ML
|
||||
|
||||
puck, _ = half_frustum(
|
||||
'AT_CoffeePuck_Cutaway', 0.0, 0.012,
|
||||
0.0285, 0.0285, visuals, [puck_mat],
|
||||
)
|
||||
puck.location = (0.0, BREW_Y, 0.264)
|
||||
parent_keep(puck, portafilter)
|
||||
puck['purpose'] = 'Test-only visual: dry to wet during saturation; no coffee output before W=A.'
|
||||
|
||||
|
||||
def cylinder(name, radius, depth, mat, collection, location=(0.0, 0.0, 0.0), vertices=20):
|
||||
bpy.ops.mesh.primitive_cylinder_add(vertices=vertices, radius=radius, depth=depth, location=location)
|
||||
obj = bpy.context.object
|
||||
obj.name = name
|
||||
link_object(obj, collection)
|
||||
obj.data.materials.append(mat)
|
||||
for polygon in obj.data.polygons:
|
||||
polygon.use_smooth = len(polygon.vertices) == 4
|
||||
return obj
|
||||
|
||||
|
||||
streams = {}
|
||||
for spout_x, suffix in SPOUTS:
|
||||
stream = cylinder('AT_CoffeeStream_' + suffix, 1.0, 1.0, coffee_mat, visuals)
|
||||
stream['source_anchor'] = 'AT_Spout' + suffix + '_Anchor'
|
||||
stream['visibility_rule'] = 'Saturated AND brew_flow>0; independent of cup position.'
|
||||
streams[suffix] = stream
|
||||
splash = cylinder('AT_TraySplash_' + suffix, 0.008, 0.00035, coffee_side_mat, visuals, vertices=24)
|
||||
streams[suffix + '_Splash'] = splash
|
||||
bpy.ops.mesh.primitive_torus_add(major_radius=0.0042, minor_radius=0.00042, major_segments=24, minor_segments=6)
|
||||
ripple = bpy.context.object
|
||||
ripple.name = 'AT_CupRipple_' + suffix
|
||||
link_object(ripple, visuals)
|
||||
ripple.data.materials.append(ripple_mat)
|
||||
streams[suffix + '_Ripple'] = ripple
|
||||
|
||||
inlet = cylinder('AT_Preinfusion_Inlet', 1.0, 1.0, water_mat, visuals)
|
||||
inlet.location = (0.0, BREW_Y, (0.2875 + 0.276) / 2.0)
|
||||
inlet.scale = (0.0015, 0.0015, 0.0115)
|
||||
|
||||
for name, location, parent in [
|
||||
('AT_BrewCenter_Anchor', (0.0, BREW_Y, TRAY_Z), machine),
|
||||
('AT_SpoutLeft_Anchor', (-0.014, BREW_Y, SPOUT_Z), portafilter),
|
||||
('AT_SpoutRight_Anchor', (0.014, BREW_Y, SPOUT_Z), portafilter),
|
||||
]:
|
||||
anchor = bpy.data.objects.new(name, None)
|
||||
rigs.objects.link(anchor)
|
||||
anchor.location = location
|
||||
anchor.empty_display_size = 0.008
|
||||
parent_keep(anchor, parent)
|
||||
|
||||
cup_bottom_anchor = bpy.data.objects.new('AT_CupBottom_Anchor', None)
|
||||
rigs.objects.link(cup_bottom_anchor)
|
||||
cup_bottom_anchor.parent = cup_rig
|
||||
cup_bottom_anchor.empty_display_size = 0.008
|
||||
cup_surface_anchor = bpy.data.objects.new('AT_CupLiquidSurface_Anchor', None)
|
||||
rigs.objects.link(cup_surface_anchor)
|
||||
cup_surface_anchor.parent = cup_rig
|
||||
cup_surface_anchor.empty_display_size = 0.008
|
||||
|
||||
for frame, state in states.items():
|
||||
cup_rig.location = (state['cup_x'], BREW_Y, TRAY_Z)
|
||||
cup_rig.keyframe_insert(data_path='location', frame=frame, group='Cup_Translation')
|
||||
controller['brew_flow'] = state['lever']
|
||||
controller.keyframe_insert(data_path='["brew_flow"]', frame=frame, group='Brew_Control')
|
||||
liquid_fill.value = state['fill']
|
||||
liquid_fill.keyframe_insert(data_path='value', frame=frame)
|
||||
liquid_height = LIQUID_BOTTOM + (LIQUID_TOP - LIQUID_BOTTOM) * state['fill']
|
||||
cup_surface_anchor.location = (0.0, 0.0, liquid_height)
|
||||
cup_surface_anchor.keyframe_insert(data_path='location', frame=frame)
|
||||
wet = state['absorbed'] / SATURATION_ML
|
||||
dry = Vector((0.20, 0.068, 0.018))
|
||||
soaked = Vector((0.022, 0.0055, 0.0015))
|
||||
color = dry.lerp(soaked, wet)
|
||||
bsdf = puck_mat.node_tree.nodes.get('Principled BSDF')
|
||||
bsdf.inputs['Base Color'].default_value = (*color, 1.0)
|
||||
bsdf.inputs['Base Color'].keyframe_insert(data_path='default_value', frame=frame)
|
||||
puck_mat.diffuse_color = (*color, 1.0)
|
||||
puck_mat.keyframe_insert(data_path='diffuse_color', frame=frame)
|
||||
inlet_scale = 0.0015 * math.sqrt(state['flow'] / FLOW) if state['flow'] > 0.0 else 0.0
|
||||
inlet.scale = (inlet_scale, inlet_scale, 0.0115 if state['flow'] > 0.0 else 0.0)
|
||||
inlet.keyframe_insert(data_path='scale', frame=frame)
|
||||
for spout_x, suffix in SPOUTS:
|
||||
caught = state['catches'][0 if suffix == 'Left' else 1]
|
||||
target_z = TRAY_Z + (liquid_height if caught else 0.0004)
|
||||
length = max(0.0001, SPOUT_Z - target_z)
|
||||
pulse = 1.0 + 0.055 * math.sin(state['time'] * 37.0 + (0.0 if suffix == 'Left' else 1.3))
|
||||
radius = STREAM_RADIUS * math.sqrt(state['flow'] / FLOW) * pulse if state['extraction'] and state['flow'] > 0.0 else 0.0
|
||||
stream = streams[suffix]
|
||||
stream.location = (spout_x, BREW_Y, target_z + length / 2.0)
|
||||
stream.scale = (radius, radius, length if radius > 0.0 else 0.0)
|
||||
stream.keyframe_insert(data_path='location', frame=frame, group='Coffee_Stream')
|
||||
stream.keyframe_insert(data_path='scale', frame=frame, group='Coffee_Stream')
|
||||
splash = streams[suffix + '_Splash']
|
||||
splash.location = (spout_x, BREW_Y, TRAY_Z + 0.00035)
|
||||
splash_scale = 1.0 + 0.15 * math.sin(state['time'] * 19.0) if state['extraction'] and state['flow'] > 0.0 and not caught else 0.0
|
||||
splash.scale = (splash_scale, splash_scale, splash_scale)
|
||||
splash.keyframe_insert(data_path='location', frame=frame)
|
||||
splash.keyframe_insert(data_path='scale', frame=frame)
|
||||
ripple = streams[suffix + '_Ripple']
|
||||
ripple.location = (spout_x, BREW_Y, TRAY_Z + liquid_height + 0.0003)
|
||||
ripple_scale = 1.0 + 0.18 * math.sin(state['time'] * 23.0) if state['extraction'] and state['flow'] > 0.0 and caught and state['cup_volume'] > 0.0 else 0.0
|
||||
ripple.scale = (ripple_scale, ripple_scale, ripple_scale)
|
||||
ripple.keyframe_insert(data_path='location', frame=frame)
|
||||
ripple.keyframe_insert(data_path='scale', frame=frame)
|
||||
|
||||
portafilter_keys = [
|
||||
(1, True), (37, False), (1297, False), (1336, True), (FRAME_END, True),
|
||||
]
|
||||
for frame, detached in portafilter_keys:
|
||||
portafilter.location = (0.0, BREW_Y - (0.035 if detached else 0.0), 0.2835 - (0.045 if detached else 0.0))
|
||||
portafilter.rotation_euler = (0.0, 0.0, math.radians(-45.0) if detached else 0.0)
|
||||
portafilter.keyframe_insert(data_path='location', frame=frame, group='Bayonet_Insert_Remove')
|
||||
portafilter.keyframe_insert(data_path='rotation_euler', frame=frame, group='Bayonet_Insert_Remove')
|
||||
|
||||
|
||||
def camera_only(obj):
|
||||
for prop in ['visible_shadow', 'visible_diffuse', 'visible_glossy', 'visible_transmission', 'visible_volume_scatter']:
|
||||
if hasattr(obj, prop):
|
||||
setattr(obj, prop, False)
|
||||
|
||||
|
||||
camera_data = bpy.data.cameras.new('AT_TestCamera')
|
||||
camera = bpy.data.objects.new('AT_TestCamera', camera_data)
|
||||
hud.objects.link(camera)
|
||||
camera.location = (0.235, -0.735, 0.365)
|
||||
target = Vector((0.015, BREW_Y, 0.195))
|
||||
camera.rotation_euler = (target - camera.location).to_track_quat('-Z', 'Y').to_euler()
|
||||
camera_data.type = 'ORTHO'
|
||||
camera_data.ortho_scale = 0.46
|
||||
camera_data.clip_start = 0.001
|
||||
camera_data.clip_end = 100.0
|
||||
scene.camera = camera
|
||||
|
||||
font_paths = [
|
||||
Path('/System/Library/Fonts/PingFang.ttc'),
|
||||
Path('/System/Library/Fonts/Hiragino Sans GB.ttc'),
|
||||
Path('/System/Library/Fonts/Supplemental/Arial.ttf'),
|
||||
]
|
||||
font = None
|
||||
for font_path in font_paths:
|
||||
if font_path.exists():
|
||||
font = bpy.data.fonts.load(str(font_path))
|
||||
break
|
||||
|
||||
|
||||
def hud_text(name, body, x, y, size, mat=white_hud, align='LEFT'):
|
||||
curve = bpy.data.curves.new(name + '_Font', 'FONT')
|
||||
curve.body = body
|
||||
curve.size = size
|
||||
curve.align_x = align
|
||||
curve.align_y = 'CENTER'
|
||||
curve.resolution_u = 3
|
||||
if font is not None:
|
||||
curve.font = font
|
||||
obj = bpy.data.objects.new(name, curve)
|
||||
hud.objects.link(obj)
|
||||
obj.parent = camera
|
||||
obj.location = (x, y, -0.06)
|
||||
obj.rotation_euler = (0.0, 0.0, 0.0)
|
||||
obj.data.materials.append(mat)
|
||||
camera_only(obj)
|
||||
return obj
|
||||
|
||||
|
||||
def hud_backdrop(name, y, height):
|
||||
mesh = bpy.data.meshes.new(name + '_Mesh')
|
||||
mesh.from_pydata([(-0.215, -height / 2.0, 0.0), (0.215, -height / 2.0, 0.0), (0.215, height / 2.0, 0.0), (-0.215, height / 2.0, 0.0)], [], [(0, 1, 2, 3)])
|
||||
obj = bpy.data.objects.new(name, mesh)
|
||||
hud.objects.link(obj)
|
||||
obj.parent = camera
|
||||
obj.location = (0.0, y, -0.065)
|
||||
obj.data.materials.append(dark_hud)
|
||||
camera_only(obj)
|
||||
return obj
|
||||
|
||||
|
||||
def show_during(obj, start, end):
|
||||
for prop in ['hide_render', 'hide_viewport']:
|
||||
setattr(obj, prop, True)
|
||||
obj.keyframe_insert(data_path=prop, frame=max(1, start - 1))
|
||||
setattr(obj, prop, False)
|
||||
obj.keyframe_insert(data_path=prop, frame=start)
|
||||
setattr(obj, prop, True)
|
||||
obj.keyframe_insert(data_path=prop, frame=end + 1)
|
||||
|
||||
|
||||
first_collection_frame = min(frame for frame, state in states.items() if state['cup_volume'] > 0.000001)
|
||||
show_during(liquid, first_collection_frame, FRAME_END)
|
||||
hud_backdrop('AT_HUD_TopBackdrop', 0.116, 0.033)
|
||||
hud_text('AT_HUD_Title', '完美咖啡|咖啡机动作可行性测试', -0.210, 0.122, 0.0068)
|
||||
hud_text('AT_HUD_Mode', '剖视 · 非流体模拟', 0.210, 0.122, 0.0055, muted_hud, 'RIGHT')
|
||||
|
||||
stages = [
|
||||
(1, 36, '01 锁定手柄'),
|
||||
(37, 60, '02 杯子就位'),
|
||||
(61, 260, '03 预浸泡|粉饼吸水,杯中不出液'),
|
||||
(261, 450, '04 萃取|杯子接取咖啡液'),
|
||||
(451, 540, '05 移杯|机器继续出液'),
|
||||
(541, 555, '06 放回杯子|保留已接咖啡'),
|
||||
(556, 1260, '07 继续萃取|杯中液量恢复增长'),
|
||||
(1261, 1296, '08 关水|再移开杯子'),
|
||||
(1297, FRAME_END, '09 取下手柄|结束冲泡'),
|
||||
]
|
||||
for index, (start, end, label) in enumerate(stages):
|
||||
obj = hud_text('AT_Stage_%02d' % index, label, 0.0, 0.105, 0.0085, accent_hud, 'CENTER')
|
||||
show_during(obj, start, end)
|
||||
|
||||
sample_frames = set(range(1, FRAME_END + 1, 15))
|
||||
sample_frames.update([1, 37, 61, 1297, 1336, FRAME_END])
|
||||
for transition_start, transition_end in [(261, 262), (451, 466), (541, 556), (1261, 1270)]:
|
||||
sample_frames.update(range(transition_start, transition_end + 1))
|
||||
sample_frames = sorted(sample_frames)
|
||||
for index, start in enumerate(sample_frames):
|
||||
end = sample_frames[index + 1] - 1 if index + 1 < len(sample_frames) else FRAME_END
|
||||
state = states[start]
|
||||
t = state['time']
|
||||
if t < T_START:
|
||||
first = '水流拨杆 %.0f%% 等待粉饼接触水' % (state['lever'] * 100.0)
|
||||
elif t < T_SATURATED:
|
||||
first = '预浸泡 %.2f s 粉饼吸水 %.1f / 60 mL' % (state['preinfusion'], state['absorbed'])
|
||||
else:
|
||||
extraction_time = min(t, T_CLOSED) - T_SATURATED
|
||||
first = '萃取 %.2f s 机器累计出液 %.1f mL' % (extraction_time, state['machine_volume'])
|
||||
if t < T_SATURATED:
|
||||
second = '杯中 0.0 mL 尚未出液'
|
||||
else:
|
||||
if state['flow'] <= 0.0:
|
||||
collection = '关水暂停'
|
||||
elif all(state['catches']):
|
||||
collection = '两股均接取'
|
||||
elif any(state['catches']):
|
||||
collection = '移杯过渡 · 部分接取'
|
||||
else:
|
||||
collection = '杯子移开 · 液量暂停'
|
||||
second = '杯中 %.1f mL %s 水流 %.1f mL/s' % (state['cup_volume'], collection, state['flow'])
|
||||
white_hud.node_tree.nodes.get('Emission').inputs['Strength'].default_value = 2.0
|
||||
first_obj = hud_text('AT_ReadoutA_%04d' % start, first, -0.205, -0.111, 0.0065, white_hud)
|
||||
second_obj = hud_text('AT_ReadoutB_%04d' % start, second, -0.205, -0.124, 0.0065, white_hud)
|
||||
show_during(first_obj, start, end)
|
||||
show_during(second_obj, start, end)
|
||||
|
||||
for name, frame in [
|
||||
('01_手柄开始锁定', 1), ('02_杯子开始就位', 37),
|
||||
('03_首次接触水_预浸泡计时开始', 61), ('04_粉饼饱和_自动进入萃取', 261),
|
||||
('05_移杯开始', 451), ('06_杯子完全移开', 466),
|
||||
('07_杯子开始放回', 541), ('08_杯子重新就位', 556),
|
||||
('09_开始关水', 1261), ('10_水流完全关闭', 1269),
|
||||
('11_取手柄开始', 1297), ('12_测试结束', FRAME_END),
|
||||
]:
|
||||
scene.timeline_markers.new(name, frame=frame)
|
||||
|
||||
notes = '''PERFECT COFFEE — GODOT IMPLEMENTATION NOTES
|
||||
|
||||
Purpose: animation and spatial feasibility only. The HUD and cutaway meshes are test-only and must not be exported as final art.
|
||||
|
||||
Godot visual anchors (meters, Blender Z-up):
|
||||
AT_BrewCenter_Anchor = (0, -0.237, 0.098)
|
||||
AT_SpoutLeft_Anchor = (-0.014, -0.237, 0.224034) while attached
|
||||
AT_SpoutRight_Anchor = (0.014, -0.237, 0.224034) while attached
|
||||
AT_CupBottom_Anchor follows AT_CupRig.
|
||||
AT_CupLiquidSurface_Anchor follows collected cup volume, not machine extraction time.
|
||||
|
||||
Runtime rules:
|
||||
1. First water contact starts pre-infusion. W integrates q until W=60 mL. Pre-infusion time continues even if q=0.
|
||||
2. At W=60 mL, immediately enter extraction. No unlock animation or confirmation gate exists.
|
||||
3. Coffee output requires saturated puck and q>0. Moving the cup never closes the machine valve.
|
||||
4. Test each spout independently against the cup opening. Integrate collected volume only for the stream segments that enter the cup.
|
||||
5. When the cup is away, cup liquid and cup collection stop; machine extraction, machine output and total waiting time continue.
|
||||
6. Replacing the cup resumes collection without clearing existing cup contents.
|
||||
7. Close flow fully before removing the portafilter. The cup moves aside before removal to preserve physical clearance.
|
||||
|
||||
Animation versus logic:
|
||||
Do not use AnimationPlayer animation_finished as the extraction state machine. Compute deterministic state in GDScript, then drive stream visibility, liquid shape, gauges and portafilter/cup transforms from that state. Use ray casts or spout/cup opening tests for the visual stream target. Partial cup contact can be handled per spout, as in this test.
|
||||
|
||||
Test parameters:
|
||||
fps=30; q_max=30 mL/s; lever=0.30; q=9 mL/s; saturation=60 mL; pre-infusion=6.6667 s; B1 reference only. Closing ramp adds 1.125 mL after the 300 mL full-flow point. This video deliberately misses some output while the cup is away and does not claim a perfect score.
|
||||
'''
|
||||
text_block = bpy.data.texts.new('GODOT_IMPLEMENTATION_NOTES')
|
||||
text_block.write(notes)
|
||||
|
||||
scene['test_only'] = True
|
||||
scene['source_machine_sha256'] = source_hashes['machine']
|
||||
scene['source_cup_contents_sha256'] = source_hashes['cup_contents']
|
||||
scene['q_max_ml_s'] = Q_MAX
|
||||
scene['test_lever_open'] = LEVER_OPEN
|
||||
scene['saturation_ml'] = SATURATION_ML
|
||||
scene['preinfusion_seconds'] = T_SATURATED - T_START
|
||||
scene['full_flow_machine_output_ml'] = 300.0
|
||||
scene['closing_ramp_output_ml'] = 1.125
|
||||
scene['cup_max_visual_ml'] = CUP_MAX_ML
|
||||
|
||||
scene.render.engine = 'BLENDER_EEVEE'
|
||||
if hasattr(scene, 'eevee') and hasattr(scene.eevee, 'taa_render_samples'):
|
||||
scene.eevee.taa_render_samples = 16
|
||||
scene.render.resolution_x = 1280
|
||||
scene.render.resolution_y = 720
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.image_settings.file_format = 'PNG'
|
||||
scene.render.image_settings.color_mode = 'RGB'
|
||||
scene.render.filepath = '//frames/frame_'
|
||||
scene.render.use_file_extension = True
|
||||
scene.view_settings.view_transform = 'AgX'
|
||||
scene.view_settings.exposure = -0.15
|
||||
|
||||
brew_light_data = bpy.data.lights.new('AT_Brew_Fill', 'AREA')
|
||||
brew_light_data.energy = 7.0
|
||||
brew_light_data.shape = 'DISK'
|
||||
brew_light_data.size = 0.18
|
||||
brew_light = bpy.data.objects.new('AT_Brew_Fill', brew_light_data)
|
||||
visuals.objects.link(brew_light)
|
||||
brew_light.location = (0.0, -0.42, 0.38)
|
||||
brew_light.rotation_euler = (Vector((0.0, BREW_Y, 0.17)) - brew_light.location).to_track_quat('-Z', 'Y').to_euler()
|
||||
|
||||
|
||||
def world_bvh(obj, depsgraph):
|
||||
evaluated = obj.evaluated_get(depsgraph)
|
||||
mesh = evaluated.to_mesh()
|
||||
vertices = [evaluated.matrix_world @ vertex.co for vertex in mesh.vertices]
|
||||
polygons = [tuple(polygon.vertices) for polygon in mesh.polygons]
|
||||
evaluated.to_mesh_clear()
|
||||
return BVHTree.FromPolygons(vertices, polygons, all_triangles=False)
|
||||
|
||||
|
||||
collision_results = {}
|
||||
for frame, label in [(61, 'centered'), (480, 'parked_right')]:
|
||||
scene.frame_set(frame)
|
||||
bpy.context.view_layer.update()
|
||||
depsgraph = bpy.context.evaluated_depsgraph_get()
|
||||
cup_bvh = world_bvh(cup_proxy, depsgraph)
|
||||
collisions = []
|
||||
for obj in machine.children_recursive:
|
||||
if obj.type not in {'MESH', 'CURVE', 'FONT'} or obj.name == 'CM_DripTray_TextureSurface':
|
||||
continue
|
||||
if cup_bvh.overlap(world_bvh(obj, depsgraph)):
|
||||
collisions.append(obj.name)
|
||||
collision_results[label] = collisions
|
||||
|
||||
scene.frame_set(300)
|
||||
bpy.context.view_layer.update()
|
||||
for screen in bpy.data.screens:
|
||||
for area in screen.areas:
|
||||
if area.type == 'VIEW_3D':
|
||||
area.spaces.active.region_3d.view_perspective = 'CAMERA'
|
||||
area.spaces.active.shading.type = 'MATERIAL'
|
||||
|
||||
assert states[180]['absorbed'] > 0.0 and states[180]['machine_volume'] == 0.0 and states[180]['cup_volume'] == 0.0
|
||||
assert abs(states[261]['preinfusion'] - 6.6666666667) < 0.00001
|
||||
assert states[261]['extraction'] and states[261]['machine_volume'] == 0.0
|
||||
assert not any(states[480]['catches']) and not any(states[540]['catches'])
|
||||
assert abs(states[540]['cup_volume'] - states[480]['cup_volume']) < 0.00001
|
||||
assert states[540]['machine_volume'] > states[480]['machine_volume']
|
||||
assert states[600]['cup_volume'] > states[540]['cup_volume']
|
||||
assert abs(states[1261]['machine_volume'] - 300.0) < 0.00001
|
||||
assert 0.0 < states[1261]['cup_volume'] < 300.0
|
||||
assert states[1270]['flow'] == 0.0
|
||||
assert all(abs(state['cup_x']) <= CUP_PARK_X for state in states.values())
|
||||
assert not collision_results['centered'], collision_results
|
||||
assert not collision_results['parked_right'], collision_results
|
||||
assert hashlib.sha256(MACHINE_SOURCE.read_bytes()).hexdigest() == source_hashes['machine']
|
||||
assert hashlib.sha256(CUP_SOURCE.read_bytes()).hexdigest() == source_hashes['cup_contents']
|
||||
|
||||
report = {
|
||||
'blend': BLEND_OUT.name,
|
||||
'fps': FPS,
|
||||
'frames': [1, FRAME_END],
|
||||
'duration_seconds': FRAME_END / FPS,
|
||||
'source_files_unchanged': True,
|
||||
'source_sha256': source_hashes,
|
||||
'parameters': {
|
||||
'q_max_ml_s': Q_MAX, 'lever_open': LEVER_OPEN, 'flow_ml_s': FLOW,
|
||||
'saturation_ml': SATURATION_ML, 'preinfusion_seconds': T_SATURATED - T_START,
|
||||
'full_flow_machine_output_ml': 300.0, 'closing_ramp_output_ml': 1.125,
|
||||
'cup_max_visual_ml': CUP_MAX_ML,
|
||||
},
|
||||
'key_states': {
|
||||
str(frame): {
|
||||
key: value for key, value in states[frame].items()
|
||||
if key in ['time', 'cup_x', 'flow', 'absorbed', 'preinfusion', 'machine_volume', 'cup_volume', 'catches', 'extraction']
|
||||
} for frame in [61, 180, 261, 451, 480, 540, 600, 1261, 1270]
|
||||
},
|
||||
'cup_collision_free': collision_results,
|
||||
'godot_notes_text_block': 'GODOT_IMPLEMENTATION_NOTES',
|
||||
'test_only_collections': [visuals.name, hud.name],
|
||||
'checks': {
|
||||
'no_output_during_preinfusion': True,
|
||||
'automatic_saturation_transition': True,
|
||||
'cup_away_pauses_only_cup_collection': True,
|
||||
'cup_return_preserves_and_resumes_collection': True,
|
||||
'streams_continue_until_valve_closes': True,
|
||||
'source_assets_not_overwritten': True,
|
||||
},
|
||||
}
|
||||
(ROOT / 'validation.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
bpy.ops.file.pack_all()
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(BLEND_OUT))
|
||||
|
||||
preview_dir = ROOT / 'previews'
|
||||
preview_dir.mkdir(exist_ok=True)
|
||||
scene.render.resolution_x = 960
|
||||
scene.render.resolution_y = 540
|
||||
for frame, name in [
|
||||
(37, '01_cup_ready'), (180, '02_preinfusion'), (270, '03_extraction'),
|
||||
(480, '04_cup_away'), (600, '05_cup_returned'), (1261, '06_close'), (1340, '07_handle_removed'),
|
||||
]:
|
||||
scene.frame_set(frame)
|
||||
scene.render.filepath = str(preview_dir / (name + '.png'))
|
||||
bpy.ops.render.render(write_still=True)
|
||||
|
||||
print('ANIMATION_TEST_VALIDATION=' + json.dumps(report, ensure_ascii=False), flush=True)
|
||||
print('ANIMATION_TEST_BUILD_COMPLETE', flush=True)
|
||||
@@ -0,0 +1,169 @@
|
||||
{
|
||||
"blend": "PerfectCoffee_Extraction_AnimationTest.blend",
|
||||
"fps": 30,
|
||||
"frames": [
|
||||
1,
|
||||
1350
|
||||
],
|
||||
"duration_seconds": 45.0,
|
||||
"source_files_unchanged": true,
|
||||
"source_sha256": {
|
||||
"machine": "634f7f6f38f0c809910aad1e83514145a0f574d38a6f9f5e239520c8cb17b442",
|
||||
"cup_contents": "62ce59ff695fcfe3d19129fc8735b3a969ab25607b6c9d1ff1b4694b6b725330"
|
||||
},
|
||||
"parameters": {
|
||||
"q_max_ml_s": 30.0,
|
||||
"lever_open": 0.3,
|
||||
"flow_ml_s": 9.0,
|
||||
"saturation_ml": 60.0,
|
||||
"preinfusion_seconds": 6.666666666666666,
|
||||
"full_flow_machine_output_ml": 300.0,
|
||||
"closing_ramp_output_ml": 1.125,
|
||||
"cup_max_visual_ml": 361.66306167923955
|
||||
},
|
||||
"key_states": {
|
||||
"61": {
|
||||
"time": 2.0,
|
||||
"cup_x": 0.0,
|
||||
"flow": 9.0,
|
||||
"absorbed": 0.0,
|
||||
"preinfusion": 0.0,
|
||||
"machine_volume": 0.0,
|
||||
"cup_volume": 0.0,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": false
|
||||
},
|
||||
"180": {
|
||||
"time": 5.966666666666667,
|
||||
"cup_x": 0.0,
|
||||
"flow": 9.0,
|
||||
"absorbed": 35.7,
|
||||
"preinfusion": 3.966666666666667,
|
||||
"machine_volume": 0.0,
|
||||
"cup_volume": 0.0,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": false
|
||||
},
|
||||
"261": {
|
||||
"time": 8.666666666666666,
|
||||
"cup_x": 0.0,
|
||||
"flow": 9.0,
|
||||
"absorbed": 59.99999999999999,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 0.0,
|
||||
"cup_volume": 0.0,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": true
|
||||
},
|
||||
"451": {
|
||||
"time": 15.0,
|
||||
"cup_x": 0.0,
|
||||
"flow": 9.0,
|
||||
"absorbed": 60.0,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 57.00000000000001,
|
||||
"cup_volume": 56.999999999999815,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": true
|
||||
},
|
||||
"480": {
|
||||
"time": 15.966666666666667,
|
||||
"cup_x": 0.145,
|
||||
"flow": 9.0,
|
||||
"absorbed": 60.0,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 65.7,
|
||||
"cup_volume": 58.4999999999998,
|
||||
"catches": [
|
||||
false,
|
||||
false
|
||||
],
|
||||
"extraction": true
|
||||
},
|
||||
"540": {
|
||||
"time": 17.966666666666665,
|
||||
"cup_x": 0.145,
|
||||
"flow": 9.0,
|
||||
"absorbed": 60.0,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 83.69999999999999,
|
||||
"cup_volume": 58.4999999999998,
|
||||
"catches": [
|
||||
false,
|
||||
false
|
||||
],
|
||||
"extraction": true
|
||||
},
|
||||
"600": {
|
||||
"time": 19.966666666666665,
|
||||
"cup_x": 0.0,
|
||||
"flow": 9.0,
|
||||
"absorbed": 60.0,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 101.69999999999999,
|
||||
"cup_volume": 73.19999999999966,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": true
|
||||
},
|
||||
"1261": {
|
||||
"time": 42.0,
|
||||
"cup_x": 0.0,
|
||||
"flow": 9.0,
|
||||
"absorbed": 60.0,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 300.0,
|
||||
"cup_volume": 271.50000000000455,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": true
|
||||
},
|
||||
"1270": {
|
||||
"time": 42.3,
|
||||
"cup_x": 0.0028530092592589443,
|
||||
"flow": 0.0,
|
||||
"absorbed": 60.0,
|
||||
"preinfusion": 6.666666666666666,
|
||||
"machine_volume": 301.125,
|
||||
"cup_volume": 272.62000000000455,
|
||||
"catches": [
|
||||
true,
|
||||
true
|
||||
],
|
||||
"extraction": true
|
||||
}
|
||||
},
|
||||
"cup_collision_free": {
|
||||
"centered": [],
|
||||
"parked_right": []
|
||||
},
|
||||
"godot_notes_text_block": "GODOT_IMPLEMENTATION_NOTES",
|
||||
"test_only_collections": [
|
||||
"AT_02_TestOnly_Cutaway_And_Liquid",
|
||||
"AT_03_TestOnly_HUD"
|
||||
],
|
||||
"checks": {
|
||||
"no_output_during_preinfusion": true,
|
||||
"automatic_saturation_transition": true,
|
||||
"cup_away_pauses_only_cup_collection": true,
|
||||
"cup_return_preserves_and_resumes_collection": true,
|
||||
"streams_continue_until_valve_closes": true,
|
||||
"source_assets_not_overwritten": true
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,664 @@
|
||||
import bpy
|
||||
import bmesh
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from mathutils import Vector
|
||||
from mathutils.bvhtree import BVHTree
|
||||
|
||||
ROOT = Path('/Users/yanchenyu/Documents/WebApps/PerfetCoffee')
|
||||
OUT = ROOT / 'playtests' / 'grinding_tamping'
|
||||
CHECKS = OUT / 'checks'
|
||||
CHECKS.mkdir(parents=True, exist_ok=True)
|
||||
BLEND = OUT / 'Grinding_Tamping_Whitebox.blend'
|
||||
SOURCES = {
|
||||
'grinder': ROOT / 'model_assets' / 'bean_grinder' / 'ElectricCoffeeGrinder_LowPoly.blend',
|
||||
'portafilter': ROOT / 'model_assets' / 'coffee_machine' / 'PerfectCoffee_Portafilter.blend',
|
||||
'tamper': ROOT / 'model_assets' / 'tamper' / 'PerfectCoffee_Tamper.blend',
|
||||
}
|
||||
SOURCE_HASHES = {name: hashlib.sha256(path.read_bytes()).hexdigest() for name, path in SOURCES.items()}
|
||||
FPS = 24
|
||||
FRAME_END = 168
|
||||
REFERENCE_SEAL_Z = 0.2135
|
||||
GRINDER_POSE = Vector((0.0, -0.1025, 0.1025))
|
||||
STATION_XY = Vector((0.225, -0.18))
|
||||
CLOTH_TOP = 0.0002
|
||||
POWDER_TOP = 0.203
|
||||
POWDER_BOTTOM = 0.192
|
||||
POWDER_LOOSE_OUTER = 0.2070
|
||||
POWDER_LOOSE_PEAK = 0.2250
|
||||
SEGMENTS = 48
|
||||
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
bpy.context.preferences.filepaths.save_version = 0
|
||||
scene = bpy.context.scene
|
||||
scene.name = 'WB_Grinding_And_Tamping'
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.length_unit = 'MILLIMETERS'
|
||||
scene.unit_settings.scale_length = 1.0
|
||||
scene.render.fps = FPS
|
||||
scene.frame_start = 1
|
||||
scene.frame_end = FRAME_END
|
||||
scene.frame_preview_end = FRAME_END
|
||||
scene['bean_remaining_portions'] = 14
|
||||
scene['whitebox_scope'] = 'Animation proof only; no gameplay logic, final powder material or fluid simulation'
|
||||
scene['press_rule'] = 'One downward press both levels and compresses; no distributor'
|
||||
scene['source_files_unmodified'] = True
|
||||
|
||||
|
||||
def collection(name):
|
||||
result = bpy.data.collections.new(name)
|
||||
scene.collection.children.link(result)
|
||||
return result
|
||||
|
||||
|
||||
grinder_collection = collection('WB_01_Grinder')
|
||||
portafilter_collection = collection('WB_02_Portafilter')
|
||||
tamper_collection = collection('WB_03_Tamper')
|
||||
powder_collection = collection('WB_04_Powder_And_Stream')
|
||||
studio_collection = collection('WB_05_Studio')
|
||||
|
||||
|
||||
def append_objects(path, names):
|
||||
with bpy.data.libraries.load(str(path), link=False) as (source, target):
|
||||
target.objects = names
|
||||
return [obj for obj in target.objects if obj is not None]
|
||||
|
||||
|
||||
with bpy.data.libraries.load(str(SOURCES['grinder']), link=False) as (source, target):
|
||||
target.collections = [name for name in source.collections if name[:2] in {'01', '02', '03', '04', '05'}]
|
||||
for coll in target.collections:
|
||||
for obj in coll.objects:
|
||||
grinder_collection.objects.link(obj)
|
||||
append_objects(SOURCES['grinder'], ['_Low bean instance source'])
|
||||
hero = bpy.data.objects['_Low bean instance source']
|
||||
grinder_collection.objects.link(hero)
|
||||
|
||||
with bpy.data.libraries.load(str(SOURCES['portafilter']), link=False) as (source, target):
|
||||
descendants = sorted(obj for obj in source.objects if obj.startswith('CM_Portafilter_') or obj.startswith('CM_Portafilter.'))
|
||||
target.objects = ['CM_Portafilter'] + descendants
|
||||
for obj in target.objects:
|
||||
portafilter_collection.objects.link(obj)
|
||||
portafilter_root = bpy.data.objects['CM_Portafilter']
|
||||
|
||||
for obj in append_objects(SOURCES['tamper'], ['TAM_Tamper_Assembly', 'TAM_Metal_Base', 'TAM_Wood_Handle']):
|
||||
tamper_collection.objects.link(obj)
|
||||
tamper_root = bpy.data.objects['TAM_Tamper_Assembly']
|
||||
|
||||
glass = bpy.data.materials.get('Low | clear glass')
|
||||
if glass is not None:
|
||||
glass_bsdf = glass.node_tree.nodes.get('Principled BSDF')
|
||||
glass_bsdf.inputs['Base Color'].default_value = (0.60, 0.76, 0.86, 1.0)
|
||||
glass_bsdf.inputs['Roughness'].default_value = 0.10
|
||||
glass_bsdf.inputs['Transmission Weight'].default_value = 0.0
|
||||
glass_bsdf.inputs['Alpha'].default_value = 0.055
|
||||
glass.diffuse_color = (0.60, 0.76, 0.86, 0.055)
|
||||
|
||||
for datablocks in (bpy.data.objects, bpy.data.shape_keys, bpy.data.node_groups):
|
||||
for datablock in datablocks:
|
||||
if datablock.animation_data is None:
|
||||
continue
|
||||
for fcurve in datablock.animation_data.drivers:
|
||||
for variable in fcurve.driver.variables:
|
||||
for target in variable.targets:
|
||||
if target.id_type == 'SCENE':
|
||||
target.id = scene
|
||||
|
||||
|
||||
def linear_channel(value):
|
||||
return value / 12.92 if value <= 0.04045 else ((value + 0.055) / 1.055) ** 2.4
|
||||
|
||||
|
||||
def rgba(hex_color):
|
||||
return tuple(linear_channel(int(hex_color[index:index + 2], 16) / 255.0) for index in (1, 3, 5)) + (1.0,)
|
||||
|
||||
|
||||
def material(name, color, roughness=0.65, metallic=0.0):
|
||||
mat = bpy.data.materials.new(name)
|
||||
mat.use_nodes = True
|
||||
mat.diffuse_color = rgba(color)
|
||||
bsdf = mat.node_tree.nodes.get('Principled BSDF')
|
||||
bsdf.inputs['Base Color'].default_value = rgba(color)
|
||||
bsdf.inputs['Roughness'].default_value = roughness
|
||||
bsdf.inputs['Metallic'].default_value = metallic
|
||||
return mat
|
||||
|
||||
|
||||
powder_mat = material('WB_Coffee_Grounds', '#4A2918', 0.96)
|
||||
nodes = powder_mat.node_tree.nodes
|
||||
links = powder_mat.node_tree.links
|
||||
coordinates = nodes.new('ShaderNodeTexCoord')
|
||||
noise = nodes.new('ShaderNodeTexNoise')
|
||||
noise.inputs['Scale'].default_value = 2400.0
|
||||
noise.inputs['Detail'].default_value = 2.0
|
||||
noise.inputs['Roughness'].default_value = 0.68
|
||||
links.new(coordinates.outputs['Object'], noise.inputs['Vector'])
|
||||
ramp = nodes.new('ShaderNodeValToRGB')
|
||||
ramp.color_ramp.elements.remove(ramp.color_ramp.elements[1])
|
||||
for position, color in [(0.20, '#26140C'), (0.46, '#4A2918'), (0.68, '#795238')]:
|
||||
element = ramp.color_ramp.elements[0] if position == 0.20 else ramp.color_ramp.elements.new(position)
|
||||
element.position = position
|
||||
element.color = rgba(color)
|
||||
ramp.color_ramp.interpolation = 'EASE'
|
||||
links.new(noise.outputs['Fac'], ramp.inputs['Fac'])
|
||||
links.new(ramp.outputs['Color'], nodes.get('Principled BSDF').inputs['Base Color'])
|
||||
bump = nodes.new('ShaderNodeBump')
|
||||
bump.inputs['Strength'].default_value = 0.38
|
||||
bump.inputs['Distance'].default_value = 0.00022
|
||||
links.new(noise.outputs['Fac'], bump.inputs['Height'])
|
||||
links.new(bump.outputs['Normal'], nodes.get('Principled BSDF').inputs['Normal'])
|
||||
|
||||
|
||||
def bowl_inner_radius(z):
|
||||
if z <= 0.2105:
|
||||
return 0.0295 + (z - 0.1915) * (0.0330 - 0.0295) / 0.0190
|
||||
return 0.0330 + (z - 0.2105) * (0.0340 - 0.0330) / 0.0030
|
||||
|
||||
|
||||
rings = [(bowl_inner_radius(POWDER_BOTTOM) - 0.00045, POWDER_BOTTOM)]
|
||||
for fraction in (1.0, 0.82, 0.62, 0.38, 0.08):
|
||||
rings.append((bowl_inner_radius(POWDER_TOP) - 0.00045, POWDER_TOP, fraction))
|
||||
vertices = []
|
||||
for ring in rings:
|
||||
radius, z = ring[:2]
|
||||
for index in range(SEGMENTS):
|
||||
angle = math.tau * index / SEGMENTS
|
||||
vertices.append((radius * math.cos(angle), radius * math.sin(angle), z))
|
||||
bottom_center = len(vertices)
|
||||
vertices.append((0.0, 0.0, POWDER_BOTTOM))
|
||||
top_center = len(vertices)
|
||||
vertices.append((0.0, 0.0, POWDER_TOP))
|
||||
faces = []
|
||||
for ring_index in range(len(rings) - 1):
|
||||
first = ring_index * SEGMENTS
|
||||
second = first + SEGMENTS
|
||||
for index in range(SEGMENTS):
|
||||
following = (index + 1) % SEGMENTS
|
||||
faces.append((first + index, first + following, second + following, second + index))
|
||||
for index in range(SEGMENTS):
|
||||
following = (index + 1) % SEGMENTS
|
||||
faces.append((bottom_center, following, index))
|
||||
faces.append((top_center, (len(rings) - 1) * SEGMENTS + index, (len(rings) - 1) * SEGMENTS + following))
|
||||
mesh = bpy.data.meshes.new('WB_Powder_MorphMesh')
|
||||
mesh.from_pydata(vertices, [], faces)
|
||||
mesh.materials.append(powder_mat)
|
||||
mesh.update()
|
||||
powder_frame = bpy.data.objects.new('WB_Powder_BowlFrame', None)
|
||||
powder_collection.objects.link(powder_frame)
|
||||
powder_frame.parent = portafilter_root
|
||||
powder_frame.location = (0.0, 0.0, -REFERENCE_SEAL_Z)
|
||||
powder_frame.empty_display_size = 0.015
|
||||
powder = bpy.data.objects.new('WB_Powder_Fill_And_Tamp', mesh)
|
||||
powder_collection.objects.link(powder)
|
||||
powder.parent = powder_frame
|
||||
powder['shape_contract'] = 'Fill=1 and Loose=0: tiny starting crumb; Fill=0 and Loose=1: full mound; Fill=0 and Loose=0: flat puck'
|
||||
powder['puck_surface_local_z_m'] = POWDER_TOP
|
||||
powder['top_vertex_indices'] = list(range(SEGMENTS, len(rings) * SEGMENTS)) + [top_center]
|
||||
powder.shape_key_add(name='Basis')
|
||||
fill_key = powder.shape_key_add(name='Fill')
|
||||
loose_key = powder.shape_key_add(name='Loose')
|
||||
for index, vertex in enumerate(vertices):
|
||||
x, y, z = vertex
|
||||
fill_key.data[index].co = (x * 0.04, y * 0.04, POWDER_BOTTOM + (0.00035 if index != bottom_center else 0.0))
|
||||
if index == bottom_center:
|
||||
loose_key.data[index].co = (x, y, z)
|
||||
continue
|
||||
if index == top_center:
|
||||
loose_key.data[index].co = (0.0, 0.0, POWDER_LOOSE_PEAK)
|
||||
continue
|
||||
ring_index = index // SEGMENTS
|
||||
if ring_index == 0:
|
||||
loose_key.data[index].co = (x, y, z)
|
||||
continue
|
||||
fraction = rings[ring_index][2]
|
||||
outer_radius = bowl_inner_radius(POWDER_LOOSE_OUTER) - 0.00045
|
||||
radius = outer_radius * fraction
|
||||
z = POWDER_LOOSE_OUTER + (POWDER_LOOSE_PEAK - POWDER_LOOSE_OUTER) * (1.0 - fraction)
|
||||
angle = math.atan2(y, x)
|
||||
loose_key.data[index].co = (radius * math.cos(angle), radius * math.sin(angle), z)
|
||||
for polygon in mesh.polygons:
|
||||
polygon.use_smooth = polygon.center.z > POWDER_BOTTOM + 0.00001
|
||||
mesh.update()
|
||||
|
||||
|
||||
def insert(obj, data_path, frame, value, index=None):
|
||||
if index is None:
|
||||
setattr(obj, data_path, value)
|
||||
obj.keyframe_insert(data_path=data_path, frame=frame)
|
||||
else:
|
||||
getattr(obj, data_path)[index] = value
|
||||
obj.keyframe_insert(data_path=data_path, index=index, frame=frame)
|
||||
|
||||
|
||||
def location_key(obj, frame, location):
|
||||
obj.location = location
|
||||
obj.keyframe_insert(data_path='location', frame=frame)
|
||||
|
||||
|
||||
def key_value(key, frame, value):
|
||||
key.value = value
|
||||
key.keyframe_insert(data_path='value', frame=frame)
|
||||
|
||||
|
||||
def visibility_key(obj, frame, hidden):
|
||||
obj.hide_render = hidden
|
||||
obj.hide_viewport = hidden
|
||||
obj.keyframe_insert(data_path='hide_render', frame=frame)
|
||||
obj.keyframe_insert(data_path='hide_viewport', frame=frame)
|
||||
for fcurve in all_fcurves(obj):
|
||||
if fcurve.data_path in {'hide_render', 'hide_viewport'}:
|
||||
for point in fcurve.keyframe_points:
|
||||
point.interpolation = 'CONSTANT'
|
||||
|
||||
|
||||
def all_fcurves(id_block):
|
||||
if id_block.animation_data is None or id_block.animation_data.action is None:
|
||||
return []
|
||||
action = id_block.animation_data.action
|
||||
result = []
|
||||
for layer in action.layers:
|
||||
for strip in layer.strips:
|
||||
for channelbag in strip.channelbags:
|
||||
result.extend(channelbag.fcurves)
|
||||
return result
|
||||
|
||||
|
||||
def interpolation(id_block, value):
|
||||
for fcurve in all_fcurves(id_block):
|
||||
for point in fcurve.keyframe_points:
|
||||
point.interpolation = value
|
||||
|
||||
|
||||
portafilter_meshes = [obj for obj in portafilter_collection.objects if obj.type == 'MESH']
|
||||
min_spout_z = min((portafilter_root.matrix_world.inverted() @ (obj.matrix_world @ vertex.co)).z for obj in portafilter_meshes for vertex in obj.data.vertices)
|
||||
station_z = CLOTH_TOP - min_spout_z
|
||||
station_pose = Vector((STATION_XY.x, STATION_XY.y, station_z))
|
||||
tamper_rest = Vector((STATION_XY.x + 0.072, STATION_XY.y + 0.035, CLOTH_TOP))
|
||||
powder_station_z = station_z - REFERENCE_SEAL_Z + POWDER_TOP
|
||||
|
||||
for frame, position in [
|
||||
(1, (0.0, -0.245, 0.135)),
|
||||
(10, GRINDER_POSE),
|
||||
(85, GRINDER_POSE),
|
||||
(91, (GRINDER_POSE.x, -0.190, GRINDER_POSE.z)),
|
||||
(96, (GRINDER_POSE.x, -0.190, 0.180)),
|
||||
(100, (STATION_XY.x, STATION_XY.y, 0.180)),
|
||||
(108, station_pose),
|
||||
(168, station_pose),
|
||||
]:
|
||||
location_key(portafilter_root, frame, position)
|
||||
portafilter_root.animation_data.action.name = 'WB_Portafilter_Grind_To_Tamping'
|
||||
interpolation(portafilter_root, 'LINEAR')
|
||||
|
||||
button = bpy.data.objects['Body | start button']
|
||||
button_y = button.location.y
|
||||
for frame, offset in [(1, 0.0), (11, 0.0), (13, 0.0022), (16, 0.0022), (18, 0.0), (168, 0.0)]:
|
||||
button.location.y = button_y + offset
|
||||
button.keyframe_insert(data_path='location', index=1, frame=frame)
|
||||
interpolation(button, 'LINEAR')
|
||||
|
||||
for frame, remaining in [(1, 14), (83, 14), (84, 13), (168, 13)]:
|
||||
scene['bean_remaining_portions'] = remaining
|
||||
scene.keyframe_insert(data_path='["bean_remaining_portions"]', frame=frame)
|
||||
interpolation(scene, 'CONSTANT')
|
||||
|
||||
for frame, hidden in [(1, True), (13, True), (14, False), (168, False)]:
|
||||
visibility_key(powder, frame, hidden)
|
||||
for frame, fill, loose in [
|
||||
(1, 1.0, 0.0),
|
||||
(14, 1.0, 0.0),
|
||||
(42, 0.50, 0.50),
|
||||
(84, 0.0, 1.0),
|
||||
(122, 0.0, 1.0),
|
||||
(126, 0.0, 0.0),
|
||||
(168, 0.0, 0.0),
|
||||
]:
|
||||
key_value(fill_key, frame, fill)
|
||||
key_value(loose_key, frame, loose)
|
||||
powder.data.shape_keys.animation_data.action.name = 'WB_Powder_Fill_Loose_To_Flat'
|
||||
interpolation(powder.data.shape_keys, 'LINEAR')
|
||||
|
||||
for frame, position in [
|
||||
(1, tamper_rest),
|
||||
(109, tamper_rest),
|
||||
(112, (tamper_rest.x, tamper_rest.y, powder_station_z + 0.060)),
|
||||
(116, (STATION_XY.x, STATION_XY.y, powder_station_z + 0.060)),
|
||||
(117, (STATION_XY.x, STATION_XY.y, powder_station_z + 0.050)),
|
||||
(122, (STATION_XY.x, STATION_XY.y, powder_station_z + 0.022)),
|
||||
(126, (STATION_XY.x, STATION_XY.y, powder_station_z)),
|
||||
(132, (STATION_XY.x, STATION_XY.y, powder_station_z)),
|
||||
(144, (STATION_XY.x, STATION_XY.y, powder_station_z + 0.050)),
|
||||
(148, (STATION_XY.x, STATION_XY.y, powder_station_z + 0.060)),
|
||||
(154, (tamper_rest.x, tamper_rest.y, powder_station_z + 0.060)),
|
||||
(158, tamper_rest),
|
||||
(168, tamper_rest),
|
||||
]:
|
||||
location_key(tamper_root, frame, position)
|
||||
tamper_root.animation_data.action.name = 'WB_Tamper_Align_Compress_Hold_Lift'
|
||||
interpolation(tamper_root, 'LINEAR')
|
||||
|
||||
random.seed(4061)
|
||||
for index in range(30):
|
||||
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1, radius=random.uniform(0.00065, 0.00105))
|
||||
particle = bpy.context.object
|
||||
particle.name = f'WB_Powder_Grain_{index:02d}'
|
||||
for coll in list(particle.users_collection):
|
||||
coll.objects.unlink(particle)
|
||||
powder_collection.objects.link(particle)
|
||||
particle.data.materials.append(powder_mat)
|
||||
for frame, hidden in [(1, True), (13, True), (14, False), (83, False), (84, True), (168, True)]:
|
||||
visibility_key(particle, frame, hidden)
|
||||
period = 6
|
||||
for start in range(14 + index % period, 84, period):
|
||||
end = min(start + period, 84)
|
||||
middle = (start + end) * 0.5
|
||||
start_xy = (random.uniform(-0.0014, 0.0014), -0.1025 + random.uniform(-0.0014, 0.0014))
|
||||
end_xy = (random.uniform(-0.0025, 0.0025), -0.1025 + random.uniform(-0.0025, 0.0025))
|
||||
location_key(particle, start, (start_xy[0], start_xy[1], 0.1175))
|
||||
location_key(particle, middle, ((start_xy[0] + end_xy[0]) * 0.5, (start_xy[1] + end_xy[1]) * 0.5, 0.108))
|
||||
location_key(particle, end, (end_xy[0], end_xy[1], 0.098))
|
||||
interpolation(particle, 'LINEAR')
|
||||
for fcurve in all_fcurves(particle):
|
||||
for point in fcurve.keyframe_points:
|
||||
point.interpolation = 'CONSTANT' if fcurve.data_path in {'hide_render', 'hide_viewport'} else 'LINEAR'
|
||||
|
||||
ground_mat = material('WB_Countertop', '#8C857A', 0.82)
|
||||
bpy.ops.mesh.primitive_plane_add(size=2.0, location=(0.0, 0.0, -0.00002))
|
||||
ground = bpy.context.object
|
||||
ground.name = 'WB_Countertop'
|
||||
for coll in list(ground.users_collection):
|
||||
coll.objects.unlink(ground)
|
||||
studio_collection.objects.link(ground)
|
||||
ground.data.materials.append(ground_mat)
|
||||
|
||||
size = 256
|
||||
yy, xx = np.mgrid[0:size, 0:size]
|
||||
weave = 0.72 + 0.06 * np.sin(xx * math.pi / 3.0) + 0.05 * np.sin(yy * math.pi / 3.0)
|
||||
cloth_pixels = np.ones((size, size, 4), dtype=np.float32)
|
||||
cloth_pixels[:, :, 0] = weave * 0.42
|
||||
cloth_pixels[:, :, 1] = weave * 0.55
|
||||
cloth_pixels[:, :, 2] = weave * 0.52
|
||||
cloth_image = bpy.data.images.new('WB_Cloth_Placeholder_NotFinal', width=size, height=size, alpha=True)
|
||||
cloth_image.pixels.foreach_set(cloth_pixels.ravel())
|
||||
cloth_image.pack()
|
||||
cloth_mat = material('WB_Cloth_Placeholder', '#738D85', 0.95)
|
||||
texture = cloth_mat.node_tree.nodes.new('ShaderNodeTexImage')
|
||||
texture.image = cloth_image
|
||||
cloth_mat.node_tree.links.new(texture.outputs['Color'], cloth_mat.node_tree.nodes.get('Principled BSDF').inputs['Base Color'])
|
||||
bpy.ops.mesh.primitive_plane_add(size=1.0, location=(STATION_XY.x + 0.025, STATION_XY.y - 0.005, CLOTH_TOP))
|
||||
cloth = bpy.context.object
|
||||
cloth.name = 'WB_ClothMat_TexturePlane_NotSolid'
|
||||
for coll in list(cloth.users_collection):
|
||||
coll.objects.unlink(cloth)
|
||||
studio_collection.objects.link(cloth)
|
||||
cloth.scale = (0.23, 0.19, 1.0)
|
||||
cloth.data.materials.append(cloth_mat)
|
||||
|
||||
|
||||
def point_at(obj, target):
|
||||
obj.rotation_euler = (Vector(target) - obj.location).to_track_quat('-Z', 'Y').to_euler()
|
||||
|
||||
|
||||
def camera(name, location, target, scale):
|
||||
data = bpy.data.cameras.new(name)
|
||||
data.type = 'ORTHO'
|
||||
data.ortho_scale = scale
|
||||
data.clip_start = 0.001
|
||||
data.clip_end = 100.0
|
||||
obj = bpy.data.objects.new(name, data)
|
||||
studio_collection.objects.link(obj)
|
||||
obj.location = location
|
||||
point_at(obj, target)
|
||||
return obj
|
||||
|
||||
|
||||
def area_light(name, location, energy, size, color, target):
|
||||
data = bpy.data.lights.new(name, 'AREA')
|
||||
data.energy = energy
|
||||
data.shape = 'DISK'
|
||||
data.size = size
|
||||
data.color = color
|
||||
obj = bpy.data.objects.new(name, data)
|
||||
studio_collection.objects.link(obj)
|
||||
obj.location = location
|
||||
point_at(obj, target)
|
||||
|
||||
|
||||
overview = camera('WB_Camera_Overview', (0.47, -0.72, 0.43), (0.10, -0.13, 0.160), 0.72)
|
||||
detail = camera('WB_Camera_Detail', (0.17, -0.04, 0.155), (0.0, -0.1025, 0.094), 0.122)
|
||||
for frame, position, target, scale in [
|
||||
(1, (0.17, -0.04, 0.155), (0.0, -0.1025, 0.094), 0.122),
|
||||
(84, (0.17, -0.04, 0.155), (0.0, -0.1025, 0.094), 0.122),
|
||||
(108, (STATION_XY.x + 0.12, STATION_XY.y - 0.16, powder_station_z + 0.115), (STATION_XY.x, STATION_XY.y, powder_station_z + 0.012), 0.132),
|
||||
(168, (STATION_XY.x + 0.12, STATION_XY.y - 0.16, powder_station_z + 0.115), (STATION_XY.x, STATION_XY.y, powder_station_z + 0.012), 0.132),
|
||||
]:
|
||||
detail.location = position
|
||||
point_at(detail, target)
|
||||
detail.keyframe_insert(data_path='location', frame=frame)
|
||||
detail.keyframe_insert(data_path='rotation_euler', frame=frame)
|
||||
detail.data.ortho_scale = scale
|
||||
detail.data.keyframe_insert(data_path='ortho_scale', frame=frame)
|
||||
interpolation(detail, 'LINEAR')
|
||||
interpolation(detail.data, 'LINEAR')
|
||||
contact_camera = camera(
|
||||
'WB_Camera_Contact_Inspection',
|
||||
(STATION_XY.x + 0.13, STATION_XY.y - 0.13, powder_station_z + 0.080),
|
||||
(STATION_XY.x, STATION_XY.y, powder_station_z + 0.005),
|
||||
0.125,
|
||||
)
|
||||
mound_profile_camera = camera(
|
||||
'WB_Camera_Mound_Profile',
|
||||
(STATION_XY.x + 0.14, STATION_XY.y - 0.04, powder_station_z + 0.055),
|
||||
(STATION_XY.x, STATION_XY.y, powder_station_z + 0.005),
|
||||
0.120,
|
||||
)
|
||||
|
||||
world = bpy.data.worlds.new('WB_World')
|
||||
world.use_nodes = True
|
||||
world.node_tree.nodes['Background'].inputs['Color'].default_value = (0.26, 0.30, 0.36, 1.0)
|
||||
world.node_tree.nodes['Background'].inputs['Strength'].default_value = 0.28
|
||||
scene.world = world
|
||||
area_light('WB_Key', (0.20, -0.20, 0.58), 4.0, 0.42, (1.0, 0.90, 0.78), (0.07, -0.12, 0.12))
|
||||
area_light('WB_Fill', (-0.35, -0.10, 0.32), 1.5, 0.34, (0.80, 0.90, 1.0), (0.05, -0.12, 0.12))
|
||||
area_light('WB_Rim', (0.15, 0.30, 0.45), 4.0, 0.35, (1.0, 0.96, 0.88), (0.08, -0.10, 0.14))
|
||||
scene.render.engine = 'BLENDER_EEVEE'
|
||||
scene.render.resolution_x = 1400
|
||||
scene.render.resolution_y = 1000
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.image_settings.file_format = 'PNG'
|
||||
scene.render.image_settings.color_mode = 'RGB'
|
||||
scene.render.film_transparent = False
|
||||
scene.view_settings.view_transform = 'AgX'
|
||||
scene.view_settings.look = 'AgX - Medium High Contrast'
|
||||
scene.view_settings.exposure = -0.2
|
||||
|
||||
markers = [
|
||||
(1, '01_EMPTY_APPROACH'), (10, '02_SEATED_IN_GRINDER'), (13, '03_GRIND_START'),
|
||||
(42, '04_POWDER_MID'), (84, '05_LOOSE_MOUND_READY'), (108, '06_AT_TAMPING_STATION'),
|
||||
(117, '07_TAMPER_DESCEND'), (122, '08_CONTACT_AND_COMPRESS'), (126, '09_FLAT_PUCK'),
|
||||
(132, '10_HOLD_END'), (144, '11_TAMPER_LIFTED'), (168, '12_FINAL_REST'),
|
||||
]
|
||||
for frame, name in markers:
|
||||
scene.timeline_markers.new(name, frame=frame)
|
||||
|
||||
|
||||
def evaluated_vertices(obj):
|
||||
depsgraph = bpy.context.evaluated_depsgraph_get()
|
||||
evaluated = obj.evaluated_get(depsgraph)
|
||||
mesh = evaluated.to_mesh()
|
||||
points = [evaluated.matrix_world @ vertex.co for vertex in mesh.vertices]
|
||||
evaluated.to_mesh_clear()
|
||||
return points
|
||||
|
||||
|
||||
def world_bvh(obj):
|
||||
depsgraph = bpy.context.evaluated_depsgraph_get()
|
||||
evaluated = obj.evaluated_get(depsgraph)
|
||||
mesh = evaluated.to_mesh()
|
||||
points = [evaluated.matrix_world @ vertex.co for vertex in mesh.vertices]
|
||||
polygons = [tuple(polygon.vertices) for polygon in mesh.polygons]
|
||||
tree = BVHTree.FromPolygons(points, polygons, all_triangles=False, epsilon=0.0)
|
||||
evaluated.to_mesh_clear()
|
||||
return tree
|
||||
|
||||
|
||||
def collisions(a_objects, b_objects):
|
||||
result = []
|
||||
trees = {obj.name: world_bvh(obj) for obj in b_objects}
|
||||
for a in a_objects:
|
||||
a_tree = world_bvh(a)
|
||||
for b in b_objects:
|
||||
overlap = a_tree.overlap(trees[b.name])
|
||||
if overlap:
|
||||
result.append({'a': a.name, 'b': b.name, 'pairs': len(overlap)})
|
||||
return result
|
||||
|
||||
|
||||
def powder_top_bounds():
|
||||
points = evaluated_vertices(powder)
|
||||
top = [points[index].z for index in powder['top_vertex_indices']]
|
||||
return min(top), max(top)
|
||||
|
||||
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(mesh)
|
||||
powder_non_manifold = sum(1 for edge in bm.edges if not edge.is_manifold)
|
||||
bm.free()
|
||||
validation = {'source_hashes_before': SOURCE_HASHES, 'fps': FPS, 'frame_end': FRAME_END, 'keyframes': {}}
|
||||
scene.frame_set(1)
|
||||
assert powder.hide_render and all(bpy.data.objects[f'WB_Powder_Grain_{index:02d}'].hide_render for index in range(30))
|
||||
scene.frame_set(13)
|
||||
bean_top_before = max(point.z for point in evaluated_vertices(bpy.data.objects['Beans | textured volume core']))
|
||||
scene.frame_set(42)
|
||||
validation['keyframes']['42_grinding'] = {'fill': fill_key.value, 'loose': loose_key.value, 'portafilter_world': list(portafilter_root.location)}
|
||||
assert abs(fill_key.value - 0.5) < 0.0001 and abs(loose_key.value - 0.5) < 0.0001
|
||||
assert not powder.hide_render
|
||||
scene.frame_set(84)
|
||||
loose_min, loose_max = powder_top_bounds()
|
||||
assert loose_max > loose_min + 0.004
|
||||
assert abs(loose_max - (portafilter_root.location.z - REFERENCE_SEAL_Z + POWDER_LOOSE_PEAK)) < 0.00001
|
||||
assert 0.003 < loose_max - portafilter_root.location.z < 0.015
|
||||
assert scene['bean_remaining_portions'] == 13
|
||||
bean_top_after = max(point.z for point in evaluated_vertices(bpy.data.objects['Beans | textured volume core']))
|
||||
assert bean_top_after < bean_top_before - 0.0001
|
||||
grinder_collisions = collisions(portafilter_meshes, [bpy.data.objects['Low | Grinder body'], bpy.data.objects['Low | Removable support']])
|
||||
powder_bowl_loose = collisions([powder], [bpy.data.objects['CM_Portafilter_Bowl']])
|
||||
filter_points = evaluated_vertices(bpy.data.objects['CM_Portafilter_FilterScreen'])
|
||||
filter_contact_error = abs(min(point.z for point in evaluated_vertices(powder)) - filter_points[0].z)
|
||||
assert filter_contact_error < 0.000001
|
||||
validation['keyframes']['84_loose_mound'] = {
|
||||
'mound_peak_local_z_m': loose_max - (portafilter_root.location.z - REFERENCE_SEAL_Z),
|
||||
'mound_peak_above_rim_mm': (loose_max - portafilter_root.location.z) * 1000.0,
|
||||
'powder_filter_contact_error_mm': filter_contact_error * 1000.0,
|
||||
'mound_height_above_final_puck_mm': (POWDER_LOOSE_PEAK - POWDER_TOP) * 1000.0,
|
||||
'bean_remaining_portions': scene['bean_remaining_portions'],
|
||||
'bean_core_top_before_m': bean_top_before,
|
||||
'bean_core_top_after_m': bean_top_after,
|
||||
'mound_slope_height_mm': (POWDER_LOOSE_PEAK - POWDER_LOOSE_OUTER) * 1000.0,
|
||||
'portafilter_grinder_collisions': grinder_collisions,
|
||||
'powder_bowl_collisions': powder_bowl_loose,
|
||||
}
|
||||
scene.frame_set(108)
|
||||
assert (portafilter_root.location - station_pose).length < 0.00001
|
||||
scene.frame_set(122)
|
||||
assert abs(tamper_root.location.z - (powder_station_z + 0.022)) < 0.00001
|
||||
assert abs(loose_key.value - 1.0) < 0.00001
|
||||
for frame in (122, 124, 126, 132):
|
||||
scene.frame_set(frame)
|
||||
powder_max = max(point.z for point in evaluated_vertices(powder))
|
||||
penetration = powder_max - tamper_root.location.z
|
||||
assert penetration <= 0.00001, (frame, penetration)
|
||||
scene.frame_set(126)
|
||||
puck_min, puck_max = powder_top_bounds()
|
||||
puck_points = evaluated_vertices(powder)
|
||||
puck_height = max(point.z for point in puck_points) - min(point.z for point in puck_points)
|
||||
tamper_grinder = collisions([bpy.data.objects['TAM_Metal_Base'], bpy.data.objects['TAM_Wood_Handle']], [bpy.data.objects['Low | Grinder body'], bpy.data.objects['Low | Removable support']])
|
||||
tamper_portafilter = collisions([bpy.data.objects['TAM_Metal_Base'], bpy.data.objects['TAM_Wood_Handle']], portafilter_meshes)
|
||||
powder_bowl_puck = collisions([powder], [bpy.data.objects['CM_Portafilter_Bowl']])
|
||||
validation['keyframes']['126_flat_puck'] = {
|
||||
'top_flatness_mm': (puck_max - puck_min) * 1000.0,
|
||||
'puck_height_mm': puck_height * 1000.0,
|
||||
'puck_top_world_z_m': puck_max,
|
||||
'tamper_bottom_world_z_m': tamper_root.location.z,
|
||||
'tamper_powder_gap_mm': (tamper_root.location.z - puck_max) * 1000.0,
|
||||
'tamper_xy_alignment_error_mm': math.hypot(tamper_root.location.x - STATION_XY.x, tamper_root.location.y - STATION_XY.y) * 1000.0,
|
||||
'tamper_grinder_collisions': tamper_grinder,
|
||||
'tamper_portafilter_collisions': tamper_portafilter,
|
||||
'powder_bowl_collisions': powder_bowl_puck,
|
||||
}
|
||||
assert abs(puck_max - puck_min) < 0.000001
|
||||
assert abs(tamper_root.location.z - puck_max) < 0.00001
|
||||
assert not tamper_grinder and not tamper_portafilter and not powder_bowl_puck
|
||||
scene.frame_set(144)
|
||||
assert abs(tamper_root.location.z - (powder_station_z + 0.050)) < 0.00001
|
||||
assert abs(loose_key.value) < 0.00001
|
||||
scene.frame_set(168)
|
||||
assert (portafilter_root.location - station_pose).length < 0.00001
|
||||
assert (tamper_root.location - tamper_rest).length < 0.00001
|
||||
assert abs(loose_key.value) < 0.00001
|
||||
mesh.calc_loop_triangles()
|
||||
validation['geometry'] = {'powder_non_manifold_edges': powder_non_manifold, 'powder_triangles': len(mesh.loop_triangles)}
|
||||
validation['source_hashes_after'] = {name: hashlib.sha256(path.read_bytes()).hexdigest() for name, path in SOURCES.items()}
|
||||
validation['source_files_unmodified'] = validation['source_hashes_after'] == SOURCE_HASHES
|
||||
validation['passed'] = (
|
||||
not grinder_collisions
|
||||
and not powder_bowl_loose
|
||||
and not powder_bowl_puck
|
||||
and powder_non_manifold == 0
|
||||
and validation['source_files_unmodified']
|
||||
)
|
||||
(OUT / 'validation.json').write_text(json.dumps(validation, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
assert validation['passed'], 'Whitebox geometry validation failed; inspect validation.json'
|
||||
|
||||
notes = bpy.data.texts.new('WHITEBOX_README')
|
||||
notes.write('''动画白盒:咖啡豆研磨、接粉与压粉\n\n时间轴:24 fps,1–168 帧。\n1–12:空手粉碗进入支架;13–84:研磨与粉堆增长;85–108:移至压粉位;109–126:粉锤接近并压粉;127–132:保持;133–156:抬起并归位;168:最终展示。\n\n粉末 WB_Powder_Fill_And_Tamp 的 Fill / Loose 形态键用于白盒验证。\nFill=1、Loose=0:初始小粉粒;Fill=0、Loose=1:沙堆;Fill=0、Loose=0:平整粉饼。\n粉锤只在第122帧接触松散粉面后开始压缩,126帧完全压平。\n\n所有源模型均为独立副本,原文件未修改。粉流为关键帧颗粒,不是物理模拟。抹布为临时贴图平面,不是最终资产。粉末材质与形态仍属于白盒。\n''')
|
||||
|
||||
scene.camera = overview
|
||||
scene.frame_set(1)
|
||||
scene.render.filepath = str(CHECKS / 'overview.png')
|
||||
for screen in bpy.data.screens:
|
||||
for area in screen.areas:
|
||||
if area.type == 'VIEW_3D':
|
||||
area.spaces.active.region_3d.view_perspective = 'CAMERA'
|
||||
area.spaces.active.shading.type = 'MATERIAL'
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(BLEND))
|
||||
|
||||
render_views = [
|
||||
(42, overview, 'frame_0042_grinding.png'),
|
||||
(42, detail, 'frame_0042_detail.png'),
|
||||
(84, detail, 'frame_0084_loose_mound.png'),
|
||||
(108, detail, 'frame_0108_at_station.png'),
|
||||
(122, detail, 'frame_0122_contact.png'),
|
||||
(126, detail, 'frame_0126_flat_puck.png'),
|
||||
(144, detail, 'frame_0144_tamper_lifted.png'),
|
||||
(168, detail, 'frame_0168_final.png'),
|
||||
]
|
||||
for frame, cam, filename in render_views:
|
||||
scene.frame_set(frame)
|
||||
scene.camera = cam
|
||||
scene.render.filepath = str(CHECKS / filename)
|
||||
bpy.ops.render.render(write_still=True)
|
||||
scene.frame_set(108)
|
||||
scene.camera = mound_profile_camera
|
||||
scene.render.filepath = str(CHECKS / 'frame_0108_mound_profile.png')
|
||||
bpy.ops.render.render(write_still=True)
|
||||
scene.frame_set(84)
|
||||
scene.camera = overview
|
||||
scene.render.filepath = str(CHECKS / 'frame_0084_overview.png')
|
||||
bpy.ops.render.render(write_still=True)
|
||||
bpy.data.objects['CM_Portafilter_Bowl'].hide_render = True
|
||||
for frame, filename in [(122, 'frame_0122_contact_cutaway.png'), (126, 'frame_0126_contact_cutaway.png')]:
|
||||
scene.frame_set(frame)
|
||||
scene.camera = contact_camera
|
||||
scene.render.filepath = str(CHECKS / filename)
|
||||
bpy.ops.render.render(write_still=True)
|
||||
bpy.data.objects['CM_Portafilter_Bowl'].hide_render = False
|
||||
scene.frame_set(1)
|
||||
scene.camera = overview
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(BLEND))
|
||||
print('WHITEBOX_VALIDATION=' + json.dumps(validation, ensure_ascii=False), flush=True)
|
||||
print('WHITEBOX_BUILD_COMPLETE', flush=True)
|
||||
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"frame_count_checked": 87,
|
||||
"frames_checked": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
84,
|
||||
85,
|
||||
86,
|
||||
87,
|
||||
88,
|
||||
89,
|
||||
90,
|
||||
91,
|
||||
92,
|
||||
93,
|
||||
94,
|
||||
95,
|
||||
96,
|
||||
97,
|
||||
98,
|
||||
99,
|
||||
100,
|
||||
101,
|
||||
102,
|
||||
103,
|
||||
104,
|
||||
105,
|
||||
106,
|
||||
107,
|
||||
108,
|
||||
109,
|
||||
110,
|
||||
111,
|
||||
112,
|
||||
113,
|
||||
114,
|
||||
115,
|
||||
116,
|
||||
117,
|
||||
118,
|
||||
119,
|
||||
120,
|
||||
121,
|
||||
122,
|
||||
123,
|
||||
124,
|
||||
125,
|
||||
126,
|
||||
127,
|
||||
128,
|
||||
129,
|
||||
130,
|
||||
131,
|
||||
132,
|
||||
133,
|
||||
134,
|
||||
135,
|
||||
136,
|
||||
137,
|
||||
138,
|
||||
139,
|
||||
140,
|
||||
141,
|
||||
142,
|
||||
143,
|
||||
144,
|
||||
145,
|
||||
146,
|
||||
147,
|
||||
148,
|
||||
149,
|
||||
150,
|
||||
151,
|
||||
152,
|
||||
153,
|
||||
154,
|
||||
155,
|
||||
156
|
||||
],
|
||||
"collisions": [],
|
||||
"continuous_contact_sync_passed": true,
|
||||
"reopen_checks": {
|
||||
"frame_end": 168,
|
||||
"fps": 24,
|
||||
"timeline_markers": 12,
|
||||
"independent_append_no_linked_libraries": true,
|
||||
"correct_portafilter_parent": true,
|
||||
"bowl_visible_on_open": true,
|
||||
"default_camera": "WB_Camera_Overview",
|
||||
"opens_at_frame": 1
|
||||
},
|
||||
"source_hashes_after": {
|
||||
"grinder": "91c3ffa8ee5cbde3c013938837ce2552272d77823b3826768965fd8b02590908",
|
||||
"portafilter": "dd9c42153a37088fbf65cf9e399107258657acdf91c987f50ce6033c907c9ed9",
|
||||
"tamper": "902828b49e93462eb2434beaa2d7f1b974a0fb569ff2f06eeedf6129445f2391"
|
||||
},
|
||||
"passed": true
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import bpy
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
OUT = Path('/Users/yanchenyu/Documents/WebApps/PerfetCoffee/playtests/grinding_tamping')
|
||||
bpy.ops.wm.open_mainfile(filepath=str(OUT / 'Grinding_Tamping_Whitebox.blend'))
|
||||
scene = bpy.context.scene
|
||||
scene.render.engine = 'BLENDER_EEVEE'
|
||||
scene.render.resolution_x = 960
|
||||
scene.render.resolution_y = 720
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.fps = 12
|
||||
scene.frame_start = 1
|
||||
scene.frame_end = 168
|
||||
scene.frame_step = 2
|
||||
scene.render.image_settings.media_type = 'VIDEO'
|
||||
scene.render.image_settings.file_format = 'FFMPEG'
|
||||
scene.render.ffmpeg.format = 'MPEG4'
|
||||
scene.render.ffmpeg.codec = 'H264'
|
||||
scene.render.ffmpeg.constant_rate_factor = 'MEDIUM'
|
||||
scene.render.ffmpeg.ffmpeg_preset = 'GOOD'
|
||||
scene.render.ffmpeg.audio_codec = 'NONE'
|
||||
for camera_name, filename in [
|
||||
('WB_Camera_Overview', 'preview_overview.mp4'),
|
||||
('WB_Camera_Detail', 'preview_detail.mp4'),
|
||||
]:
|
||||
scene.camera = bpy.data.objects[camera_name]
|
||||
scene.render.filepath = str(OUT / filename)
|
||||
scene.frame_set(1)
|
||||
bpy.ops.render.render(animation=True)
|
||||
print('WHITEBOX_VIDEO_RENDERED=' + filename, flush=True)
|
||||
subprocess.run([
|
||||
'ffmpeg', '-y', '-hide_banner', '-loglevel', 'warning',
|
||||
'-i', str(OUT / 'preview_overview.mp4'), '-i', str(OUT / 'preview_detail.mp4'),
|
||||
'-filter_complex', '[0:v][1:v]hstack=inputs=2[out]',
|
||||
'-map', '[out]', '-c:v', 'libx264', '-crf', '20', '-pix_fmt', 'yuv420p',
|
||||
'-movflags', '+faststart', str(OUT / 'preview_animation.mp4'),
|
||||
], check=True)
|
||||
probe = subprocess.run([
|
||||
'ffprobe', '-v', 'error', '-show_entries',
|
||||
'format=duration:stream=width,height,r_frame_rate,nb_frames', '-of', 'json',
|
||||
str(OUT / 'preview_animation.mp4'),
|
||||
], check=True, text=True, capture_output=True)
|
||||
video_report = json.loads(probe.stdout)
|
||||
video_report['source_frame_range'] = [1, 168]
|
||||
video_report['source_fps'] = 24
|
||||
video_report['preview_fps'] = 12
|
||||
video_report['dual_view'] = True
|
||||
(OUT / 'video_validation.json').write_text(json.dumps(video_report, indent=2), encoding='utf-8')
|
||||
for filename in ('preview_overview.mp4', 'preview_detail.mp4'):
|
||||
(OUT / filename).unlink()
|
||||
print('WHITEBOX_VIDEO_RENDER_COMPLETE', flush=True)
|
||||
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"source_hashes_before": {
|
||||
"grinder": "91c3ffa8ee5cbde3c013938837ce2552272d77823b3826768965fd8b02590908",
|
||||
"portafilter": "dd9c42153a37088fbf65cf9e399107258657acdf91c987f50ce6033c907c9ed9",
|
||||
"tamper": "902828b49e93462eb2434beaa2d7f1b974a0fb569ff2f06eeedf6129445f2391"
|
||||
},
|
||||
"fps": 24,
|
||||
"frame_end": 168,
|
||||
"keyframes": {
|
||||
"42_grinding": {
|
||||
"fill": 0.5,
|
||||
"loose": 0.5,
|
||||
"portafilter_world": [
|
||||
0.0,
|
||||
-0.10249999910593033,
|
||||
0.10249999910593033
|
||||
]
|
||||
},
|
||||
"84_loose_mound": {
|
||||
"mound_peak_local_z_m": 0.2250000009536743,
|
||||
"mound_peak_above_rim_mm": 11.500000953674316,
|
||||
"powder_filter_contact_error_mm": 0.0,
|
||||
"mound_height_above_final_puck_mm": 21.999999999999993,
|
||||
"bean_remaining_portions": 13,
|
||||
"bean_core_top_before_m": 0.29820001125335693,
|
||||
"bean_core_top_after_m": 0.293745219707489,
|
||||
"mound_slope_height_mm": 18.000000000000014,
|
||||
"portafilter_grinder_collisions": [],
|
||||
"powder_bowl_collisions": []
|
||||
},
|
||||
"126_flat_puck": {
|
||||
"top_flatness_mm": 0.0,
|
||||
"puck_height_mm": 10.999992489814758,
|
||||
"puck_top_world_z_m": 0.05865471065044403,
|
||||
"tamper_bottom_world_z_m": 0.058654699474573135,
|
||||
"tamper_powder_gap_mm": -1.1175870895385742e-05,
|
||||
"tamper_xy_alignment_error_mm": 0.0,
|
||||
"tamper_grinder_collisions": [],
|
||||
"tamper_portafilter_collisions": [],
|
||||
"powder_bowl_collisions": []
|
||||
}
|
||||
},
|
||||
"geometry": {
|
||||
"powder_non_manifold_edges": 0,
|
||||
"powder_triangles": 576
|
||||
},
|
||||
"source_hashes_after": {
|
||||
"grinder": "91c3ffa8ee5cbde3c013938837ce2552272d77823b3826768965fd8b02590908",
|
||||
"portafilter": "dd9c42153a37088fbf65cf9e399107258657acdf91c987f50ce6033c907c9ed9",
|
||||
"tamper": "902828b49e93462eb2434beaa2d7f1b974a0fb569ff2f06eeedf6129445f2391"
|
||||
},
|
||||
"source_files_unmodified": true,
|
||||
"passed": true,
|
||||
"visual_review": {
|
||||
"conical_mound_shape_passed": true,
|
||||
"mound_peak_above_rim_mm": 11.5,
|
||||
"mound_slope_height_mm": 18.0,
|
||||
"mound_height_above_final_puck_mm": 22.0,
|
||||
"tamper_bowl_fit_and_press_passed": true,
|
||||
"tamper_contact_height_above_puck_mm": 22.0,
|
||||
"flat_puck_shape_passed": true,
|
||||
"contact_cutaway_passed": true,
|
||||
"powder_stream_stops_before_transfer": true,
|
||||
"portafilter_pulls_forward_before_lifting": true,
|
||||
"tamper_raises_before_horizontal_motion": true,
|
||||
"puck_remains_flat_after_tamper_lift": true,
|
||||
"mound_profile_image": "checks/frame_0108_mound_profile.png",
|
||||
"contact_sheet": "checks/contact_sheet.png",
|
||||
"video_contact_sheet": "checks/video_contact_sheet.png"
|
||||
},
|
||||
"motion_sweep": {
|
||||
"checked_frames": 87,
|
||||
"collision_count": 0,
|
||||
"continuous_contact_sync_passed": true,
|
||||
"report": "motion_validation.json"
|
||||
},
|
||||
"preview_video": {
|
||||
"file": "preview_animation.mp4",
|
||||
"duration_seconds": 7.0,
|
||||
"fps": 12,
|
||||
"frame_count": 84,
|
||||
"resolution": [1920, 720],
|
||||
"dual_view": true,
|
||||
"report": "video_validation.json"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import bpy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from mathutils.bvhtree import BVHTree
|
||||
|
||||
ROOT = Path('/Users/yanchenyu/Documents/WebApps/PerfetCoffee')
|
||||
OUT = ROOT / 'playtests' / 'grinding_tamping'
|
||||
SOURCES = {
|
||||
'grinder': ROOT / 'model_assets' / 'bean_grinder' / 'ElectricCoffeeGrinder_LowPoly.blend',
|
||||
'portafilter': ROOT / 'model_assets' / 'coffee_machine' / 'PerfectCoffee_Portafilter.blend',
|
||||
'tamper': ROOT / 'model_assets' / 'tamper' / 'PerfectCoffee_Tamper.blend',
|
||||
}
|
||||
bpy.ops.wm.open_mainfile(filepath=str(OUT / 'Grinding_Tamping_Whitebox.blend'))
|
||||
scene = bpy.context.scene
|
||||
assert scene.frame_end == 168 and scene.render.fps == 24
|
||||
assert len(scene.timeline_markers) == 12
|
||||
assert len(bpy.data.libraries) == 0
|
||||
assert bpy.data.objects['CM_Portafilter_Bowl'].parent.name == 'CM_Portafilter'
|
||||
assert not any(obj.name.startswith('CM_Portafilter.') for obj in bpy.data.objects)
|
||||
assert not bpy.data.objects['CM_Portafilter_Bowl'].hide_render
|
||||
|
||||
|
||||
def evaluated_mesh(obj, depsgraph):
|
||||
evaluated = obj.evaluated_get(depsgraph)
|
||||
mesh = evaluated.to_mesh()
|
||||
points = [evaluated.matrix_world @ vertex.co for vertex in mesh.vertices]
|
||||
polygons = [tuple(polygon.vertices) for polygon in mesh.polygons]
|
||||
evaluated.to_mesh_clear()
|
||||
return points, polygons
|
||||
|
||||
|
||||
def bvh(obj, depsgraph):
|
||||
points, polygons = evaluated_mesh(obj, depsgraph)
|
||||
return BVHTree.FromPolygons(points, polygons, all_triangles=False, epsilon=0.0)
|
||||
|
||||
|
||||
def overlap(a, b, depsgraph):
|
||||
return len(bvh(a, depsgraph).overlap(bvh(b, depsgraph)))
|
||||
|
||||
|
||||
portafilter = [obj for obj in bpy.data.objects if obj.type == 'MESH' and obj.name.startswith('CM_Portafilter_')]
|
||||
tamper = [bpy.data.objects['TAM_Metal_Base'], bpy.data.objects['TAM_Wood_Handle']]
|
||||
grinder = [bpy.data.objects['Low | Grinder body'], bpy.data.objects['Low | Removable support']]
|
||||
powder = bpy.data.objects['WB_Powder_Fill_And_Tamp']
|
||||
bowl = bpy.data.objects['CM_Portafilter_Bowl']
|
||||
collisions = []
|
||||
checked = []
|
||||
|
||||
|
||||
def check_frame(frame, pf_grinder=False, tamper_pf=False, powder_bowl=False):
|
||||
scene.frame_set(frame)
|
||||
bpy.context.view_layer.update()
|
||||
depsgraph = bpy.context.evaluated_depsgraph_get()
|
||||
checked.append(frame)
|
||||
if pf_grinder:
|
||||
for a in portafilter:
|
||||
for b in grinder:
|
||||
pairs = overlap(a, b, depsgraph)
|
||||
if pairs:
|
||||
collisions.append({'frame': frame, 'a': a.name, 'b': b.name, 'pairs': pairs})
|
||||
if tamper_pf:
|
||||
for a in tamper:
|
||||
for b in portafilter:
|
||||
pairs = overlap(a, b, depsgraph)
|
||||
if pairs:
|
||||
collisions.append({'frame': frame, 'a': a.name, 'b': b.name, 'pairs': pairs})
|
||||
if powder_bowl:
|
||||
pairs = overlap(powder, bowl, depsgraph)
|
||||
if pairs:
|
||||
collisions.append({'frame': frame, 'a': powder.name, 'b': bowl.name, 'pairs': pairs})
|
||||
|
||||
|
||||
for frame in list(range(1, 15)) + list(range(84, 109)):
|
||||
check_frame(frame, pf_grinder=True, powder_bowl=frame >= 14)
|
||||
for frame in range(109, 157):
|
||||
check_frame(frame, tamper_pf=True, powder_bowl=frame <= 126)
|
||||
for frame in (122, 123, 124, 125, 126, 132):
|
||||
scene.frame_set(frame)
|
||||
bpy.context.view_layer.update()
|
||||
powder_peak = max(point.z for point in evaluated_mesh(powder, bpy.context.evaluated_depsgraph_get())[0])
|
||||
tamper_bottom = bpy.data.objects['TAM_Tamper_Assembly'].location.z
|
||||
assert powder_peak <= tamper_bottom + 0.00001, (frame, powder_peak - tamper_bottom)
|
||||
|
||||
scene.frame_set(1)
|
||||
report = {
|
||||
'frame_count_checked': len(checked),
|
||||
'frames_checked': checked,
|
||||
'collisions': collisions,
|
||||
'continuous_contact_sync_passed': True,
|
||||
'reopen_checks': {
|
||||
'frame_end': scene.frame_end,
|
||||
'fps': scene.render.fps,
|
||||
'timeline_markers': len(scene.timeline_markers),
|
||||
'independent_append_no_linked_libraries': len(bpy.data.libraries) == 0,
|
||||
'correct_portafilter_parent': True,
|
||||
'bowl_visible_on_open': not bowl.hide_render,
|
||||
'default_camera': scene.camera.name,
|
||||
'opens_at_frame': scene.frame_current,
|
||||
},
|
||||
'source_hashes_after': {name: hashlib.sha256(path.read_bytes()).hexdigest() for name, path in SOURCES.items()},
|
||||
'passed': not collisions,
|
||||
}
|
||||
(OUT / 'motion_validation.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
print('WHITEBOX_MOTION_VALIDATION=' + json.dumps(report, ensure_ascii=False), flush=True)
|
||||
assert report['passed'], 'Motion sweep found collisions; inspect motion_validation.json'
|
||||
print('WHITEBOX_REOPEN_AND_MOTION_PASSED', flush=True)
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"programs": [],
|
||||
"stream_groups": [],
|
||||
"streams": [
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 720,
|
||||
"r_frame_rate": "12/1",
|
||||
"nb_frames": "84"
|
||||
}
|
||||
],
|
||||
"format": {
|
||||
"duration": "7.000000"
|
||||
},
|
||||
"source_frame_range": [
|
||||
1,
|
||||
168
|
||||
],
|
||||
"source_fps": 24,
|
||||
"preview_fps": 12,
|
||||
"dual_view": true
|
||||
}
|
||||
Reference in New Issue
Block a user