refactor BlenderEnumPropHelper

This commit is contained in:
yyc12345 2023-12-15 21:57:50 +08:00
parent 52f3936e42
commit a6de69c882
10 changed files with 401 additions and 395 deletions

View File

@ -94,7 +94,12 @@ def _check_component_existance(comp_type: PROP_ballance_element.BallanceElementT
if expect_name in bpy.data.objects: return expect_name
else: return None
def _general_create_component(comp_type: PROP_ballance_element.BallanceElementType, comp_sector: int, comp_count: int, comp_offset: typing.Callable[[int], mathutils.Matrix]) -> None:
def _general_create_component(
comp_type: PROP_ballance_element.BallanceElementType,
comp_sector: int,
comp_count: int,
comp_offset: typing.Callable[[int], mathutils.Matrix]
) -> None:
"""
General component creation function.
@ -122,39 +127,23 @@ def _general_create_component(comp_type: PROP_ballance_element.BallanceElementTy
# move with extra offset by calling offset getter
obj.matrix_world = obj.matrix_world @ comp_offset(i)
class EnumPropHelper():
"""
Generate component types for this module's operator
"""
@staticmethod
def generate_items() -> tuple[tuple, ...]:
# token, display name, descriptions, icon, index
return tuple(
(
str(item.value),
item.name,
"",
UTIL_icons_manager.get_component_icon(PROP_ballance_element.get_ballance_element_name(item)),
item.value
) for item in PROP_ballance_element.BallanceElementType
)
@staticmethod
def get_selection(prop: str) -> PROP_ballance_element.BallanceElementType:
# prop will return identifier which is defined as the string type of int value.
# so we parse it to int and then parse it to enum type.
return PROP_ballance_element.BallanceElementType(int(prop))
@staticmethod
def to_selection(val: PROP_ballance_element.BallanceElementType) -> str:
# like get_selection, we need get it int value, then convert it to string as the indetifier of enum props
# them enum property will accept it.
return str(val.value)
#endregion
#region Noemal Component Adder
# element enum prop helper
def _get_component_icon_by_name(elename: str):
icon: int | None = UTIL_icons_manager.get_component_icon(elename)
if icon is None: return UTIL_icons_manager.get_empty_icon()
else: return icon
_g_EnumHelper_Component: UTIL_functions.EnumPropHelper = UTIL_functions.EnumPropHelper(
PROP_ballance_element.BallanceElementType,
lambda x: x.name,
lambda x: '',
lambda x: _get_component_icon_by_name(PROP_ballance_element.get_ballance_element_name(x)),
)
class BBP_OT_add_component(bpy.types.Operator, ComponentSectorParam):
"""Add Component"""
bl_idname = "bbp.add_component"
@ -164,7 +153,7 @@ class BBP_OT_add_component(bpy.types.Operator, ComponentSectorParam):
component_type: bpy.props.EnumProperty(
name = "Type",
description = "This component type",
items = EnumPropHelper.generate_items(),
items = _g_EnumHelper_Component.generate_items(),
)
def invoke(self, context, event):
@ -177,35 +166,35 @@ class BBP_OT_add_component(bpy.types.Operator, ComponentSectorParam):
layout.prop(self, "component_type")
# only show sector for non-PE/PS component
eletype: PROP_ballance_element.BallanceElementType = EnumPropHelper.get_selection(self.component_type)
eletype: PROP_ballance_element.BallanceElementType = _g_EnumHelper_Component.get_selection(self.component_type)
if eletype != PROP_ballance_element.BallanceElementType.PS_FourFlames and eletype != PROP_ballance_element.BallanceElementType.PE_Balloon:
self.draw_component_sector_params(layout)
# check for some special components and show warning
elename: str | None = _check_component_existance(EnumPropHelper.get_selection(self.component_type), self.general_get_component_sector())
elename: str | None = _check_component_existance(_g_EnumHelper_Component.get_selection(self.component_type), self.general_get_component_sector())
if elename is not None:
layout.label(text = f'Warning: {elename} already exist.')
def execute(self, context):
# call general creator
_general_create_component(
EnumPropHelper.get_selection(self.component_type),
_g_EnumHelper_Component.get_selection(self.component_type),
self.general_get_component_sector(),
1, # only create one
lambda _: mathutils.Matrix.Identity(4)
)
return {'FINISHED'}
@classmethod
def draw_blc_menu(self, layout: bpy.types.UILayout):
@staticmethod
def draw_blc_menu(layout: bpy.types.UILayout):
for item in PROP_ballance_element.BallanceElementType:
item_name: str = PROP_ballance_element.get_ballance_element_name(item)
cop = layout.operator(
self.bl_idname, text = item_name,
BBP_OT_add_component.bl_idname, text = item_name,
icon_value = UTIL_icons_manager.get_component_icon(item_name)
)
cop.component_type = EnumPropHelper.to_selection(item)
cop.component_type = _g_EnumHelper_Component.to_selection(item)
#endregion
@ -235,8 +224,8 @@ class BBP_OT_add_nong_extra_point(bpy.types.Operator, ComponentSectorParam, Comp
)
return {'FINISHED'}
@classmethod
def draw_blc_menu(self, layout: bpy.types.UILayout):
@staticmethod
def draw_blc_menu(layout: bpy.types.UILayout):
layout.operator(
BBP_OT_add_nong_extra_point.bl_idname,
icon_value = UTIL_icons_manager.get_component_icon(
@ -282,8 +271,8 @@ class BBP_OT_add_tilting_block_series(bpy.types.Operator, ComponentSectorParam,
return {'FINISHED'}
@classmethod
def draw_blc_menu(self, layout: bpy.types.UILayout):
@staticmethod
def draw_blc_menu(layout: bpy.types.UILayout):
layout.operator(
BBP_OT_add_tilting_block_series.bl_idname,
icon_value = UTIL_icons_manager.get_component_icon(
@ -326,8 +315,8 @@ class BBP_OT_add_ventilator_series(bpy.types.Operator, ComponentSectorParam, Com
return {'FINISHED'}
@classmethod
def draw_blc_menu(self, layout: bpy.types.UILayout):
@staticmethod
def draw_blc_menu(layout: bpy.types.UILayout):
layout.operator(
BBP_OT_add_ventilator_series.bl_idname,
icon_value = UTIL_icons_manager.get_component_icon(
@ -407,8 +396,8 @@ class BBP_OT_add_sector_component_pair(bpy.types.Operator, ComponentSectorParam)
return {'FINISHED'}
@classmethod
def draw_blc_menu(self, layout: bpy.types.UILayout):
@staticmethod
def draw_blc_menu(layout: bpy.types.UILayout):
layout.operator(
BBP_OT_add_sector_component_pair.bl_idname,
icon_value = UTIL_icons_manager.get_component_icon(

View File

@ -6,6 +6,9 @@ from . import UTIL_virtools_types, UTIL_functions, UTIL_file_browser, UTIL_blend
from . import PROP_virtools_group, PROP_virtools_material, PROP_virtools_mesh, PROP_virtools_texture
from .PyBMap import bmap_wrapper as bmap
# define global tex save opt blender enum prop helper
_g_EnumHelper_CK_TEXTURE_SAVEOPTIONS: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS)
class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtoolsFile, UTIL_ioport_shared.ExportParams, UTIL_ioport_shared.VirtoolsParams):
"""Export Virtools File"""
bl_idname = "bbp.export_virtools"
@ -15,11 +18,8 @@ class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtool
texture_save_opt: bpy.props.EnumProperty(
name = "Global Texture Save Options",
description = "Decide how texture saved if texture is specified as Use Global as its Save Options.",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS,
UTIL_virtools_types.g_Annotation_CK_TEXTURE_SAVEOPTIONS
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL)
items = _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.generate_items(),
default = _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.to_selection(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL)
)
use_compress: bpy.props.BoolProperty(
@ -56,7 +56,7 @@ class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtool
_export_virtools(
self.general_get_filename(),
self.general_get_vt_encodings(),
UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS, self.texture_save_opt),
_g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.get_selection(self.texture_save_opt),
self.use_compress,
self.compress_level,
objls

View File

@ -238,6 +238,13 @@ def _get_group_icon_by_name(gp_name: str) -> int:
value = UTIL_icons_manager.get_component_icon(gp_name)
if value is not None: return value
else: return UTIL_icons_manager.get_empty_icon()
# blender group name prop helper
_g_EnumHelper_Group: UTIL_functions.EnumPropHelper = UTIL_functions.EnumPropHelper(
VirtoolsGroupsPreset,
lambda x: x.value,
lambda _: '',
lambda x: _get_group_icon_by_name(x.value)
)
class SharedGroupNameInputProperties():
group_name_source: bpy.props.EnumProperty(
@ -249,12 +256,9 @@ class SharedGroupNameInputProperties():
)
preset_group_name: bpy.props.EnumProperty(
name="Group Name",
description="Pick vanilla Ballance group name.",
items=tuple(
# token, display name, descriptions, icon, index
(str(idx), grp, "", _get_group_icon_by_name(grp), idx) for idx, grp in enumerate(_g_VtGrpPresetValues)
),
name = "Group Name",
description = "Pick vanilla Ballance group name.",
items = _g_EnumHelper_Group.generate_items(),
)
custom_group_name: bpy.props.StringProperty(
@ -274,7 +278,7 @@ class SharedGroupNameInputProperties():
if self.group_name_source == 'CUSTOM':
return self.custom_group_name
else:
return _g_VtGrpPresetValues[int(self.preset_group_name)]
return _g_EnumHelper_Group.get_selection(self.preset_group_name).value
#endregion

View File

@ -112,6 +112,18 @@ class RawVirtoolsMaterial():
# specular power
self.mSpecularPower = UTIL_functions.clamp_float(self.mSpecularPower, 0.0, 100.0)
#region Blender Enum Prop Helper (Virtools type specified)
_g_Helper_VXTEXTURE_BLENDMODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXTEXTURE_BLENDMODE)
_g_Helper_VXTEXTURE_FILTERMODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXTEXTURE_FILTERMODE)
_g_Helper_VXTEXTURE_ADDRESSMODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXTEXTURE_ADDRESSMODE)
_g_Helper_VXBLEND_MODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXBLEND_MODE)
_g_Helper_VXFILL_MODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXFILL_MODE)
_g_Helper_VXSHADE_MODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXSHADE_MODE)
_g_Helper_VXCMPFUNC: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXCMPFUNC)
#endregion
class BBP_PG_virtools_material(bpy.types.PropertyGroup):
ambient: bpy.props.FloatVectorProperty(
name = "Ambient",
@ -180,81 +192,57 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
texture_blend_mode: bpy.props.EnumProperty(
name = "Texture Blend",
description = "Texture blend mode",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_BLENDMODE,
UTIL_virtools_types.g_Annotation_VXTEXTURE_BLENDMODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureBlendMode)
items = _g_Helper_VXTEXTURE_BLENDMODE.generate_items(),
default = _g_Helper_VXTEXTURE_BLENDMODE.to_selection(RawVirtoolsMaterial.cDefaultTextureBlendMode)
)
texture_min_mode: bpy.props.EnumProperty(
name = "Filter Min",
description = "Texture filter mode when the texture is minified",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_FILTERMODE,
UTIL_virtools_types.g_Annotation_VXTEXTURE_FILTERMODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureMinMode)
items = _g_Helper_VXTEXTURE_FILTERMODE.generate_items(),
default = _g_Helper_VXTEXTURE_FILTERMODE.to_selection(RawVirtoolsMaterial.cDefaultTextureMinMode)
)
texture_mag_mode: bpy.props.EnumProperty(
name = "Filter Mag",
description = "Texture filter mode when the texture is magnified",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_FILTERMODE,
UTIL_virtools_types.g_Annotation_VXTEXTURE_FILTERMODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureMagMode)
items = _g_Helper_VXTEXTURE_FILTERMODE.generate_items(),
default = _g_Helper_VXTEXTURE_FILTERMODE.to_selection(RawVirtoolsMaterial.cDefaultTextureMagMode)
)
texture_address_mode: bpy.props.EnumProperty(
name = "Address Mode",
description = "The address mode controls how the texture coordinates outside the range 0..1",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE,
UTIL_virtools_types.g_Annotation_VXTEXTURE_ADDRESSMODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureAddressMode)
items = _g_Helper_VXTEXTURE_ADDRESSMODE.generate_items(),
default = _g_Helper_VXTEXTURE_ADDRESSMODE.to_selection(RawVirtoolsMaterial.cDefaultTextureAddressMode)
)
source_blend: bpy.props.EnumProperty(
name = "Source Blend",
description = "Source blend factor",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXBLEND_MODE,
UTIL_virtools_types.g_Annotation_VXBLEND_MODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultSourceBlend)
items = _g_Helper_VXBLEND_MODE.generate_items(),
default = _g_Helper_VXBLEND_MODE.to_selection(RawVirtoolsMaterial.cDefaultSourceBlend)
)
dest_blend: bpy.props.EnumProperty(
name = "Destination Blend",
description = "Destination blend factor",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXBLEND_MODE,
UTIL_virtools_types.g_Annotation_VXBLEND_MODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultDestBlend)
items = _g_Helper_VXBLEND_MODE.generate_items(),
default = _g_Helper_VXBLEND_MODE.to_selection(RawVirtoolsMaterial.cDefaultDestBlend)
)
fill_mode: bpy.props.EnumProperty(
name = "Fill Mode",
description = "Fill mode",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXFILL_MODE,
UTIL_virtools_types.g_Annotation_VXFILL_MODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultFillMode)
items = _g_Helper_VXFILL_MODE.generate_items(),
default = _g_Helper_VXFILL_MODE.to_selection(RawVirtoolsMaterial.cDefaultFillMode)
)
shade_mode: bpy.props.EnumProperty(
name = "Shade Mode",
description = "Shade mode",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXSHADE_MODE,
UTIL_virtools_types.g_Annotation_VXSHADE_MODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultShadeMode)
items = _g_Helper_VXSHADE_MODE.generate_items(),
default = _g_Helper_VXSHADE_MODE.to_selection(RawVirtoolsMaterial.cDefaultShadeMode)
)
enable_alpha_test: bpy.props.BoolProperty(
@ -294,21 +282,15 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
alpha_func: bpy.props.EnumProperty(
name = "Alpha Test Function",
description = "Alpha comparision function",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXCMPFUNC,
UTIL_virtools_types.g_Annotation_VXCMPFUNC
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultAlphaFunc)
items = _g_Helper_VXCMPFUNC.generate_items(),
default = _g_Helper_VXCMPFUNC.to_selection(RawVirtoolsMaterial.cDefaultAlphaFunc)
)
z_func: bpy.props.EnumProperty(
name = "Z Compare Function",
description = "Z Comparison function",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXCMPFUNC,
UTIL_virtools_types.g_Annotation_VXCMPFUNC
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultZFunc)
items = _g_Helper_VXCMPFUNC.generate_items(),
default = _g_Helper_VXCMPFUNC.to_selection(RawVirtoolsMaterial.cDefaultZFunc)
)
#region Getter Setter
@ -329,15 +311,15 @@ def get_raw_virtools_material(mtl: bpy.types.Material) -> RawVirtoolsMaterial:
rawdata.mTexture = props.texture
rawdata.mTextureBorderColor.from_const_rgba(props.texture_border_color)
rawdata.mTextureBlendMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXTEXTURE_BLENDMODE, props.texture_blend_mode)
rawdata.mTextureMinMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXTEXTURE_FILTERMODE, props.texture_min_mode)
rawdata.mTextureMagMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXTEXTURE_FILTERMODE, props.texture_mag_mode)
rawdata.mTextureAddressMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXTEXTURE_ADDRESSMODE, props.texture_address_mode)
rawdata.mTextureBlendMode = _g_Helper_VXTEXTURE_BLENDMODE.get_selection(props.texture_blend_mode)
rawdata.mTextureMinMode = _g_Helper_VXTEXTURE_FILTERMODE.get_selection(props.texture_min_mode)
rawdata.mTextureMagMode = _g_Helper_VXTEXTURE_FILTERMODE.get_selection(props.texture_mag_mode)
rawdata.mTextureAddressMode = _g_Helper_VXTEXTURE_ADDRESSMODE.get_selection(props.texture_address_mode)
rawdata.mSourceBlend = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXBLEND_MODE, props.source_blend)
rawdata.mDestBlend = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXBLEND_MODE, props.dest_blend)
rawdata.mFillMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXFILL_MODE, props.fill_mode)
rawdata.mShadeMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXSHADE_MODE, props.shade_mode)
rawdata.mSourceBlend = _g_Helper_VXBLEND_MODE.get_selection(props.source_blend)
rawdata.mDestBlend = _g_Helper_VXBLEND_MODE.get_selection(props.dest_blend)
rawdata.mFillMode = _g_Helper_VXFILL_MODE.get_selection(props.fill_mode)
rawdata.mShadeMode = _g_Helper_VXSHADE_MODE.get_selection(props.shade_mode)
rawdata.mEnableAlphaTest = props.enable_alpha_test
rawdata.mEnableAlphaBlend = props.enable_alpha_blend
@ -346,8 +328,8 @@ def get_raw_virtools_material(mtl: bpy.types.Material) -> RawVirtoolsMaterial:
rawdata.mEnableTwoSided = props.enable_two_sided
rawdata.mAlphaRef = props.alpha_ref
rawdata.mAlphaFunc = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXCMPFUNC, props.alpha_func)
rawdata.mZFunc = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXCMPFUNC, props.z_func)
rawdata.mAlphaFunc = _g_Helper_VXCMPFUNC.get_selection(props.alpha_func)
rawdata.mZFunc = _g_Helper_VXCMPFUNC.get_selection(props.z_func)
rawdata.regulate()
return rawdata
@ -364,15 +346,15 @@ def set_raw_virtools_material(mtl: bpy.types.Material, rawdata: RawVirtoolsMater
props.texture = rawdata.mTexture
props.texture_border_color = rawdata.mTextureBorderColor.to_const_rgba()
props.texture_blend_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mTextureBlendMode)
props.texture_min_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mTextureMinMode)
props.texture_mag_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mTextureMagMode)
props.texture_address_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mTextureAddressMode)
props.texture_blend_mode = _g_Helper_VXTEXTURE_BLENDMODE.to_selection(rawdata.mTextureBlendMode)
props.texture_min_mode = _g_Helper_VXTEXTURE_FILTERMODE.to_selection(rawdata.mTextureMinMode)
props.texture_mag_mode = _g_Helper_VXTEXTURE_FILTERMODE.to_selection(rawdata.mTextureMagMode)
props.texture_address_mode = _g_Helper_VXTEXTURE_ADDRESSMODE.to_selection(rawdata.mTextureAddressMode)
props.source_blend = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mSourceBlend)
props.dest_blend = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mDestBlend)
props.fill_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mFillMode)
props.shade_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mShadeMode)
props.source_blend = _g_Helper_VXBLEND_MODE.to_selection(rawdata.mSourceBlend)
props.dest_blend = _g_Helper_VXBLEND_MODE.to_selection(rawdata.mDestBlend)
props.fill_mode = _g_Helper_VXFILL_MODE.to_selection(rawdata.mFillMode)
props.shade_mode = _g_Helper_VXSHADE_MODE.to_selection(rawdata.mShadeMode)
props.enable_alpha_test = rawdata.mEnableAlphaTest
props.enable_alpha_blend = rawdata.mEnableAlphaBlend
@ -381,8 +363,8 @@ def set_raw_virtools_material(mtl: bpy.types.Material, rawdata: RawVirtoolsMater
props.enable_two_sided = rawdata.mEnableTwoSided
props.alpha_ref = rawdata.mAlphaRef
props.alpha_func = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mAlphaFunc)
props.z_func = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mZFunc)
props.alpha_func = _g_Helper_VXCMPFUNC.to_selection(rawdata.mAlphaFunc)
props.z_func = _g_Helper_VXCMPFUNC.to_selection(rawdata.mZFunc)
def apply_to_blender_material(mtl: bpy.types.Material):
# get raw material data
@ -536,37 +518,13 @@ def preset_virtools_material(mtl: bpy.types.Material, preset_type: MaterialPrese
preset_data: MaterialPresetData = _g_MaterialPresets[preset_type]
set_raw_virtools_material(mtl, preset_data.mData)
class _MtlPresetEnumPropHelper():
"""
Operate like UTIL_virtools_types.EnumPropHelper
"""
@staticmethod
def __get_name(v: MaterialPresetType) -> str:
entry: MaterialPresetData | None = _g_MaterialPresets.get(v, None)
if entry: return entry.mDisplayName
else: return ""
@staticmethod
def generate_items() -> tuple[tuple, ...]:
# token, display name, descriptions, icon, index
return tuple(
(
str(member.value),
_MtlPresetEnumPropHelper.__get_name(member),
"",
"",
member.value
) for member in MaterialPresetType
)
@staticmethod
def get_selection(prop: str) -> MaterialPresetType:
return MaterialPresetType(int(prop))
@staticmethod
def to_selection(val: MaterialPresetType) -> str:
return str(val.value)
# create preset enum blender helper
_g_Helper_MtlPreset: UTIL_functions.EnumPropHelper = UTIL_functions.EnumPropHelper(
MaterialPresetType,
lambda x: x.name,
lambda _: '',
lambda _: ''
)
#endregion
@ -596,7 +554,7 @@ class BBP_OT_preset_virtools_material(bpy.types.Operator):
preset_type: bpy.props.EnumProperty(
name = "Preset",
description = "The preset which you want to apply.",
items = _MtlPresetEnumPropHelper.generate_items(),
items = _g_Helper_MtlPreset.generate_items(),
)
@classmethod
@ -613,7 +571,7 @@ class BBP_OT_preset_virtools_material(bpy.types.Operator):
def execute(self, context):
# get essential value
mtl: bpy.types.Material = context.material
expected_preset: MaterialPresetType = _MtlPresetEnumPropHelper.get_selection(self.preset_type)
expected_preset: MaterialPresetType = _g_Helper_MtlPreset.get_selection(self.preset_type)
# apply preset to material
preset_virtools_material(mtl, expected_preset)

View File

@ -14,17 +14,17 @@ class RawVirtoolsMesh():
# assign default value for each component
self.mLitMode = kwargs.get('mLitMode', RawVirtoolsMesh.cDefaultLitMode)
# blender enum prop helper defines
_g_Helper_VXMESH_LITMODE: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VXMESH_LITMODE)
# Blender Property Group
class BBP_PG_virtools_mesh(bpy.types.PropertyGroup):
lit_mode: bpy.props.EnumProperty(
name = "Lit Mode",
description = "Lighting mode of the mesh.",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXMESH_LITMODE,
UTIL_virtools_types.g_Annotation_VXMESH_LITMODE
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMesh.cDefaultLitMode)
items = _g_Helper_VXMESH_LITMODE.generate_items(),
default = _g_Helper_VXMESH_LITMODE.to_selection(RawVirtoolsMesh.cDefaultLitMode)
)
# Getter Setter
@ -36,14 +36,14 @@ def get_raw_virtools_mesh(mesh: bpy.types.Mesh) -> RawVirtoolsMesh:
props: BBP_PG_virtools_mesh = get_virtools_mesh(mesh)
rawdata: RawVirtoolsMesh = RawVirtoolsMesh()
rawdata.mLitMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXMESH_LITMODE, props.lit_mode)
rawdata.mLitMode = _g_Helper_VXMESH_LITMODE.get_selection(props.lit_mode)
return rawdata
def set_raw_virtools_mesh(mesh: bpy.types.Mesh, rawdata: RawVirtoolsMesh) -> None:
props: BBP_PG_virtools_mesh = get_virtools_mesh(mesh)
props.lit_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mLitMode)
props.lit_mode = _g_Helper_VXMESH_LITMODE.to_selection(rawdata.mLitMode)
# Display Panel

View File

@ -19,26 +19,24 @@ class RawVirtoolsTexture():
self.mSaveOptions = kwargs.get('mSaveOptions', RawVirtoolsTexture.cDefaultSaveOptions)
self.mVideoFormat = kwargs.get('mVideoFormat', RawVirtoolsTexture.cDefaultVideoFormat)
# blender enum prop helper defines
_g_Helper_CK_TEXTURE_SAVEOPTIONS: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS)
_g_Helper_VX_PIXELFORMAT: UTIL_virtools_types.EnumPropHelper = UTIL_virtools_types.EnumPropHelper(UTIL_virtools_types.VX_PIXELFORMAT)
class BBP_PG_virtools_texture(bpy.types.PropertyGroup):
save_options: bpy.props.EnumProperty(
name = "Save Options",
description = "When saving a composition textures or sprites can be kept as reference to external files or converted to a given format and saved inside the composition file.",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS,
UTIL_virtools_types.g_Annotation_CK_TEXTURE_SAVEOPTIONS
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsTexture.cDefaultSaveOptions)
items = _g_Helper_CK_TEXTURE_SAVEOPTIONS.generate_items(),
default = _g_Helper_CK_TEXTURE_SAVEOPTIONS.to_selection(RawVirtoolsTexture.cDefaultSaveOptions)
)
video_format: bpy.props.EnumProperty(
name = "Video Format",
description = "The desired surface pixel format in video memory.",
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VX_PIXELFORMAT,
UTIL_virtools_types.g_Annotation_VX_PIXELFORMAT
),
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsTexture.cDefaultVideoFormat)
items = _g_Helper_VX_PIXELFORMAT.generate_items(),
default = _g_Helper_VX_PIXELFORMAT.to_selection(RawVirtoolsTexture.cDefaultVideoFormat)
)
#region Virtools Texture Getter Setter
@ -50,15 +48,15 @@ def get_raw_virtools_texture(img: bpy.types.Image) -> RawVirtoolsTexture:
props: BBP_PG_virtools_texture = get_virtools_texture(img)
rawdata: RawVirtoolsTexture = RawVirtoolsTexture()
rawdata.mSaveOptions = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS, props.save_options)
rawdata.mVideoFormat = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VX_PIXELFORMAT, props.video_format)
rawdata.mSaveOptions = _g_Helper_CK_TEXTURE_SAVEOPTIONS.get_selection(props.save_options)
rawdata.mVideoFormat = _g_Helper_VX_PIXELFORMAT.get_selection(props.video_format)
return rawdata
def set_raw_virtools_texture(img: bpy.types.Image, rawdata: RawVirtoolsTexture) -> None:
props: BBP_PG_virtools_texture = get_virtools_texture(img)
props.save_options = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mSaveOptions)
props.video_format = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mVideoFormat)
props.save_options = _g_Helper_CK_TEXTURE_SAVEOPTIONS.to_selection(rawdata.mSaveOptions)
props.video_format = _g_Helper_VX_PIXELFORMAT.to_selection(rawdata.mVideoFormat)
#endregion

View File

@ -188,7 +188,7 @@ class VX_PIXELFORMAT(enum.IntEnum):
"""!
Pixel format types.
"""
UNKNOWN_PF = 0 ##< Unknown pixel format
#UNKNOWN_PF = 0 ##< Unknown pixel format
_32_ARGB8888 = 1 ##< 32-bit ARGB pixel format with alpha
_32_RGB888 = 2 ##< 32-bit RGB pixel format without alpha
_24_RGB888 = 3 ##< 24-bit RGB pixel format

View File

@ -67,3 +67,94 @@ def add_into_scene_and_move_to_cursor(obj: bpy.types.Object):
collection.objects.link(obj)
move_to_cursor(obj)
class EnumPropHelper():
"""
These class contain all functions related to EnumProperty creation for Python Enums
"""
# define some type hint
_TEnumVar = typing.TypeVar('_TEnumVar', bound = enum.Enum) ##< Mean a variable of enum.Enum's children
_TEnum = type[_TEnumVar] ##< Mean the type self which is enum.Enum's children.
_TFctName = typing.Callable[[_TEnumVar], str]
_TFctDesc = typing.Callable[[_TEnumVar], str]
_TFctIcon = typing.Callable[[_TEnumVar], str | int]
# define class member
__mTy: _TEnum
__mIsIntEnum: bool
__mFctName: _TFctName
__mFctDesc: _TFctDesc
__mFctIcon: _TFctIcon
def __init__(
self,
ty: _TEnum,
fct_name: _TFctName,
fct_desc: _TFctDesc,
fct_icon: _TFctIcon):
# check type
if not issubclass(ty, enum.Enum):
raise BBPException('invalid type for EnumPropHelper')
# assign member
self.__mTy = ty
self.__mIsIntEnum = issubclass(ty, enum.IntEnum)
self.__mFctName = fct_name
self.__mFctDesc = fct_desc
self.__mFctIcon = fct_icon
def generate_items(self) -> tuple[tuple[str, str, str, int | str, int], ...]:
"""
Generate a tuple which can be applied to Blender EnumProperty's "items".
"""
# blender enum prop item format:
# (token, display name, descriptions, icon, index)
if self.__mIsIntEnum:
# for intenum, we can use its value as index number directly.
# and use the string format of index as blender prop token.
return tuple(
(
str(member.value),
self.__mFctName(member),
self.__mFctDesc(member),
self.__mFctIcon(member),
member.value
) for member in self.__mTy
)
else:
# for non-intenum, we need create number index manually for it.
# and directly use its value as blender prop token
return tuple(
(
member.value,
self.__mFctName(member),
self.__mFctDesc(member),
self.__mFctIcon(member),
idx
) for idx, member in enumerate(self.__mTy)
)
def get_selection(self, prop: str) -> _TEnumVar:
"""
Return Python enum value from given Blender EnumProp.
"""
# for intenum, param is its string format, we need use int() to convert it first
# for non-intenum, param is just its value, we use it directly
# then we parse it to python enum type
if self.__mIsIntEnum:
return self.__mTy(int(prop))
else:
return self.__mTy(prop)
def to_selection(self, val: _TEnumVar) -> str:
"""
Parse Python enum value to Blender EnumProp acceptable string.
"""
# the inversed operation of get_selection().
if self.__mIsIntEnum:
return str(val.value)
else:
return val.value

View File

@ -187,43 +187,43 @@ class BallanceObjectInfo():
#region Naming Convention Declaration
_g_BlcNormalComponents: set[str] = set((
PROP_virtools_group.VirtoolsGroupsPreset.P_Extra_Life.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Extra_Point.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Trafo_Paper.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Trafo_Stone.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Trafo_Wood.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Ball_Paper.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Ball_Stone.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Ball_Wood.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Box.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Dome.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_01.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_03.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_08.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_17.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_18.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_19.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_25.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_26.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_29.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_30.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_34.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_37.value,
PROP_virtools_group.VirtoolsGroupsPreset.P_Modul_41.value,
"P_Extra_Life",
"P_Extra_Point",
"P_Trafo_Paper",
"P_Trafo_Stone",
"P_Trafo_Wood",
"P_Ball_Paper",
"P_Ball_Stone",
"P_Ball_Wood",
"P_Box",
"P_Dome",
"P_Modul_01",
"P_Modul_03",
"P_Modul_08",
"P_Modul_17",
"P_Modul_18",
"P_Modul_19",
"P_Modul_25",
"P_Modul_26",
"P_Modul_29",
"P_Modul_30",
"P_Modul_34",
"P_Modul_37",
"P_Modul_41"
))
_g_BlcUniqueComponents: set[str] = set((
PROP_virtools_group.VirtoolsGroupsPreset.PS_Levelstart.value,
PROP_virtools_group.VirtoolsGroupsPreset.PE_Levelende.value,
PROP_virtools_group.VirtoolsGroupsPreset.PC_Checkpoints.value,
PROP_virtools_group.VirtoolsGroupsPreset.PR_Resetpoints.value,
"PS_Levelstart",
"PE_Levelende",
"PC_Checkpoints",
"PR_Resetpoints"
))
_g_BlcFloor: set[str] = set((
PROP_virtools_group.VirtoolsGroupsPreset.Sound_HitID_01.value,
PROP_virtools_group.VirtoolsGroupsPreset.Sound_RollID_01.value,
"Sound_HitID_01",
"Sound_RollID_01"
))
_g_BlcWood: set[str] = set((
PROP_virtools_group.VirtoolsGroupsPreset.Sound_HitID_02.value,
PROP_virtools_group.VirtoolsGroupsPreset.Sound_RollID_02.value,
"Sound_HitID_02",
"Sound_RollID_02"
))
class VirtoolsGroupConvention():
@ -277,11 +277,11 @@ class VirtoolsGroupConvention():
if len(inter_gps) == 1:
# get it
match((tuple(inter_gps))[0]):
case PROP_virtools_group.VirtoolsGroupsPreset.PS_Levelstart.value:
case 'PS_Levelstart':
return BallanceObjectInfo.create_from_others(BallanceObjectType.LEVEL_START)
case PROP_virtools_group.VirtoolsGroupsPreset.PE_Levelende.value:
case 'PE_Levelende':
return BallanceObjectInfo.create_from_others(BallanceObjectType.LEVEL_END)
case PROP_virtools_group.VirtoolsGroupsPreset.PC_Checkpoints.value | PROP_virtools_group.VirtoolsGroupsPreset.PR_Resetpoints.value:
case 'PC_Checkpoints' | 'PR_Resetpoints':
# these type's data should be gotten from its name
return VirtoolsGroupConvention.__get_pcpr_from_name(obj.name, reporter)
case _:
@ -312,10 +312,10 @@ class VirtoolsGroupConvention():
return None
# distinguish road
if gp.contain_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_FloorRails.value):
if gp.contain_group('Phys_FloorRails'):
# rail
return BallanceObjectInfo.create_from_others(BallanceObjectType.RAIL)
elif gp.contain_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_Floors.value):
elif gp.contain_group('Phys_Floors'):
# distinguish it between Floor and Wood
floor_result = gp.intersect_groups(_g_BlcFloor)
rail_result = gp.intersect_groups(_g_BlcWood)
@ -326,9 +326,9 @@ class VirtoolsGroupConvention():
else:
if reporter: reporter.add_warning("Can't distinguish object between Floors and Rails. Suppose it is Floors.")
return BallanceObjectInfo.create_from_others(BallanceObjectType.FLOOR)
elif gp.contain_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_FloorStopper.value):
elif gp.contain_group('Phys_FloorStopper'):
return BallanceObjectInfo.create_from_others(BallanceObjectType.STOPPER)
elif gp.contain_group(PROP_virtools_group.VirtoolsGroupsPreset.DepthTestCubes.value):
elif gp.contain_group('DepthTestCubes'):
return BallanceObjectInfo.create_from_others(BallanceObjectType.DEPTH_CUBE)
# no matched
@ -345,31 +345,31 @@ class VirtoolsGroupConvention():
case BallanceObjectType.SKYLAYER: pass # sky layer do not need group
case BallanceObjectType.LEVEL_START:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.PS_Levelstart.value)
gp.add_group('PS_Levelstart')
case BallanceObjectType.LEVEL_END:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.PE_Levelende.value)
gp.add_group('PE_Levelende')
case BallanceObjectType.CHECKPOINT:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.PC_Checkpoints.value)
gp.add_group('PC_Checkpoints')
case BallanceObjectType.RESETPOINT:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.PR_Resetpoints.value)
gp.add_group('PR_Resetpoints')
case BallanceObjectType.DEPTH_CUBE:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.PE_Levelende.value)
gp.add_group('PE_Levelende')
case BallanceObjectType.FLOOR:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_Floors.value)
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Sound_HitID_01.value)
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Sound_RollID_01.value)
gp.add_group('Phys_Floors')
gp.add_group('Sound_HitID_01')
gp.add_group('Sound_RollID_01')
case BallanceObjectType.RAIL:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_FloorRails.value)
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Sound_HitID_02.value)
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Sound_RollID_02.value)
gp.add_group('Phys_FloorRails')
gp.add_group('Sound_HitID_02')
gp.add_group('Sound_RollID_02')
case BallanceObjectType.WOOD:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_Floors.value)
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Sound_HitID_03.value)
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Sound_RollID_03.value)
gp.add_group('Phys_Floors')
gp.add_group('Sound_HitID_03')
gp.add_group('Sound_RollID_03')
case BallanceObjectType.STOPPER:
gp.add_group(PROP_virtools_group.VirtoolsGroupsPreset.Phys_FloorStopper.value)
gp.add_group('Phys_FloorStopper')
case BallanceObjectType.COMPONENT:
# group into component type

View File

@ -1,5 +1,6 @@
import mathutils
import typing, sys
from . import UTIL_functions
# extract all declarations in PyBMap
from .PyBMap.virtools_types import *
@ -84,60 +85,8 @@ class EnumAnnotation():
self.mDisplayName = display_name
self.mDescription = description
class EnumPropHelper():
"""
These class contain all functions related to EnumProperty creation for Virtools Enums
"""
_TIntEnumChildrenVar = typing.TypeVar('_TIntEnumChildrenVar', bound = enum.IntEnum) ##< Mean a variable of IntEnum's children
_TIntEnumChildren = type[_TIntEnumChildrenVar] ##< Mean the type self which is IntEnum's children.
_TAnnoDict = dict[int, EnumAnnotation]
@staticmethod
def __get_name(v: _TIntEnumChildrenVar, anno: _TAnnoDict):
entry: EnumAnnotation | None = anno.get(v, None)
if entry is not None: return entry.mDisplayName
else: return v.name
@staticmethod
def __get_desc(v: _TIntEnumChildrenVar, anno: _TAnnoDict):
entry: EnumAnnotation | None = anno.get(v, None)
if entry is not None: return entry.mDescription
else: return ""
@staticmethod
def generate_items(enum_data: _TIntEnumChildren, anno: _TAnnoDict) -> tuple[tuple, ...]:
"""
Generate a tuple which can be applied to Blender EnumProperty's "items".
"""
# token, display name, descriptions, icon, index
return tuple(
(
str(member.value),
EnumPropHelper.__get_name(member, anno),
EnumPropHelper.__get_desc(member, anno),
"",
member.value
) for member in enum_data
)
@staticmethod
def get_selection(enum_define: _TIntEnumChildren, prop: str) -> _TIntEnumChildrenVar:
# prop will return identifier which is defined as the string type of int value.
# so we parse it to int and then parse it to enum type.
return enum_define(int(prop))
@staticmethod
def to_selection(val: _TIntEnumChildrenVar) -> str:
# like get_selection, we need get it int value, then convert it to string as the indetifier of enum props
# them enum property will accept it.
return str(val.value)
#endregion
#region Enum Annotations
g_Annotation_VXTEXTURE_BLENDMODE: dict[int, EnumAnnotation] = {
_g_Annotation: dict[type, dict[int, EnumAnnotation]] = {
VXTEXTURE_BLENDMODE: {
VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECAL.value: EnumAnnotation("Decal", "Texture replace any material information "),
VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATE.value: EnumAnnotation("Modulate", "Texture and material are combine. Alpha information of the texture replace material alpha component. "),
VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECALALPHA.value: EnumAnnotation("Decal Alpha", "Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component. "),
@ -148,8 +97,8 @@ g_Annotation_VXTEXTURE_BLENDMODE: dict[int, EnumAnnotation] = {
VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_ADD.value: EnumAnnotation("Add", ""),
VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DOTPRODUCT3.value: EnumAnnotation("Dot Product 3", "Perform a Dot Product 3 between texture (normal map) and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR. "),
VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MAX.value: EnumAnnotation("Max", ""),
}
g_Annotation_VXTEXTURE_FILTERMODE: dict[int, EnumAnnotation] = {
},
VXTEXTURE_FILTERMODE: {
VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_NEAREST.value: EnumAnnotation("Nearest", "No Filter "),
VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEAR.value: EnumAnnotation("Linear", "Bilinear Interpolation "),
VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_MIPNEAREST.value: EnumAnnotation("Mip Nearest", "Mip mapping "),
@ -157,8 +106,8 @@ g_Annotation_VXTEXTURE_FILTERMODE: dict[int, EnumAnnotation] = {
VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEARMIPNEAREST.value: EnumAnnotation("Linear Mip Nearest", "Mip Mapping with Bilinear interpolation between mipmap levels. "),
VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEARMIPLINEAR.value: EnumAnnotation("Linear Mip Linear", "Trilinear Filtering "),
VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_ANISOTROPIC.value: EnumAnnotation("Anisotropic", "Anisotropic filtering "),
}
g_Annotation_VXBLEND_MODE: dict[int, EnumAnnotation] = {
},
VXBLEND_MODE: {
VXBLEND_MODE.VXBLEND_ZERO.value: EnumAnnotation("Zero", "Blend factor is (0, 0, 0, 0). "),
VXBLEND_MODE.VXBLEND_ONE.value: EnumAnnotation("One", "Blend factor is (1, 1, 1, 1). "),
VXBLEND_MODE.VXBLEND_SRCCOLOR.value: EnumAnnotation("Src Color", "Blend factor is (Rs, Gs, Bs, As). "),
@ -172,25 +121,25 @@ g_Annotation_VXBLEND_MODE: dict[int, EnumAnnotation] = {
VXBLEND_MODE.VXBLEND_SRCALPHASAT.value: EnumAnnotation("Src Alpha Sat", "Blend factor is (f, f, f, 1); f = min(As, 1-Ad). "),
#VXBLEND_MODE.VXBLEND_BOTHSRCALPHA.value: EnumAnnotation("Both Src Alpha", "Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As) "),
#VXBLEND_MODE.VXBLEND_BOTHINVSRCALPHA.value: EnumAnnotation("Both Inv Src Alpha", "Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As) "),
}
g_Annotation_VXTEXTURE_ADDRESSMODE: dict[int, EnumAnnotation] = {
},
VXTEXTURE_ADDRESSMODE: {
VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSWRAP.value: EnumAnnotation("Wrap", "Default mesh wrap mode is used (see CKMesh::SetWrapMode) "),
VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSMIRROR.value: EnumAnnotation("Mirror", "Texture coordinates outside the range [0..1] are flipped evenly. "),
VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSCLAMP.value: EnumAnnotation("Clamp", "Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0. "),
VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSBORDER.value: EnumAnnotation("Border", "When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor. "),
VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSMIRRORONCE.value: EnumAnnotation("Mirror Once", " "),
}
g_Annotation_VXFILL_MODE: dict[int, EnumAnnotation] = {
},
VXFILL_MODE: {
VXFILL_MODE.VXFILL_POINT.value: EnumAnnotation("Point", "Vertices rendering "),
VXFILL_MODE.VXFILL_WIREFRAME.value: EnumAnnotation("Wireframe", "Edges rendering "),
VXFILL_MODE.VXFILL_SOLID.value: EnumAnnotation("Solid", "Face rendering "),
}
g_Annotation_VXSHADE_MODE: dict[int, EnumAnnotation] = {
},
VXSHADE_MODE: {
VXSHADE_MODE.VXSHADE_FLAT.value: EnumAnnotation("Flat", "Flat Shading "),
VXSHADE_MODE.VXSHADE_GOURAUD.value: EnumAnnotation("Gouraud", "Gouraud Shading "),
VXSHADE_MODE.VXSHADE_PHONG.value: EnumAnnotation("Phong", "Phong Shading (Not yet supported by most implementation) "),
}
g_Annotation_VXCMPFUNC: dict[int, EnumAnnotation] = {
},
VXCMPFUNC: {
VXCMPFUNC.VXCMP_NEVER.value: EnumAnnotation("Never", "Always fail the test. "),
VXCMPFUNC.VXCMP_LESS.value: EnumAnnotation("Less", "Accept if value if less than current value. "),
VXCMPFUNC.VXCMP_EQUAL.value: EnumAnnotation("Equal", "Accept if value if equal than current value. "),
@ -199,16 +148,15 @@ g_Annotation_VXCMPFUNC: dict[int, EnumAnnotation] = {
VXCMPFUNC.VXCMP_NOTEQUAL.value: EnumAnnotation("Not Equal", "Accept if value if different than current value. "),
VXCMPFUNC.VXCMP_GREATEREQUAL.value: EnumAnnotation("Greater Equal", "Accept if value if greater or equal current value. "),
VXCMPFUNC.VXCMP_ALWAYS.value: EnumAnnotation("Always", "Always accept the test. "),
}
g_Annotation_CK_TEXTURE_SAVEOPTIONS: dict[int, EnumAnnotation] = {
},
CK_TEXTURE_SAVEOPTIONS: {
CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_RAWDATA.value: EnumAnnotation("Raw Data", "Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format. "),
CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL.value: EnumAnnotation("External", "Store only the file name for the texture. The bitmap file must be present in the bitmap paths when loading the composition. "),
CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_IMAGEFORMAT.value: EnumAnnotation("Image Format", "Save using format specified. The bitmap data will be converted to the specified format by the correspondant bitmap plugin and saved inside file. "),
CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_USEGLOBAL.value: EnumAnnotation("Use Global", "Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions). "),
CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_INCLUDEORIGINALFILE.value: EnumAnnotation("Include Original File", "Insert original image file inside CMO file. The bitmap file that was used originally for the texture or sprite will be append to the composition file and extracted when the file is loaded. "),
}
g_Annotation_VX_PIXELFORMAT: dict[int, EnumAnnotation] = {
},
VX_PIXELFORMAT: {
VX_PIXELFORMAT._32_ARGB8888.value: EnumAnnotation("32 Bits ARGB8888", "32-bit ARGB pixel format with alpha "),
VX_PIXELFORMAT._32_RGB888.value: EnumAnnotation("32 Bits RGB888", "32-bit RGB pixel format without alpha "),
VX_PIXELFORMAT._24_RGB888.value: EnumAnnotation("24 Bits RGB888", "24-bit RGB pixel format "),
@ -240,13 +188,31 @@ g_Annotation_VX_PIXELFORMAT: dict[int, EnumAnnotation] = {
VX_PIXELFORMAT._8_ARGB8888_CLUT.value: EnumAnnotation("8 Bits ARGB8888 CLUT", "8 bits indexed CLUT (ARGB) "),
VX_PIXELFORMAT._4_ABGR8888_CLUT.value: EnumAnnotation("4 Bits ABGR8888 CLUT", "4 bits indexed CLUT (ABGR) "),
VX_PIXELFORMAT._4_ARGB8888_CLUT.value: EnumAnnotation("4 Bits ARGB8888 CLUT", "4 bits indexed CLUT (ARGB) "),
}
g_Annotation_VXMESH_LITMODE: dict[int, EnumAnnotation] = {
},
VXMESH_LITMODE: {
VXMESH_LITMODE.VX_PRELITMESH.value: EnumAnnotation("Prelit", "Lighting use color information store with vertices "),
VXMESH_LITMODE.VX_LITMESH.value: EnumAnnotation("Lit", "Lighting is done by renderer using normals and face material information. "),
}
}
class EnumPropHelper(UTIL_functions.EnumPropHelper):
"""
Virtools type specified Blender EnumProp helper.
"""
__mAnnotationDict: dict[int, EnumAnnotation]
def __init__(self, ty: UTIL_functions.EnumPropHelper._TEnum):
# set self annotation ref
self.__mAnnotationDict = _g_Annotation[ty]
# init parent data
UTIL_functions.EnumPropHelper.__init__(
self,
ty,
lambda x: self.__mAnnotationDict[x.value].mDisplayName,
lambda x: self.__mAnnotationDict[x.value].mDescription,
lambda _: ''
)
#endregion
#region Virtools Blender Bridge Funcs & Vars