Skip to content

Commit d89c62d

Browse files
Recursive load from folder and new template (#35)
* add a template for doing comparison renders * update comparison render and add recursive sequence loading operator * increase version number
1 parent 0783423 commit d89c62d

File tree

6 files changed

+123
-8
lines changed

6 files changed

+123
-8
lines changed

Diff for: __init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Sequence Loader",
33
"description": "Loader for meshio supported mesh files/ simulation sequences",
44
"author": "Interactive Computer Graphics",
5-
"version": (0, 3, 1),
5+
"version": (0, 3, 2),
66
"blender": (4, 0, 0),
77
"warning": "",
88
"support": "COMMUNITY",
@@ -65,7 +65,8 @@
6565
# BSEQ_OT_import_zip,
6666
# BSEQ_OT_delete_zips,
6767
# BSEQ_addon_preferences,
68-
BSEQ_OT_load_all
68+
BSEQ_OT_load_all,
69+
BSEQ_OT_load_all_recursive
6970
]
7071

7172
def register():

Diff for: bseq/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from bseq.utils import refresh_obj
2-
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, BSEQ_OT_batch_sequences, BSEQ_PT_batch_sequences_settings, BSEQ_OT_meshio_object, BSEQ_OT_import_zip, BSEQ_OT_delete_zips, BSEQ_addon_preferences, BSEQ_OT_load_all
2+
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, BSEQ_OT_batch_sequences, BSEQ_PT_batch_sequences_settings, BSEQ_OT_meshio_object, BSEQ_OT_import_zip, BSEQ_OT_delete_zips, BSEQ_addon_preferences, BSEQ_OT_load_all, BSEQ_OT_load_all_recursive
33
from .properties import BSEQ_scene_property, BSEQ_obj_property, BSEQ_mesh_property
44
from .panels import BSEQ_UL_Obj_List, BSEQ_List_Panel, BSEQ_Settings, BSEQ_PT_Import, BSEQ_PT_Import_Child1, BSEQ_PT_Import_Child2, BSEQ_Globals_Panel, BSEQ_Advanced_Panel, BSEQ_Templates, BSEQ_UL_Att_List, draw_template
55
from .messenger import subscribe_to_selected, unsubscribe_to_selected
@@ -62,5 +62,6 @@ def BSEQ_initialize(scene):
6262
"BSEQ_OT_import_zip",
6363
"BSEQ_OT_delete_zips",
6464
"BSEQ_addon_preferences",
65-
"BSEQ_OT_load_all"
65+
"BSEQ_OT_load_all",
66+
"BSEQ_OT_load_all_recursive"
6667
]

Diff for: bseq/operators.py

+47
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .utils import refresh_obj, show_message_box, get_relative_path
77
from .importer import create_obj, create_meshio_obj
88
import numpy as np
9+
import os
910

1011
addon_name = "blendersequenceloader"
1112

@@ -541,6 +542,52 @@ def execute(self, context):
541542
for s in seqs:
542543
create_obj_wrapper(s, importer_prop)
543544
return {'FINISHED'}
545+
546+
class BSEQ_OT_load_all_recursive(bpy.types.Operator):
547+
"""Load all sequences from selected folder recursively"""
548+
bl_idname = "bseq.load_all_recursive"
549+
bl_label = "Load All Recursive"
550+
bl_options = {'PRESET', 'UNDO'}
551+
552+
def execute(self, context):
553+
importer_prop = context.scene.BSEQ
554+
555+
if importer_prop.use_relative and not bpy.data.is_saved:
556+
return relative_path_error()
557+
558+
root_dir = importer_prop.path
559+
# Recurse through subdirectories
560+
for root, dirs, files in os.walk(bpy.path.abspath(root_dir)):
561+
for dir in sorted(dirs):
562+
# Process subdirectory
563+
subdirectory = os.path.join(root, dir)
564+
565+
seqs = fileseq.findSequencesOnDisk(subdirectory)
566+
if len(seqs) == 0:
567+
continue
568+
569+
# Get list of directories from the root_dir to the current subdirectory
570+
coll_list = bpy.path.relpath(subdirectory, start=root_dir).strip("//").split("/")
571+
572+
# Get or create a nested collection starting from the root
573+
last_coll = bpy.context.scene.collection
574+
layer_collection = bpy.context.view_layer.layer_collection
575+
for coll in coll_list:
576+
cur_coll = bpy.data.collections.get(coll) if bpy.data.collections.get(coll) is not None else bpy.data.collections.new(coll)
577+
if last_coll is not None and cur_coll.name not in last_coll.children:
578+
last_coll.children.link(cur_coll)
579+
layer_collection = layer_collection.children[cur_coll.name]
580+
last_coll = cur_coll
581+
582+
# Set the last collection as the active collection by recursing through the collections
583+
context.view_layer.active_layer_collection = layer_collection
584+
585+
# for s in seqs:
586+
# print(s)
587+
588+
for s in seqs:
589+
create_obj_wrapper(s, importer_prop)
590+
return {'FINISHED'}
544591

