Created
November 30, 2023 19:43
-
-
Save santolucito/2085e0d4483f93e427b5176ff98d5a50 to your computer and use it in GitHub Desktop.
main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import random | |
#delete all objects | |
bpy.ops.object.select_all(action='SELECT') | |
bpy.ops.object.delete() | |
#delete all materials | |
for m in bpy.data.materials: | |
bpy.data.materials.remove(m) | |
bpy.data.materials.new(name="red") | |
bpy.data.materials['red'].diffuse_color = (1, 0, 0, 1) | |
bpy.data.materials['red'].metallic = 0.9 | |
bpy.data.materials.new(name="black") | |
bpy.data.materials['black'].diffuse_color = (0, 0, 0, 1) | |
bpy.data.materials.new(name="white") | |
bpy.data.materials['white'].diffuse_color = (1, 0.9, 0.9, 1) | |
bpy.data.materials['white'].metallic = 0.09 | |
bpy.data.materials['white'].roughness = 0.01 | |
bpy.ops.mesh.primitive_plane_add(size=200, enter_editmode=False, align='WORLD', location=(0, 0, -3), scale=(1, 1, 1)) | |
bpy.context.object.data.materials.append(bpy.data.materials["black"]) | |
#the white cube | |
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0), scale=(0.3, 0.3, 0.3)) | |
bpy.context.object.scale = (0.99, 0.99, 0.99) | |
materialChoice = "white" | |
bpy.context.object.data.materials.append(bpy.data.materials[materialChoice]) | |
# move the white cube | |
bpy.context.object.keyframe_insert("location", frame=1) | |
for i in range(10): | |
bpy.context.object.location = (random.randrange(10), random.randrange(10), random.randrange(10)) | |
bpy.context.object.keyframe_insert("location", frame=50*i) | |
for i_x in range(5): | |
for i_y in range(5): | |
for i_z in range(5): | |
materialChoice = "red" | |
bpy.ops.mesh.primitive_cube_add(location=(i_x*2, i_y*2, i_z*2), scale=(0.3, 0.3, 0.3)) | |
bpy.context.object.data.materials.append(bpy.data.materials[materialChoice]) | |
bpy.ops.object.camera_add(location=(15,15,15)) | |
cam = bpy.context.active_object | |
bpy.ops.object.constraint_add(type='TRACK_TO') | |
bpy.context.object.constraints["Track To"].target = bpy.data.objects["Cube"] | |
for i in range(15): | |
bpy.ops.object.light_add(type='AREA', radius=1, align='WORLD', location=(random.randrange(10*2), random.randrange(10*2), random.randrange(10*2)), scale=(1, 1, 1)) | |
light = bpy.context.active_object | |
bpy.context.object.data.energy = 1000 | |
#add keyframes for the camera | |
cam.keyframe_insert("location", frame=1) | |
cam.location.x = 20 | |
cam.location.z = 0 | |
cam.keyframe_insert("location", frame=100) | |
cam.location.y = 0 | |
cam.location.z = 20 | |
cam.keyframe_insert("location", frame=200) | |
#add keyframes for the light | |
light.keyframe_insert("location", frame=1) | |
light.location.x = 2 | |
light.keyframe_insert("location", frame=50) | |
bpy.context.scene.frame_end = 251 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment