Kamera: trac to Empty
Lernziel
Handlungsanweisungen/Aufgaben
Erstelle ein neues Python-Script (verwende ein Template)
Erstelle eine neue Klasse
Führe einmalig alle Schritte aus, die notwendig sind
Im Info-Panel sind alle Python-Anweisungen als Protokoll auffindbar, kopiere diese und füge sie in das Script ein.
Mach alle notwendigen Anpassungen für das Script
Teste das Script
Welche Schritte sind notwendig?
Lösche die Objekte Camera und Cube
Füge eine neue Kamera hinzu und anschließend ein Empty hinzu
Wähle beide Objekte aus, zuerste das Empty und im zweiten Schritt die Kamera
Füge eine Constraint »trac to« mit den folgendne Eigenschaften hinzu:
Target: Empty
To: -Z
Up: Y
Kopiere die Python-Kommandos aus dem Info-Bereich und füge sie in das Script ein …
Mit der der Bearbeitung können folgende Änderungen vorgenommen werden:
der Layer-Parameter kann gelöscht werden (wird nicht benötigt)
ersetze die Koordinaten für location und rotation durch Nullen
bpy.ops.object.delete(use_global=False) bpy.ops.object.camera_add(view_align=True, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0)) bpy.ops.object.empty_add(type='PLAIN_AXES', view_align=False, location=(0, 0, 0)) bpy.ops.object.constraint_add(type='TRACK_TO') bpy.context.object.constraints["Track To"].target = bpy.data.objects["Empty"] bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z' bpy.context.object.constraints["Track To"].up_axis = 'UP_Y'
Nun kann das Script beliebig oft aufgerufen werden. Ein Bewegung des Empty-Objektes wird von der Kamera registriert und sie folgt der Ortsveränderung. Damit ist es recht einfach, die Kamera auf das gewünschte Objekt der Szene auszurichten.
Das komplette Script
#!bpy
"""
Name: 'SceneConfigurator'
Blender: 2.7x
Group: 'Low poly'
Tooltip: 'Configure standard settings in a new scene'
"""
import bpy
class SceneConfigurator:
"""Configure a scene"""
def __init__(self):
pass
def cam2empty(self):
"""Trac camera to empty
Move the empty and the camera will point in this direction
"""
bpy.ops.object.empty_add(type='PLAIN_AXES',
view_align=False,
location=(0, 0, 0))
bpy.ops.object.camera_add(view_align=True,
enter_editmode=False,
location=(8, 8, 30),
rotation=(0, 0, 0))
bpy.ops.object.select_pattern(pattern='Empty')
bpy.ops.object.select_pattern(pattern='Camera')
bpy.ops.object.constraint_add(type='TRACK_TO')
bpy.context.object.constraints["Track To"].target = bpy.data.objects["Empty"]
bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
bpy.context.object.constraints["Track To"].up_axis = 'UP_Y'
def sky(self):
bpy.context.scene.world.use_sky_paper = True
bpy.context.scene.world.use_sky_blend = True
bpy.context.scene.world.horizon_color = (0.606907, 0.613911, 0.837134)
def remove(self, name=None):
""" Delete an object by name"""
if name:
bpy.ops.object.select_pattern(pattern=name)
else:
print('nothing to do')
bpy.ops.object.delete()
if __name__ == "__main__":
# switch to object mode, if nessasary
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
ctrl = SceneConfigurator()
ctrl.remove(name="Empty")
ctrl.remove(name="Camera")
ctrl.cam2empty()
ctrl.sky()