add virtools texture support

This commit is contained in:
yyc12345 2023-11-11 13:32:58 +08:00
parent 5bbaa895eb
commit b7ad5c67d4
6 changed files with 246 additions and 103 deletions

View File

@ -1,5 +1,5 @@
import bpy import bpy
import typing import typing, enum
from . import UTIL_functions from . import UTIL_functions
#region Virtools Groups Define & Help Class #region Virtools Groups Define & Help Class
@ -133,60 +133,61 @@ class VirtoolsGroupsHelper():
#region Preset Group Names #region Preset Group Names
_g_VirtoolsGroupsPreset: tuple[str] = ( class VirtoolsGroupsPreset(enum.Enum):
"Sector_01", Sector_01 = "Sector_01"
"Sector_02", Sector_02 = "Sector_02"
"Sector_03", Sector_03 = "Sector_03"
"Sector_04", Sector_04 = "Sector_04"
"Sector_05", Sector_05 = "Sector_05"
"Sector_06", Sector_06 = "Sector_06"
"Sector_07", Sector_07 = "Sector_07"
"Sector_08", Sector_08 = "Sector_08"
"P_Extra_Life", P_Extra_Life = "P_Extra_Life"
"P_Extra_Point", P_Extra_Point = "P_Extra_Point"
"P_Trafo_Paper", P_Trafo_Paper = "P_Trafo_Paper"
"P_Trafo_Stone", P_Trafo_Stone = "P_Trafo_Stone"
"P_Trafo_Wood", P_Trafo_Wood = "P_Trafo_Wood"
"P_Ball_Paper", P_Ball_Paper = "P_Ball_Paper"
"P_Ball_Stone", P_Ball_Stone = "P_Ball_Stone"
"P_Ball_Wood", P_Ball_Wood = "P_Ball_Wood"
"P_Box", P_Box = "P_Box"
"P_Dome", P_Dome = "P_Dome"
"P_Modul_01", P_Modul_01 = "P_Modul_01"
"P_Modul_03", P_Modul_03 = "P_Modul_03"
"P_Modul_08", P_Modul_08 = "P_Modul_08"
"P_Modul_17", P_Modul_17 = "P_Modul_17"
"P_Modul_18", P_Modul_18 = "P_Modul_18"
"P_Modul_19", P_Modul_19 = "P_Modul_19"
"P_Modul_25", P_Modul_25 = "P_Modul_25"
"P_Modul_26", P_Modul_26 = "P_Modul_26"
"P_Modul_29", P_Modul_29 = "P_Modul_29"
"P_Modul_30", P_Modul_30 = "P_Modul_30"
"P_Modul_34", P_Modul_34 = "P_Modul_34"
"P_Modul_37", P_Modul_37 = "P_Modul_37"
"P_Modul_41", P_Modul_41 = "P_Modul_41"
"PS_Levelstart", PS_Levelstart = "PS_Levelstart"
"PE_Levelende", PE_Levelende = "PE_Levelende"
"PC_Checkpoints", PC_Checkpoints = "PC_Checkpoints"
"PR_Resetpoints", PR_Resetpoints = "PR_Resetpoints"
"Sound_HitID_01", Sound_HitID_01 = "Sound_HitID_01"
"Sound_RollID_01", Sound_RollID_01 = "Sound_RollID_01"
"Sound_HitID_02", Sound_HitID_02 = "Sound_HitID_02"
"Sound_RollID_02", Sound_RollID_02 = "Sound_RollID_02"
"Sound_HitID_03", Sound_HitID_03 = "Sound_HitID_03"
"Sound_RollID_03", Sound_RollID_03 = "Sound_RollID_03"
"DepthTestCubes", DepthTestCubes = "DepthTestCubes"
"Phys_Floors", Phys_Floors = "Phys_Floors"
"Phys_FloorRails", Phys_FloorRails = "Phys_FloorRails"
"Phys_FloorStopper", Phys_FloorStopper = "Phys_FloorStopper"
"Shadow" Shadow = "Shadow"
)
_g_VtGrpPresetValues: tuple[str] = tuple(map(lambda x: x.value, VirtoolsGroupsPreset))
class SharedGroupNameInputProperties(): class SharedGroupNameInputProperties():
group_name_source: bpy.props.EnumProperty( group_name_source: bpy.props.EnumProperty(
@ -202,7 +203,7 @@ class SharedGroupNameInputProperties():
description="Pick vanilla Ballance group name.", description="Pick vanilla Ballance group name.",
items=tuple( items=tuple(
# token, display name, descriptions, icon, index # token, display name, descriptions, icon, index
(str(idx), grp, "", "", idx) for idx, grp in enumerate(_g_VirtoolsGroupsPreset) (str(idx), grp, "", "", idx) for idx, grp in enumerate(_g_VtGrpPresetValues)
), ),
) )
@ -223,7 +224,7 @@ class SharedGroupNameInputProperties():
if self.group_name_source == 'CUSTOM': if self.group_name_source == 'CUSTOM':
return self.custom_group_name return self.custom_group_name
else: else:
return _g_VirtoolsGroupsPreset[int(self.preset_group_name)] return _g_VtGrpPresetValues[int(self.preset_group_name)]
#endregion #endregion

