add name convention

This commit is contained in:
yyc12345 2023-11-26 20:37:19 +08:00
parent 5bb3abed20
commit 88fe1519e3
8 changed files with 318 additions and 223 deletions

View File

@ -104,7 +104,7 @@ def _import_virtools_textures(
tex = UTIL_ballance_texture.load_other_texture(texpath_to_load)
# rename and insert it to map
tex.name = UTIL_functions.virtools_name_regulator(vttexture.get_name())
tex.name = UTIL_virtools_types.virtools_name_regulator(vttexture.get_name())
texture_cret_map[vttexture] = tex
# inc steps
@ -162,7 +162,7 @@ def _import_virtools_materials(
# create mtl and apply it
mtl: bpy.types.Material = bpy.data.materials.new(
UTIL_functions.virtools_name_regulator(vtmaterial.get_name())
UTIL_virtools_types.virtools_name_regulator(vtmaterial.get_name())
)
PROP_virtools_material.set_raw_virtools_material(mtl, rawmtl)
PROP_virtools_material.apply_to_blender_material(mtl)
@ -187,7 +187,7 @@ def _import_virtools_meshes(
for vtmesh in reader.get_meshs():
# create mesh
mesh: bpy.types.Mesh = bpy.data.meshes.new(
UTIL_functions.virtools_name_regulator(vtmesh.get_name())
UTIL_virtools_types.virtools_name_regulator(vtmesh.get_name())
)
# open mesh writer
@ -284,7 +284,7 @@ def _import_virtools_3dobjects(
for vt3dobj in reader.get_3dobjects():
# create 3d object with mesh
obj3d: bpy.types.Object = bpy.data.objects.new(
UTIL_functions.virtools_name_regulator(vt3dobj.get_name()),
UTIL_virtools_types.virtools_name_regulator(vt3dobj.get_name()),
mesh_cret_map.get(vt3dobj.get_current_mesh(), None)
)

View File

@ -5,70 +5,68 @@ from . import PROP_virtools_texture
#region Enums Annotations
from .UTIL_functions import AnnotationData, BlenderEnumPropEntry_t, generate_vt_enums_for_bl_enumprop
g_Annotation_VXTEXTURE_BLENDMODE: dict[int, AnnotationData] = {
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECAL.value: AnnotationData("Decal", "Texture replace any material information "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATE.value: AnnotationData("Modulate", "Texture and material are combine. Alpha information of the texture replace material alpha component. "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECALALPHA.value: AnnotationData("Decal Alpha", "Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component. "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATEALPHA.value: AnnotationData("Modulate Alpha", "Alpha information in the texture specify how material and texture are combined "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECALMASK.value: AnnotationData("Decal Mask", ""),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATEMASK.value: AnnotationData("Modulate Mask", ""),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_COPY.value: AnnotationData("Copy", "Equivalent to DECAL "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_ADD.value: AnnotationData("Add", ""),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DOTPRODUCT3.value: AnnotationData("Dot Product 3", "Perform a Dot Product 3 between texture (normal map) and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR. "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MAX.value: AnnotationData("Max", ""),
g_Annotation_VXTEXTURE_BLENDMODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECAL.value: UTIL_virtools_types.EnumAnnotation("Decal", "Texture replace any material information "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATE.value: UTIL_virtools_types.EnumAnnotation("Modulate", "Texture and material are combine. Alpha information of the texture replace material alpha component. "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECALALPHA.value: UTIL_virtools_types.EnumAnnotation("Decal Alpha", "Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component. "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATEALPHA.value: UTIL_virtools_types.EnumAnnotation("Modulate Alpha", "Alpha information in the texture specify how material and texture are combined "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DECALMASK.value: UTIL_virtools_types.EnumAnnotation("Decal Mask", ""),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MODULATEMASK.value: UTIL_virtools_types.EnumAnnotation("Modulate Mask", ""),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_COPY.value: UTIL_virtools_types.EnumAnnotation("Copy", "Equivalent to DECAL "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_ADD.value: UTIL_virtools_types.EnumAnnotation("Add", ""),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_DOTPRODUCT3.value: UTIL_virtools_types.EnumAnnotation("Dot Product 3", "Perform a Dot Product 3 between texture (normal map) and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR. "),
UTIL_virtools_types.VXTEXTURE_BLENDMODE.VXTEXTUREBLEND_MAX.value: UTIL_virtools_types.EnumAnnotation("Max", ""),
}
g_Annotation_VXTEXTURE_FILTERMODE: dict[int, AnnotationData] = {
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_NEAREST.value: AnnotationData("Nearest", "No Filter "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEAR.value: AnnotationData("Linear", "Bilinear Interpolation "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_MIPNEAREST.value: AnnotationData("Mip Nearest", "Mip mapping "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_MIPLINEAR.value: AnnotationData("Mip Linear", "Mip Mapping with Bilinear interpolation "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEARMIPNEAREST.value: AnnotationData("Linear Mip Nearest", "Mip Mapping with Bilinear interpolation between mipmap levels. "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEARMIPLINEAR.value: AnnotationData("Linear Mip Linear", "Trilinear Filtering "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_ANISOTROPIC.value: AnnotationData("Anisotropic", "Anisotropic filtering "),
g_Annotation_VXTEXTURE_FILTERMODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_NEAREST.value: UTIL_virtools_types.EnumAnnotation("Nearest", "No Filter "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEAR.value: UTIL_virtools_types.EnumAnnotation("Linear", "Bilinear Interpolation "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_MIPNEAREST.value: UTIL_virtools_types.EnumAnnotation("Mip Nearest", "Mip mapping "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_MIPLINEAR.value: UTIL_virtools_types.EnumAnnotation("Mip Linear", "Mip Mapping with Bilinear interpolation "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEARMIPNEAREST.value: UTIL_virtools_types.EnumAnnotation("Linear Mip Nearest", "Mip Mapping with Bilinear interpolation between mipmap levels. "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_LINEARMIPLINEAR.value: UTIL_virtools_types.EnumAnnotation("Linear Mip Linear", "Trilinear Filtering "),
UTIL_virtools_types.VXTEXTURE_FILTERMODE.VXTEXTUREFILTER_ANISOTROPIC.value: UTIL_virtools_types.EnumAnnotation("Anisotropic", "Anisotropic filtering "),
}
g_Annotation_VXBLEND_MODE: dict[int, AnnotationData] = {
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_ZERO.value: AnnotationData("Zero", "Blend factor is (0, 0, 0, 0). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_ONE.value: AnnotationData("One", "Blend factor is (1, 1, 1, 1). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_SRCCOLOR.value: AnnotationData("Src Color", "Blend factor is (Rs, Gs, Bs, As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVSRCCOLOR.value: AnnotationData("Inv Src Color", "Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_SRCALPHA.value: AnnotationData("Src Alpha", "Blend factor is (As, As, As, As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVSRCALPHA.value: AnnotationData("Inv Src Alpha", "Blend factor is (1-As, 1-As, 1-As, 1-As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_DESTALPHA.value: AnnotationData("Dest Alpha", "Blend factor is (Ad, Ad, Ad, Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVDESTALPHA.value: AnnotationData("Inv Dest Alpha", "Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_DESTCOLOR.value: AnnotationData("Dest Color", "Blend factor is (Rd, Gd, Bd, Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVDESTCOLOR.value: AnnotationData("Inv Dest Color", "Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_SRCALPHASAT.value: AnnotationData("Src Alpha Sat", "Blend factor is (f, f, f, 1); f = min(As, 1-Ad). "),
#UTIL_virtools_types.VXBLEND_MODE.VXBLEND_BOTHSRCALPHA.value: AnnotationData("Both Src Alpha", "Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As) "),
#UTIL_virtools_types.VXBLEND_MODE.VXBLEND_BOTHINVSRCALPHA.value: AnnotationData("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_VXBLEND_MODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_ZERO.value: UTIL_virtools_types.EnumAnnotation("Zero", "Blend factor is (0, 0, 0, 0). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_ONE.value: UTIL_virtools_types.EnumAnnotation("One", "Blend factor is (1, 1, 1, 1). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_SRCCOLOR.value: UTIL_virtools_types.EnumAnnotation("Src Color", "Blend factor is (Rs, Gs, Bs, As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVSRCCOLOR.value: UTIL_virtools_types.EnumAnnotation("Inv Src Color", "Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_SRCALPHA.value: UTIL_virtools_types.EnumAnnotation("Src Alpha", "Blend factor is (As, As, As, As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVSRCALPHA.value: UTIL_virtools_types.EnumAnnotation("Inv Src Alpha", "Blend factor is (1-As, 1-As, 1-As, 1-As). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_DESTALPHA.value: UTIL_virtools_types.EnumAnnotation("Dest Alpha", "Blend factor is (Ad, Ad, Ad, Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVDESTALPHA.value: UTIL_virtools_types.EnumAnnotation("Inv Dest Alpha", "Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_DESTCOLOR.value: UTIL_virtools_types.EnumAnnotation("Dest Color", "Blend factor is (Rd, Gd, Bd, Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_INVDESTCOLOR.value: UTIL_virtools_types.EnumAnnotation("Inv Dest Color", "Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad). "),
UTIL_virtools_types.VXBLEND_MODE.VXBLEND_SRCALPHASAT.value: UTIL_virtools_types.EnumAnnotation("Src Alpha Sat", "Blend factor is (f, f, f, 1); f = min(As, 1-Ad). "),
#UTIL_virtools_types.VXBLEND_MODE.VXBLEND_BOTHSRCALPHA.value: UTIL_virtools_types.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) "),
#UTIL_virtools_types.VXBLEND_MODE.VXBLEND_BOTHINVSRCALPHA.value: UTIL_virtools_types.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, AnnotationData] = {
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSWRAP.value: AnnotationData("Wrap", "Default mesh wrap mode is used (see CKMesh::SetWrapMode) "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSMIRROR.value: AnnotationData("Mirror", "Texture coordinates outside the range [0..1] are flipped evenly. "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSCLAMP.value: AnnotationData("Clamp", "Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0. "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSBORDER.value: AnnotationData("Border", "When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor. "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSMIRRORONCE.value: AnnotationData("Mirror Once", " "),
g_Annotation_VXTEXTURE_ADDRESSMODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSWRAP.value: UTIL_virtools_types.EnumAnnotation("Wrap", "Default mesh wrap mode is used (see CKMesh::SetWrapMode) "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSMIRROR.value: UTIL_virtools_types.EnumAnnotation("Mirror", "Texture coordinates outside the range [0..1] are flipped evenly. "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSCLAMP.value: UTIL_virtools_types.EnumAnnotation("Clamp", "Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0. "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSBORDER.value: UTIL_virtools_types.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. "),
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE.VXTEXTURE_ADDRESSMIRRORONCE.value: UTIL_virtools_types.EnumAnnotation("Mirror Once", " "),
}
g_Annotation_VXFILL_MODE: dict[int, AnnotationData] = {
UTIL_virtools_types.VXFILL_MODE.VXFILL_POINT.value: AnnotationData("Point", "Vertices rendering "),
UTIL_virtools_types.VXFILL_MODE.VXFILL_WIREFRAME.value: AnnotationData("Wireframe", "Edges rendering "),
UTIL_virtools_types.VXFILL_MODE.VXFILL_SOLID.value: AnnotationData("Solid", "Face rendering "),
g_Annotation_VXFILL_MODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXFILL_MODE.VXFILL_POINT.value: UTIL_virtools_types.EnumAnnotation("Point", "Vertices rendering "),
UTIL_virtools_types.VXFILL_MODE.VXFILL_WIREFRAME.value: UTIL_virtools_types.EnumAnnotation("Wireframe", "Edges rendering "),
UTIL_virtools_types.VXFILL_MODE.VXFILL_SOLID.value: UTIL_virtools_types.EnumAnnotation("Solid", "Face rendering "),
}
g_Annotation_VXSHADE_MODE: dict[int, AnnotationData] = {
UTIL_virtools_types.VXSHADE_MODE.VXSHADE_FLAT.value: AnnotationData("Flat", "Flat Shading "),
UTIL_virtools_types.VXSHADE_MODE.VXSHADE_GOURAUD.value: AnnotationData("Gouraud", "Gouraud Shading "),
UTIL_virtools_types.VXSHADE_MODE.VXSHADE_PHONG.value: AnnotationData("Phong", "Phong Shading (Not yet supported by most implementation) "),
g_Annotation_VXSHADE_MODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXSHADE_MODE.VXSHADE_FLAT.value: UTIL_virtools_types.EnumAnnotation("Flat", "Flat Shading "),
UTIL_virtools_types.VXSHADE_MODE.VXSHADE_GOURAUD.value: UTIL_virtools_types.EnumAnnotation("Gouraud", "Gouraud Shading "),
UTIL_virtools_types.VXSHADE_MODE.VXSHADE_PHONG.value: UTIL_virtools_types.EnumAnnotation("Phong", "Phong Shading (Not yet supported by most implementation) "),
}
g_Annotation_VXCMPFUNC: dict[int, AnnotationData] = {
UTIL_virtools_types.VXCMPFUNC.VXCMP_NEVER.value: AnnotationData("Never", "Always fail the test. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_LESS.value: AnnotationData("Less", "Accept if value if less than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_EQUAL.value: AnnotationData("Equal", "Accept if value if equal than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_LESSEQUAL.value: AnnotationData("Less Equal", "Accept if value if less or equal than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_GREATER.value: AnnotationData("Greater", "Accept if value if greater than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_NOTEQUAL.value: AnnotationData("Not Equal", "Accept if value if different than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_GREATEREQUAL.value: AnnotationData("Greater Equal", "Accept if value if greater or equal current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_ALWAYS.value: AnnotationData("Always", "Always accept the test. "),
g_Annotation_VXCMPFUNC: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXCMPFUNC.VXCMP_NEVER.value: UTIL_virtools_types.EnumAnnotation("Never", "Always fail the test. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_LESS.value: UTIL_virtools_types.EnumAnnotation("Less", "Accept if value if less than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_EQUAL.value: UTIL_virtools_types.EnumAnnotation("Equal", "Accept if value if equal than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_LESSEQUAL.value: UTIL_virtools_types.EnumAnnotation("Less Equal", "Accept if value if less or equal than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_GREATER.value: UTIL_virtools_types.EnumAnnotation("Greater", "Accept if value if greater than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_NOTEQUAL.value: UTIL_virtools_types.EnumAnnotation("Not Equal", "Accept if value if different than current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_GREATEREQUAL.value: UTIL_virtools_types.EnumAnnotation("Greater Equal", "Accept if value if greater or equal current value. "),
UTIL_virtools_types.VXCMPFUNC.VXCMP_ALWAYS.value: UTIL_virtools_types.EnumAnnotation("Always", "Always accept the test. "),
}
#endregion
@ -250,81 +248,81 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
texture_blend_mode: bpy.props.EnumProperty(
name = "Texture Blend",
description = "Texture blend mode",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_BLENDMODE,
g_Annotation_VXTEXTURE_BLENDMODE
),
default = RawVirtoolsMaterial.cDefaultTextureBlendMode.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureBlendMode)
)
texture_min_mode: bpy.props.EnumProperty(
name = "Filter Min",
description = "Texture filter mode when the texture is minified",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_FILTERMODE,
g_Annotation_VXTEXTURE_FILTERMODE
),
default = RawVirtoolsMaterial.cDefaultTextureMinMode.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureMinMode)
)
texture_mag_mode: bpy.props.EnumProperty(
name = "Filter Mag",
description = "Texture filter mode when the texture is magnified",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_FILTERMODE,
g_Annotation_VXTEXTURE_FILTERMODE
),
default = RawVirtoolsMaterial.cDefaultTextureMagMode.value
default = UTIL_virtools_types.EnumPropHelper.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 = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE,
g_Annotation_VXTEXTURE_ADDRESSMODE
),
default = RawVirtoolsMaterial.cDefaultTextureAddressMode.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultTextureAddressMode)
)
source_blend: bpy.props.EnumProperty(
name = "Source Blend",
description = "Source blend factor",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXBLEND_MODE,
g_Annotation_VXBLEND_MODE
),
default = RawVirtoolsMaterial.cDefaultSourceBlend.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultSourceBlend)
)
dest_blend: bpy.props.EnumProperty(
name = "Destination Blend",
description = "Destination blend factor",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXBLEND_MODE,
g_Annotation_VXBLEND_MODE
),
default = RawVirtoolsMaterial.cDefaultDestBlend.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultDestBlend)
)
fill_mode: bpy.props.EnumProperty(
name = "Fill Mode",
description = "Fill mode",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXFILL_MODE,
g_Annotation_VXFILL_MODE
),
default = RawVirtoolsMaterial.cDefaultFillMode.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultFillMode)
)
shade_mode: bpy.props.EnumProperty(
name = "Shade Mode",
description = "Shade mode",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXSHADE_MODE,
g_Annotation_VXSHADE_MODE
),
default = RawVirtoolsMaterial.cDefaultShadeMode.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultShadeMode)
)
enable_alpha_test: bpy.props.BoolProperty(
@ -364,21 +362,21 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
alpha_func: bpy.props.EnumProperty(
name = "Alpha Test Function",
description = "Alpha comparision function",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXCMPFUNC,
g_Annotation_VXCMPFUNC
),
default = RawVirtoolsMaterial.cDefaultAlphaFunc.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultAlphaFunc)
)
z_func: bpy.props.EnumProperty(
name = "Z Compare Function",
description = "Z Comparison function",
items = generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXCMPFUNC,
g_Annotation_VXCMPFUNC
),
default = RawVirtoolsMaterial.cDefaultZFunc.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMaterial.cDefaultZFunc)
)
#region Getter Setter
@ -399,15 +397,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.VXTEXTURE_BLENDMODE(int(props.texture_blend_mode))
rawdata.mTextureMinMode = UTIL_virtools_types.VXTEXTURE_FILTERMODE(int(props.texture_min_mode))
rawdata.mTextureMagMode = UTIL_virtools_types.VXTEXTURE_FILTERMODE(int(props.texture_mag_mode))
rawdata.mTextureAddressMode = UTIL_virtools_types.VXTEXTURE_ADDRESSMODE(int(props.texture_address_mode))
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.mSourceBlend = UTIL_virtools_types.VXBLEND_MODE(int(props.source_blend))
rawdata.mDestBlend = UTIL_virtools_types.VXBLEND_MODE(int(props.dest_blend))
rawdata.mFillMode = UTIL_virtools_types.VXFILL_MODE(int(props.fill_mode))
rawdata.mShadeMode = UTIL_virtools_types.VXSHADE_MODE(int(props.shade_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.mEnableAlphaTest = props.enable_alpha_test
rawdata.mEnableAlphaBlend = props.enable_alpha_blend
@ -416,8 +414,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.VXCMPFUNC(int(props.alpha_func))
rawdata.mZFunc = UTIL_virtools_types.VXCMPFUNC(int(props.z_func))
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.regulate()
return rawdata
@ -434,15 +432,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 = str(rawdata.mTextureBlendMode.value)
props.texture_min_mode = str(rawdata.mTextureMinMode.value)
props.texture_mag_mode = str(rawdata.mTextureMagMode.value)
props.texture_address_mode = str(rawdata.mTextureAddressMode.value)
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.source_blend = str(rawdata.mSourceBlend.value)
props.dest_blend = str(rawdata.mDestBlend.value)
props.fill_mode = str(rawdata.mFillMode.value)
props.shade_mode = str(rawdata.mShadeMode.value)
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.enable_alpha_test = rawdata.mEnableAlphaTest
props.enable_alpha_blend = rawdata.mEnableAlphaBlend
@ -451,8 +449,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 = str(rawdata.mAlphaFunc.value)
props.z_func = str(rawdata.mZFunc.value)
props.alpha_func = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mAlphaFunc)
props.z_func = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mZFunc)
def apply_to_blender_material(mtl: bpy.types.Material):
# get raw material data
@ -603,17 +601,37 @@ def preset_virtools_material(mtl: bpy.types.Material, preset_type: MaterialPrese
preset_data: MaterialPresetData = g_MaterialPresets[preset_type.value]
set_raw_virtools_material(mtl, preset_data.mData)
def _generate_mtl_presets_for_bl_enumprop() -> tuple[BlenderEnumPropEntry_t, ...]:
# define 2 assist functions
def get_display_name(v: int):
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 ""
# token, display name, descriptions, icon, index
return tuple(
(str(member.value), get_display_name(member.value), "", "", member.value) for member in MaterialPresetType
)
@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)
#endregion
@ -643,7 +661,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 = _generate_mtl_presets_for_bl_enumprop(),
items = _MtlPresetEnumPropHelper.generate_items(),
)
@classmethod
@ -660,7 +678,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 = MaterialPresetType(int(self.preset_type))
expected_preset: MaterialPresetType = _MtlPresetEnumPropHelper.get_selection(self.preset_type)
# apply preset to material
preset_virtools_material(mtl, expected_preset)

View File

@ -4,11 +4,9 @@ from . import UTIL_functions, UTIL_virtools_types
# Annotation
from .UTIL_functions import AnnotationData, BlenderEnumPropEntry_t
g_Annotation_VXMESH_LITMODE: dict[int, AnnotationData] = {
UTIL_virtools_types.VXMESH_LITMODE.VX_PRELITMESH.value: AnnotationData("Prelit", "Lighting use color information store with vertices "),
UTIL_virtools_types.VXMESH_LITMODE.VX_LITMESH.value: AnnotationData("Lit", "Lighting is done by renderer using normals and face material information. "),
g_Annotation_VXMESH_LITMODE: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VXMESH_LITMODE.VX_PRELITMESH.value: UTIL_virtools_types.EnumAnnotation("Prelit", "Lighting use color information store with vertices "),
UTIL_virtools_types.VXMESH_LITMODE.VX_LITMESH.value: UTIL_virtools_types.EnumAnnotation("Lit", "Lighting is done by renderer using normals and face material information. "),
}
# Raw Data
@ -29,11 +27,11 @@ class BBP_PG_virtools_mesh(bpy.types.PropertyGroup):
lit_mode: bpy.props.EnumProperty(
name = "Lit Mode",
description = "Lighting mode of the mesh.",
items = UTIL_functions.generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VXMESH_LITMODE,
g_Annotation_VXMESH_LITMODE
),
default = RawVirtoolsMesh.cDefaultLitMode.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsMesh.cDefaultLitMode)
)
# Getter Setter
@ -45,14 +43,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.VXMESH_LITMODE(int(props.lit_mode))
rawdata.mLitMode = UTIL_virtools_types.EnumPropHelper.get_selection(UTIL_virtools_types.VXMESH_LITMODE, 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 = str(rawdata.mLitMode.value)
props.lit_mode = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mLitMode)
# Display Panel

View File

@ -4,48 +4,46 @@ from . import UTIL_virtools_types, UTIL_functions
#region Virtools Texture Annotation Data
from .UTIL_functions import AnnotationData
g_Annotation_CK_TEXTURE_SAVEOPTIONS: dict[int, AnnotationData] = {
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_RAWDATA.value: AnnotationData("Raw Data", "Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format. "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL.value: AnnotationData("External", "Store only the file name for the texture. The bitmap file must be present in the bitmap paths when loading the composition. "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_IMAGEFORMAT.value: AnnotationData("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. "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_USEGLOBAL.value: AnnotationData("Use Global", "Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions). "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_INCLUDEORIGINALFILE.value: AnnotationData("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_CK_TEXTURE_SAVEOPTIONS: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_RAWDATA.value: UTIL_virtools_types.EnumAnnotation("Raw Data", "Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format. "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL.value: UTIL_virtools_types.EnumAnnotation("External", "Store only the file name for the texture. The bitmap file must be present in the bitmap paths when loading the composition. "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_IMAGEFORMAT.value: UTIL_virtools_types.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. "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_USEGLOBAL.value: UTIL_virtools_types.EnumAnnotation("Use Global", "Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions). "),
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_INCLUDEORIGINALFILE.value: UTIL_virtools_types.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, AnnotationData] = {
UTIL_virtools_types.VX_PIXELFORMAT._32_ARGB8888.value: AnnotationData("32 Bits ARGB8888", "32-bit ARGB pixel format with alpha "),
UTIL_virtools_types.VX_PIXELFORMAT._32_RGB888.value: AnnotationData("32 Bits RGB888", "32-bit RGB pixel format without alpha "),
UTIL_virtools_types.VX_PIXELFORMAT._24_RGB888.value: AnnotationData("24 Bits RGB888", "24-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_RGB565.value: AnnotationData("16 Bits RGB565", "16-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_RGB555.value: AnnotationData("16 Bits RGB555", "16-bit RGB pixel format (5 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB1555.value: AnnotationData("16 Bits ARGB1555", "16-bit ARGB pixel format (5 bits per color + 1 bit for alpha) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB4444.value: AnnotationData("16 Bits ARGB4444", "16-bit ARGB pixel format (4 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._8_RGB332.value: AnnotationData("8 Bits RGB332", "8-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ARGB2222.value: AnnotationData("8 Bits ARGB2222", "8-bit ARGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_ABGR8888.value: AnnotationData("32 Bits ABGR8888", "32-bit ABGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_RGBA8888.value: AnnotationData("32 Bits RGBA8888", "32-bit RGBA pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_BGRA8888.value: AnnotationData("32 Bits BGRA8888", "32-bit BGRA pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_BGR888.value: AnnotationData("32 Bits BGR888", "32-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._24_BGR888.value: AnnotationData("24 Bits BGR888", "24-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_BGR565.value: AnnotationData("16 Bits BGR565", "16-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_BGR555.value: AnnotationData("16 Bits BGR555", "16-bit BGR pixel format (5 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ABGR1555.value: AnnotationData("16 Bits ABGR1555", "16-bit ABGR pixel format (5 bits per color + 1 bit for alpha) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ABGR4444.value: AnnotationData("16 Bits ABGR4444", "16-bit ABGR pixel format (4 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT1.value: AnnotationData("DXT1", "S3/DirectX Texture Compression 1 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT2.value: AnnotationData("DXT2", "S3/DirectX Texture Compression 2 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT3.value: AnnotationData("DXT3", "S3/DirectX Texture Compression 3 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT4.value: AnnotationData("DXT4", "S3/DirectX Texture Compression 4 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT5.value: AnnotationData("DXT5", "S3/DirectX Texture Compression 5 "),
UTIL_virtools_types.VX_PIXELFORMAT._16_V8U8.value: AnnotationData("16 Bits V8U8", "16-bit Bump Map format format (8 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._32_V16U16.value: AnnotationData("32 Bits V16U16", "32-bit Bump Map format format (16 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_L6V5U5.value: AnnotationData("16 Bits L6V5U5", "16-bit Bump Map format format with luminance "),
UTIL_virtools_types.VX_PIXELFORMAT._32_X8L8V8U8.value: AnnotationData("32 Bits X8L8V8U8", "32-bit Bump Map format format with luminance "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ABGR8888_CLUT.value: AnnotationData("8 Bits ABGR8888 CLUT", "8 bits indexed CLUT (ABGR) "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ARGB8888_CLUT.value: AnnotationData("8 Bits ARGB8888 CLUT", "8 bits indexed CLUT (ARGB) "),
UTIL_virtools_types.VX_PIXELFORMAT._4_ABGR8888_CLUT.value: AnnotationData("4 Bits ABGR8888 CLUT", "4 bits indexed CLUT (ABGR) "),
UTIL_virtools_types.VX_PIXELFORMAT._4_ARGB8888_CLUT.value: AnnotationData("4 Bits ARGB8888 CLUT", "4 bits indexed CLUT (ARGB) "),
g_Annotation_VX_PIXELFORMAT: dict[int, UTIL_virtools_types.EnumAnnotation] = {
UTIL_virtools_types.VX_PIXELFORMAT._32_ARGB8888.value: UTIL_virtools_types.EnumAnnotation("32 Bits ARGB8888", "32-bit ARGB pixel format with alpha "),
UTIL_virtools_types.VX_PIXELFORMAT._32_RGB888.value: UTIL_virtools_types.EnumAnnotation("32 Bits RGB888", "32-bit RGB pixel format without alpha "),
UTIL_virtools_types.VX_PIXELFORMAT._24_RGB888.value: UTIL_virtools_types.EnumAnnotation("24 Bits RGB888", "24-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_RGB565.value: UTIL_virtools_types.EnumAnnotation("16 Bits RGB565", "16-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_RGB555.value: UTIL_virtools_types.EnumAnnotation("16 Bits RGB555", "16-bit RGB pixel format (5 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB1555.value: UTIL_virtools_types.EnumAnnotation("16 Bits ARGB1555", "16-bit ARGB pixel format (5 bits per color + 1 bit for alpha) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB4444.value: UTIL_virtools_types.EnumAnnotation("16 Bits ARGB4444", "16-bit ARGB pixel format (4 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._8_RGB332.value: UTIL_virtools_types.EnumAnnotation("8 Bits RGB332", "8-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ARGB2222.value: UTIL_virtools_types.EnumAnnotation("8 Bits ARGB2222", "8-bit ARGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_ABGR8888.value: UTIL_virtools_types.EnumAnnotation("32 Bits ABGR8888", "32-bit ABGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_RGBA8888.value: UTIL_virtools_types.EnumAnnotation("32 Bits RGBA8888", "32-bit RGBA pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_BGRA8888.value: UTIL_virtools_types.EnumAnnotation("32 Bits BGRA8888", "32-bit BGRA pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_BGR888.value: UTIL_virtools_types.EnumAnnotation("32 Bits BGR888", "32-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._24_BGR888.value: UTIL_virtools_types.EnumAnnotation("24 Bits BGR888", "24-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_BGR565.value: UTIL_virtools_types.EnumAnnotation("16 Bits BGR565", "16-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_BGR555.value: UTIL_virtools_types.EnumAnnotation("16 Bits BGR555", "16-bit BGR pixel format (5 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ABGR1555.value: UTIL_virtools_types.EnumAnnotation("16 Bits ABGR1555", "16-bit ABGR pixel format (5 bits per color + 1 bit for alpha) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ABGR4444.value: UTIL_virtools_types.EnumAnnotation("16 Bits ABGR4444", "16-bit ABGR pixel format (4 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT1.value: UTIL_virtools_types.EnumAnnotation("DXT1", "S3/DirectX Texture Compression 1 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT2.value: UTIL_virtools_types.EnumAnnotation("DXT2", "S3/DirectX Texture Compression 2 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT3.value: UTIL_virtools_types.EnumAnnotation("DXT3", "S3/DirectX Texture Compression 3 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT4.value: UTIL_virtools_types.EnumAnnotation("DXT4", "S3/DirectX Texture Compression 4 "),
UTIL_virtools_types.VX_PIXELFORMAT._DXT5.value: UTIL_virtools_types.EnumAnnotation("DXT5", "S3/DirectX Texture Compression 5 "),
UTIL_virtools_types.VX_PIXELFORMAT._16_V8U8.value: UTIL_virtools_types.EnumAnnotation("16 Bits V8U8", "16-bit Bump Map format format (8 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._32_V16U16.value: UTIL_virtools_types.EnumAnnotation("32 Bits V16U16", "32-bit Bump Map format format (16 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_L6V5U5.value: UTIL_virtools_types.EnumAnnotation("16 Bits L6V5U5", "16-bit Bump Map format format with luminance "),
UTIL_virtools_types.VX_PIXELFORMAT._32_X8L8V8U8.value: UTIL_virtools_types.EnumAnnotation("32 Bits X8L8V8U8", "32-bit Bump Map format format with luminance "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ABGR8888_CLUT.value: UTIL_virtools_types.EnumAnnotation("8 Bits ABGR8888 CLUT", "8 bits indexed CLUT (ABGR) "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ARGB8888_CLUT.value: UTIL_virtools_types.EnumAnnotation("8 Bits ARGB8888 CLUT", "8 bits indexed CLUT (ARGB) "),
UTIL_virtools_types.VX_PIXELFORMAT._4_ABGR8888_CLUT.value: UTIL_virtools_types.EnumAnnotation("4 Bits ABGR8888 CLUT", "4 bits indexed CLUT (ABGR) "),
UTIL_virtools_types.VX_PIXELFORMAT._4_ARGB8888_CLUT.value: UTIL_virtools_types.EnumAnnotation("4 Bits ARGB8888 CLUT", "4 bits indexed CLUT (ARGB) "),
}
#endregion
@ -72,21 +70,21 @@ 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_functions.generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS,
g_Annotation_CK_TEXTURE_SAVEOPTIONS
),
default = RawVirtoolsTexture.cDefaultSaveOptions.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsTexture.cDefaultSaveOptions)
)
video_format: bpy.props.EnumProperty(
name = "Video Format",
description = "The desired surface pixel format in video memory.",
items = UTIL_functions.generate_vt_enums_for_bl_enumprop(
items = UTIL_virtools_types.EnumPropHelper.generate_items(
UTIL_virtools_types.VX_PIXELFORMAT,
g_Annotation_VX_PIXELFORMAT
),
default = RawVirtoolsTexture.cDefaultVideoFormat.value
default = UTIL_virtools_types.EnumPropHelper.to_selection(RawVirtoolsTexture.cDefaultVideoFormat)
)
#region Virtools Texture Getter Setter
@ -98,15 +96,15 @@ def get_raw_virtools_texture(img: bpy.types.Image) -> RawVirtoolsTexture:
props: BBP_PG_virtools_texture = get_virtools_texture(img)
rawdata: RawVirtoolsTexture = RawVirtoolsTexture()
rawdata.cDefaultSaveOptions = UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS(int(props.save_options))
rawdata.mVideoFormat = UTIL_virtools_types.VX_PIXELFORMAT(int(props.video_format))
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)
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 = str(rawdata.mSaveOptions.value)
props.video_format = str(rawdata.mVideoFormat.value)
props.save_options = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mSaveOptions)
props.video_format = UTIL_virtools_types.EnumPropHelper.to_selection(rawdata.mVideoFormat)
#endregion

View File

@ -37,10 +37,6 @@ def clamp_int(v: int, min_val: int, max_val: int) -> int:
elif (v > max_val): return max_val
else: return v
def virtools_name_regulator(name: str | None) -> str:
if name: return name
else: return 'annoymous'
def message_box(message: tuple[str], title: str, icon: str):
"""
Show a message box in Blender. Non-block mode.
@ -55,47 +51,3 @@ def message_box(message: tuple[str], title: str, icon: str):
layout.label(text=item, translate=False)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
#region Virtools Enums Annotation Help
class AnnotationData():
mDisplayName: str
mDescription: str
def __init__(self, display_name: str, description: str):
self.mDisplayName = display_name
self.mDescription = description
InheritingIntEnum_t = typing.TypeVar('InheritingIntEnum_t', bound = enum.IntEnum)
BlenderEnumPropEntry_t = tuple[str, str, str, str | int, int]
def generate_vt_enums_for_bl_enumprop(enum_data: type[InheritingIntEnum_t], anno: dict[int, AnnotationData]) -> tuple[BlenderEnumPropEntry_t, ...]:
# define 2 assist functions
def get_display_name(v: int, fallback: str):
entry: AnnotationData | None = anno.get(v, None)
if entry: return entry.mDisplayName
else: return fallback
def get_description(v: int, fallback: str):
entry: AnnotationData | None = anno.get(v, None)
if entry: return entry.mDescription
else: return fallback
# token, display name, descriptions, icon, index
return tuple(
(str(member.value), get_display_name(member.value, member.name), get_description(member.value, ""), "", member.value) for member in enum_data
)
#endregion
#region Default Encoding of BMap
# Use semicolon split each encodings. Support Western European and Simplified Chinese in default.
g_PyBMapDefaultEncoding: str
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
# See: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
g_PyBMapDefaultEncoding = "1252;936"
else:
# See: https://www.gnu.org/software/libiconv/
g_PyBMapDefaultEncoding = "CP1252;CP936"
#endregion

View File

@ -1,6 +1,6 @@
import bpy
import enum
from . import UTIL_functions
from . import UTIL_virtools_types
from . import PROP_ptrprop_resolver
## Intent
@ -92,7 +92,7 @@ class VirtoolsParams():
vt_encodings: bpy.props.StringProperty(
name = "Encodings",
description = "The encoding list used by Virtools engine to resolve object name. Use `;` to split multiple encodings",
default = UTIL_functions.g_PyBMapDefaultEncoding
default = UTIL_virtools_types.g_PyBMapDefaultEncoding
)
def draw_virtools_params(self, layout: bpy.types.UILayout) -> None:

View File

@ -18,9 +18,6 @@ class _RenameErrorItem():
self.mErrType = err_t
self.mDescription = description
def get_presentation(self):
return "[{}]\t{}".format(_RenameErrorType.cvt_err_from_int_to_str(self.err_type), self.description)
class _RenameErrorReporter():
mErrList: list[_RenameErrorItem]
@ -129,6 +126,19 @@ class _NamingConventionProfile():
self.mParseFct = parse_fct
self.mSetFct = set_fct
def __eq__(self, obj: object) -> bool:
if isinstance(obj, self.__class__):
if obj.mNameFct != self.mNameFct: return False
if obj.mDescFct != self.mDescFct: return False
if obj.mParseFct != self.mParseFct: return False
if obj.mSetFct != self.mSetFct: return False
return True
else:
return False
def __hash__(self) -> int:
return hash((self.mNameFct, self.mDescFct, self.mParseFct, self.mSetFct))
#endregion
#region Naming Convention Declaration
@ -191,7 +201,7 @@ class _ImengyuConvention():
#region Nameing Convention Register
## The native naming convention is Virtools Group
## The native naming convention is
# We treat it as naming convention because we want use a universal interface to process naming converting.
# So Virtools Group can no be seen as a naming convention, but we treat it like naming convention in code.
# The "native" mean this is
@ -206,8 +216,50 @@ _g_NamingConventions: tuple[_NamingConventionProfile, ...] = (
_ImengyuConvention.register(),
)
class _EnumPropHelper():
"""
Operate like UTIL_virtools_types.EnumPropHelper
Return the identifier (index) of naming convention.
"""
@staticmethod
def generate_items() -> tuple[tuple, ...]:
# create a function to filter Virtools Group profile
# and return index at the same time
def naming_convention_iter() -> typing.Iterator[tuple[int, _NamingConventionProfile]]:
for i in range(len(_g_NamingConventions)):
profile: _NamingConventionProfile = _g_NamingConventions[i]
if profile != _g_NativeNamingConvention:
yield (i, profile)
# token, display name, descriptions, icon, index
return tuple(
(
str(idx),
item.mNameFct(),
item.mDescFct(),
"",
idx
) for idx, item in naming_convention_iter()
)
@staticmethod
def get_selection(prop: str) -> int:
return int(prop)
@staticmethod
def to_selection(val: int) -> str:
return str(val)
@staticmethod
def get_virtools_group_identifier() -> int:
return _g_NamingConventions.index(_g_NativeNamingConvention)
#endregion
def name_convention_core(src_ident: int, dst_ident: int) -> None:
# no convert needed
if src_ident == dst_ident: return

View File

@ -1,5 +1,5 @@
import mathutils
import typing
import typing, sys
# extract all declarations in PyBMap
from .PyBMap.virtools_types import *
@ -75,3 +75,80 @@ def vxmatrix_to_blender(self: VxMatrix) -> mathutils.Matrix:
#endregion
#region Blender EnumProperty Creation
class EnumAnnotation():
mDisplayName: str
mDescription: str
def __init__(self, display_name: str, description: str):
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 Virtools Blender Bridge Funcs & Vars
def virtools_name_regulator(name: str | None) -> str:
if name: return name
else: return 'annoymous'
## Default Encoding for PyBMap
# Use semicolon split each encodings. Support Western European and Simplified Chinese in default.
g_PyBMapDefaultEncoding: str
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
# See: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
g_PyBMapDefaultEncoding = "1252;936"
else:
# See: https://www.gnu.org/software/libiconv/
g_PyBMapDefaultEncoding = "CP1252;CP936"
#endregion