Merge branch 'main' into Texture-Atlasing

This commit is contained in:
Onan Chew
2024-07-24 20:49:25 -04:00
committed by GitHub
6 changed files with 295 additions and 18 deletions
+76 -1
View File
@@ -146,6 +146,9 @@ def get_all_meshes(context: Context) -> List[Object]:
return [obj for obj in bpy.data.objects if obj.type == 'MESH' and obj.parent == armature]
return []
def get_mesh_items(self, context):
return [(obj.name, obj.name, "") for obj in get_all_meshes(context)]
def open_web_after_delay_multi_threaded(delay: typing.Optional[float] = 1.0, url: typing.Union[str, typing.Any] = ""):
thread = threading.Thread(target=open_web_after_delay,args=[delay,url],name="open_browser_thread")
thread.start()
@@ -164,4 +167,76 @@ def duplicatebone(b: bpy.types.EditBone) -> bpy.types.EditBone:
cb.tail = b.tail
cb.matrix = b.matrix
cb.parent = b.parent
return cb
return cb
def has_shapekeys(mesh_obj: Object) -> bool:
return mesh_obj.data.shape_keys is not None
def sort_shape_keys(mesh: Object) -> None:
print("Starting shape key sorting...")
if not has_shapekeys(mesh):
print("No shape keys found. Exiting sort function.")
return
# Set the mesh as the active object
bpy.context.view_layer.objects.active = mesh
bpy.ops.object.mode_set(mode='OBJECT')
order = [
'Basis',
'vrc.blink_left',
'vrc.blink_right',
'vrc.lowerlid_left',
'vrc.lowerlid_right',
'vrc.v_aa',
'vrc.v_ch',
'vrc.v_dd',
'vrc.v_e',
'vrc.v_ff',
'vrc.v_ih',
'vrc.v_kk',
'vrc.v_nn',
'vrc.v_oh',
'vrc.v_ou',
'vrc.v_pp',
'vrc.v_rr',
'vrc.v_sil',
'vrc.v_ss',
'vrc.v_th',
]
shape_keys = mesh.data.shape_keys.key_blocks
print(f"Total shape keys: {len(shape_keys)}")
# Create a list of shape key names in their current order
current_order = [key.name for key in shape_keys]
# Create a new order list
new_order = []
# First, add all the keys that are in the predefined order
for name in order:
if name in current_order:
new_order.append(name)
current_order.remove(name)
# Then add any remaining keys that weren't in the predefined order
new_order.extend(current_order)
print("New order:", new_order)
# Now, rearrange the shape keys based on the new order
for i, name in enumerate(new_order):
index = shape_keys.find(name)
if index != i:
print(f"Moving {name} from index {index} to {i}")
mesh.active_shape_key_index = index
while mesh.active_shape_key_index > i:
bpy.ops.object.shape_key_move(type='UP')
print("Shape key sorting completed.")
def get_shapekeys(mesh: Object, prefix: str = '') -> List[tuple]:
if not has_shapekeys(mesh):
return []
return [(key.name, key.name, key.name) for key in mesh.data.shape_keys.key_blocks if key.name != 'Basis' and key.name.startswith(prefix)]
+43 -6
View File
@@ -1,13 +1,13 @@
import bpy
from ..functions.translations import t, get_languages_list, update_ui
from ..functions.translations import t, get_languages_list, update_language
from ..core.register import register_property
from bpy.types import Scene, Object, Material, TextureNode, Context, SceneObjects, PropertyGroup
from bpy.props import BoolProperty, EnumProperty, FloatProperty, IntProperty, CollectionProperty, StringProperty, FloatVectorProperty, PointerProperty
from bpy.utils import register_class
from ..core.register import register_wrap
from ..core.addon_preferences import get_preference
from ..core.common import SceneMatClass, material_list_bool, get_armatures
from ..core.common import SceneMatClass, material_list_bool, get_armatures, get_mesh_items
@@ -21,9 +21,35 @@ def register() -> None:
default=default_language,
update=update_language
)
bpy.types.Scene.selected_mesh = bpy.props.EnumProperty(
items=get_mesh_items,
name="Selected Mesh",
description="The currently selected mesh for viseme operations"
)
bpy.types.Scene.avatar_toolkit_language_changed = bpy.props.BoolProperty(default=False)
bpy.types.Scene.mouth_a = bpy.props.StringProperty(
name=t("Scene.mouth_a.label"),
description=t("Scene.mouth_a.desc")
)
bpy.types.Scene.mouth_o = bpy.props.StringProperty(
name=t("Scene.mouth_o.label"),
description=t("Scene.mouth_o.desc")
)
bpy.types.Scene.mouth_ch = bpy.props.StringProperty(
name=t("Scene.mouth_ch.label"),
description=t("Scene.mouth_ch.desc")
)
bpy.types.Scene.shape_intensity = bpy.props.FloatProperty(
name=t("Scene.shape_intensity.label"),
description=t("Scene.shape_intensity.desc"),
default=1.0,
min=0.0,
max=2.0
)
bpy.types.Scene.selected_armature = bpy.props.EnumProperty(
items=get_armatures,
name="Selected Armature",
@@ -55,13 +81,24 @@ def register() -> None:
register_property((Scene, "texture_atlas_Has_Mat_List_Shown", BoolProperty(default=False, get=material_list_bool.get_bool, set=material_list_bool.set_bool)))
def unregister():
def unregister() -> None:
if hasattr(bpy.types.Scene, "avatar_toolkit_language"):
del bpy.types.Scene.avatar_toolkit_language
if hasattr(bpy.types.Scene, "avatar_toolkit_language_changed"):
del bpy.types.Scene.avatar_toolkit_language_changed
if hasattr(bpy.types.Scene, "mouth_a"):
del bpy.types.Scene.mouth_a
if hasattr(bpy.types.Scene, "mouth_o"):
del bpy.types.Scene.mouth_o
if hasattr(bpy.types.Scene, "mouth_ch"):
del bpy.types.Scene.mouth_ch
if hasattr(bpy.types.Scene, "shape_intensity"):
del bpy.types.Scene.shape_intensity
if hasattr(bpy.types.Scene, "selected_armature"):
del bpy.types.Scene.selected_armature