View File

@ -1,15 +1,11 @@
import bpy import bpy
import typing, enum import typing, enum
from . import UTIL_virtools_types, UTIL_functions from . import UTIL_virtools_types, UTIL_functions
from . import PROP_virtools_texture
#region Enums Annotations #region Enums Annotations
class AnnotationData(): from .UTIL_functions import AnnotationData, BlenderEnumPropEntry_t, generate_vt_enums_for_bl_enumprop
mDisplayName: str
mDescription: str
def __init__(self, display_name: str, description: str):
self.mDisplayName = display_name
self.mDescription = description
g_Annotation_VXTEXTURE_BLENDMODE: dict[int, AnnotationData] = { 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_DECAL.value: AnnotationData("Decal", "Texture replace any material information "),
@ -75,25 +71,6 @@ g_Annotation_VXCMPFUNC: dict[int, AnnotationData] = {
UTIL_virtools_types.VXCMPFUNC.VXCMP_ALWAYS.value: AnnotationData("Always", "Always accept the test. "), UTIL_virtools_types.VXCMPFUNC.VXCMP_ALWAYS.value: AnnotationData("Always", "Always accept the test. "),
} }
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 #endregion
class RawVirtoolsMaterial(): class RawVirtoolsMaterial():
@ -273,7 +250,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
texture_blend_mode: bpy.props.EnumProperty( texture_blend_mode: bpy.props.EnumProperty(
name = "Texture Blend", name = "Texture Blend",
description = "Texture blend mode", description = "Texture blend mode",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXTEXTURE_BLENDMODE, UTIL_virtools_types.VXTEXTURE_BLENDMODE,
g_Annotation_VXTEXTURE_BLENDMODE g_Annotation_VXTEXTURE_BLENDMODE
), ),
@ -283,7 +260,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
texture_min_mode: bpy.props.EnumProperty( texture_min_mode: bpy.props.EnumProperty(
name = "Filter Min", name = "Filter Min",
description = "Texture filter mode when the texture is minified", description = "Texture filter mode when the texture is minified",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXTEXTURE_FILTERMODE, UTIL_virtools_types.VXTEXTURE_FILTERMODE,
g_Annotation_VXTEXTURE_FILTERMODE g_Annotation_VXTEXTURE_FILTERMODE
), ),
@ -293,7 +270,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
texture_mag_mode: bpy.props.EnumProperty( texture_mag_mode: bpy.props.EnumProperty(
name = "Filter Mag", name = "Filter Mag",
description = "Texture filter mode when the texture is magnified", description = "Texture filter mode when the texture is magnified",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXTEXTURE_FILTERMODE, UTIL_virtools_types.VXTEXTURE_FILTERMODE,
g_Annotation_VXTEXTURE_FILTERMODE g_Annotation_VXTEXTURE_FILTERMODE
), ),
@ -303,7 +280,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
texture_address_mode: bpy.props.EnumProperty( texture_address_mode: bpy.props.EnumProperty(
name = "Address Mode", name = "Address Mode",
description = "The address mode controls how the texture coordinates outside the range 0..1", description = "The address mode controls how the texture coordinates outside the range 0..1",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXTEXTURE_ADDRESSMODE, UTIL_virtools_types.VXTEXTURE_ADDRESSMODE,
g_Annotation_VXTEXTURE_ADDRESSMODE g_Annotation_VXTEXTURE_ADDRESSMODE
), ),
@ -313,7 +290,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
source_blend: bpy.props.EnumProperty( source_blend: bpy.props.EnumProperty(
name = "Source Blend", name = "Source Blend",
description = "Source blend factor", description = "Source blend factor",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXBLEND_MODE, UTIL_virtools_types.VXBLEND_MODE,
g_Annotation_VXBLEND_MODE g_Annotation_VXBLEND_MODE
), ),
@ -323,7 +300,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
dest_blend: bpy.props.EnumProperty( dest_blend: bpy.props.EnumProperty(
name = "Destination Blend", name = "Destination Blend",
description = "Destination blend factor", description = "Destination blend factor",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXBLEND_MODE, UTIL_virtools_types.VXBLEND_MODE,
g_Annotation_VXBLEND_MODE g_Annotation_VXBLEND_MODE
), ),
@ -333,7 +310,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
fill_mode: bpy.props.EnumProperty( fill_mode: bpy.props.EnumProperty(
name = "Fill Mode", name = "Fill Mode",
description = "Fill mode", description = "Fill mode",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXFILL_MODE, UTIL_virtools_types.VXFILL_MODE,
g_Annotation_VXFILL_MODE g_Annotation_VXFILL_MODE
), ),
@ -343,7 +320,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
shade_mode: bpy.props.EnumProperty( shade_mode: bpy.props.EnumProperty(
name = "Shade Mode", name = "Shade Mode",
description = "Shade mode", description = "Shade mode",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXSHADE_MODE, UTIL_virtools_types.VXSHADE_MODE,
g_Annotation_VXSHADE_MODE g_Annotation_VXSHADE_MODE
), ),
@ -387,7 +364,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
alpha_func: bpy.props.EnumProperty( alpha_func: bpy.props.EnumProperty(
name = "Alpha Test Function", name = "Alpha Test Function",
description = "Alpha comparision function", description = "Alpha comparision function",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXCMPFUNC, UTIL_virtools_types.VXCMPFUNC,
g_Annotation_VXCMPFUNC g_Annotation_VXCMPFUNC
), ),
@ -397,7 +374,7 @@ class BBP_PG_virtools_material(bpy.types.PropertyGroup):
z_func: bpy.props.EnumProperty( z_func: bpy.props.EnumProperty(
name = "Z Compare Function", name = "Z Compare Function",
description = "Z Comparison function", description = "Z Comparison function",
items = _generate_vt_enums_for_bl_enumprop( items = generate_vt_enums_for_bl_enumprop(
UTIL_virtools_types.VXCMPFUNC, UTIL_virtools_types.VXCMPFUNC,
g_Annotation_VXCMPFUNC g_Annotation_VXCMPFUNC
), ),
@ -715,6 +692,12 @@ class BBP_PT_virtools_material(bpy.types.Panel):
layout.separator() layout.separator()
layout.label(text="Texture Parameters") layout.label(text="Texture Parameters")
layout.prop(props, 'texture', emboss = True) layout.prop(props, 'texture', emboss = True)
if props.texture is not None:
# if we have texture, we show its virtools texture data
PROP_virtools_texture.draw_virtools_texture(props.texture, layout)
layout.separator()
layout.prop(props, 'texture_blend_mode') layout.prop(props, 'texture_blend_mode')
layout.prop(props, 'texture_min_mode') layout.prop(props, 'texture_min_mode')
layout.prop(props, 'texture_mag_mode') layout.prop(props, 'texture_mag_mode')
@ -743,17 +726,6 @@ class BBP_PT_virtools_material(bpy.types.Panel):
if props.enable_z_write: if props.enable_z_write:
layout.prop(props, 'z_func') layout.prop(props, 'z_func')
g_BldClasses: tuple[typing.Any, ...] = (
# basic property
BBP_PG_virtools_material,
# 2 operator used in panel
BBP_OT_apply_virtools_material,
BBP_OT_preset_virtools_material,
# panel
BBP_PT_virtools_material,
)
def register(): def register():
bpy.utils.register_class(BBP_PG_virtools_material) bpy.utils.register_class(BBP_PG_virtools_material)
bpy.utils.register_class(BBP_OT_apply_virtools_material) bpy.utils.register_class(BBP_OT_apply_virtools_material)

View File

@ -0,0 +1,138 @@
import bpy
import typing
from . import UTIL_virtools_types, UTIL_functions
#region Anno Data
from .UTIL_functions import AnnotationData, generate_vt_enums_for_bl_enumprop
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_VX_PIXELFORMAT: dict[int, AnnotationData] = {
UTIL_virtools_types.VX_PIXELFORMAT._32_ARGB8888.value: AnnotationData("_32_ARGB8888", "32-bit ARGB pixel format with alpha "),
UTIL_virtools_types.VX_PIXELFORMAT._32_RGB888.value: AnnotationData("_32_RGB888", "32-bit RGB pixel format without alpha "),
UTIL_virtools_types.VX_PIXELFORMAT._24_RGB888.value: AnnotationData("_24_RGB888", "24-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_RGB565.value: AnnotationData("_16_RGB565", "16-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_RGB555.value: AnnotationData("_16_RGB555", "16-bit RGB pixel format (5 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB1555.value: AnnotationData("_16_ARGB1555", "16-bit ARGB pixel format (5 bits per color + 1 bit for alpha) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB4444.value: AnnotationData("_16_ARGB4444", "16-bit ARGB pixel format (4 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._8_RGB332.value: AnnotationData("_8_RGB332", "8-bit RGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ARGB2222.value: AnnotationData("_8_ARGB2222", "8-bit ARGB pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_ABGR8888.value: AnnotationData("_32_ABGR8888", "32-bit ABGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_RGBA8888.value: AnnotationData("_32_RGBA8888", "32-bit RGBA pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_BGRA8888.value: AnnotationData("_32_BGRA8888", "32-bit BGRA pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._32_BGR888.value: AnnotationData("_32_BGR888", "32-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._24_BGR888.value: AnnotationData("_24_BGR888", "24-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_BGR565.value: AnnotationData("_16_BGR565", "16-bit BGR pixel format "),
UTIL_virtools_types.VX_PIXELFORMAT._16_BGR555.value: AnnotationData("_16_BGR555", "16-bit BGR pixel format (5 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ABGR1555.value: AnnotationData("_16_ABGR1555", "16-bit ABGR pixel format (5 bits per color + 1 bit for alpha) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_ABGR4444.value: AnnotationData("_16_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_V8U8", "16-bit Bump Map format format (8 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._32_V16U16.value: AnnotationData("_32_V16U16", "32-bit Bump Map format format (16 bits per color) "),
UTIL_virtools_types.VX_PIXELFORMAT._16_L6V5U5.value: AnnotationData("_16_L6V5U5", "16-bit Bump Map format format with luminance "),
UTIL_virtools_types.VX_PIXELFORMAT._32_X8L8V8U8.value: AnnotationData("_32_X8L8V8U8", "32-bit Bump Map format format with luminance "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ABGR8888_CLUT.value: AnnotationData("_8_ABGR8888_CLUT", "8 bits indexed CLUT (ABGR) "),
UTIL_virtools_types.VX_PIXELFORMAT._8_ARGB8888_CLUT.value: AnnotationData("_8_ARGB8888_CLUT", "8 bits indexed CLUT (ARGB) "),
UTIL_virtools_types.VX_PIXELFORMAT._4_ABGR8888_CLUT.value: AnnotationData("_4_ABGR8888_CLUT", "4 bits indexed CLUT (ABGR) "),
UTIL_virtools_types.VX_PIXELFORMAT._4_ARGB8888_CLUT.value: AnnotationData("_4_ARGB8888_CLUT", "4 bits indexed CLUT (ARGB) "),
}
#endregion
class RawVirtoolsTexture():
# Instance Member Declarations
mSaveOptions: UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS
mVideoFormat: UTIL_virtools_types.VX_PIXELFORMAT
# Default Value Declarations
cDefaultSaveOptions: typing.ClassVar[UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS] = UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_RAWDATA
cDefaultVideoFormat: typing.ClassVar[UTIL_virtools_types.VX_PIXELFORMAT] = UTIL_virtools_types.VX_PIXELFORMAT._16_ARGB1555
def __init__(self, **kwargs):
# assign default value for each component
self.mSaveOptions = kwargs.get('mSaveOptions', RawVirtoolsTexture.cDefaultSaveOptions)
self.mVideoFormat = kwargs.get('mVideoFormat', RawVirtoolsTexture.cDefaultVideoFormat)
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(
UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS,
g_Annotation_CK_TEXTURE_SAVEOPTIONS
),
default = RawVirtoolsTexture.cDefaultSaveOptions.value
)
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(
UTIL_virtools_types.VX_PIXELFORMAT,
g_Annotation_VX_PIXELFORMAT
),
default = RawVirtoolsTexture.cDefaultVideoFormat.value
)
#region Getter Setter
def get_virtools_texture(img: bpy.types.Image) -> BBP_PG_virtools_texture:
return img.virtools_texture
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))
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)
#endregion
#region Drawer
# because Image do not have its unique properties window
# so we only can draw virtools texture properties in other window
# we provide various function to help draw property
def draw_virtools_texture(img: bpy.types.Image, layout: bpy.types.UILayout):
props: BBP_PG_virtools_texture = get_virtools_texture(img)
layout.prop(props, 'save_options')
layout.prop(props, 'video_format')
#endregion
def register():
bpy.utils.register_class(BBP_PG_virtools_texture)
# add into image metadata
bpy.types.Image.virtools_texture = bpy.props.PointerProperty(type = BBP_PG_virtools_texture)
def unregister():
# del from image metadata
del bpy.types.Image.virtools_texture
bpy.utils.unregister_class(BBP_PG_virtools_texture)

View File

@ -52,7 +52,7 @@ class MeshWriterIngredient():
mVertexNormal: typing.Iterator[UTIL_virtools_types.VxVector3] | None mVertexNormal: typing.Iterator[UTIL_virtools_types.VxVector3] | None
mVertexUV: typing.Iterator[UTIL_virtools_types.VxVector2] | None mVertexUV: typing.Iterator[UTIL_virtools_types.VxVector2] | None
mFace: typing.Iterator[FaceData] | None mFace: typing.Iterator[FaceData] | None
mMaterial: typing.Iterator[bpy.types.Material] | None mMaterial: typing.Iterator[bpy.types.Material | None] | None
def __init__(self): def __init__(self):
self.mVertexPosition = None self.mVertexPosition = None
@ -241,7 +241,7 @@ class MeshReader():
return len(self.__mAssocMesh.materials) return len(self.__mAssocMesh.materials)
def get_material_slot(self) -> typing.Iterator[bpy.types.Material]: def get_material_slot(self) -> typing.Iterator[bpy.types.Material | None]:
""" """
@remark This generator may return None if this slot do not link to may material. @remark This generator may return None if this slot do not link to may material.
""" """
@ -338,11 +338,11 @@ class MeshWriter():
## Material Slot. ## Material Slot.
# Each item is unique make sure by __mMtlSlotMap # Each item is unique make sure by __mMtlSlotMap
__mMtlSlot: list[bpy.types.Material] __mMtlSlot: list[bpy.types.Material | None]
## The map to make sure every item in __mMtlSlot is unique. ## The map to make sure every item in __mMtlSlot is unique.
# Key is bpy.types.Material # Key is bpy.types.Material
# Value is key's index in __mMtlSlot. # Value is key's index in __mMtlSlot.
__mMtlSlotMap: dict[bpy.types.Material, int] __mMtlSlotMap: dict[bpy.types.Material | None, int]
def __init__(self, assoc_mesh: bpy.types.Mesh): def __init__(self, assoc_mesh: bpy.types.Mesh):
self.__mAssocMesh = assoc_mesh self.__mAssocMesh = assoc_mesh

View File

@ -1,5 +1,5 @@
import bpy import bpy
import math, typing import math, typing, enum
class BBPException(Exception): class BBPException(Exception):
""" """
@ -56,3 +56,33 @@ def message_box(message: tuple[str], title: str, icon: str):
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon) 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

View File

@ -23,7 +23,7 @@ if "bpy" in locals():
#endregion #endregion
from . import PROP_preferences, PROP_virtools_material, PROP_ballance_element, PROP_virtools_group from . import PROP_preferences, PROP_virtools_material, PROP_virtools_texture, PROP_ballance_element, PROP_virtools_group
from . import OP_IMPORT_bmfile, OP_EXPORT_bmfile, OP_IMPORT_virtools, OP_EXPORT_virtools from . import OP_IMPORT_bmfile, OP_EXPORT_bmfile, OP_IMPORT_virtools, OP_EXPORT_virtools
from . import OP_UV_flatten_uv, OP_UV_rail_uv from . import OP_UV_flatten_uv, OP_UV_rail_uv
@ -86,6 +86,7 @@ def register() -> None:
# register module # register module
PROP_preferences.register() PROP_preferences.register()
PROP_virtools_material.register() PROP_virtools_material.register()
PROP_virtools_texture.register()
PROP_ballance_element.register() PROP_ballance_element.register()
PROP_virtools_group.register() PROP_virtools_group.register()
@ -128,6 +129,7 @@ def unregister() -> None:
PROP_virtools_group.unregister() PROP_virtools_group.unregister()
PROP_ballance_element.unregister() PROP_ballance_element.unregister()
PROP_virtools_texture.unregister()
PROP_virtools_material.unregister() PROP_virtools_material.unregister()
PROP_preferences.unregister() PROP_preferences.unregister()