一个简单的功能,相机一直对准物体,不管物体怎么移动,用blender做过这功能的都知道只要添加一个阻尼跟踪就好了
代码
def execute(self, context):
camera = None
for obj in bpy.context.collection.all_objects:
if obj.type == 'CAMERA':
camera = obj
break
if camera is None:
return {'FINISHED'}
parent_object = None
if '酒瓶' in bpy.context.collection.all_objects:
parent_object = bpy.context.collection.all_objects['酒瓶']
if parent_object is None:
return {'FINISHED'}
constraint = camera.constraints.new('DAMPED_TRACK')
constraint.target = parent_object
constraint.track_axis = 'TRACK_NEGATIVE_Z'
return {'FINISHED'}
下次写个相机绕着物体旋转的功能,把前边写的功能给用上,算做一个总结