diff --git a/__init__.py b/__init__.py index cb4bed4..eb9c57b 100644 --- a/__init__.py +++ b/__init__.py @@ -46,6 +46,7 @@ BSEQ_OT_disable_all, BSEQ_OT_enable_all, BSEQ_OT_refresh_sequences, + BSEQ_OT_set_start_end_frames, WM_OT_batchSequences, WM_OT_MeshioObject ] diff --git a/bseq/__init__.py b/bseq/__init__.py index 361914c..d039423 100644 --- a/bseq/__init__.py +++ b/bseq/__init__.py @@ -1,5 +1,5 @@ from bseq.utils import refresh_obj -from .operators import BSEQ_OT_load, BSEQ_OT_edit, BSEQ_OT_resetpt, BSEQ_OT_resetmesh, BSEQ_OT_resetins, BSEQ_OT_set_as_split_norm, BSEQ_OT_remove_split_norm, BSEQ_OT_disable_selected, BSEQ_OT_enable_selected, BSEQ_OT_refresh_seq, BSEQ_OT_disable_all, BSEQ_OT_enable_all, BSEQ_OT_refresh_sequences, WM_OT_batchSequences, WM_OT_MeshioObject +from .operators import BSEQ_OT_load, BSEQ_OT_edit, BSEQ_OT_resetpt, BSEQ_OT_resetmesh, BSEQ_OT_resetins, BSEQ_OT_set_as_split_norm, BSEQ_OT_remove_split_norm, BSEQ_OT_disable_selected, BSEQ_OT_enable_selected, BSEQ_OT_refresh_seq, BSEQ_OT_disable_all, BSEQ_OT_enable_all, BSEQ_OT_refresh_sequences, BSEQ_OT_set_start_end_frames, WM_OT_batchSequences, WM_OT_MeshioObject from .properties import BSEQ_scene_property, BSEQ_obj_property, BSEQ_mesh_property from .panels import BSEQ_UL_Obj_List, BSEQ_List_Panel, BSEQ_Settings, BSEQ_Import, BSEQ_Templates, BSEQ_UL_Att_List, draw_template from .messenger import subscribe_to_selected, unsubscribe_to_selected @@ -46,6 +46,7 @@ def BSEQ_initialize(scene): "BSEQ_OT_disable_all", "BSEQ_OT_enable_all", "BSEQ_OT_refresh_sequences", + "BSEQ_OT_set_start_end_frames", "WM_OT_batchSequences", "WM_OT_MeshioObject" ] diff --git a/bseq/importer.py b/bseq/importer.py index d5dbc93..7a3e5fa 100644 --- a/bseq/importer.py +++ b/bseq/importer.py @@ -63,8 +63,8 @@ def has_keyframe(obj, attr): def apply_transformation(meshio_mesh, obj, depsgraph): # evaluate the keyframe animation system - eval_location = obj.evaluated_get(depsgraph).location if has_keyframe(obj, "location") else None - eval_scale = obj.evaluated_get(depsgraph).scale if has_keyframe(obj, "scale") else None + eval_location = obj.evaluated_get(depsgraph).location if has_keyframe(obj, "location") else obj.location + eval_scale = obj.evaluated_get(depsgraph).scale if has_keyframe(obj, "scale") else obj.scale if has_keyframe(obj, "rotation_quaternion"): eval_rotation = obj.evaluated_get(depsgraph).rotation_quaternion @@ -73,7 +73,7 @@ def apply_transformation(meshio_mesh, obj, depsgraph): elif has_keyframe(obj, "rotation_euler"): eval_rotation = obj.evaluated_get(depsgraph).rotation_euler else: - eval_rotation = None + eval_rotation = obj.rotation_euler eval_transform_matrix = mathutils.Matrix.LocRotScale(eval_location, eval_rotation, eval_scale) @@ -83,7 +83,7 @@ def apply_transformation(meshio_mesh, obj, depsgraph): rigid_body_transformation = meshio_mesh.field_data["transformation_matrix"] # multiply everything together (with custom transform matrix) - obj.matrix_world = rigid_body_transformation @ obj.BSEQ.initial_transform_matrix @ eval_transform_matrix + obj.matrix_world = rigid_body_transformation @ eval_transform_matrix def update_mesh(meshio_mesh, mesh): # extract information from the meshio mesh @@ -219,8 +219,8 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0, object.BSEQ.pattern = str(fileseq) object.BSEQ.init = True object.BSEQ.enabled = enabled - # Flatten custom transformation matrix for the property - object.BSEQ.initial_transform_matrix = [transform_matrix[j][i] for i in range(4) for j in range(4)] + object.BSEQ.start_end_frame = (fileseq.start(), fileseq.end()) + object.matrix_world = transform_matrix driver = object.driver_add("BSEQ.frame") driver.driver.expression = 'frame' if enabled: diff --git a/bseq/operators.py b/bseq/operators.py index 0190329..ca2b636 100644 --- a/bseq/operators.py +++ b/bseq/operators.py @@ -315,7 +315,24 @@ def execute(self, context): scene = context.scene # call the update function of path by setting it to its own value scene.BSEQ.path = scene.BSEQ.path + return {"FINISHED"} + +class BSEQ_OT_set_start_end_frames(bpy.types.Operator): + '''This changes the timeline start and end frames to the length of a specific sequence''' + bl_label = "Set timeline" + bl_idname = "bseq.set_start_end_frames" + bl_options = {"UNDO"} + + def execute(self, context): + scene = context.scene + obj = bpy.data.objects[scene.BSEQ.selected_obj_num] + (start, end) = obj.BSEQ.start_end_frame + scene.frame_start = 0 + scene.frame_end = end - start + + return {"FINISHED"} + from pathlib import Path import meshio diff --git a/bseq/panels.py b/bseq/panels.py index c35ec7a..d75cefb 100644 --- a/bseq/panels.py +++ b/bseq/panels.py @@ -77,6 +77,7 @@ def draw(self, context): row = layout.row() row.operator("bseq.enableall", text="Enable All") row.operator("bseq.disableall", text="Disable All") + row.operator("bseq.set_start_end_frames", text="Set timeline") diff --git a/bseq/properties.py b/bseq/properties.py index d839791..7e31f59 100644 --- a/bseq/properties.py +++ b/bseq/properties.py @@ -83,10 +83,7 @@ class BSEQ_obj_property(bpy.types.PropertyGroup): use_relative: bpy.props.BoolProperty(default=False) pattern: bpy.props.StringProperty() frame: bpy.props.IntProperty() - initial_transform_matrix: bpy.props.FloatVectorProperty(name='Custom Transformation Matrix', - description='Set custom transformation', - size=16, - subtype="MATRIX") + start_end_frame: bpy.props.IntVectorProperty(name="Start and End Frames", size=2, default=(0, 0)) # set this property for mesh, not object (maybe change later?) class BSEQ_mesh_property(bpy.types.PropertyGroup): diff --git a/bseq/utils.py b/bseq/utils.py index af686b6..7cd5c40 100644 --- a/bseq/utils.py +++ b/bseq/utils.py @@ -29,10 +29,17 @@ def stop_animation(): def refresh_obj(obj, scene): fs = obj.BSEQ.pattern if obj.BSEQ.use_relative: - fs = bpy.path.abspath(fs, start=scene.BSEQ.root_path) + if scene.BSEQ.root_path != "": + fs = bpy.path.abspath(fs, start=scene.BSEQ.root_path) + else: + fs = bpy.path.abspath(fs) fs = fileseq.findSequenceOnDisk(fs) fs = fileseq.findSequenceOnDisk(fs.dirname() + fs.basename() + "@" + fs.extension()) + obj.BSEQ.start_end_frame = (fs.start(), fs.end()) fs = str(fs) if obj.BSEQ.use_relative: - fs = bpy.path.relpath(fs, start=scene.BSEQ.root_path) - obj.BSEQ.pattern = fs \ No newline at end of file + if scene.BSEQ.root_path != "": + fs = bpy.path.relpath(fs, start=scene.BSEQ.root_path) + else: + fs = bpy.path.relpath(fs) + obj.BSEQ.pattern = fs