Reputation: 23
I am currently creating a 3D star map for my A-Level coursework, and I was wondering; how would it be possible to to retrieve and enumerate through the coordinates of all objects in my Blender scene and then use these coordinates to adjust the camera position accordingly?
Thank you
Upvotes: 1
Views: 4070
Reputation: 7079
The following script will find the centre of all the objects in your scene that have a name starting with 'star'.
import bpy
lx = [] # list of objects x locations
ly = [] # list of objects y locations
lz = [] # list of objects z locations
for obj in bpy.data.objects:
if obj.name.startswith('star'):
lx.append(obj.location.x)
ly.append(obj.location.y)
lz.append(obj.location.z)
def centre(points):
return min(points) + (max(points) - min(points))/2
focus_centre = (centre(lx), centre(ly), centre(lz))
From that you can position your camera to suit, you could use it to position an empty that is setup as the target of a trackTo constraint in the camera. You might also want to use the min and max to ensure the camera is outside the area containing the stars.
Upvotes: 1