You are participating in Blender-Bench, a public benchmark where AI models complete the same Blender task.

Your result will be compared head-to-head with another model. Anyone on the internet can vote based on two equally important published views: a 2D rendered presentation and an interactive 3D scene exported to GLB. Treat neither view as optional; make the result clear and compelling in both.

Complete the request as well as you can. The benchmark does not prescribe a workflow or visual style; use whichever Blender techniques you consider appropriate. Make the important requirements evident in the published result, save a complete scene, and present the work clearly in every requested output.

The 2D presentation is rendered by the benchmark from your saved scene using Cycles at 1536 x 1536, 64 samples, denoising enabled, and GPU acceleration when available with a CPU fallback. It is the native-fidelity view of the Blender scene, so you may use Blender's full feature set. Preview and validate your materials, lighting, color management, and camera composition in Cycles, and do not rely on EEVEE-only effects for the final appearance.

The interactive 3D view is a best-effort GLB export containing geometry, compatible materials, the contestant camera, and supported lights. Because glTF cannot represent every Blender feature, native effects such as particles, hair or curves, volumes, simulations, and some procedural geometry may appear only in the 2D render. The benchmark may also generate a separate preview GLB by baking supported procedural material inputs to textures; this does not convert unsupported geometry or guarantee exact parity with Blender. When practical, keep the core form and scene readable in the 3D view while using the 2D presentation to show native Blender features faithfully.

## Harness Instructions

You are writing a single Python script for Blender 5.1 using the bpy API. The scene starts empty. Your script must build everything the user's prompt asks for.

You are building a real three-dimensional scene, and evaluators judge the whole scene and your final render side by side — an interactive 3D view and a benchmark-generated 360° camera orbit rendered in Cycles from your saved scene appear next to your presentation render, so forms that only read correctly from one angle will show. Build genuine 3D first, then present it well: before you finish, set up a camera and lighting to frame a single, well-composed presentation image of your result — a good scene that happens to have a well-placed camera and lights. The final benchmark capture overrides the scene render settings and renders in Cycles at 1536x1536, 64 samples, with denoising and GPU acceleration (CPU fallback). Preview and validate materials, lighting, color management, and composition in Cycles; do not rely on EEVEE-only effects. Use whatever Blender features best serve the result; a best-effort GLB export is also provided for interactive inspection, and features glTF cannot represent are not expected to survive it.

You get one attempt: the script runs once, headless, with no feedback and no chance to iterate, so write robust code. Reply with exactly one fenced Python code block containing the complete script and nothing else.


## Task

Complete the following Blender task:

<task>

A red sphere of 1 meter diameter resting on a white ground plane — touching it
exactly, neither floating nor sunk. Smooth shading, a plain red material on the
ball, plain white on the floor.

The floor is the sphere, the color, and the contact. The ceiling is presentation:
a soft believable shadow under the ball, a hint of glossiness that catches the
light, and clean framing.

</task>


```python
import bpy
from mathutils import Vector

def clear_scene():
    for obj in list(bpy.data.objects):
        bpy.data.objects.remove(obj, do_unlink=True)

def make_material(name, color, roughness, specular=0.5):
    mat = bpy.data.materials.new(name)
    mat.use_nodes = True
    nodes = mat.node_tree.nodes

    bsdf = nodes.get("Principled BSDF")
    if bsdf is None:
        bsdf = nodes.new("ShaderNodeBsdfPrincipled")

    output = nodes.get("Material Output")
    if output is None:
        output = nodes.new("ShaderNodeOutputMaterial")

    if not output.inputs["Surface"].links:
        mat.node_tree.links.new(bsdf.outputs["BSDF"], output.inputs["Surface"])

    bsdf.inputs["Base Color"].default_value = (color[0], color[1], color[2], 1.0)
    bsdf.inputs["Roughness"].default_value = roughness

    try:
        bsdf.inputs["Specular IOR Level"].default_value = specular
    except Exception:
        try:
            bsdf.inputs["Specular"].default_value = specular
        except Exception:
            pass

    return mat

def shade_smooth(obj):
    for poly in obj.data.polygons:
        poly.use_smooth = True

def add_area_light(name, location, target, energy, size, cast_shadow=True):
    bpy.ops.object.light_add(type="AREA", location=location)
    obj = bpy.context.active_object
    obj.name = name
    light = obj.data
    light.energy = energy
    light.size = size

    try:
        light.shape = "SQUARE"
    except Exception:
        pass

    if cast_shadow:
        try:
            light.use_shadow = True
        except Exception:
            pass
    else:
        try:
            light.use_shadow = False
        except Exception:
            pass
        try:
            obj.visible_shadow = False
        except Exception:
            pass

    direction = Vector(target) - Vector(location)
    obj.rotation_euler = direction.to_track_quat("-Z", "Y").to_euler()
    return obj

# ---------------------------------------------------------------------------
# Scene setup
# ---------------------------------------------------------------------------
clear_scene()

scene = bpy.context.scene
scene.render.engine = "CYCLES"

# Units: one Blender unit is one metre.
try:
    scene.unit_settings.system = "METRIC"
    scene.unit_settings.scale_length = 1.0
    scene.unit_settings.length_unit = "METERS"
except Exception:
    pass

# Ground plane, exactly at z = 0.
bpy.ops.mesh.primitive_plane_add(size=100, location=(0.0, 0.0, 0.0))
ground = bpy.context.active_object
ground.name = "Ground"
ground.data.name = "GroundMesh"
shade_smooth(ground)

# Red sphere, 1 m diameter, centre at z = 0.5 so the bottom touches the plane.
bpy.ops.mesh.primitive_uv_sphere_add(
    radius=0.5,
    location=(0.0, 0.0, 0.5),
    segments=64,
    ring_count=32,
)
sphere = bpy.context.active_object
sphere.name = "RedSphere"
sphere.data.name = "RedSphereMesh"
shade_smooth(sphere)

# Materials
red_mat = make_material("RedMat", (0.80, 0.03, 0.03), roughness=0.30, specular=0.7)
white_mat = make_material("WhiteFloor", (1.0, 1.0, 1.0), roughness=0.85, specular=0.05)

if sphere.data.materials:
    sphere.data.materials[0] = red_mat
else:
    sphere.data.materials.append(red_mat)

if ground.data.materials:
    ground.data.materials[0] = white_mat
else:
    ground.data.materials.append(white_mat)

# World: very dark, so the lit floor and soft shadow stay the visual focus.
world = bpy.data.worlds.new("World")
scene.world = world
world.use_nodes = True
world_ntree = world.node_tree
world_ntree.nodes.clear()
world_out = world_ntree.nodes.new("ShaderNodeOutputWorld")
world_bg = world_ntree.nodes.new("ShaderNodeBackground")
world_bg.inputs[0].default_value = (0.02, 0.02, 0.025, 1.0)
world_bg.inputs[1].default_value = 0.2
world_ntree.links.new(world_bg.outputs[0], world_out.inputs[0])

# Lighting: soft area key, gentle fill from the camera side.
add_area_light(
    "KeyLight",
    location=(-2.8, 1.0, 4.2),
    target=(0.0, 0.0, 0.5),
    energy=600.0,
    size=4.5,
    cast_shadow=True,
)

add_area_light(
    "FillLight",
    location=(3.5, -3.5, 2.2),
    target=(0.0, 0.0, 0.5),
    energy=140.0,
    size=5.0,
    cast_shadow=False,
)

# Camera: clean, slightly raised product view.
bpy.ops.object.camera_add(location=(3.2, -3.4, 1.8))
cam = bpy.context.active_object
cam.name = "Camera"
cam.data.name = "CameraData"
cam.data.lens = 50
cam.data.sensor_width = 36

cam_direction = Vector((0.0, 0.0, 0.4)) - cam.location
cam.rotation_euler = cam_direction.to_track_quat("-Z", "Y").to_euler()
scene.camera = cam

# Final still settings.
scene.render.resolution_x = 1536
scene.render.resolution_y = 1536
scene.render.resolution_percentage = 100

try:
    scene.cycles.samples = 64
    scene.cycles.use_denoising = True
except Exception:
    pass

try:
    scene.view_settings.view_transform = "Filmic"
    scene.view_settings.look = "Medium Contrast"
    scene.view_settings.exposure = 0.0
except Exception:
    pass
```