Merge branch 'main' into Digitigrade-legs-tool
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import bpy
|
||||
import os
|
||||
import json
|
||||
from bpy.types import AddonPreferences
|
||||
from typing import Any, Dict
|
||||
|
||||
# Get the directory of the current file
|
||||
PREFERENCES_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
PREFERENCES_FILE = os.path.join(PREFERENCES_DIR, "preferences.json")
|
||||
|
||||
def save_preference(key: str, value: Any) -> None:
|
||||
"""Save a single preference to the JSON file."""
|
||||
prefs = load_preferences()
|
||||
prefs[key] = value
|
||||
with open(PREFERENCES_FILE, 'w') as f:
|
||||
json.dump(prefs, f, indent=4)
|
||||
|
||||
def load_preferences() -> Dict[str, Any]:
|
||||
"""Load all preferences from the JSON file."""
|
||||
if os.path.exists(PREFERENCES_FILE):
|
||||
with open(PREFERENCES_FILE, 'r') as f:
|
||||
return json.load(f)
|
||||
return {}
|
||||
|
||||
def get_preference(key: str, default: Any = None) -> Any:
|
||||
"""Get a single preference from the JSON file."""
|
||||
prefs = load_preferences()
|
||||
return prefs.get(key, default)
|
||||
|
||||
class AvatarToolkitPreferences(AddonPreferences):
|
||||
bl_idname = __package__.rsplit('.', 1)[0]
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.label(text="Preferences are managed internally.")
|
||||
# You can add more UI elements here if needed
|
||||
|
||||
def get_addon_preferences(context):
|
||||
return context.preferences.addons[AvatarToolkitPreferences.bl_idname].preferences
|
||||
|
||||
# Initialize preferences if the file doesn't exist
|
||||
if not os.path.exists(PREFERENCES_FILE):
|
||||
save_preference("language", 0) # Set default language to 0 (auto)
|
||||
@@ -5,13 +5,14 @@ from .common import get_armature
|
||||
from bpy.types import Object, ShapeKey, Mesh, Context, Operator
|
||||
from functools import lru_cache
|
||||
from ..core.register import register_wrap
|
||||
from ..functions.translations import t
|
||||
|
||||
|
||||
@register_wrap
|
||||
class ExportResonite(Operator):
|
||||
bl_idname = 'avatar_toolkit.export_resonite'
|
||||
bl_label = "Export to Resonite"
|
||||
bl_description = "Export a GLB with all animations and materials. For animation data see: "
|
||||
bl_label = t("Export.resonite.label")
|
||||
bl_description = t("Export.resonite.desc")
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
filepath: bpy.props.StringProperty()
|
||||
|
||||
|
||||
+14
-86
@@ -1,92 +1,20 @@
|
||||
import bpy
|
||||
from ..functions.translations import t, get_languages_list, update_ui
|
||||
from ..core.register import register_property
|
||||
from typing import Tuple
|
||||
from bpy.types import Scene, PropertyGroup, Object, Material, TextureNode, Context, SceneObjects
|
||||
from bpy.props import BoolProperty, EnumProperty, FloatProperty, IntProperty, CollectionProperty, StringProperty, FloatVectorProperty, PointerProperty
|
||||
from bpy.utils import register_class
|
||||
|
||||
|
||||
class material_list_bool:
|
||||
#For the love that is holy do not ever touch these. If this was java I would make these private
|
||||
#They should only be accessed via context.scene.texture_atlas_Has_Mat_List_Shown
|
||||
#This is so we know if the materials are up to date. messing with these variables directly will make the thing blow up.
|
||||
def register():
|
||||
default_language = get_preference("language", 0)
|
||||
|
||||
#The only exception to this is the ExpandSection_Materials operator which populates this with new data once the materials have changed and need reloading.
|
||||
old_list: dict[str,list[Material]] = {}
|
||||
bool_material_list_expand: dict[str,bool] = {}
|
||||
|
||||
def set_bool(self, value: bool) -> None:
|
||||
material_list_bool.bool_material_list_expand[bpy.context.scene.name] = value
|
||||
if value == False:
|
||||
material_list_bool.old_list[bpy.context.scene.name] = []
|
||||
|
||||
def get_bool(self) -> bool:
|
||||
newlist: list[Material] = []
|
||||
for obj in bpy.context.scene.objects:
|
||||
if len(obj.material_slots)>0:
|
||||
for mat_slot in obj.material_slots:
|
||||
if mat_slot.material:
|
||||
if mat_slot.material not in newlist:
|
||||
newlist.append(mat_slot.material)
|
||||
|
||||
still_the_same: bool = True
|
||||
if bpy.context.scene.name in material_list_bool.old_list:
|
||||
for item in newlist:
|
||||
if item not in material_list_bool.old_list[bpy.context.scene.name]:
|
||||
still_the_same = False
|
||||
break
|
||||
for item in material_list_bool.old_list[bpy.context.scene.name]:
|
||||
if item not in newlist:
|
||||
still_the_same = False
|
||||
break
|
||||
else:
|
||||
still_the_same = False
|
||||
material_list_bool.bool_material_list_expand[bpy.context.scene.name] = still_the_same
|
||||
|
||||
return material_list_bool.bool_material_list_expand[bpy.context.scene.name]
|
||||
|
||||
class SceneMatClass(PropertyGroup):
|
||||
mat: PointerProperty(type=Material)
|
||||
|
||||
def register() -> None:
|
||||
register_property((Scene, "language", bpy.props.EnumProperty(
|
||||
name=t("Settings.language.label"),
|
||||
description=t("Settings.language.desc"),
|
||||
bpy.types.Scene.avatar_toolkit_language = bpy.props.EnumProperty(
|
||||
name=t("Settings.language.label", "Language"),
|
||||
description=t("Settings.language.desc", "Select the language for the addon"),
|
||||
items=get_languages_list,
|
||||
update=update_ui
|
||||
)))
|
||||
default=default_language,
|
||||
update=update_language
|
||||
)
|
||||
|
||||
register_class(SceneMatClass)
|
||||
|
||||
#happy with how compressed this get_texture_node_list method is - @989onan
|
||||
def get_texture_node_list(self: Material, context: Context) -> list[set[3]]:
|
||||
if self.use_nodes:
|
||||
Object.Enum = [((i.image.name if i.image else i.name+"_image"),(i.image.name if i.image else "node with no image..."),(i.image.name if i.image else i.name),index+1) for index,i in enumerate(self.node_tree.nodes) if i.bl_idname == "ShaderNodeTexImage"]
|
||||
if not len(Object.Enum):
|
||||
Object.Enum = [("ERROR", "THIS MATERIAL HAS NO IMAGES!", "ERROR", 0)]
|
||||
else:
|
||||
Object.Enum = [("ERROR", "THIS MATERIAL DOES NOT USE NODES!", "ERROR", 0)]
|
||||
Object.Enum.append(("None", "None", "None", 0))
|
||||
return Object.Enum
|
||||
|
||||
bpy.types.Scene.avatar_toolkit_language_changed = bpy.props.BoolProperty(default=False)
|
||||
def unregister():
|
||||
if hasattr(bpy.types.Scene, "avatar_toolkit_language"):
|
||||
del bpy.types.Scene.avatar_toolkit_language
|
||||
|
||||
|
||||
register_property(Material, "texture_atlas_albedo", EnumProperty(name="Albedo", description="The texture that will be used for the albedo map atlas", default=0, items=get_texture_node_list))
|
||||
register_property(Material, "texture_atlas_normal", EnumProperty(name="Normal", description="The texture that will be used for the normal map atlas", default=0, items=get_texture_node_list))
|
||||
register_property(Material, "texture_atlas_emission", EnumProperty(name="Emission", description="The texture that will be used for the emission map atlas", default=0, items=get_texture_node_list))
|
||||
register_property(Material, "texture_atlas_ambient_occlusion", EnumProperty(name="Ambient Occlusion", description="The texture that will be used for the ambient occlusion map atlas", default=0, items=get_texture_node_list))
|
||||
register_property(Material, "texture_atlas_height", EnumProperty(name="Height", description="The texture that will be used for the height map atlas", default=0, items=get_texture_node_list))
|
||||
register_property(Material, "texture_atlas_roughness", EnumProperty(name="Roughness", description="The texture that will be used for the roughness map atlas", default=0, items=get_texture_node_list))
|
||||
|
||||
register_property(Scene, "texture_atlas_material_index", IntProperty(default=-1, get=(lambda self : -1), set=(lambda self,context : None)))
|
||||
|
||||
|
||||
|
||||
|
||||
register_property(Scene, "materials", CollectionProperty(type=SceneMatClass))
|
||||
|
||||
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() -> None:
|
||||
pass
|
||||
if hasattr(bpy.types.Scene, "avatar_toolkit_language_changed"):
|
||||
del bpy.types.Scene.avatar_toolkit_language_changed
|
||||
|
||||
+6
-3
@@ -1,5 +1,6 @@
|
||||
import bpy
|
||||
import typing
|
||||
from typing import List, Type
|
||||
|
||||
# List to store the classes to register
|
||||
__bl_classes = []
|
||||
@@ -21,8 +22,11 @@ def register_property(prop):
|
||||
|
||||
def register_properties():
|
||||
for prop in __bl_props:
|
||||
setattr(prop[0], prop[1], prop[2])
|
||||
|
||||
if isinstance(prop[2], bpy.props._PropertyDeferred):
|
||||
setattr(prop[0], prop[1], prop[2])
|
||||
else:
|
||||
prop()
|
||||
|
||||
def unregister_properties():
|
||||
for prop in reversed(__bl_props):
|
||||
delattr(prop[0], prop[1])
|
||||
@@ -109,4 +113,3 @@ def toposort(deps_dict):
|
||||
deps_dict = {value : deps_dict[value] - sorted_values for value in unsorted}
|
||||
|
||||
return sorted_list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user