Added part of Texture Atlas UI

-added dynamic list for texture atlas ui
- ui isn't the most intuitive but it will do for now
This commit is contained in:
989onan
2024-07-07 22:36:10 -04:00
parent bfdbac8412
commit 23b4656859
3 changed files with 98 additions and 13 deletions
+2
View File
@@ -7,6 +7,7 @@ if "bpy" not in locals():
from . import functions
from .core import register
from .core.register import __bl_ordered_classes
from .core.properties import register_properties
else:
import importlib
importlib.reload(ui)
@@ -18,6 +19,7 @@ def register():
print("Registering Avatar Toolkit")
# Order the classes before registration
core.register.order_classes()
register_properties()
# Register the UI classes
# Iterate over the classes to register and register them
+24 -12
View File
@@ -1,25 +1,37 @@
from bpy.types import Scene, PropertyGroup, Object, Material, TextureNode
import bpy
from bpy.types import Scene, PropertyGroup, Object, Material, TextureNode, Context
from bpy.props import BoolProperty, EnumProperty, FloatProperty, IntProperty, CollectionProperty, StringProperty, FloatVectorProperty, PointerProperty
from bpy.utils import register_class
def register_properties():
class Material_Texture_Atlas_PropertyGroup(PropertyGroup):
normal: PointerProperty(type=TextureNode)
albedo: PointerProperty(type=TextureNode)
emission: PointerProperty(type=TextureNode)
ambient_occlusion: PointerProperty(type=TextureNode)
height: PointerProperty(type=TextureNode)
#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.name+"_image",(i.image.name if i.image else "node with no image..."),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
register_class(Material_Texture_Atlas_PropertyGroup)
Material.texture_atlas = PointerProperty(type=Material_Texture_Atlas_PropertyGroup)
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)
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)
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)
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)
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)
class Texture_Atlas_PropertyGroup(PropertyGroup):
materials: CollectionProperty(type=Material)
Scene.texture_atlas_material_index = IntProperty()#default=-1, get=(lambda self : -1), set=(lambda self,context : None)
Scene.texture_atlas_properties = PointerProperty(type=Texture_Atlas_PropertyGroup)
#class Texture_Atlas_PropertyGroup(PropertyGroup):
# materials: CollectionProperty(type=Material)
#register_class(Texture_Atlas_PropertyGroup)
#Scene.texture_atlas_properties = PointerProperty(type=Texture_Atlas_PropertyGroup)
+71
View File
@@ -0,0 +1,71 @@
from bpy.types import UIList, Panel, UILayout, Object,Context,MaterialSlot
import bpy
from ..core.register import register_wrap
from .panel import AvatarToolkitPanel
@register_wrap
class MaterialTextureAtlasProperties(UIList):
bl_label = "Texture Atlas Material List Material"
bl_idname = "Material_UL_avatar_toolkit_texture_atlas_mat_list_mat"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw_item(self, context: Context, layout: UILayout, data: bpy.types.Object, item:MaterialSlot, icon, active_data, active_propname, index):
if item.material:
box = layout.box()
col = box.row()
col.label(text="Material: \""+item.material.name+"\"")
if data.active_material_index == index:
col = box.row()
col.prop(item.material, "texture_atlas_albedo")
col = box.row()
col.prop(item.material, "texture_atlas_normal")
col = box.row()
col.prop(item.material, "texture_atlas_emission")
col = box.row()
col.prop(item.material, "texture_atlas_ambient_occlusion")
col = box.row()
col.prop(item.material, "texture_atlas_height")
else:
box = layout.box()
col = box.row()
col.label(text="Empty Material Slot.")
@register_wrap
class MaterialListPanel(UIList):
bl_label = "Texture Atlas Material List"
bl_idname = "Material_UL_avatar_toolkit_texture_atlas_mat_list"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw_item(self, context: Context, layout: UILayout, data, item:Object, icon, active_data, active_propname, index):
custom_icon = "OBJECT_DATAMODE"
box = layout.box()
row = box.row()
row.label(text=item.name, icon = custom_icon)
if context.scene.texture_atlas_material_index == index:
row = box.row()
box = row.box()
box.template_list("Material_UL_avatar_toolkit_texture_atlas_mat_list_mat", "The_Texture_Atlas_List_mat_"+item.name, item, "material_slots", item, "active_material_index")
@register_wrap
class TextureAtlasPanel(Panel):
bl_label = "Texture Atlasing"
bl_idname = "OBJECT_PT_avatar_toolkit_texture_atlas"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Avatar Toolkit"
bl_parent_id = "OBJECT_PT_avatar_toolkit"
def draw(self, context: Context):
layout = self.layout
row = layout.row()
boxoutter = row.box()
row = boxoutter.row()
row.label(text=MaterialListPanel.bl_label)
row = boxoutter.row()
row.template_list("Material_UL_avatar_toolkit_texture_atlas_mat_list", "The_Texture_Atlas_List", context.scene, "objects", context.scene, "texture_atlas_material_index")