feat: add croissant cake and cream toast
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
from mathutils import Vector
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
ASSETS = [
|
||||
("01 CROISSANT", "bakery_and_cake/Croissant/PerfectCoffee_Croissant.blend"),
|
||||
("02 CAKE SLICE", "bakery_and_cake/CakeSlice/PerfectCoffee_CakeSlice.blend"),
|
||||
("03 CREAM TOAST", "toast_and_wrap/AvocadoToast/PerfectCoffee_AvocadoToast.blend"),
|
||||
]
|
||||
POSITIONS = [(-0.25, 0), (0, 0), (0.25, 0)]
|
||||
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
scene = bpy.context.scene
|
||||
scene.render.engine = "BLENDER_EEVEE"
|
||||
scene.render.resolution_x = 1600
|
||||
scene.render.resolution_y = 1250
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.image_settings.file_format = "PNG"
|
||||
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
|
||||
scene.world = bpy.data.worlds.new("Review_World")
|
||||
scene.world.use_nodes = True
|
||||
scene.world.node_tree.nodes["Background"].inputs["Color"].default_value = (0.72, 0.78, 0.82, 1)
|
||||
scene.world.node_tree.nodes["Background"].inputs["Strength"].default_value = 0.3
|
||||
|
||||
for (label, relative_path), (x, y) in zip(ASSETS, POSITIONS):
|
||||
with bpy.data.libraries.load(str(ROOT / relative_path), link=False) as (source, target):
|
||||
target.collections = ["Model"]
|
||||
model = target.collections[0]
|
||||
instance = bpy.data.objects.new(label, None)
|
||||
instance.instance_type = "COLLECTION"
|
||||
instance.instance_collection = model
|
||||
instance.location = (x, y, 0)
|
||||
scene.collection.objects.link(instance)
|
||||
meshes = [obj for obj in model.all_objects if obj.type == "MESH"]
|
||||
triangle_count = 0
|
||||
for obj in meshes:
|
||||
obj.data.calc_loop_triangles()
|
||||
triangle_count += len(obj.data.loop_triangles)
|
||||
assert triangle_count <= 1000, (label, triangle_count)
|
||||
print("FOOD_REVIEW", label, triangle_count, flush=True)
|
||||
for text, size, offset in [(label, 0.015, -0.105), (f"{triangle_count} TRIANGLES", 0.008, -0.121)]:
|
||||
curve = bpy.data.curves.new(text, "FONT")
|
||||
curve.body = text
|
||||
curve.align_x = "CENTER"
|
||||
curve.size = size
|
||||
text_object = bpy.data.objects.new(text, curve)
|
||||
text_object.location = (x, y + offset, 0.001)
|
||||
scene.collection.objects.link(text_object)
|
||||
|
||||
curve = bpy.data.curves.new("Review_Notes", "FONT")
|
||||
curve.body = "FOOD MODEL REVIEW\n\n3 FOOD ASSETS\nBLENDER 5.2\n1000 TRI LIMIT EACH\nNO PACKAGING\n\nREVIEW SCENE ONLY"
|
||||
curve.align_x = "CENTER"
|
||||
curve.size = 0.014
|
||||
notes = bpy.data.objects.new("Review_Notes", curve)
|
||||
notes.location = (0, 0.29, 0.001)
|
||||
scene.collection.objects.link(notes)
|
||||
|
||||
text_material = bpy.data.materials.new("Review_Text")
|
||||
text_material.diffuse_color = (0.045, 0.055, 0.065, 1)
|
||||
text_material.use_nodes = True
|
||||
text_material.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = (0.045, 0.055, 0.065, 1)
|
||||
for obj in scene.objects:
|
||||
if obj.type == "FONT":
|
||||
obj.data.materials.append(text_material)
|
||||
|
||||
material = bpy.data.materials.new("Review_Background")
|
||||
material.diffuse_color = (0.38, 0.41, 0.36, 1)
|
||||
material.use_nodes = True
|
||||
material.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = (0.38, 0.41, 0.36, 1)
|
||||
material.node_tree.nodes["Principled BSDF"].inputs["Roughness"].default_value = 0.86
|
||||
bpy.ops.mesh.primitive_plane_add(size=200, location=(0, 0, -0.0002))
|
||||
bpy.context.object.data.materials.append(material)
|
||||
|
||||
for label, offset, power, size in [
|
||||
("Key", (-0.5, -0.5, 0.9), 8, 0.7),
|
||||
("Fill", (0.6, -0.1, 0.5), 4, 0.6),
|
||||
("Rim", (0.0, 0.7, 0.8), 6, 0.6),
|
||||
]:
|
||||
light_data = bpy.data.lights.new(label, "AREA")
|
||||
light_data.energy = power
|
||||
light_data.shape = "DISK"
|
||||
light_data.size = size
|
||||
light_object = bpy.data.objects.new(label, light_data)
|
||||
light_object.location = offset
|
||||
light_object.rotation_euler = (Vector((0, 0.12, 0)) - light_object.location).to_track_quat("-Z", "Y").to_euler()
|
||||
scene.collection.objects.link(light_object)
|
||||
|
||||
camera_data = bpy.data.cameras.new("Review_Camera")
|
||||
camera = bpy.data.objects.new("Review_Camera", camera_data)
|
||||
camera_data.type = "ORTHO"
|
||||
camera_data.ortho_scale = 0.78
|
||||
scene.collection.objects.link(camera)
|
||||
scene.camera = camera
|
||||
center = Vector((0, 0.105, 0))
|
||||
camera.location = center + Vector((0.25, -0.60, 0.72))
|
||||
camera.rotation_euler = (center - camera.location).to_track_quat("-Z", "Y").to_euler()
|
||||
scene.render.filepath = str(ROOT / "review_three_quarter.png")
|
||||
bpy.ops.render.render(write_still=True)
|
||||
|
||||
camera.location = (0, 0.105, 1)
|
||||
camera.rotation_euler = (0, 0, 0)
|
||||
camera_data.ortho_scale = 0.78
|
||||
scene.render.filepath = str(ROOT / "review_top.png")
|
||||
bpy.ops.render.render(write_still=True)
|
||||
print("FOOD_REVIEW_COMPLETE", flush=True)
|
||||
Reference in New Issue
Block a user