refactored type init

This commit is contained in:
Michel Fedde 2024-01-30 20:28:36 +01:00
parent 060612d789
commit c0ab4bb7ad
7 changed files with 66 additions and 58 deletions

View file

@ -3,7 +3,8 @@ import math
import bpy
from .. types import (get_source, get_target)
from .. types.sources import get_source
from .. types.targets import get_target
class BakeToIDMapOperator(bpy.types.Operator):

View file

@ -1,7 +1,6 @@
import bpy
from .. operators.bake_to_id_map import BakeToIDMapOperator
from ..types import get_source
from .. types.sources import get_source
class BakeToIDInfoPanel(bpy.types.Panel):

View file

@ -2,7 +2,8 @@ import textwrap
import bpy
from src.types import get_source, get_target
from .. types.sources import get_source
from .. types.targets import get_target
class BakeToIDOptionsPanel(bpy.types.Panel):
@ -22,6 +23,8 @@ class BakeToIDOptionsPanel(bpy.types.Panel):
layout.prop(props, "source")
source = get_source(props.source)
if len(source.connected_properties) > 0:
source_settings_box = layout.box()
for setting in source.connected_properties:
source_settings_box.prop(props, setting)
@ -30,6 +33,7 @@ class BakeToIDOptionsPanel(bpy.types.Panel):
layout.prop(props, "target")
target = get_target(props.target)
if len(target.connected_properties) > 0:
target_settings_box = layout.box()
for setting in target.connected_properties:
target_settings_box.prop(props, setting)

View file

@ -1,7 +1,8 @@
from bpy.types import (PropertyGroup)
from bpy.props import (EnumProperty, BoolProperty, IntProperty, StringProperty)
from src.types import get_source_enum, get_targets_enum
from src.types.sources import get_source_enum
from src.types.targets import get_targets_enum
class BakeToIDProperties(PropertyGroup):
@ -21,8 +22,8 @@ class BakeToIDProperties(PropertyGroup):
name="Source",
description="From where should the IDs be taken",
default="MATERIAL_INDEX"
)
target: EnumProperty(
items=get_targets_enum(),
name="Target",
@ -30,7 +31,7 @@ class BakeToIDProperties(PropertyGroup):
default=get_targets_enum()[0][0]
)
source_materials_remove_all : BoolProperty(
source_materials_remove_all: BoolProperty(
name="Remove all source materials",
default=False,
description="Removes every material except the first one."

View file

@ -1,45 +0,0 @@
from . sources import material_index as source_mat_index
from . sources import object as source_object
from . targets import vertex_colors as target_vertex_colors
_sources = [
source_mat_index,
source_object
]
_targets = [
target_vertex_colors
]
def get_source(id):
for source in _sources:
if source.source_id == id:
return source
raise Exception("Source not found: " + id)
def get_target(id):
for target in _targets:
if target.target_id == id:
return target
raise Exception("Target not found: " + id)
def get_source_enum():
enumList = []
i = 0
for source in _sources:
enumList.append((source.source_id, source.name, source.description, i))
i += 1
return enumList
def get_targets_enum():
enumList = []
i = 0
for target in _targets:
enumList.append((target.target_id, target.name, target.description, i))
i += 1
return enumList

View file

@ -0,0 +1,25 @@
from . import material_index
from . import object
_sources = [
material_index,
object
]
def get_source(id):
for source in _sources:
if source.source_id == id:
return source
raise Exception("Source not found: " + id)
def get_source_enum():
enum_list = []
i = 0
for source in _sources:
enum_list.append((source.source_id, source.name, source.description, i))
i += 1
return enum_list

View file

@ -0,0 +1,23 @@
from . import vertex_colors
_targets = [
vertex_colors
]
def get_target(id):
for target in _targets:
if target.target_id == id:
return target
raise Exception("Target not found: " + id)
def get_targets_enum():
enum_list = []
i = 0
for target in _targets:
enum_list.append((target.target_id, target.name, target.description, i))
i += 1
return enum_list