feat: upgrade low-poly bean fill with PBR textures

This commit is contained in:
Yanchen
2026-11-11 15:34:14 +08:00
parent 965197d227
commit fd52a56baf
10 changed files with 97 additions and 16 deletions
@@ -233,6 +233,38 @@ bean_texture = bean_material.node_tree.nodes.new('ShaderNodeTexImage')
bean_texture.image = bean_image
bean_material.node_tree.links.new(bean_texture.outputs['Color'], bean_bsdf.inputs['Base Color'])
pbr_dir = OUT / 'textures' / 'coffee_beans_pbr'
pile_material = bpy.data.materials.new('Low | coffee bean pile PBR')
pile_material.use_nodes = True
pile_bsdf = pile_material.node_tree.nodes.get('Principled BSDF')
pile_bsdf.inputs['Specular IOR Level'].default_value = 0.18
pile_nodes = pile_material.node_tree.nodes
pile_links = pile_material.node_tree.links
pbr_color = bpy.data.images.load(str(pbr_dir / 'food_0008_color_roast_1k.jpg'))
pbr_color.name = 'TextureCan_Food0008_RoastColor_1K'
pbr_color.colorspace_settings.name = 'sRGB'
pbr_color.pack()
color_node = pile_nodes.new('ShaderNodeTexImage')
color_node.image = pbr_color
pile_links.new(color_node.outputs['Color'], pile_bsdf.inputs['Base Color'])
pbr_roughness = bpy.data.images.load(str(pbr_dir / 'food_0008_roughness_1k.jpg'))
pbr_roughness.name = 'TextureCan_Food0008_Roughness_1K'
pbr_roughness.colorspace_settings.name = 'Non-Color'
pbr_roughness.pack()
roughness_node = pile_nodes.new('ShaderNodeTexImage')
roughness_node.image = pbr_roughness
pile_links.new(roughness_node.outputs['Color'], pile_bsdf.inputs['Roughness'])
pbr_normal = bpy.data.images.load(str(pbr_dir / 'food_0008_normal_opengl_512.png'))
pbr_normal.name = 'TextureCan_Food0008_NormalGL_512'
pbr_normal.colorspace_settings.name = 'Non-Color'
pbr_normal.pack()
normal_image_node = pile_nodes.new('ShaderNodeTexImage')
normal_image_node.image = pbr_normal
normal_node = pile_nodes.new('ShaderNodeNormalMap')
normal_node.inputs['Strength'].default_value = 0.35
pile_links.new(normal_image_node.outputs['Color'], normal_node.inputs['Color'])
pile_links.new(normal_node.outputs['Normal'], pile_bsdf.inputs['Normal'])
beans_collection = bpy.data.collections.new('05 | Coffee Beans')
scene.collection.children.link(beans_collection)
beans_root = bpy.data.objects.new('05 | Coffee Beans', None)
@@ -241,7 +273,7 @@ beans_root.parent = bpy.data.objects['03 | Coffee Bean Hopper']
beans_root.empty_display_size = 0.02
beans_root['capacity_portions'] = CAPACITY
beans_root['consumption'] = 'One fixed portion per completed portafilter. No vibration, rigid bodies or particle simulation.'
beans_root['visuals'] = 'One textured core with 15 morph levels and at most 20 GPU-instanced low-poly beans.'
beans_root['visuals'] = 'TextureCan CC0 PBR core with 15 morph levels and at most 20 GPU-instanced low-poly beans. No extra top instances.'
scene['bean_capacity_portions'] = CAPACITY
scene['bean_remaining_portions'] = CAPACITY
scene['beans_per_grind'] = 1
@@ -321,11 +353,11 @@ for segment in range(SEGMENTS):
faces.append((top_center, ring_starts[-1] + segment, ring_starts[-1] + nxt))
uv = []
for x, y, z in [vertices[top_center], vertices[ring_starts[-1] + segment], vertices[ring_starts[-1] + nxt]]:
uv.append((0.5 + x / (2 * profile_r[-1]), 0.5 + (y - 0.020) / (2 * profile_r[-1])))
uv.append((0.5 + x / profile_r[-1], 0.5 + (y - 0.020) / profile_r[-1]))
face_uvs.append(uv)
core_mesh = bpy.data.meshes.new('Low bean core mesh')
core_mesh.from_pydata(vertices, [], faces)
core_mesh.materials.append(bean_material)
core_mesh.materials.append(pile_material)
core_mesh.update()
uv_layer = core_mesh.uv_layers.new(name='BeanTextureUV')
for polygon, uvs in zip(core_mesh.polygons, face_uvs):
@@ -510,7 +542,7 @@ scene.render.resolution_y = 1100
scene.render.resolution_percentage = 100
scene.render.image_settings.file_format = 'PNG'
scene.render.image_settings.color_mode = 'RGBA'
scene.render.filepath = str(OUT / 'preview_low_poly.png')
scene.render.filepath = str(OUT / 'preview_low_poly_pbr.png')
camera = bpy.data.objects['Preview Camera']
scene.camera = camera
camera.data.type = 'PERSP'
@@ -602,6 +634,19 @@ report = {
'glb_gpu_instances': instance_count,
'glb_primitive_draw_calls': primitive_draw_calls,
'texture_sizes': {'beans_low.png': list(bean_image.size), 'grind_scale_low.png': list(small_scale.size)},
'pbr_source': {
'asset': 'https://www.texturecan.com/details/226/',
'license': 'CC0-1.0',
'license_url': 'https://www.texturecan.com/terms',
'core_material': pile_material.name,
'color': 'food_0008_color_roast_1k.jpg',
'color_source': 'food_0008_color_1k.jpg',
'color_multipliers': [0.62, 0.56, 0.50],
'normal_opengl': 'food_0008_normal_opengl_512.png',
'roughness': 'food_0008_roughness_1k.jpg',
'normal_strength': 0.35,
'extra_instances': 0,
},
'portafilter_included': False,
'vibration_or_particles': False,
}
@@ -35,18 +35,36 @@
128
]
},
"pbr_source": {
"asset": "https://www.texturecan.com/details/226/",
"license": "CC0-1.0",
"license_url": "https://www.texturecan.com/terms",
"core_material": "Low | coffee bean pile PBR",
"color": "food_0008_color_roast_1k.jpg",
"color_source": "food_0008_color_1k.jpg",
"color_multipliers": [
0.62,
0.56,
0.5
],
"normal_opengl": "food_0008_normal_opengl_512.png",
"roughness": "food_0008_roughness_1k.jpg",
"normal_strength": 0.35,
"extra_instances": 0
},
"portafilter_included": false,
"vibration_or_particles": false,
"validation": {
"levels_checked": [14, 7, 1, 0],
"cross_component_collisions": 0,
"core_glass_collisions": 0,
"single_sided_glb_glass": true,
"cycles": {
"rendered": true,
"packed_pbr_maps": 3,
"total_render_triangles_including_instances": 4588,
"bean_instance_count": 20,
"glb_primitive_draw_calls": 12,
"comparison": {
"engine": "CYCLES",
"samples": 64,
"remaining_portions": 14,
"preview": "preview_low_poly.png"
"same_camera_and_lighting": true,
"baseline_commit": "a55f327",
"image": "preview_low_poly_comparison.png"
}
}
}
Binary file not shown.
Binary file not shown.