feat: add approved 2L milk bottle

Preserve the user-approved square-body design with an integral curved grip and late shoulder taper. Includes independent cap, reference image, Blender/GLB exports, and assembly validation.
This commit is contained in:
Yanchen
2026-11-15 13:16:32 +08:00
parent d190c496d0
commit 036ee25a2a
17 changed files with 1248 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,208 @@
import bpy
import bmesh
import json
from pathlib import Path
from mathutils import Vector
from mathutils.bvhtree import BVHTree
OUT = Path(__file__).resolve().parent
SOURCE = OUT.parent / "PerfectCoffee_milk_2l.blend"
bpy.ops.wm.open_mainfile(filepath=str(SOURCE))
bpy.context.preferences.filepaths.save_version = 0
scene = bpy.context.scene
body = bpy.data.objects["Milk_Bottle_Body"]
cap = bpy.data.objects["Milk_Cap"]
pivot = bpy.data.objects["Milk_Cap_Pivot"]
root = bpy.data.objects["Milk2L_Root"]
def bvh(obj):
return BVHTree.FromPolygons(
[obj.matrix_world @ vertex.co for vertex in obj.data.vertices],
[list(polygon.vertices) for polygon in obj.data.polygons],
)
def triangles(obj):
obj.data.calc_loop_triangles()
return len(obj.data.loop_triangles)
bpy.context.view_layer.update()
bm = bmesh.new()
bm.from_mesh(body.data)
non_manifold = sum(not edge.is_manifold for edge in bm.edges)
euler = len(bm.verts) - len(bm.edges) + len(bm.faces)
bm.free()
body_eval = body.evaluated_get(bpy.context.evaluated_depsgraph_get())
factor = root["neck_outer_radius_m"] / 0.018
side_hit = body_eval.ray_cast(Vector((0.1, -0.005 * factor, 0.165)), Vector((-1, 0, 0)), distance=0.2)
center_hit = body_eval.ray_cast(Vector((0, -0.1, 0.165)), Vector((0, 1, 0)), distance=0.2)
handle_path = [Vector((point[0] * factor, point[1] * factor, 0.165)) for point in root["handle_path_xy"]]
blocked_segments = []
for index, (start, end) in enumerate(zip(handle_path[:-1], handle_path[1:])):
direction = end - start
hit = body_eval.ray_cast(start, direction.normalized(), distance=direction.length + 0.000001)
if hit[0]:
blocked_segments.append({"segment": index, "point": list(hit[1])})
arc_path_clear = not blocked_segments
bottom_probe = handle_path[6]
bottom_hit = body_eval.ray_cast(Vector((bottom_probe.x, bottom_probe.y, 0.213)), Vector((0, 0, -1)), distance=0.12)
mouth_vertices = [vertex.co for vertex in body.data.vertices if abs(vertex.co.z - root["mouth_z_m"]) < 0.000001]
mouth_center = sum(mouth_vertices, Vector()) / len(mouth_vertices)
cap_center = pivot.matrix_world.translation
alignment_error = Vector((mouth_center.x - cap_center.x, mouth_center.y - cap_center.y)).length
mouth_center_error = Vector((mouth_center.x, mouth_center.y)).length
lower_vertices = [vertex.co for vertex in body.data.vertices if abs(vertex.co.z - root["lower_segment_top_z_m"]) < 0.000001]
lower_width = max(point.x for point in lower_vertices) - min(point.x for point in lower_vertices)
lower_depth = max(point.y for point in lower_vertices) - min(point.y for point in lower_vertices)
intersections = bvh(body).overlap(bvh(cap))
old_cap_location = pivot.location.copy()
old_cap_z = cap.matrix_world.translation.z
pivot.location.z += 0.04
bpy.context.view_layer.update()
removal_distance = cap.matrix_world.translation.z - old_cap_z
pivot.location = old_cap_location
bpy.context.view_layer.update()
side_entry = bool(side_hit[0]) and side_hit[1].x < 0.061 * factor and side_hit[1].x > -0.061 * factor
center_blocked = bool(center_hit[0]) and center_hit[1].y < 0
limited_bottom = bool(bottom_hit[0]) and 0.115 < bottom_hit[1].z < 0.135
report = {
"source_blend": SOURCE.name,
"test_blend": "MilkCap_AssemblyTest.blend",
"assembled_triangles": triangles(body) + triangles(cap),
"triangle_limit": 1000,
"body_non_manifold_edges": non_manifold,
"body_euler_characteristic": euler,
"expected_body_genus_for_corner_grip": 1,
"expected_euler_characteristic": 0,
"square_lower_section_width_m": lower_width,
"square_lower_section_depth_m": lower_depth,
"square_lower_section_passed": abs(lower_width - lower_depth) < 0.000001,
"lower_segment_top_z_m": root["lower_segment_top_z_m"],
"shoulder_start_height_ratio": root["shoulder_start_height_ratio"],
"shoulder_start_height_passed": 0.79 <= root["shoulder_start_height_ratio"] <= 0.81,
"mouth_center_error_m": mouth_center_error,
"mouth_centered_passed": mouth_center_error < 0.000001,
"shoulder_to_mouth_ratio": root["shoulder_to_mouth_ratio"],
"upper_shoulder_termination_passed": root["shoulder_to_mouth_ratio"] <= 1.25,
"handle_construction": root["handle_construction"],
"handle_cavity_overlap_ml": root["handle_cavity_overlap_ml"],
"handle_cavity_separation_passed": root["handle_cavity_overlap_ml"] < 0.001,
"side_pocket_entry_point_m": list(side_hit[1]) if side_hit[0] else None,
"side_pocket_entry_passed": side_entry,
"central_body_stop_point_m": list(center_hit[1]) if center_hit[0] else None,
"no_full_depth_tunnel_passed": center_blocked,
"handle_path_blocked_segments": blocked_segments,
"arched_handle_path_clear_passed": arc_path_clear,
"handle_aperture_width_m": root["handle_aperture_width_m"],
"handle_aperture_height_m": root["handle_aperture_height_m"],
"handle_aperture_size_passed": root["handle_aperture_width_m"] >= 0.015 and root["handle_aperture_height_m"] >= 0.08,
"pocket_bottom_point_m": list(bottom_hit[1]) if bottom_hit[0] else None,
"limited_height_pocket_passed": limited_bottom,
"integral_corner_handle_passed": arc_path_clear and center_blocked and limited_bottom and non_manifold == 0 and euler == 0,
"handle_is_separate_object": False,
"cap_body_triangle_intersections": len(intersections),
"cap_body_intersection_passed": not intersections,
"cap_radial_clearance_m": root["cap_radial_clearance_m"],
"cap_radial_clearance_passed": root["cap_radial_clearance_m"] >= 0.0005,
"cap_top_clearance_m": root["cap_top_clearance_m"],
"cap_top_clearance_passed": root["cap_top_clearance_m"] >= 0.0004,
"cap_axis_alignment_error_m": alignment_error,
"cap_axis_alignment_passed": alignment_error < 0.00001,
"cap_removal_distance_m": removal_distance,
"cap_removal_passed": abs(removal_distance - 0.04) < 0.00001,
"mouth_height_m": root["mouth_z_m"],
"cap_base_height_m": root["cap_base_z_m"],
"preview_assembled": "assembled_closeup.png",
"preview_exploded": "exploded_closeup.png",
"preview_handle": "handle_corner.png",
"preview_top": "top_view.png",
"preview_handle_top_detail": "handle_top_detail.png",
"top_section_height_m": 0.165,
}
checks = [value for key, value in report.items() if key.endswith("_passed")]
report["passed"] = all(checks) and report["assembled_triangles"] <= 1000
(OUT / "validation.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
assert report["passed"], json.dumps(report, ensure_ascii=False)
camera = scene.camera
original_matrix = camera.matrix_world.copy()
original_scale = camera.data.ortho_scale
original_filepath = scene.render.filepath
scene.render.resolution_x = 900
scene.render.resolution_y = 900
neck_target = Vector((cap_center.x, cap_center.y, 0.263))
camera.location = neck_target + Vector((0.085, -0.13, 0.060))
camera.rotation_euler = (neck_target - camera.location).to_track_quat("-Z", "Y").to_euler()
camera.data.ortho_scale = 0.090
scene.render.filepath = str(OUT / "assembled_closeup.png")
bpy.ops.render.render(write_still=True)
pivot.location.z += 0.04
exploded_target = Vector((cap_center.x, cap_center.y, 0.282))
camera.location = exploded_target + Vector((0.095, -0.15, 0.035))
camera.rotation_euler = (exploded_target - camera.location).to_track_quat("-Z", "Y").to_euler()
camera.data.ortho_scale = 0.120
scene.render.filepath = str(OUT / "exploded_closeup.png")
bpy.ops.render.render(write_still=True)
pivot.location = old_cap_location
corner_target = Vector((0.034 * factor, 0.030 * factor, 0.166))
camera.location = corner_target + Vector((0.20, 0.22, 0.14))
camera.rotation_euler = (corner_target - camera.location).to_track_quat("-Z", "Y").to_euler()
camera.data.ortho_scale = 0.155
scene.render.filepath = str(OUT / "handle_corner.png")
bpy.ops.render.render(write_still=True)
section_mesh = body.data.copy()
bm = bmesh.new()
bm.from_mesh(section_mesh)
bmesh.ops.bisect_plane(
bm, geom=list(bm.verts) + list(bm.edges) + list(bm.faces),
dist=0.000001, plane_co=(0, 0, 0.165), plane_no=(0, 0, 1),
clear_inner=False, clear_outer=True,
)
cut_edges = [edge for edge in bm.edges if edge.is_boundary]
outline_data = bpy.data.curves.new("Handle_Level_Outline", "CURVE")
outline_data.dimensions = "3D"
outline_data.resolution_u = 1
outline_data.bevel_depth = 0.00035
outline_data.bevel_resolution = 0
for edge in cut_edges:
spline = outline_data.splines.new("POLY")
spline.points.add(1)
for point, vertex in zip(spline.points, edge.verts):
point.co = (*vertex.co, 1)
bm.free()
bpy.data.meshes.remove(section_mesh)
section_material = bpy.data.materials.new("Handle_Section_Contrast")
section_material.diffuse_color = (0.025, 0.055, 0.08, 1)
section_material.use_nodes = True
section_material.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = (0.025, 0.055, 0.08, 1)
section_material.node_tree.nodes["Principled BSDF"].inputs["Roughness"].default_value = 0.8
outline_data.materials.append(section_material)
section = bpy.data.objects.new("Handle_Level_Section_Preview", outline_data)
scene.collection.objects.link(section)
section.matrix_world = body.matrix_world.copy()
body.hide_render = True
cap.hide_render = True
top_target = Vector((0, 0, 0.165))
camera.location = (0, 0, 0.60)
camera.rotation_euler = (top_target - camera.location).to_track_quat("-Z", "Y").to_euler()
camera.data.ortho_scale = 0.155
scene.render.filepath = str(OUT / "top_view.png")
bpy.ops.render.render(write_still=True)
detail_target = Vector((0.043, 0.035, 0.165))
camera.location = (0.043, 0.035, 0.60)
camera.rotation_euler = (detail_target - camera.location).to_track_quat("-Z", "Y").to_euler()
camera.data.ortho_scale = 0.068
scene.render.filepath = str(OUT / "handle_top_detail.png")
bpy.ops.render.render(write_still=True)
bpy.data.objects.remove(section, do_unlink=True)
body.hide_render = False
cap.hide_render = False
camera.matrix_world = original_matrix
camera.data.ortho_scale = original_scale
scene.render.filepath = original_filepath
scene.render.resolution_x = 720
scene.render.resolution_y = 720
bpy.ops.wm.save_as_mainfile(filepath=str(OUT / "MilkCap_AssemblyTest.blend"), compress=True)
print(json.dumps(report, ensure_ascii=False, indent=2))
Binary file not shown.
@@ -0,0 +1,67 @@
{
"source_blend": "PerfectCoffee_milk_2l.blend",
"test_blend": "MilkCap_AssemblyTest.blend",
"assembled_triangles": 906,
"triangle_limit": 1000,
"body_non_manifold_edges": 0,
"body_euler_characteristic": 0,
"expected_body_genus_for_corner_grip": 1,
"expected_euler_characteristic": 0,
"square_lower_section_width_m": 0.1261652559041977,
"square_lower_section_depth_m": 0.1261652559041977,
"square_lower_section_passed": true,
"lower_segment_top_z_m": 0.222,
"shoulder_start_height_ratio": 0.7985611510791366,
"shoulder_start_height_passed": true,
"mouth_center_error_m": 8.677086097498004e-11,
"mouth_centered_passed": true,
"shoulder_to_mouth_ratio": 1.1666666666666667,
"upper_shoulder_termination_passed": true,
"handle_construction": "Large arched corner opening from +X toward +Y around an integral vertical grip; central body is not cut through",
"handle_cavity_overlap_ml": 0.0,
"handle_cavity_separation_passed": true,
"side_pocket_entry_point_m": [
0.059036735445261,
-0.005256885662674904,
0.16500000655651093
],
"side_pocket_entry_passed": true,
"central_body_stop_point_m": [
0.0,
-0.06308262795209885,
0.16500000655651093
],
"no_full_depth_tunnel_passed": true,
"handle_path_blocked_segments": [],
"arched_handle_path_clear_passed": true,
"handle_aperture_width_m": 0.017,
"handle_aperture_height_m": 0.092,
"handle_aperture_size_passed": true,
"pocket_bottom_point_m": [
0.04626059532165527,
0.024181675165891647,
0.12200000882148743
],
"limited_height_pocket_passed": true,
"integral_corner_handle_passed": true,
"handle_is_separate_object": false,
"cap_body_triangle_intersections": 0,
"cap_body_intersection_passed": true,
"cap_radial_clearance_m": 0.0009609587100767681,
"cap_radial_clearance_passed": true,
"cap_top_clearance_m": 0.0005,
"cap_top_clearance_passed": true,
"cap_axis_alignment_error_m": 8.677086097498004e-11,
"cap_axis_alignment_passed": true,
"cap_removal_distance_m": 0.03999999165534973,
"cap_removal_passed": true,
"mouth_height_m": 0.278,
"cap_base_height_m": 0.264,
"preview_assembled": "assembled_closeup.png",
"preview_exploded": "exploded_closeup.png",
"preview_handle": "handle_corner.png",
"preview_top": "top_view.png",
"preview_handle_top_detail": "handle_top_detail.png",
"top_section_height_m": 0.165,
"passed": true
}
Binary file not shown.
Binary file not shown.
+98
View File
@@ -0,0 +1,98 @@
{
"asset": "Milk2L_Root",
"design_id": "premade_milk",
"release_status": "approved_for_official_release",
"release_role": "Official 2L plastic milk bottle for future game versions",
"approval_note": "User approved this version after enlarging the curved handle and moving the shoulder transition to 79.856 percent of total height.",
"reference_source": "https://www.woolworths.com.au/shop/productdetails/888137/woolworths-full-cream-milk",
"reference_usage": "Shape and proportion reference only; no branding or packaging labels are used.",
"blender_version": "5.2.0 LTS",
"units": "meters",
"axis_convention": "Blender Z up; GLB Y up",
"triangle_limit": 1000,
"triangles": 906,
"passed_triangle_budget": true,
"mesh_components": {
"Milk_Bottle_Body": 682,
"Milk_Cap": 224
},
"bounds_min_m": [
-0.06308262795209885,
-0.06308262795209885,
0.0020000000949949026
],
"bounds_max_m": [
0.06308262795209885,
0.06308262795209885,
0.2809999883174896
],
"dimensions_m": [
0.1261652559041977,
0.1261652559041977,
0.2789999882224947
],
"reference_photo": "milk_2l_woolworths.png",
"reference_images_packed": true,
"labels_or_brand_graphics": false,
"blend": "PerfectCoffee_milk_2l.blend",
"glb": "PerfectCoffee_milk_2l.glb",
"preview": "preview.png",
"native_reopen_passed": true,
"glb_reimport_passed": true,
"nominal_capacity_ml": 2000,
"cap_independent": true,
"interior_capacity_ml": 2150.0000000000005,
"body_profile": "Chamfered square lower cuboid; centered shrinking upper segment; circular centered mouth",
"handle_construction": "Large arched corner opening from +X toward +Y around an integral vertical grip; central body is not cut through",
"body_non_manifold_edges": 0,
"mouth_z_m": 0.278,
"cap_base_z_m": 0.264,
"neck_outer_radius_m": 0.018924788601074174,
"cap_inner_radius_m": 0.02060699203228077,
"cap_radial_clearance_m": 0.0009609587100767681,
"cap_top_clearance_m": 0.0005,
"lower_segment_square": true,
"lower_segment_top_z_m": 0.222,
"shoulder_start_height_ratio": 0.7985611510791366,
"mouth_center_xy": [
0.0,
0.0
],
"shoulder_to_mouth_ratio": 1.1666666666666667,
"handle_bottom_z_m": 0.122,
"handle_top_z_m": 0.214,
"handle_cavity_overlap_ml": 0.0,
"handle_aperture_width_m": 0.017,
"handle_aperture_height_m": 0.092,
"cap_mesh": "Milk_Cap",
"cap_triangles": 224,
"cap_files": [
"PerfectCoffee_milk_2l_Cap.blend",
"PerfectCoffee_milk_2l_Cap.glb"
],
"preview_cap_removed": "preview_cap_removed.png",
"visual_review_passed": true,
"visual_review_notes": "Shoulder starts at Z 222 mm, 79.856 percent of total height. Enlarged curved corner opening creates a clearly visible vertical grip; the full arched path is unobstructed, the central body and inner liquid cavity remain intact, and cap assembly is collision-free. Main, corner, top-section and cap views inspected.",
"passed": true,
"native_triangles": 906,
"native_dimensions_m": [
0.1261652559041977,
0.1261652559041977,
0.2789999882224947
],
"no_image_textures_or_labels": true,
"cap_detach_parenting_passed": true,
"cap_assembly_test_passed": true,
"cap_blend_and_glb_passed": true,
"liquid_volume_2000ml_passed": null,
"plausible_dimensions_passed": true,
"transparent_pet_passed": null,
"glb_triangles": 906,
"glb_dimensions_m": [
0.1261652559041977,
0.1261652559041977,
0.2789999882224947
],
"studio_excluded_from_glb": true,
"technical_validation_passed": true
}