Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import math
- # Clean up default scene objects
- bpy.ops.object.select_all(action='SELECT')
- bpy.ops.object.delete(use_global=False)
- def create_material(name, color, roughness=0.25, specular=0.5):
- mat = bpy.data.materials.new(name=name)
- mat.use_nodes = True
- nodes = mat.node_tree.nodes
- bsdf = nodes.get("Principled BSDF")
- if bsdf:
- bsdf.inputs['Base Color'].default_value = color
- bsdf.inputs['Roughness'].default_value = roughness
- if 'Specular IOR Level' in bsdf.inputs:
- bsdf.inputs['Specular IOR Level'].default_value = specular
- return mat
- # --- Materials ---
- mat_face = create_material("Mat_YellowFace", (1.0, 0.72, 0.05, 1.0), roughness=0.2)
- mat_eyes = create_material("Mat_DarkBrown", (0.1, 0.05, 0.02, 1.0), roughness=0.3)
- mat_mouth_dark = create_material("Mat_MouthInterior", (0.15, 0.02, 0.02, 1.0), roughness=0.4)
- mat_teeth = create_material("Mat_Teeth", (0.95, 0.95, 0.95, 1.0), roughness=0.2)
- mat_tooth_line = create_material("Mat_Divider", (0.7, 0.65, 0.65, 1.0), roughness=0.5)
- mesh_parts = []
- # 1. Head
- bpy.ops.mesh.primitive_uv_sphere_add(
- segments=64,
- ring_count=32,
- radius=1.0,
- location=(0, 0, 0)
- )
- head = bpy.context.active_object
- head.data.materials.append(mat_face)
- mesh_parts.append(head)
- # 2. Smiling / Squinting Eyes
- def add_squint_eye(x_pos):
- bpy.ops.mesh.primitive_torus_add(
- major_radius=0.18,
- minor_radius=0.038,
- major_segments=36,
- minor_segments=16,
- location=(x_pos, 0.88, 0.22),
- rotation=(math.radians(55), 0, 0)
- )
- eye = bpy.context.active_object
- eye.scale = (1.0, 0.6, 1.2)
- eye.data.materials.append(mat_eyes)
- return eye
- mesh_parts.append(add_squint_eye(-0.36))
- mesh_parts.append(add_squint_eye(0.36))
- # 3. Mouth Background Rim
- bpy.ops.mesh.primitive_cylinder_add(
- vertices=64,
- radius=0.58,
- depth=0.25,
- location=(0, 0.86, -0.26),
- rotation=(math.radians(82), 0, 0)
- )
- mouth_base = bpy.context.active_object
- mouth_base.scale = (1.05, 0.45, 0.7)
- mouth_base.data.materials.append(mat_mouth_dark)
- mesh_parts.append(mouth_base)
- # 4. Front Teeth Array
- bpy.ops.mesh.primitive_cylinder_add(
- vertices=64,
- radius=0.56,
- depth=0.24,
- location=(0, 0.875, -0.26),
- rotation=(math.radians(82), 0, 0)
- )
- teeth = bpy.context.active_object
- teeth.scale = (1.02, 0.43, 0.68)
- teeth.data.materials.append(mat_teeth)
- mesh_parts.append(teeth)
- # 5. Horizontal Tooth Divider
- bpy.ops.mesh.primitive_cube_add(
- size=1.0,
- location=(0, 0.96, -0.26)
- )
- horiz_line = bpy.context.active_object
- horiz_line.scale = (1.1, 0.08, 0.015)
- horiz_line.data.materials.append(mat_tooth_line)
- mesh_parts.append(horiz_line)
- # 6. Vertical Tooth Dividers
- for x_coord in [-0.36, -0.18, 0.0, 0.18, 0.36]:
- bpy.ops.mesh.primitive_cube_add(
- size=1.0,
- location=(x_coord, 0.96, -0.26)
- )
- vert_line = bpy.context.active_object
- vert_line.scale = (0.015, 0.08, 0.36)
- vert_line.data.materials.append(mat_tooth_line)
- mesh_parts.append(vert_line)
- # --- Join all parts into a single mesh object ---
- bpy.ops.object.select_all(action='DESELECT')
- for part in mesh_parts:
- part.select_set(True)
- bpy.context.view_layer.objects.active = head
- bpy.ops.object.join()
- emoji = bpy.context.active_object
- emoji.name = "Emoji_Grinning_Face"
- # Apply all transforms and smooth shading
- bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
- bpy.ops.object.shade_smooth()
- # Camera and lighting
- bpy.ops.object.light_add(type='AREA', radius=2.0, location=(2.0, 3.5, 2.5))
- bpy.context.active_object.data.energy = 400.0
- bpy.ops.object.light_add(type='POINT', radius=1.5, location=(-2.5, 2.5, 1.0))
- bpy.context.active_object.data.energy = 150.0
- bpy.ops.object.camera_add(
- location=(0.0, 3.2, 0.0),
- rotation=(math.radians(90), 0, math.radians(180))
- )
- bpy.context.scene.camera = bpy.context.active_object
Advertisement
Add Comment
Please, Sign In to add comment