Created
August 17, 2020 18:20
-
-
Save j6k4m8/aea365450d70a0768b97302032532aee to your computer and use it in GitHub Desktop.
Set up an infinite Blender background (beveled plane), with Camera, Focus-empty, and DOF
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 math | |
import bpy | |
def add_infinite_background(coll_name = None): | |
mesh = bpy.data.meshes.new("InfiniteBackground") | |
obj = bpy.data.objects.new(mesh.name, mesh) | |
col = bpy.data.collections.get("Collection") | |
col.objects.link(obj) | |
bpy.context.view_layer.objects.active = obj | |
verts = [ | |
( 1.0, 1.0, 0.0), | |
( 1.0, -1.0, 0.0), | |
(-1.0, -1.0, 0.0), | |
(-1.0, 1.0, 0.0), | |
(-1.0, -1.0, 2.0), | |
(-1.0, 1.0, 2.0), | |
] | |
edges = [] | |
faces = [[0, 1, 2, 3,], [3, 2, 4, 5]] | |
mesh.from_pydata(verts, edges, faces) | |
return obj.name | |
def bevel_mesh(obj_name): | |
bpy.data.objects[objname].select_set(True) | |
bpy.ops.object.modifier_add(type='BEVEL') | |
bpy.context.object.modifiers["Bevel"].width = 0.3 | |
bpy.context.object.modifiers["Bevel"].segments = 8 | |
bpy.ops.object.shade_smooth() | |
objname = add_infinite_background() | |
bevel_mesh(objname) | |
bpy.ops.transform.resize(value=(10, 10, 10)) | |
# Create Focus: | |
empty = bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 1)) | |
# Create camera: | |
bpy.ops.object.camera_add( | |
enter_editmode=False, | |
location=(8, 0, 1.5), | |
rotation=(math.pi/2, 0, math.pi/2) | |
) | |
# Add constraint for look-at: | |
bpy.ops.object.constraint_add(type='TRACK_TO') | |
bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z' | |
bpy.context.object.constraints["Track To"].target = bpy.data.objects["Empty"] | |
bpy.context.object.constraints["Track To"].up_axis = 'UP_Y' | |
# Set DOF: | |
bpy.context.object.data.dof.use_dof = True | |
bpy.context.object.data.dof.focus_object = bpy.data.objects["Empty"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment