<?php
import bpy
import random
# Clear existing objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
# Create the ground plane
bpy.ops.mesh.primitive_plane_add(size=20, location=(0, 0, 0))
ground = bpy.context.object
bpy.ops.rigidbody.object_add()
ground.rigid_body.type = 'PASSIVE'
# Create cubes with random positions
num_cubes = 20
for i in range(num_cubes):
x = random.uniform(-8, 8)
y = random.uniform(-8, 8)
z = random.uniform(5, 15)
bpy.ops.mesh.primitive_cube_add(size=1, location=(x, y, z))
cube = bpy.context.object
bpy.ops.rigidbody.object_add()
cube.rigid_body.mass = random.uniform(0.5, 2.0)
# Add a camera
bpy.ops.object.camera_add(location=(0, -20, 10), rotation=(1.2, 0, 0))
camera = bpy.context.object
bpy.context.scene.camera = camera
# Add a light
bpy.ops.object.light_add(type='SUN', location=(0, 0, 20))
light = bpy.context.object
light.data.energy = 5