545592

546593
class BSEQ_OT_meshio_object(bpy.types.Operator, ImportHelper):

Diff for: bseq/panels.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ def draw(self, context):
292292
col3.prop(importer_prop, "fileseq", text="")
293293
col4.operator("bseq.refreshall", text='', icon="FILE_REFRESH")
294294

295-
split = layout.split(factor=0.7)
295+
split = layout.split(factor=0.5)
296296
col1 = split.column()
297297
col2 = split.column()
298298
col1.operator("sequence.load")
299-
col2.operator("bseq.load_all")
299+
row = col2.row()
300+
row.operator("bseq.load_all")
301+
row.operator("bseq.load_all_recursive")
300302

301303
# split = layout.split(factor=0.5)
302304
# col1 = split.column()

Diff for: docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

99
project = 'blender-sequence-loader'
10-
copyright = '2022, InteractiveComputerGraphics'
10+
copyright = '2024, InteractiveComputerGraphics'
1111
author = 'InteractiveComputerGraphics'
12-
release = '0.3.1'
12+
release = '0.3.2'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

Diff for: template/Comparison Render.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import bpy
2+
3+
# Utilities for comparison rendering
4+
def toggle_on_single(obj):
5+
obj.hide_render = False
6+
if isinstance(obj, bpy.types.Object) and obj.BSEQ.init:
7+
obj.BSEQ.enabled = True
8+
for child in obj.children:
9+
toggle_on_single(child)
10+
elif isinstance(obj, bpy.types.Collection):
11+
for child in obj.objects:
12+
toggle_on_single(child)
13+
for child in obj.children:
14+
toggle_on_single(child)
15+
16+
def toggle_on(objs):
17+
if type(objs) == list:
18+
for obj in objs:
19+
toggle_on_single(obj)
20+
else:
21+
toggle_on_single(objs)
22+
23+
def toggle_off_single(obj):
24+
obj.hide_render = True
25+
if isinstance(obj, bpy.types.Object) and obj.BSEQ.init:
26+
obj.BSEQ.enabled = False
27+
for child in obj.children:
28+
toggle_off_single(child)
29+
elif isinstance(obj, bpy.types.Collection):
30+
for child in obj.objects:
31+
toggle_off_single(child)
32+
for child in obj.children:
33+
toggle_off_single(child)
34+
35+
def toggle_off(objs):
36+
if type(objs) == list:
37+
for obj in objs:
38+
toggle_off_single(obj)
39+
else:
40+
toggle_off_single(objs)
41+
42+
def toggle_off_all():
43+
for obj in bpy.data.objects:
44+
toggle_off_single(obj)
45+
46+
def toggle_on_all():
47+
for obj in bpy.data.objects:
48+
toggle_on_single(obj)
49+
50+
# Declare which collection to render comparison for
51+
# Change this to the name of the collection you want to render
52+
comparison_collection = "Sequences"
53+
54+
# Iterate over children in the collection
55+
comparison_objects = list(bpy.data.collections[comparison_collection].children) + list(bpy.data.collections[comparison_collection].objects)
56+
orig_path = bpy.context.scene.render.filepath
57+
for obj in comparison_objects:
58+
toggle_off(comparison_objects)
59+
toggle_on(obj)
60+
bpy.context.scene.render.filepath = f"{orig_path}/{obj.name}/"
61+
# bpy.ops.render.render(write_still=True)
62+
bpy.ops.render.render(animation=True)
63+
64+
bpy.context.scene.render.filepath = orig_path

0 commit comments

Comments
 (0)