feat: replay duration
This commit is contained in:
@ -35,6 +35,7 @@ from operator import itemgetter
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from time import gmtime, strftime
|
||||
from numpy import interp
|
||||
|
||||
from bpy.props import FloatProperty
|
||||
import bmesh
|
||||
@ -1052,6 +1053,8 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
|
||||
def execute(self, context):
|
||||
from replication.repository import Repository
|
||||
|
||||
runtime_settings = context.window_manager.session
|
||||
|
||||
# init the factory with supported types
|
||||
bpy_protocol = bl_types.get_data_translation_protocol()
|
||||
repo = Repository(bpy_protocol)
|
||||
@ -1062,7 +1065,7 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
|
||||
|
||||
persistent_collection = bpy.data.collections.get("multiuser_timelapse")
|
||||
if self.replay and \
|
||||
context.window_manager.session.replay_persistent_collection and \
|
||||
runtime_settings.replay_persistent_collection and \
|
||||
persistent_collection:
|
||||
collection_repo = Repository(
|
||||
rdp=bpy_protocol,
|
||||
@ -1088,14 +1091,17 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
|
||||
porcelain.apply(repo, node.uuid)
|
||||
|
||||
if len(self.files) > 1:
|
||||
context.window_manager.session.replay_files.clear()
|
||||
runtime_settings.replay_files.clear()
|
||||
context.scene.active_replay_file = len(self.files)-1
|
||||
directory = Path(self.filepath).parent
|
||||
for f in self.files:
|
||||
snap = context.window_manager.session.replay_files.add()
|
||||
snap.name = str(Path(directory, f['name']))
|
||||
file_list = [f['name'] for f in self.files]
|
||||
file_list.sort()
|
||||
for f in file_list:
|
||||
snap = runtime_settings.replay_files.add()
|
||||
snap.name = str(Path(directory, f))
|
||||
print(f)
|
||||
|
||||
if context.window_manager.session.replay_mode == 'TIMELINE':
|
||||
if runtime_settings.replay_mode == 'TIMELINE':
|
||||
replay_action = bpy.data.actions.get('replay_action', bpy.data.actions.new('replay_action'))
|
||||
|
||||
bpy.context.scene.animation_data_create()
|
||||
@ -1108,9 +1114,12 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
|
||||
for p in reversed(replay_fcurve.keyframe_points):
|
||||
replay_fcurve.keyframe_points.remove(p, fast=True)
|
||||
|
||||
intrv = context.window_manager.session.replay_interval
|
||||
for frame in range(0, len(self.files)-1):
|
||||
replay_fcurve.keyframe_points.insert(frame * intrv, frame)
|
||||
duration = runtime_settings.replay_duration
|
||||
file_count = len(self.files)-1
|
||||
for index in range(0, file_count):
|
||||
frame = interp(index, [0, file_count], [bpy.context.scene.frame_start, duration])
|
||||
replay_fcurve.keyframe_points.insert(frame, index)
|
||||
|
||||
|
||||
if self.draw_users:
|
||||
f = gzip.open(self.filepath, "rb")
|
||||
@ -1124,15 +1133,27 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
|
||||
if metadata:
|
||||
draw_user(username, metadata, radius=self.user_skin_radius, intensity=self.user_color_intensity)
|
||||
|
||||
# Relink the persistent collection
|
||||
if self.replay and persistent_collection:
|
||||
logging.info(f"Relinking {persistent_collection.name}")
|
||||
bpy.context.scene.collection.children.link(persistent_collection)
|
||||
|
||||
# Reasign scene action
|
||||
if self.replay and \
|
||||
context.window_manager.session.replay_mode == 'TIMELINE' and \
|
||||
runtime_settings.replay_mode == 'TIMELINE' and \
|
||||
not bpy.context.scene.animation_data :
|
||||
bpy.context.scene.animation_data_create()
|
||||
bpy.context.scene.animation_data.action = bpy.data.actions.get('replay_action')
|
||||
bpy.context.scene.frame_end = runtime_settings.replay_duration
|
||||
|
||||
# Reasign the scene camera
|
||||
if self.replay and \
|
||||
runtime_settings.replay_persistent_collection and \
|
||||
runtime_settings.replay_camera:
|
||||
bpy.context.scene.camera = runtime_settings.replay_camera
|
||||
|
||||
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
@classmethod
|
||||
|
Reference in New Issue
Block a user