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:
@@ -0,0 +1,515 @@
|
||||
import bpy
|
||||
import bmesh
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from mathutils import Vector
|
||||
from mathutils.bvhtree import BVHTree
|
||||
|
||||
OUT = Path('/Users/yanchenyu/Documents/WebApps/PerfetCoffee/model_assets/coffee_cup')
|
||||
SOURCE = OUT / 'PerfectCoffee_CoffeeCup.blend'
|
||||
TEXTURES = OUT / 'textures'
|
||||
TEXTURES.mkdir(exist_ok=True)
|
||||
SOURCE_SHA256 = hashlib.sha256(SOURCE.read_bytes()).hexdigest()
|
||||
|
||||
SEGMENTS = 96
|
||||
CUP_SEGMENTS = 24
|
||||
CUP_HEIGHT = 0.110
|
||||
CUP_INNER_BOTTOM_RADIUS = 0.028
|
||||
CUP_INNER_TOP_RADIUS = 0.0405
|
||||
CUP_INNER_FLOOR = 0.002
|
||||
LIQUID_BOTTOM = CUP_INNER_FLOOR + 0.00020
|
||||
LIQUID_TOP = 0.10380
|
||||
FOAM_BOTTOM = LIQUID_TOP + 0.00002
|
||||
FOAM_EDGE_TOP = 0.10570
|
||||
FOAM_DOME = 0.00035
|
||||
FIT_CLEARANCE = 0.00012
|
||||
LIQUID_UV_RADIUS = (CUP_INNER_BOTTOM_RADIUS + (CUP_INNER_TOP_RADIUS - CUP_INNER_BOTTOM_RADIUS) * LIQUID_TOP / CUP_HEIGHT) * math.cos(math.pi / CUP_SEGMENTS) - FIT_CLEARANCE
|
||||
FOAM_UV_RADIUS = (CUP_INNER_BOTTOM_RADIUS + (CUP_INNER_TOP_RADIUS - CUP_INNER_BOTTOM_RADIUS) * FOAM_EDGE_TOP / CUP_HEIGHT) * math.cos(math.pi / CUP_SEGMENTS) - FIT_CLEARANCE
|
||||
|
||||
bpy.ops.wm.open_mainfile(filepath=str(SOURCE))
|
||||
bpy.context.preferences.filepaths.save_version = 0
|
||||
scene = bpy.context.scene
|
||||
scene.unit_settings.system = 'METRIC'
|
||||
scene.unit_settings.length_unit = 'METERS'
|
||||
scene.unit_settings.scale_length = 1.0
|
||||
|
||||
lid = bpy.data.objects.get('CC_Lid')
|
||||
if lid is not None:
|
||||
bpy.data.objects.remove(lid, do_unlink=True)
|
||||
for obj in list(bpy.data.collections['Studio_Exclude_From_Export'].objects):
|
||||
bpy.data.objects.remove(obj, do_unlink=True)
|
||||
source_root = bpy.data.objects.get('CC_CoffeeCup_Assembly')
|
||||
if source_root is not None:
|
||||
bpy.data.objects.remove(source_root, do_unlink=True)
|
||||
|
||||
cup = bpy.data.objects['CC_Cup_Body']
|
||||
cup.parent = None
|
||||
cup.location = (0.0, 0.0, 0.0)
|
||||
cup.rotation_euler = (0.0, 0.0, 0.0)
|
||||
model_collection = bpy.data.collections.get('CC_CoffeeCup_Model')
|
||||
model_collection.name = 'CC_CupContents_Preview'
|
||||
studio = bpy.data.collections['Studio_Exclude_From_Export']
|
||||
|
||||
root = bpy.data.objects.new('CC_CupContents_Assembly', None)
|
||||
model_collection.objects.link(root)
|
||||
root.empty_display_type = 'PLAIN_AXES'
|
||||
root.empty_display_size = 0.02
|
||||
root['units'] = 'meters; Z up; liquid +Y corresponds to UV +V'
|
||||
root['source_cup'] = SOURCE.name
|
||||
root['source_cup_sha256'] = SOURCE_SHA256
|
||||
root['liquid_top_m'] = LIQUID_TOP
|
||||
root['foam_edge_top_m'] = FOAM_EDGE_TOP
|
||||
root['foam_dome_m'] = FOAM_DOME
|
||||
root['foam_thickness_mm'] = (FOAM_EDGE_TOP - FOAM_BOTTOM) * 1000.0
|
||||
root['rim_clearance_mm'] = (CUP_HEIGHT - FOAM_EDGE_TOP - FOAM_DOME) * 1000.0
|
||||
root['liquid_material_slot'] = 'CC_Coffee_Liquid'
|
||||
root['foam_material_slot'] = 'CC_Milk_Foam'
|
||||
root['uv_usage'] = 'LiquidSurfaceUV: planar X/Y top projection, center=(0.5,0.5), full top bounds=(0,0)-(1,1)'
|
||||
root['runtime_hint'] = 'Hide CC_Milk_Foam for Americano; override CC_Coffee_Liquid and CC_Milk_Foam materials independently in Godot'
|
||||
|
||||
|
||||
def inner_radius(z):
|
||||
if z <= 0.022:
|
||||
return 0.028 + (z - CUP_INNER_FLOOR) * (0.0305 - 0.028) / (0.022 - CUP_INNER_FLOOR)
|
||||
return 0.0305 + (z - 0.022) * (0.038 - 0.0305) / (0.088 - 0.022)
|
||||
|
||||
|
||||
def fitted_radius(z):
|
||||
return inner_radius(z) * math.cos(math.pi / CUP_SEGMENTS) - FIT_CLEARANCE
|
||||
|
||||
|
||||
def linear_channel(value):
|
||||
return value / 12.92 if value <= 0.04045 else ((value + 0.055) / 1.055) ** 2.4
|
||||
|
||||
|
||||
def rgba_from_hex(value):
|
||||
return tuple(linear_channel(int(value[index:index + 2], 16) / 255.0) for index in (1, 3, 5)) + (1.0,)
|
||||
|
||||
|
||||
def set_input(node, name, value):
|
||||
socket = node.inputs.get(name)
|
||||
if socket is not None:
|
||||
socket.default_value = value
|
||||
|
||||
|
||||
def new_material(name, hex_color, roughness):
|
||||
mat = bpy.data.materials.new(name)
|
||||
mat.use_nodes = True
|
||||
mat.diffuse_color = rgba_from_hex(hex_color)
|
||||
bsdf = mat.node_tree.nodes.get('Principled BSDF')
|
||||
bsdf.inputs['Base Color'].default_value = rgba_from_hex(hex_color)
|
||||
bsdf.inputs['Roughness'].default_value = roughness
|
||||
return mat, bsdf
|
||||
|
||||
|
||||
def micro_bump(mat, bsdf, scale, distance, strength):
|
||||
nodes = mat.node_tree.nodes
|
||||
links = mat.node_tree.links
|
||||
noise = nodes.new('ShaderNodeTexNoise')
|
||||
noise.name = 'Micro_Surface_Only_In_Blender'
|
||||
noise.label = 'Cycles micro detail; use a Godot shader for equivalent detail'
|
||||
noise.inputs['Scale'].default_value = scale
|
||||
noise.inputs['Detail'].default_value = 2.0
|
||||
noise.inputs['Roughness'].default_value = 0.65
|
||||
bump = nodes.new('ShaderNodeBump')
|
||||
bump.inputs['Strength'].default_value = strength
|
||||
bump.inputs['Distance'].default_value = distance
|
||||
links.new(noise.outputs['Fac'], bump.inputs['Height'])
|
||||
links.new(bump.outputs['Normal'], bsdf.inputs['Normal'])
|
||||
noise.location = (-480, -150)
|
||||
bump.location = (-220, -100)
|
||||
|
||||
|
||||
def make_texture(name, pixels):
|
||||
size = pixels.shape[0]
|
||||
image = bpy.data.images.new(name, width=size, height=size, alpha=True)
|
||||
image.colorspace_settings.name = 'sRGB'
|
||||
rgba = np.ones((size, size, 4), dtype=np.float32)
|
||||
rgba[:, :, :3] = np.clip(pixels, 0.0, 1.0)
|
||||
image.pixels.foreach_set(rgba.ravel())
|
||||
image.filepath_raw = str(TEXTURES / (name + '.png'))
|
||||
image.file_format = 'PNG'
|
||||
image.save()
|
||||
image.pack()
|
||||
return image
|
||||
|
||||
|
||||
def attach_albedo(mat, bsdf, image):
|
||||
nodes = mat.node_tree.nodes
|
||||
links = mat.node_tree.links
|
||||
uv = nodes.new('ShaderNodeUVMap')
|
||||
uv.uv_map = 'LiquidSurfaceUV'
|
||||
uv.location = (-680, 220)
|
||||
texture = nodes.new('ShaderNodeTexImage')
|
||||
texture.image = image
|
||||
texture.interpolation = 'Linear'
|
||||
texture.extension = 'EXTEND'
|
||||
texture.location = (-420, 220)
|
||||
links.new(uv.outputs['UV'], texture.inputs['Vector'])
|
||||
links.new(texture.outputs['Color'], bsdf.inputs['Base Color'])
|
||||
bsdf.location = (0, 160)
|
||||
mat.node_tree.nodes.get('Material Output').location = (310, 160)
|
||||
|
||||
|
||||
SIZE = 1024
|
||||
axis = np.linspace(-1.0, 1.0, SIZE, dtype=np.float32)
|
||||
x, y = np.meshgrid(axis, axis)
|
||||
radius = np.sqrt(x * x + y * y)
|
||||
angle = np.arctan2(y, x)
|
||||
rng = np.random.default_rng(4061)
|
||||
noise = (
|
||||
np.sin(x * 21.0 + y * 13.0) * 0.35
|
||||
+ np.sin(x * 57.0 - y * 43.0) * 0.17
|
||||
+ np.cos(x * 109.0 + y * 83.0) * 0.08
|
||||
+ rng.normal(0.0, 0.10, (SIZE, SIZE))
|
||||
)
|
||||
|
||||
coffee_dark = np.array([39.0, 20.0, 9.0]) / 255.0
|
||||
coffee_edge = np.array([87.0, 45.0, 16.0]) / 255.0
|
||||
edge = np.clip((radius - 0.82) / 0.18, 0.0, 1.0) ** 3
|
||||
swirl = (0.5 + 0.5 * np.sin(angle * 3.0 + radius * 38.0)) * np.exp(-((radius - 0.91) / 0.055) ** 2)
|
||||
coffee_pixels = coffee_dark[None, None, :] * (1.0 - edge[:, :, None] * 0.64) + coffee_edge[None, None, :] * edge[:, :, None] * 0.64
|
||||
coffee_pixels += swirl[:, :, None] * np.array([0.020, 0.010, 0.002])[None, None, :]
|
||||
coffee_pixels += noise[:, :, None] * 0.007
|
||||
coffee_image = make_texture('CC_Coffee_Surface', coffee_pixels)
|
||||
|
||||
latte_base = np.array([163.0, 101.0, 51.0]) / 255.0
|
||||
latte_edge = np.array([119.0, 70.0, 31.0]) / 255.0
|
||||
milk = np.array([255.0, 241.0, 214.0]) / 255.0
|
||||
foam_edge = np.clip((radius - 0.80) / 0.20, 0.0, 1.0) ** 2
|
||||
latte_pixels = latte_base[None, None, :] * (1.0 - foam_edge[:, :, None] * 0.52) + latte_edge[None, None, :] * foam_edge[:, :, None] * 0.52
|
||||
latte_pixels += noise[:, :, None] * 0.010
|
||||
|
||||
curve_size = 2048
|
||||
curve_axis = np.linspace(-1.0, 1.0, curve_size, dtype=np.float32)
|
||||
t = np.linspace(0.0, math.tau, 512, endpoint=False)
|
||||
heart_x = 16.0 * np.sin(t) ** 3 / 17.0 * 0.65
|
||||
heart_y = (13.0 * np.cos(t) - 5.0 * np.cos(2.0 * t) - 2.0 * np.cos(3.0 * t) - np.cos(4.0 * t)) / 17.0 * 0.68 + 0.065
|
||||
next_x = np.roll(heart_x, -1)
|
||||
next_y = np.roll(heart_y, -1)
|
||||
heart_large = np.zeros((curve_size, curve_size), dtype=np.float32)
|
||||
for row, y_value in enumerate(curve_axis):
|
||||
crossing = (heart_y > y_value) != (next_y > y_value)
|
||||
x_crossings = heart_x[crossing] + (y_value - heart_y[crossing]) * (next_x[crossing] - heart_x[crossing]) / (next_y[crossing] - heart_y[crossing])
|
||||
x_crossings.sort()
|
||||
for pair in range(0, len(x_crossings), 2):
|
||||
left = np.searchsorted(curve_axis, x_crossings[pair])
|
||||
right = np.searchsorted(curve_axis, x_crossings[pair + 1])
|
||||
heart_large[row, left:right] = 1.0
|
||||
heart = heart_large.reshape(SIZE, 2, SIZE, 2).mean(axis=(1, 3))
|
||||
latte_pixels = latte_pixels * (1.0 - heart[:, :, None]) + milk[None, None, :] * heart[:, :, None]
|
||||
|
||||
for _ in range(100):
|
||||
bubble_angle = rng.uniform(0.0, math.tau)
|
||||
bubble_radius = rng.uniform(0.82, 0.975)
|
||||
bx = math.cos(bubble_angle) * bubble_radius
|
||||
by = math.sin(bubble_angle) * bubble_radius
|
||||
br = rng.uniform(0.0020, 0.0065)
|
||||
distance = np.sqrt((x - bx) ** 2 + (y - by) ** 2)
|
||||
ring = np.exp(-((distance - br) / 0.0016) ** 2) * 0.26
|
||||
latte_pixels = latte_pixels * (1.0 - ring[:, :, None]) + milk[None, None, :] * ring[:, :, None]
|
||||
latte_image = make_texture('CC_Latte_Surface', latte_pixels)
|
||||
|
||||
coffee_mat, coffee_bsdf = new_material('CC_Coffee_Liquid', '#271409', 0.20)
|
||||
set_input(coffee_bsdf, 'IOR', 1.333)
|
||||
set_input(coffee_bsdf, 'Specular IOR Level', 0.32)
|
||||
set_input(coffee_bsdf, 'Coat Weight', 0.18)
|
||||
set_input(coffee_bsdf, 'Coat Roughness', 0.16)
|
||||
attach_albedo(coffee_mat, coffee_bsdf, coffee_image)
|
||||
micro_bump(coffee_mat, coffee_bsdf, 95.0, 0.000015, 0.08)
|
||||
|
||||
foam_mat, foam_bsdf = new_material('CC_Milk_Foam', '#A36533', 0.62)
|
||||
set_input(foam_bsdf, 'IOR', 1.35)
|
||||
set_input(foam_bsdf, 'Specular IOR Level', 0.20)
|
||||
set_input(foam_bsdf, 'Subsurface Weight', 0.035)
|
||||
set_input(foam_bsdf, 'Subsurface Radius', (0.001, 0.0006, 0.0003))
|
||||
set_input(foam_bsdf, 'Subsurface Scale', 0.001)
|
||||
attach_albedo(foam_mat, foam_bsdf, latte_image)
|
||||
micro_bump(foam_mat, foam_bsdf, 145.0, 0.000055, 0.13)
|
||||
|
||||
|
||||
def recalculate_normals(mesh):
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(mesh)
|
||||
bmesh.ops.recalc_face_normals(bm, faces=list(bm.faces))
|
||||
bm.to_mesh(mesh)
|
||||
bm.free()
|
||||
mesh.update()
|
||||
|
||||
|
||||
def apply_planar_uv(obj, uv_radius):
|
||||
uv = obj.data.uv_layers['LiquidSurfaceUV']
|
||||
for polygon in obj.data.polygons:
|
||||
polygon.use_smooth = abs(polygon.normal.z) < 0.995
|
||||
for loop_index in polygon.loop_indices:
|
||||
vertex = obj.data.vertices[obj.data.loops[loop_index].vertex_index].co
|
||||
uv.data[loop_index].uv = (0.5 + vertex.x / (2.0 * uv_radius), 0.5 + vertex.y / (2.0 * uv_radius))
|
||||
obj['uv_radius_m'] = uv_radius
|
||||
|
||||
|
||||
def make_object(name, vertices, faces, top_face_start, material, uv_radius):
|
||||
mesh = bpy.data.meshes.new(name + '_Mesh')
|
||||
mesh.from_pydata(vertices, [], faces)
|
||||
recalculate_normals(mesh)
|
||||
obj = bpy.data.objects.new(name, mesh)
|
||||
model_collection.objects.link(obj)
|
||||
obj.parent = root
|
||||
obj.data.materials.append(material)
|
||||
mesh.uv_layers.new(name='LiquidSurfaceUV')
|
||||
mesh.uv_layers.active = mesh.uv_layers['LiquidSurfaceUV']
|
||||
apply_planar_uv(obj, uv_radius)
|
||||
obj['uv_map'] = 'LiquidSurfaceUV'
|
||||
obj['top_uv_faces'] = len(mesh.polygons) - top_face_start
|
||||
obj['material_slot'] = material.name
|
||||
return obj
|
||||
|
||||
|
||||
liquid_rings = [
|
||||
(fitted_radius(LIQUID_BOTTOM), LIQUID_BOTTOM),
|
||||
(fitted_radius(LIQUID_TOP), LIQUID_TOP),
|
||||
]
|
||||
vertices = []
|
||||
for ring_radius, z in liquid_rings:
|
||||
for index in range(SEGMENTS):
|
||||
angle = math.tau * index / SEGMENTS
|
||||
vertices.append((ring_radius * math.cos(angle), ring_radius * math.sin(angle), z))
|
||||
faces = [tuple(reversed(range(SEGMENTS)))]
|
||||
for index in range(SEGMENTS):
|
||||
following = (index + 1) % SEGMENTS
|
||||
faces.append((index, following, SEGMENTS + following, SEGMENTS + index))
|
||||
liquid = make_object('CC_Coffee_Liquid', vertices, faces, len(faces), coffee_mat, LIQUID_UV_RADIUS)
|
||||
liquid_top_start = len(liquid.data.polygons)
|
||||
cap = bmesh.new()
|
||||
cap.from_mesh(liquid.data)
|
||||
outer = [vertex for vertex in cap.verts if abs(vertex.co.z - LIQUID_TOP) < 0.0000001]
|
||||
bmesh.ops.triangle_fill(cap, edges=[edge for edge in cap.edges if all(vertex in outer for vertex in edge.verts)], use_beauty=True)
|
||||
bmesh.ops.recalc_face_normals(cap, faces=list(cap.faces))
|
||||
cap.to_mesh(liquid.data)
|
||||
cap.free()
|
||||
liquid.data.update()
|
||||
apply_planar_uv(liquid, LIQUID_UV_RADIUS)
|
||||
liquid['top_uv_faces'] = len(liquid.data.polygons) - liquid_top_start
|
||||
liquid['fill_height_mm'] = (LIQUID_TOP - LIQUID_BOTTOM) * 1000.0
|
||||
liquid['top_clearance_to_rim_mm'] = (CUP_HEIGHT - LIQUID_TOP) * 1000.0
|
||||
|
||||
foam_rings = [
|
||||
(fitted_radius(FOAM_BOTTOM) - 0.00008, FOAM_BOTTOM),
|
||||
(fitted_radius(FOAM_BOTTOM), FOAM_BOTTOM + 0.00012),
|
||||
(fitted_radius(FOAM_EDGE_TOP) - 0.00008, FOAM_EDGE_TOP - 0.00012),
|
||||
]
|
||||
for fraction in (1.0, 0.975, 0.92, 0.78, 0.55, 0.30, 0.12):
|
||||
z = FOAM_EDGE_TOP + FOAM_DOME * (1.0 - fraction * fraction)
|
||||
foam_rings.append((fitted_radius(FOAM_EDGE_TOP) * fraction, z))
|
||||
vertices = []
|
||||
for ring_radius, z in foam_rings:
|
||||
for index in range(SEGMENTS):
|
||||
angle = math.tau * index / SEGMENTS
|
||||
vertices.append((ring_radius * math.cos(angle), ring_radius * math.sin(angle), z))
|
||||
faces = [tuple(reversed(range(SEGMENTS)))]
|
||||
for ring_index in range(len(foam_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))
|
||||
foam_top_start = len(faces) - 7 * SEGMENTS
|
||||
center_index = len(vertices)
|
||||
vertices.append((0.0, 0.0, FOAM_EDGE_TOP + FOAM_DOME))
|
||||
last = (len(foam_rings) - 1) * SEGMENTS
|
||||
for index in range(SEGMENTS):
|
||||
following = (index + 1) % SEGMENTS
|
||||
faces.append((last + index, last + following, center_index))
|
||||
foam = make_object('CC_Milk_Foam', vertices, faces, foam_top_start, foam_mat, FOAM_UV_RADIUS)
|
||||
foam['thickness_at_edge_mm'] = (FOAM_EDGE_TOP - FOAM_BOTTOM) * 1000.0
|
||||
foam['dome_rise_mm'] = FOAM_DOME * 1000.0
|
||||
foam['surface_texture'] = 'CC_Latte_Surface.png'
|
||||
foam['surface_texture_uv'] = 'LiquidSurfaceUV; replace this image for other latte art'
|
||||
|
||||
|
||||
def point_at(obj, target):
|
||||
obj.rotation_euler = (Vector(target) - obj.location).to_track_quat('-Z', 'Y').to_euler()
|
||||
|
||||
|
||||
def camera(name, location, target, ortho_scale):
|
||||
data = bpy.data.cameras.new(name)
|
||||
data.type = 'ORTHO'
|
||||
data.ortho_scale = ortho_scale
|
||||
data.clip_start = 0.001
|
||||
data.clip_end = 100.0
|
||||
obj = bpy.data.objects.new(name, data)
|
||||
studio.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.objects.link(obj)
|
||||
obj.location = location
|
||||
point_at(obj, target)
|
||||
return obj
|
||||
|
||||
|
||||
ground_mat, ground_bsdf = new_material('Studio_Warm_Stone', '#A89D8D', 0.78)
|
||||
bpy.ops.mesh.primitive_plane_add(size=2.0, location=(0.0, 0.0, -0.00008))
|
||||
ground = bpy.context.object
|
||||
ground.name = 'Studio_Ground'
|
||||
for collection in list(ground.users_collection):
|
||||
collection.objects.unlink(ground)
|
||||
studio.objects.link(ground)
|
||||
ground.data.materials.append(ground_mat)
|
||||
|
||||
world = bpy.data.worlds.new('CupContents_Studio_World')
|
||||
world.use_nodes = True
|
||||
world.node_tree.nodes['Background'].inputs['Color'].default_value = (0.32, 0.36, 0.42, 1.0)
|
||||
world.node_tree.nodes['Background'].inputs['Strength'].default_value = 0.20
|
||||
scene.world = world
|
||||
area_light('Studio_Key', (0.10, 0.08, 0.25), 0.75, 0.17, (1.0, 0.89, 0.75), (0.0, 0.0, 0.07))
|
||||
area_light('Studio_Fill', (-0.16, 0.04, 0.16), 0.30, 0.14, (0.80, 0.89, 1.0), (0.0, 0.0, 0.065))
|
||||
area_light('Studio_Rim', (0.02, -0.15, 0.23), 0.90, 0.13, (1.0, 0.96, 0.87), (0.0, 0.0, 0.08))
|
||||
hero_camera = camera('Acceptance_Latte_Cycles', (0.145, 0.205, 0.285), (0.0, 0.0, 0.061), 0.165)
|
||||
top_camera = camera('Acceptance_Latte_Top_UV', (0.0, 0.0, 0.31), (0.0, 0.0, 0.0), 0.103)
|
||||
detail_camera = camera('Acceptance_Foam_Detail', (0.095, 0.135, 0.255), (0.0, 0.0, 0.098), 0.107)
|
||||
|
||||
scene.render.engine = 'CYCLES'
|
||||
scene.cycles.samples = 96
|
||||
scene.cycles.use_denoising = True
|
||||
scene.cycles.max_bounces = 8
|
||||
scene.render.resolution_x = 1400
|
||||
scene.render.resolution_y = 1400
|
||||
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.5
|
||||
|
||||
|
||||
def non_manifold_count(obj):
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(obj.data)
|
||||
result = sum(1 for edge in bm.edges if not edge.is_manifold)
|
||||
bm.free()
|
||||
return result
|
||||
|
||||
|
||||
def uv_report(obj, top_z):
|
||||
uv = obj.data.uv_layers['LiquidSurfaceUV']
|
||||
top_loops = [loop_index for polygon in obj.data.polygons if abs(polygon.normal.z) > 0.5 for loop_index in polygon.loop_indices if obj.data.vertices[obj.data.loops[loop_index].vertex_index].co.z >= top_z - 0.000001]
|
||||
center_uv = None
|
||||
if obj == foam:
|
||||
center = obj.data.vertices[center_index]
|
||||
for loop in obj.data.loops:
|
||||
if loop.vertex_index == center_index:
|
||||
center_uv = list(uv.data[loop.index].uv)
|
||||
break
|
||||
return {
|
||||
'uv_map': uv.name,
|
||||
'uv_bounds': [min(uv.data[index].uv[axis] for axis in (0, 1) for index in top_loops), max(uv.data[index].uv[axis] for axis in (0, 1) for index in top_loops)],
|
||||
'center_uv': center_uv,
|
||||
'top_faces': obj['top_uv_faces'],
|
||||
'material_slots': [slot.material.name for slot in obj.material_slots],
|
||||
'non_manifold_edges': non_manifold_count(obj),
|
||||
}
|
||||
|
||||
|
||||
bpy.context.view_layer.update()
|
||||
cup_bvh = BVHTree.FromObject(cup, bpy.context.evaluated_depsgraph_get())
|
||||
liquid_bvh = BVHTree.FromObject(liquid, bpy.context.evaluated_depsgraph_get())
|
||||
foam_bvh = BVHTree.FromObject(foam, bpy.context.evaluated_depsgraph_get())
|
||||
liquid_cup_intersections = len(cup_bvh.overlap(liquid_bvh))
|
||||
foam_cup_intersections = len(cup_bvh.overlap(foam_bvh))
|
||||
foam_liquid_intersections = len(liquid_bvh.overlap(foam_bvh))
|
||||
liquid_uv = uv_report(liquid, LIQUID_TOP)
|
||||
foam_uv = uv_report(foam, FOAM_EDGE_TOP)
|
||||
report = {
|
||||
'source_cup': SOURCE.name,
|
||||
'source_cup_sha256_before_build': SOURCE_SHA256,
|
||||
'source_cup_sha256_after_build': hashlib.sha256(SOURCE.read_bytes()).hexdigest(),
|
||||
'lid_included': False,
|
||||
'liquid_top_mm': LIQUID_TOP * 1000.0,
|
||||
'foam_edge_thickness_mm': (FOAM_EDGE_TOP - FOAM_BOTTOM) * 1000.0,
|
||||
'foam_center_rise_mm': FOAM_DOME * 1000.0,
|
||||
'rim_clearance_mm': (CUP_HEIGHT - FOAM_EDGE_TOP - FOAM_DOME) * 1000.0,
|
||||
'radial_fit_clearance_min_mm': FIT_CLEARANCE * 1000.0,
|
||||
'liquid_cup_triangle_intersections': liquid_cup_intersections,
|
||||
'foam_cup_triangle_intersections': foam_cup_intersections,
|
||||
'foam_liquid_triangle_intersections': foam_liquid_intersections,
|
||||
'coffee': liquid_uv,
|
||||
'foam': foam_uv,
|
||||
'textures_packed': {image.name: bool(image.packed_file) for image in (coffee_image, latte_image)},
|
||||
'render_engine': scene.render.engine,
|
||||
}
|
||||
report['passed'] = (
|
||||
report['source_cup_sha256_before_build'] == report['source_cup_sha256_after_build']
|
||||
and liquid_cup_intersections == 0
|
||||
and foam_cup_intersections == 0
|
||||
and foam_liquid_intersections == 0
|
||||
and liquid.data.uv_layers.active.name == 'LiquidSurfaceUV'
|
||||
and foam.data.uv_layers.active.name == 'LiquidSurfaceUV'
|
||||
and liquid_uv['non_manifold_edges'] == 0
|
||||
and foam_uv['non_manifold_edges'] == 0
|
||||
and len(liquid.material_slots) == 1
|
||||
and len(foam.material_slots) == 1
|
||||
and liquid.material_slots[0].material != foam.material_slots[0].material
|
||||
and all(0.0 <= value <= 1.0 for value in liquid_uv['uv_bounds'] + foam_uv['uv_bounds'])
|
||||
and all(abs(value - 0.5) < 0.000001 for value in foam_uv['center_uv'])
|
||||
and all(report['textures_packed'].values())
|
||||
)
|
||||
(OUT / 'validation_contents.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
print('CUP_CONTENTS_VALIDATION=' + json.dumps(report, ensure_ascii=False), flush=True)
|
||||
assert report['passed'], 'Cup contents validation failed; inspect validation_contents.json'
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
root.select_set(True)
|
||||
liquid.select_set(True)
|
||||
foam.select_set(True)
|
||||
bpy.context.view_layer.objects.active = root
|
||||
bpy.ops.export_scene.gltf(
|
||||
filepath=str(OUT / 'PerfectCoffee_CupContents.glb'),
|
||||
export_format='GLB',
|
||||
use_selection=True,
|
||||
export_apply=True,
|
||||
export_animations=False,
|
||||
export_extras=True,
|
||||
export_cameras=False,
|
||||
export_lights=False,
|
||||
)
|
||||
|
||||
scene.camera = hero_camera
|
||||
scene.render.filepath = str(OUT / 'preview_contents_latte.png')
|
||||
bpy.ops.render.render(write_still=True)
|
||||
|
||||
scene.camera = top_camera
|
||||
scene.render.filepath = str(OUT / 'preview_contents_latte_top.png')
|
||||
bpy.ops.render.render(write_still=True)
|
||||
|
||||
foam.hide_render = True
|
||||
scene.camera = detail_camera
|
||||
scene.render.filepath = str(OUT / 'preview_contents_americano.png')
|
||||
bpy.ops.render.render(write_still=True)
|
||||
foam.hide_render = False
|
||||
scene.camera = hero_camera
|
||||
scene.render.filepath = str(OUT / 'preview_contents_latte.png')
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
root.select_set(True)
|
||||
bpy.context.view_layer.objects.active = root
|
||||
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(OUT / 'PerfectCoffee_CupContents.blend'))
|
||||
print('CUP_CONTENTS_BUILD_COMPLETE', flush=True)
|
||||
Reference in New Issue
Block a user