Camera Align feature is all set up except the actual alignment code.

This commit is contained in:
Nathan Vegdahl 2022-12-20 14:16:02 -08:00
parent 1289197b3b
commit 9a96f282bf

View File

@ -7,7 +7,7 @@ class CompifyCameraAlignPanel(bpy.types.Panel):
bl_idname = "DATA_PT_compify_camera_align"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_context = "scene"
@classmethod
def poll(cls, context):
@ -37,24 +37,23 @@ class CompifyCameraAlignPanel(bpy.types.Panel):
if scene.compify_align_points_active_index < len(scene.compify_align_points):
point = scene.compify_align_points[scene.compify_align_points_active_index]
col = layout.column()
col.prop(point, "name")
col.row().prop(point, "scene_point")
col.row().prop(point, "track_point")
# col.separator(factor=2.0)
row = col.row()
row.prop(point, "scene_point", text="Target Point")
row.operator("scene.compify_align_set_scene_point_to_cursor", text="", icon="CURSOR")
# row = layout.row()
# row.alignment = 'LEFT'
# header_text = "Misc Utilties"
# if wm.camera_shake_show_utils:
# row.prop(wm, "camera_shake_show_utils", icon="DISCLOSURE_TRI_DOWN", text=header_text, expand=False, emboss=False)
# else:
# row.prop(wm, "camera_shake_show_utils", icon="DISCLOSURE_TRI_RIGHT", text=header_text, emboss=False)
# row.separator_spacer()
col.separator(factor=2.0)
# col = layout.column()
# if wm.camera_shake_show_utils:
# col.operator("object.camera_shakes_fix_global")
row = col.row()
row.prop(point, "track_point", text="Tracker")
row.operator("scene.compify_align_set_track_point_to_cursor", text="", icon="CURSOR")
col = layout.column()
col.separator(factor=2.0)
col.operator("scene.compify_camera_align_transform")
class OBJECT_UL_compify_camera_align_items(bpy.types.UIList):
@ -63,7 +62,9 @@ class OBJECT_UL_compify_camera_align_items(bpy.types.UIList):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
row = layout.row()
row.label(text=item.name)
row.prop(item, "scene_point", text="")
row.label(text="{:.2f}".format(item.scene_point[0]))
row.label(text="{:.2f}".format(item.scene_point[1]))
row.label(text="{:.2f}".format(item.scene_point[2]))
# 'GRID' layout type should be as compact as possible (typically a single icon!).
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
@ -72,6 +73,32 @@ class OBJECT_UL_compify_camera_align_items(bpy.types.UIList):
#========================================================
class CompifyCameraAlignTransform(bpy.types.Operator):
"""Transforms the active object to move the specified track points to the specified target points"""
bl_idname = "scene.compify_camera_align_transform"
bl_label = "Align Transform"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object != None and len(context.scene.compify_align_points) >= 3
def execute(self, context):
obj = context.active_object
align_points = context.scene.compify_align_points
# TODO: the actual alignment math.
# Set the track points to be equal to the scene points, so
# double-tapping the align button doesn't un-align after
# aligning.
for point in align_points:
point.track_point[0] = point.scene_point[0]
point.track_point[1] = point.scene_point[1]
point.track_point[2] = point.scene_point[2]
return {'FINISHED'}
class CompifyAlignPointAdd(bpy.types.Operator):
"""Adds an alignment point"""
@ -136,6 +163,43 @@ class CompifyAlignPointMove(bpy.types.Operator):
scene.compify_align_points_active_index += 1
return {'FINISHED'}
class CompifyAlignSetScenePointToCursor(bpy.types.Operator):
"""Sets the target point to the current 3D cursor position"""
bl_idname = "scene.compify_align_set_scene_point_to_cursor"
bl_label = "Set target to 3D cursor"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
return context.scene.compify_align_points_active_index < len(context.scene.compify_align_points)
def execute(self, context):
align_point = context.scene.compify_align_points[context.scene.compify_align_points_active_index]
align_point.scene_point[0] = context.scene.cursor.location[0]
align_point.scene_point[1] = context.scene.cursor.location[1]
align_point.scene_point[2] = context.scene.cursor.location[2]
return {'FINISHED'}
class CompifyAlignSetTrackPointToCursor(bpy.types.Operator):
"""Sets the tracking point to the current 3D cursor position"""
bl_idname = "scene.compify_align_set_track_point_to_cursor"
bl_label = "Set track point to 3D cursor"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
return context.scene.compify_align_points_active_index < len(context.scene.compify_align_points)
def execute(self, context):
align_point = context.scene.compify_align_points[context.scene.compify_align_points_active_index]
align_point.track_point[0] = context.scene.cursor.location[0]
align_point.track_point[1] = context.scene.cursor.location[1]
align_point.track_point[2] = context.scene.cursor.location[2]
return {'FINISHED'}
#========================================================
@ -166,6 +230,10 @@ def camera_align_register():
bpy.utils.register_class(CompifyAlignPointAdd)
bpy.utils.register_class(CompifyAlignPointRemove)
bpy.utils.register_class(CompifyAlignPointMove)
bpy.utils.register_class(CompifyAlignSetScenePointToCursor)
bpy.utils.register_class(CompifyAlignSetTrackPointToCursor)
bpy.utils.register_class(CompifyCameraAlignTransform)
bpy.types.Scene.compify_align_points = bpy.props.CollectionProperty(type=CompifyAlignPoint)
bpy.types.Scene.compify_align_points_active_index = bpy.props.IntProperty(name="Align Points List Active Item Index")
@ -176,5 +244,9 @@ def camera_align_unregister():
bpy.utils.unregister_class(CompifyAlignPointAdd)
bpy.utils.unregister_class(CompifyAlignPointRemove)
bpy.utils.unregister_class(CompifyAlignPointMove)
bpy.utils.unregister_class(CompifyAlignSetScenePointToCursor)
bpy.utils.unregister_class(CompifyAlignSetTrackPointToCursor)
bpy.utils.unregister_class(CompifyCameraAlignTransform)
del bpy.types.Scene.compify_align_points
del bpy.types.Scene.compify_align_points_active_index