Skip to content

Commit

Permalink
Display alternative image when AssetSearch cannot download thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed Apr 24, 2024
1 parent e9d24b5 commit f0090f8
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 173 deletions.
4 changes: 2 additions & 2 deletions mmd_uuunyaa_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
'name': 'mmd_uuunyaa_tools',
'description': 'Utility tools for MMD model & scene editing by Uuu(/>ω<)/Nyaa!.',
'author': 'UuuNyaa',
'version': (1, 7, 2),
'blender': (2, 83, 0),
'version': (1, 8, 0),
'blender': (3, 6, 0),
'warning': '',
'location': 'View3D > Sidebar > MMD Tools Panel',
'wiki_url': 'https://github.com/UuuNyaa/blender_mmd_uuunyaa_tools/wiki',
Expand Down
28 changes: 17 additions & 11 deletions mmd_uuunyaa_tools/asset_search/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,26 @@ def try_get_task(self, url: URL) -> Optional[Task]:
return self._tasks[url] if url in self._tasks else None

def async_get_content(self, url: URL, callback: Callback) -> Future:
def queue_callback():
task = self._tasks[url]
if task.state not in {Task.State.QUEUING, Task.State.RUNNING}:
raise ValueError(f'task (={task.url}) is invalid state (={task.state})')
task.callbacks.append(callback)
return task.future

with self._lock:
if url in self._tasks:
return queue_callback()

content = self.try_get_content(url)
if content is not None:
if content.state in {Content.State.CACHED, Content.State.FETCHING}:
return self._executor.submit(self._invoke_callback, callback, content)

self.remove_content(url)

elif url in self._tasks:
task = self._tasks[url]

if task.state in {Task.State.QUEUING, Task.State.RUNNING}:
task.callbacks.append(callback)
return task.future
match content.state:
case Content.State.CACHED:
return self._executor.submit(self._invoke_callback, callback, content)
case Content.State.FETCHING:
return queue_callback()
case _: # maybe failed
self.remove_content(url)

task = Task(url, Task.State.QUEUING, [callback])
task.future = self._executor.submit(self._fetch, task)
Expand Down
4 changes: 4 additions & 0 deletions mmd_uuunyaa_tools/asset_search/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# This file is part of MMD UuuNyaa Tools.

import functools
import os
import time
from enum import Enum
from typing import List, Optional, Tuple

import bpy
import bpy.utils.previews
from mmd_uuunyaa_tools import PACKAGE_PATH
from mmd_uuunyaa_tools.asset_search.actions import ImportActionExecutor, MessageException
from mmd_uuunyaa_tools.asset_search.assets import ASSETS, AssetDescription, AssetType
from mmd_uuunyaa_tools.asset_search.cache import CONTENT_CACHE, Content, Task
Expand Down Expand Up @@ -80,6 +82,8 @@ def _on_thumbnail_fetched(search_result, region, update_time, asset, content):

global PREVIEWS # pylint: disable=global-statement
if asset.thumbnail_url not in PREVIEWS:
if content.filepath is None:
content.filepath = os.path.join(PACKAGE_PATH, 'thumbnails', 'ASSET_THUMBNAIL_EMPTY.png')
PREVIEWS.load(asset.thumbnail_url, content.filepath, 'IMAGE')

region.tag_redraw()
Expand Down
8 changes: 6 additions & 2 deletions mmd_uuunyaa_tools/editors/armatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import rna_prop_ui
from mathutils import Matrix, Vector
from mmd_uuunyaa_tools import PACKAGE_PATH
from mmd_uuunyaa_tools.utilities import raise_installation_error

PATH_BLENDS_RIGSHAPELIBRARY = os.path.join(PACKAGE_PATH, 'blends', 'RigShapeLibrary.blend')

Expand Down Expand Up @@ -309,8 +310,11 @@ def load_custom_shapes(custom_shape_names: List[str]):
if len(custom_shape_names) == 0:
return

with bpy.data.libraries.load(PATH_BLENDS_RIGSHAPELIBRARY, link=False) as (_, data_to):
data_to.objects = custom_shape_names
try:
with bpy.data.libraries.load(PATH_BLENDS_RIGSHAPELIBRARY, link=False) as (_, data_to):
data_to.objects = custom_shape_names
except OSError as exception:
raise_installation_error(exception)


class ArmatureEditor(EditBoneEditor, PoseBoneEditor):
Expand Down
8 changes: 6 additions & 2 deletions mmd_uuunyaa_tools/editors/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ShaderNodeVertexColor)
from mmd_uuunyaa_tools import PACKAGE_PATH
from mmd_uuunyaa_tools.m17n import _
from mmd_uuunyaa_tools.utilities import raise_installation_error

PATH_BLENDS_UUUNYAA_MATERIALS = os.path.join(PACKAGE_PATH, 'blends', 'UuuNyaa_Materials.blend')

Expand All @@ -42,8 +43,11 @@ def append_node_group(self, name: str):
if name in bpy.data.node_groups:
return

with bpy.data.libraries.load(self._library_blend_file_path, link=False) as (_, data_to):
data_to.node_groups = [name]
try:
with bpy.data.libraries.load(self._library_blend_file_path, link=False) as (_, data_to):
data_to.node_groups = [name]
except OSError as exception:
raise_installation_error(exception)

@abstractmethod
def get_output_node(self) -> Node:
Expand Down
4 changes: 2 additions & 2 deletions mmd_uuunyaa_tools/editors/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ def execute(self, context: bpy.types.Context):

distance_threshold = self.distance_threshold

obj_mesh = obj.data
obj_mesh: bpy.types.Mesh = obj.data
shape_keys = obj_mesh.shape_keys
key_block = shape_keys.key_blocks[obj.active_shape_key_index]
relative_key_block = key_block.relative_key

mesh = bmesh.from_edit_mesh(obj_mesh) # pylint: disable=assignment-from-no-return
mesh.select_mode |= {'VERT'}
bmesh_vertices = mesh.verts
for i, (origin, morph) in enumerate(zip(relative_key_block.data, key_block.data)):
if (origin.co - morph.co).length > distance_threshold:
bmesh_vertices[i].select_set(True)

mesh.select_mode |= {'VERT'}
mesh.select_flush_mode()

bmesh.update_edit_mesh(obj_mesh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ def register(bl_info):
# if support for a future version of blender is going away, and you don't
# want users to be prompted to install a non-functioning addon)
# updater.version_max_update = (9,9,9)
updater.version_max_update = None # None or default for no max.
updater.version_max_update = (4, 0, 0) # None or default for no max.

# Function defined above, customize as appropriate per repository
updater.skip_tag = skip_tag_function # min and max used in this function
Expand Down
Loading

0 comments on commit f0090f8

Please sign in to comment.