Update most var and function names for FX_Source_Img to avoid potential conflicts

This commit is contained in:
mgfxer
2024-07-13 13:03:39 -05:00
parent 8594ca486a
commit 588bcd00da
+52 -52
View File
@@ -30,94 +30,94 @@ class EdgeFXSourceImages:
# Define the return names for the function outputs
RETURN_NAMES = ("first_timeline", "second_timeline", "first_text_output", "second_text_output", "total_frames")
# Name of the function to be executed
FUNCTION = "generate_mask_definitions"
FUNCTION = "generate_mask_definitions_v2"
# Category of the node
CATEGORY = "advanced"
def generate_mask_definitions(self, image_stream, num_images, hold_length, transition_length, padding_frames, push, retract):
def generate_mask_definitions_v2(self, image_stream, num_images, hold_length, transition_length, padding_frames, push, retract):
# Initialize lists to hold the timelines and mask definitions
first_timeline = []
second_timeline = []
first_text_output = ""
second_text_output = ""
primary_timeline = []
secondary_timeline = []
primary_text_output = ""
secondary_text_output = ""
# Calculate the total number of frames for each image and the total number of frames for the entire animation
frame_distance = hold_length + transition_length
total_frames = num_images * frame_distance + padding_frames
frame_interval = hold_length + transition_length
total_frame_count = num_images * frame_interval + padding_frames
# Get the actual number of images provided
num_images_provided = image_stream.shape[0]
provided_image_count = image_stream.shape[0]
# Adjust hold value for the first cycle
adjusted_first_hold = hold_length - retract + push
adjusted_initial_hold = hold_length - retract + push
# Generate the first timeline with adjusted first hold value
# Generate the primary timeline with adjusted initial hold value
for i in range(num_images):
index = i % num_images_provided
current_hold = adjusted_first_hold if i == 0 else hold_length
frame_distance = current_hold + transition_length
repeated_images = image_stream[index:index+1].repeat(frame_distance, 1, 1, 1)
first_timeline.append(repeated_images)
index = i % provided_image_count
current_hold_duration = adjusted_initial_hold if i == 0 else hold_length
frame_interval = current_hold_duration + transition_length
repeated_images = image_stream[index:index+1].repeat(frame_interval, 1, 1, 1)
primary_timeline.append(repeated_images)
# Concatenate the list of tensors into a single tensor
first_timeline = torch.cat(first_timeline, dim=0)
primary_timeline = torch.cat(primary_timeline, dim=0)
# Adjust padding length
adjusted_padding_length = padding_frames + retract - push
adjusted_padding_duration = padding_frames + retract - push
# Generate the second timeline
# Generate the secondary timeline
for i in range(1, num_images):
index = i % num_images_provided
repeated_images = image_stream[index:index+1].repeat(frame_distance, 1, 1, 1)
second_timeline.append(repeated_images)
repeated_images = image_stream[0:1].repeat(frame_distance, 1, 1, 1)
second_timeline.append(repeated_images)
index = i % provided_image_count
repeated_images = image_stream[index:index+1].repeat(frame_interval, 1, 1, 1)
secondary_timeline.append(repeated_images)
repeated_images = image_stream[0:1].repeat(frame_interval, 1, 1, 1)
secondary_timeline.append(repeated_images)
# Concatenate the list of tensors into a single tensor
second_timeline = torch.cat(second_timeline, dim=0)
secondary_timeline = torch.cat(secondary_timeline, dim=0)
# Initialize frame number and create mask text outputs
frame = 0
while frame < num_images * frame_distance:
frame_end_hold = frame + hold_length - 1
frame_start_transition = frame_end_hold + 1
frame_end_transition = frame_start_transition + transition_length - 1
frame_counter = 0
while frame_counter < num_images * frame_interval:
hold_end_frame = frame_counter + hold_length - 1
transition_start_frame = hold_end_frame + 1
transition_end_frame = transition_start_frame + transition_length - 1
first_text_output += f"{frame}:(1.0),\n"
first_text_output += f"{frame_end_hold}:(1.0),\n"
first_text_output += f"{frame_end_transition}:(0.0),\n"
primary_text_output += f"{frame_counter}:(1.0),\n"
primary_text_output += f"{hold_end_frame}:(1.0),\n"
primary_text_output += f"{transition_end_frame}:(0.0),\n"
second_text_output += f"{frame}:(0.0),\n"
second_text_output += f"{frame_end_hold}:(0.0),\n"
second_text_output += f"{frame_end_transition}:(1.0),\n"
secondary_text_output += f"{frame_counter}:(0.0),\n"
secondary_text_output += f"{hold_end_frame}:(0.0),\n"
secondary_text_output += f"{transition_end_frame}:(1.0),\n"
frame = frame_end_transition + 1
frame_counter = transition_end_frame + 1
# Add padding frames if specified
if adjusted_padding_length > 0:
padding_start_frame = frame
last_image_first_timeline = first_timeline[-1:]
last_image_second_timeline = second_timeline[-1:]
if adjusted_padding_duration > 0:
padding_start_frame = frame_counter
last_image_primary_timeline = primary_timeline[-1:]
last_image_secondary_timeline = secondary_timeline[-1:]
# Add padding frames to the timelines
padding_images_first = last_image_first_timeline.repeat(adjusted_padding_length, 1, 1, 1)
first_timeline = torch.cat((first_timeline, padding_images_first), dim=0)
padding_images_primary = last_image_primary_timeline.repeat(adjusted_padding_duration, 1, 1, 1)
primary_timeline = torch.cat((primary_timeline, padding_images_primary), dim=0)
padding_images_second = last_image_second_timeline.repeat(adjusted_padding_length, 1, 1, 1)
second_timeline = torch.cat((second_timeline, padding_images_second), dim=0)
padding_images_secondary = last_image_secondary_timeline.repeat(adjusted_padding_duration, 1, 1, 1)
secondary_timeline = torch.cat((secondary_timeline, padding_images_secondary), dim=0)
# Append padding frames to the text outputs
for i in range(adjusted_padding_length):
frame = padding_start_frame + i
first_text_output += f"{frame}:(0.0),\n"
second_text_output += f"{frame}:(1.0),\n" # Set to 1.0 for the second timeline
for i in range(adjusted_padding_duration):
frame_counter = padding_start_frame + i
primary_text_output += f"{frame_counter}:(0.0),\n"
secondary_text_output += f"{frame_counter}:(1.0),\n" # Set to 1.0 for the secondary timeline
# Ensure the text output ends correctly
first_text_output = first_text_output.strip().rstrip(',')
second_text_output = second_text_output.strip().rstrip(',')
primary_text_output = primary_text_output.strip().rstrip(',')
secondary_text_output = secondary_text_output.strip().rstrip(',')
# Return the generated timelines, text outputs, and total frames
return first_timeline, second_timeline, first_text_output, second_text_output, total_frames
return primary_timeline, secondary_timeline, primary_text_output, secondary_text_output, total_frame_count
# Mapping the class to its name for the node system
NODE_CLASS_MAPPINGS = {