Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Blender Versions #3

Open
wants to merge 1 commit into
base: 1.0-Alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 38 additions & 49 deletions ops/asset_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def execute(self, context):
self.report({"ERROR"}, "No active asset found")
return {"CANCELLED"}

prefs = utils.get_prefs()

asset = utils.Asset(context.asset)

if context.asset.metadata.sh_catalog == "CUSTOM":
Expand Down Expand Up @@ -99,9 +97,7 @@ def _invoke(self, context: Context, event):
self.prog = self.scene_sets.side_panel_batch_asset_update_progress_bar
self.prog.metadata_label = "Metadata Update"
self.prog.start()
self.prog.draw_icon_rendering = (
self.scene_sets.metadata_update.render_thumbnails
)
self.prog.draw_icon_rendering = self.scene_sets.metadata_update.render_thumbnails

self.active_bar = self.prog.metadata_bar

Expand Down Expand Up @@ -151,9 +147,7 @@ def modal(self, context: Context, event: Event):
context.window_manager.event_timer_remove(self._timer)
bpy.app.timers.register(self.prog.end, first_interval=1)
return {"FINISHED"}
elif event.value == "ESC" and utils.mouse_in_window(
context.window, event.mouse_x, event.mouse_y
):
elif event.value == "ESC" and utils.mouse_in_window(context.window, event.mouse_x, event.mouse_y):
self.prog.cancel = True
elif self.prog.cancel:
self._thread.join()
Expand All @@ -180,55 +174,52 @@ def main(
break
asset = utils.Asset(bpy_asset)
md_update.process_asset_metadata(asset, bpy_asset, lib)
asset.update_asset(
prefs.ensure_default_blender_version().path, debug=md_update.debug_scene
)
asset.update_asset(prefs.ensure_default_blender_version().path, debug=md_update.debug_scene)
self.metadata_progress = (i + 1) / len(selected_assets)
self.update = True

if md_update.render_thumbnails and not self.prog.cancel:
self.start_icon = True
self.update = True

blends = {}
blend_files_dict: dict[str, dict[str, list[tuple[str, str]]]] = {}
for a in selected_assets:
# if a.id_type=='OBJECT' or a.id_type=='COLLECTION' or a.id_type=='MATERIAL':
if a.id_type in {"OBJECT", "COLLECTION", "MATERIAL"}:
blend_data = blends.get(a.full_library_path)
blends[a.full_library_path] = (
blend_data + [(a.name, a.id_type)]
if blend_data
else [(a.name, a.id_type)]
exe = a.metadata.sh_get_blender_version.path
exe_data = blend_files_dict.get(exe)
if not exe_data:
exe_data = {}
blend_files_dict[exe] = exe_data

blend_data = exe_data.get(a.full_library_path)

blend_files_dict[a.full_library_path] = (
blend_data + [(a.name, a.id_type)] if blend_data else [(a.name, a.id_type)]
)

lib_path = [
a
for a in bpy.context.preferences.filepaths.asset_libraries
if a.name == library_name
]
lib_path = [a for a in bpy.context.preferences.filepaths.asset_libraries if a.name == library_name]
if lib_path:
lib_path = lib_path[0].path

prefs = utils.get_prefs()
utils.rerender_thumbnail(
paths=[b for b in blends.keys()],
directory=lib_path,
objects=[f for f in blends.values()],
shading=md_update.shading,
angle=utils.resolve_angle(
md_update.camera_angle,
md_update.flip_x,
md_update.flip_y,
md_update.flip_z,
),
add_plane=prefs.add_ground_plane and not md_update.flip_z,
world_name=md_update.scene_lighting,
world_strength=md_update.world_strength,
padding=1 - md_update.padding,
rotate_world=md_update.rotate_world,
debug_scene=md_update.debug_scene,
op=self,
)
for i, (exe, blend_files) in enumerate(blend_files_dict.items()):
utils.rerender_thumbnail(
paths=[b for b in blend_files.keys()],
directory=lib_path,
objects=[f for f in blend_files.values()],
shading=md_update.shading,
angle=utils.resolve_angle(
md_update.camera_angle, md_update.flip_x, md_update.flip_y, md_update.flip_z
),
add_plane=prefs.add_ground_plane and not md_update.flip_z,
world_name=md_update.scene_lighting,
world_strength=md_update.world_strength,
padding=1 - md_update.padding,
rotate_world=md_update.rotate_world,
debug_scene=md_update.debug_scene,
op=self,
)

if md_update.reset_settings:
md_update.reset()
Expand Down Expand Up @@ -367,7 +358,7 @@ def poll(cls, context):

@classmethod
def description(cls, context, operator_properties):
return f"Rerender the thumbnail of the asset{'s' if len(context.selected_assets)>1 else ''}"
return f"Rerender the thumbnail of the asset{'s' if len(context.selected_assets) > 1 else ''}"

def draw(self, context):
self.draw_thumbnail_props(self.layout)
Expand All @@ -383,9 +374,7 @@ def execute(self, context):
if a.id_type in {"OBJECT", "COLLECTION", "MATERIAL"}:
blend_data = blends.get(a.full_library_path)
blends[a.full_library_path] = (
blend_data + [(a.name, a.id_type)]
if blend_data
else [(a.name, a.id_type)]
blend_data + [(a.name, a.id_type)] if blend_data else [(a.name, a.id_type)]
)

self.threads = []
Expand All @@ -404,9 +393,7 @@ def execute(self, context):
directory=lib_path,
objects=[f for f in blends.values()],
shading=self.shading,
angle=utils.resolve_angle(
self.camera_angle, self.flip_x, self.flip_y, self.flip_z
),
angle=utils.resolve_angle(self.camera_angle, self.flip_x, self.flip_y, self.flip_z),
add_plane=prefs.add_ground_plane and not self.flip_z,
world_name=self.scene_lighting,
world_strength=self.world_strength,
Expand All @@ -432,7 +419,7 @@ def execute(self, context):

def modal(self, context, event):
if event.type == "TIMER":
context.scene.sh_progress_t = f"Regenerating Thumbnails..."
context.scene.sh_progress_t = "Regenerating Thumbnails..."
if context.area:
context.area.tag_redraw()
if not self.thread.is_alive():
Expand Down Expand Up @@ -479,6 +466,8 @@ def execute(self, context):
asset = utils.Asset(context.asset)
asset.icon_path = self.filepath

asset.update_asset()

prefs = utils.get_prefs()
asset.update_asset(prefs.ensure_default_blender_version().path)

Expand Down
32 changes: 31 additions & 1 deletion ops/blender_exes_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from .. import utils

from time import time


class SH_OT_GatherBlenderExes(Operator):
bl_idname = "bkeeper.gather_blender_exes"
Expand All @@ -20,14 +22,42 @@ def execute(self, context):

prefs = utils.get_prefs()

print()
for path in paths:
p = Path(path)
for bexe in p.glob(f"**/{executable_name}"):

t = time()
bexes = self.find_blender_executables(str(p), executable_name)

if not bexes:
continue

print(f"Search: {time() - t:.2f}s")
t = time()

for bexe in bexes:
prefs.add_blender_version(
bexe.parent.name.replace("-", " ").title(), str(bexe)
)
print()

return {"FINISHED"}

def find_blender_executables(self, path: str, executable_name: str) -> list[Path]:
if not os.path.exists(path):
return []
found_files = []

def scan_dir(directory):
with os.scandir(directory) as it:
for entry in it:
if entry.is_file() and entry.name == executable_name:
found_files.append(Path(entry.path))
elif entry.is_dir():
scan_dir(entry.path)

scan_dir(path)
return found_files

def _get_blender_paths(self) -> list[str]:
system = platform.system()
Expand Down
Loading