work
save startup blend for animation tab & whatnot
This commit is contained in:
@@ -23,7 +23,7 @@ from typing import Any
|
||||
import bpy
|
||||
from bpy.props import BoolProperty, FloatVectorProperty, IntProperty, StringProperty
|
||||
|
||||
from . import colors, global_vars, paths, search, ui_bgl, utils
|
||||
from . import colors, global_vars, keymap_utils, paths, search, ui_bgl, utils
|
||||
|
||||
|
||||
draw_time = 0
|
||||
@@ -103,41 +103,63 @@ def get_large_thumbnail_image(asset_data):
|
||||
return img
|
||||
|
||||
|
||||
def get_full_photo_thumbnail(asset_data):
|
||||
"""Get full photo thumbnail from asset data. This is different from the large thumbnail
|
||||
as the photo_thumbnails are not available on the asset data root, but inside the files[].
|
||||
We need to get the data from files[] where assetType=='photo_thumbnail'."""
|
||||
# Find the photo thumbnail file
|
||||
photo_file = None
|
||||
def get_full_thumbnail_variant(asset_data, variant: str):
|
||||
"""Get full thumbnail variant from asset data.
|
||||
|
||||
Args:
|
||||
asset_data: The asset data dictionary.
|
||||
variant (str): The variant type to retrieve ('photo' or 'wire').
|
||||
Returns:
|
||||
The Blender image object for the requested variant, or None if not found.
|
||||
"""
|
||||
# Find the file corresponding to the requested variant
|
||||
file_data = None
|
||||
for file in asset_data.get("files", []):
|
||||
if file.get("fileType") == "photo_thumbnail":
|
||||
photo_file = file
|
||||
if file.get("fileType") == f"{variant.lower()}_thumbnail":
|
||||
file_data = file
|
||||
break
|
||||
|
||||
if photo_file is None:
|
||||
bk_logger.warning("No photo thumbnail file found in asset data")
|
||||
if file_data is None:
|
||||
bk_logger.log(1, f"No {variant} thumbnail file found in asset data")
|
||||
return None
|
||||
|
||||
photo_url = photo_file.get("thumbnailMiddleUrl")
|
||||
if photo_url is None:
|
||||
bk_logger.warning("No thumbnail URL found in photo file")
|
||||
file_url = file_data.get("thumbnailMiddleUrl")
|
||||
if file_url is None:
|
||||
bk_logger.warning(f"No thumbnail URL found in {variant} file")
|
||||
return None
|
||||
|
||||
# Get the directory and construct the path
|
||||
ui_props = bpy.context.window_manager.blenderkitUI
|
||||
directory = paths.get_temp_dir(f"{ui_props.asset_type.lower()}_search")
|
||||
photo_name = os.path.basename(photo_url)
|
||||
tpath = os.path.join(directory, photo_name)
|
||||
file_name = os.path.basename(file_url)
|
||||
tpath = os.path.join(directory, file_name)
|
||||
|
||||
# Load the image into Blender
|
||||
if os.path.exists(tpath):
|
||||
img = utils.get_hidden_image(tpath, photo_name, colorspace="")
|
||||
img = utils.get_hidden_image(tpath, file_name, colorspace="")
|
||||
bk_logger.debug(f"{variant} thumbnail loaded from path: {tpath}")
|
||||
return img
|
||||
|
||||
bk_logger.info(f"Photo thumbnail file not found at path: {tpath}")
|
||||
bk_logger.info("Thumbnail file not found at path: %s", tpath)
|
||||
return None
|
||||
|
||||
|
||||
def get_full_photo_thumbnail(asset_data):
|
||||
"""Get full photo thumbnail from asset data. This is different from the large thumbnail
|
||||
as the photo_thumbnails are not available on the asset data root, but inside the files[].
|
||||
We need to get the data from files[] where assetType=='photo_thumbnail'."""
|
||||
# Find the photo thumbnail file
|
||||
thumb = get_full_thumbnail_variant(asset_data, "photo")
|
||||
return thumb
|
||||
|
||||
|
||||
def get_full_wire_thumbnail(asset_data):
|
||||
"""Get full wireframe thumbnail from asset data."""
|
||||
# Find the photo thumbnail file
|
||||
thumb = get_full_thumbnail_variant(asset_data, "wire")
|
||||
return thumb
|
||||
|
||||
|
||||
def is_rating_possible() -> tuple[bool, bool, Any, Any]:
|
||||
# TODO remove this, but first check and reuse the code for new rating system...
|
||||
ao = bpy.context.active_object
|
||||
@@ -472,9 +494,6 @@ classes = (
|
||||
ParticlesDropDialog,
|
||||
)
|
||||
|
||||
# store keymap items here to access after registration
|
||||
addon_keymapitems = []
|
||||
|
||||
|
||||
# @persistent
|
||||
def pre_load(context):
|
||||
@@ -490,32 +509,7 @@ def register_ui():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
|
||||
wm = bpy.context.window_manager
|
||||
|
||||
# spaces solved by registering shortcut to Window. Couldn't register object mode before somehow.
|
||||
if not wm.keyconfigs.addon:
|
||||
return
|
||||
km = wm.keyconfigs.addon.keymaps.new(name="Window", space_type="EMPTY")
|
||||
# asset bar shortcut
|
||||
kmi = km.keymap_items.new(
|
||||
"view3d.run_assetbar_fix_context",
|
||||
"SEMI_COLON",
|
||||
"PRESS",
|
||||
ctrl=False,
|
||||
shift=False,
|
||||
)
|
||||
kmi.properties.keep_running = False
|
||||
kmi.properties.do_search = False
|
||||
addon_keymapitems.append(kmi)
|
||||
# fast rating shortcut
|
||||
wm = bpy.context.window_manager
|
||||
km = wm.keyconfigs.addon.keymaps["Window"]
|
||||
kmi = km.keymap_items.new(
|
||||
"wm.blenderkit_menu_rating_upload", "R", "PRESS", ctrl=False, shift=False
|
||||
)
|
||||
addon_keymapitems.append(kmi)
|
||||
# kmi = km.keymap_items.new(upload.FastMetadata.bl_idname, 'F', 'PRESS', ctrl=True, shift=False)
|
||||
# addon_keymapitems.append(kmi)
|
||||
keymap_utils.register_keymaps()
|
||||
|
||||
|
||||
def unregister_ui():
|
||||
@@ -524,15 +518,4 @@ def unregister_ui():
|
||||
for c in classes:
|
||||
bpy.utils.unregister_class(c)
|
||||
|
||||
wm = bpy.context.window_manager
|
||||
if not wm.keyconfigs.addon:
|
||||
return
|
||||
|
||||
km = wm.keyconfigs.addon.keymaps.get("Window")
|
||||
if km:
|
||||
for kmi in addon_keymapitems:
|
||||
try:
|
||||
km.keymap_items.remove(kmi)
|
||||
except:
|
||||
pass
|
||||
del addon_keymapitems[:]
|
||||
keymap_utils.unregister_keymaps()
|
||||
|
||||
Reference in New Issue
Block a user