My objects sounds like a bit large, I guess I need to move camera far away from origin (put a sphere there) but if I increase the camera location x value, it will can not see anything.
import bpy
from math import radians,cos,sin,tan
from mathutils import Matrix, Vector, Euler
def clean_objects():
if len(bpy.data.objects) == 0:
return
oldMode = bpy.context.mode
if oldMode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
for o in bpy.data.objects:
if o.type == 'MESH':
o.select = True
else:
o.select = False
o.select = True
#print("%s -> %d"%(o.name,o.select))
bpy.ops.object.delete()
if oldMode != 'OBJECT':
bpy.ops.object.mode_set(mode=oldMode)
return
def dump_objects():
for ob in bpy.data.objects:
print(ob.name)
return
def setOrigin(loc):
for ob in bpy.data.objects:
ob.location -= loc
return
def add_objects():
m = 16
n = 12
h = 96
outer = 100
stud_x = 4
stud_y = 8
stud_z = 96
alpha = 30
for i in range(0,m):
print(i)
for j in range(0,n):
if (i == 0 or i== m-1 or j == 0 or j == n-1):
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = (stud_x,stud_y,h)
bpy.context.object.location = (16*i,16*j,0)
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = ((m-1)*16 + stud_x,stud_y,stud_x)
bpy.context.object.location = ((m-1)*16/2,0,(h+stud_x)/2)
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = ((m-1)*16 + stud_x,stud_y,stud_x)
bpy.context.object.location = ((m-1)*16/2,(n-1)*16,(h+stud_x)/2)
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = (stud_x,(n-1)*16,stud_x) # overlap
bpy.context.object.location = (0,(n-1)*16/2,(h+stud_x)/2)
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = (stud_x,(n-1)*16,stud_x) # overlap
bpy.context.object.location = ((m-1)*16,(n-1)*16/2,(h+stud_x)/2)
for i in range(0,m):
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = (stud_x,(n-1)*16+2*outer,stud_x)
bpy.context.object.location = (16*i,(n-1)*16/2,(h+stud_x)/2+stud_x)
p = outer + (n-1)*16/2
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = (stud_x,p/cos(radians(alpha)),stud_x)
bpy.context.object.location = (16*i,p/2 -outer,(h+stud_x)/2+stud_x + p*tan(radians(alpha))/2)
bpy.context.object.rotation_euler = (radians(alpha),0,0)
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.dimensions = (stud_x,p/cos(radians(alpha)),stud_x)
bpy.context.object.location = (16*i,p/2 -outer + p,(h+stud_x)/2+stud_x + p*tan(radians(alpha))/2)
bpy.context.object.rotation_euler = (radians(180-alpha),0,0)
bpy.ops.mesh.primitive_plane_add()
bpy.context.object.dimensions = (16*(m+5),16*(n+5),10)
bpy.context.object.location = (16*m/2,16*n/2,-h/2)
setOrigin(Vector(((m-1)*16/2, (n-1)*16/2, h/2)))
return
def add_camera():
bpy.ops.object.camera_add()
bpy.context.object.location = (150,50,150)
bpy.ops.object.lamp_add(type='SPOT')
bpy.context.object.location = (200,200,200)
bpy.context.object.dimensions = (200,200,200)
bpy.ops.curve.primitive_bezier_circle_add(radius=400)
camera = bpy.data.objects['Camera']
path = bpy.data.objects['BezierCircle']
lamp = bpy.data.objects['Spot']
camera.select = True
lamp.select = True
path.select = True
bpy.context.scene.objects.active = path #parent
bpy.ops.object.parent_set(type='FOLLOW') #follow path
bpy.ops.mesh.primitive_uv_sphere_add(size=20, location=(0,0,0))
target = bpy.context.object;
camera.constraints.new(type='TRACK_TO').target = target
camera.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
camera.constraints["Track To"].up_axis = 'UP_Y'
bpy.context.scene.camera = camera
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
area.spaces[0].region_3d.view_perspective = 'CAMERA'
break
return
def select_objects():
for ob in bpy.context.scene.objects:
ob.select = False
for ob in bpy.context.visible_objects:
ob.select = True
return
#-----------------------------------------
clean_objects()
add_objects()
add_camera()
I guess "track to" feature should be able to adjust the angle of camera, how can I adjust my camera parameter to view full objects?
