From 729e12ed7b992d0735c29b7923cf7e892b942bf0 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 30 Dec 2024 17:53:42 +0800 Subject: [PATCH] feat: update virtools file importer and exporter - use panel to organise property group in virtools file importer and exporter. - move all ballance params and virtools params into ioport_shared module and enable different showcase according to the argument passed to show function presenting whether current window is importer or exporter. - add multiple type ignore to ignore the error of bpy operator member field type hints. --- bbp_ng/OP_EXPORT_virtools.py | 87 ++++++--------------- bbp_ng/OP_IMPORT_virtools.py | 10 +-- bbp_ng/PROP_ballance_element.py | 4 +- bbp_ng/PROP_bme_material.py | 4 +- bbp_ng/PROP_preferences.py | 4 +- bbp_ng/PROP_ptrprop_resolver.py | 6 +- bbp_ng/PROP_virtools_group.py | 6 +- bbp_ng/PROP_virtools_mesh.py | 2 +- bbp_ng/PROP_virtools_texture.py | 4 +- bbp_ng/UTIL_file_browser.py | 12 +-- bbp_ng/UTIL_file_io.py | 12 ++- bbp_ng/UTIL_ioport_shared.py | 131 ++++++++++++++++++++++++++++---- 12 files changed, 172 insertions(+), 110 deletions(-) diff --git a/bbp_ng/OP_EXPORT_virtools.py b/bbp_ng/OP_EXPORT_virtools.py index cb03da3..b56d1cf 100644 --- a/bbp_ng/OP_EXPORT_virtools.py +++ b/bbp_ng/OP_EXPORT_virtools.py @@ -3,44 +3,15 @@ from bpy_extras.wm_utils.progress_report import ProgressReport import tempfile, os, typing from . import PROP_preferences, UTIL_ioport_shared from . import UTIL_virtools_types, UTIL_functions, UTIL_file_browser, UTIL_blender_mesh, UTIL_ballance_texture, UTIL_icons_manager, UTIL_naming_convension -from . import PROP_virtools_group, PROP_virtools_material, PROP_virtools_mesh, PROP_virtools_texture, PROP_ballance_map_info +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): +class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtoolsFile, UTIL_ioport_shared.ExportParams, UTIL_ioport_shared.VirtoolsParams, UTIL_ioport_shared.BallanceParams): """Export Virtools File""" bl_idname = "bbp.export_virtools" bl_label = "Export Virtools File" bl_options = {'PRESET'} - 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 = _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.generate_items(), - default = _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.to_selection(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL) - ) # type: ignore - - use_compress: bpy.props.BoolProperty( - name="Use Compress", - description = "Whether use ZLib to compress result when saving composition.", - default = True, - ) # type: ignore - - compress_level: bpy.props.IntProperty( - name = "Compress Level", - description = "The ZLib compress level used by Virtools Engine when saving composition.", - min = 1, max = 9, - default = 5, - ) # type: ignore - - successive_sector: bpy.props.BoolProperty( - name="Successive Sector", - description = "Whether order exporter to use document specified sector count to make sure sector is successive.", - default = True, - ) # type: ignore - @classmethod def poll(self, context): return ( @@ -58,15 +29,26 @@ class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtool ) return {'CANCELLED'} + # check texture save option to prevent real stupid user. + texture_save_opt = self.general_get_texture_save_opt() + if texture_save_opt == UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_USEGLOBAL: + UTIL_functions.message_box( + ('You can not specify "Use Global" as global texture save option!', ), + 'Wrong Parameters', + UTIL_icons_manager.BlenderPresetIcons.Error.value + ) + return {'CANCELLED'} + # start exporting with UTIL_ioport_shared.ExportEditModeBackup() as editmode_guard: _export_virtools( self.general_get_filename(), self.general_get_vt_encodings(), - _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.get_selection(self.texture_save_opt), - self.use_compress, - self.compress_level, - self.successive_sector, + texture_save_opt, + self.general_get_use_compress(), + self.general_get_compress_level(), + self.general_get_successive_sector(), + self.general_get_successive_sector_count(), objls ) @@ -75,30 +57,9 @@ class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtool def draw(self, context): layout = self.layout - layout.label(text = 'Export Target') - self.draw_export_params(layout.box()) - - layout.separator() - layout.label(text = 'Virtools Params') - box = layout.box() - self.draw_virtools_params(box) - - box.separator() - box.label(text = 'Global Texture Save Option') - box.prop(self, 'texture_save_opt', text = '') - - box.separator() - box.prop(self, 'use_compress') - if self.use_compress: - box.prop(self, 'compress_level') - - # show sector info to notice user - layout.separator() - layout.label(text = 'Ballance Params') - box = layout.box() - map_info: PROP_ballance_map_info.RawBallanceMapInfo = PROP_ballance_map_info.get_raw_ballance_map_info(bpy.context.scene) - box.prop(self, 'successive_sector') - box.label(text = f'Map Sectors: {map_info.mSectorCount}') + self.draw_export_params(layout) + self.draw_virtools_params(layout, False) + self.draw_ballance_params(layout, False) _TObj3dPair = tuple[bpy.types.Object, bmap.BM3dObject] _TMeshPair = tuple[bpy.types.Object, bpy.types.Mesh, bmap.BMMesh] @@ -112,6 +73,7 @@ def _export_virtools( use_compress_: bool, compress_level_: int, successive_sector_: bool, + successive_sector_count_: int, export_objects: tuple[bpy.types.Object, ...] ) -> None: @@ -131,7 +93,7 @@ def _export_virtools( obj3d_crets: tuple[_TObj3dPair, ...] = _prepare_virtools_3dobjects( writer, progress, export_objects) # export group and 3dobject by prepared 3dobject - _export_virtools_groups(writer, progress, successive_sector_, obj3d_crets) + _export_virtools_groups(writer, progress, successive_sector_, successive_sector_count_, obj3d_crets) mesh_crets: tuple[_TMeshPair, ...] = _export_virtools_3dobjects( writer, progress, obj3d_crets) # export mesh @@ -181,6 +143,7 @@ def _export_virtools_groups( writer: bmap.BMFileWriter, progress: ProgressReport, successive_sector: bool, + successive_sector_count: int, obj3d_crets: tuple[_TObj3dPair, ...] ) -> None: # create virtools group @@ -197,9 +160,7 @@ def _export_virtools_groups( # # So we create all needed sector group in here to make sure exported virtools file can be read by Ballancde correctly. if successive_sector: - map_info: PROP_ballance_map_info.RawBallanceMapInfo - map_info = PROP_ballance_map_info.get_raw_ballance_map_info(bpy.context.scene) - for i in range(map_info.mSectorCount): + for i in range(successive_sector_count): gp_name: str = UTIL_naming_convension.build_name_from_sector_index(i + 1) vtgroup: bmap.BMGroup | None = group_cret_map.get(gp_name, None) if vtgroup is None: diff --git a/bbp_ng/OP_IMPORT_virtools.py b/bbp_ng/OP_IMPORT_virtools.py index 670bd9f..0a56671 100644 --- a/bbp_ng/OP_IMPORT_virtools.py +++ b/bbp_ng/OP_IMPORT_virtools.py @@ -6,7 +6,7 @@ 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, PROP_ballance_map_info from .PyBMap import bmap_wrapper as bmap -class BBP_OT_import_virtools(bpy.types.Operator, UTIL_file_browser.ImportVirtoolsFile, UTIL_ioport_shared.ImportParams, UTIL_ioport_shared.VirtoolsParams): +class BBP_OT_import_virtools(bpy.types.Operator, UTIL_file_browser.ImportVirtoolsFile, UTIL_ioport_shared.ImportParams, UTIL_ioport_shared.VirtoolsParams, UTIL_ioport_shared.BallanceParams): """Import Virtools File""" bl_idname = "bbp.import_virtools" bl_label = "Import Virtools File" @@ -29,11 +29,9 @@ class BBP_OT_import_virtools(bpy.types.Operator, UTIL_file_browser.ImportVirtool def draw(self, context): layout = self.layout - layout.label(text = 'Conflict Options') - self.draw_import_params(layout.box()) - layout.separator() - layout.label(text = 'Virtools Params') - self.draw_virtools_params(layout.box()) + self.draw_import_params(layout) + self.draw_virtools_params(layout, True) + self.draw_ballance_params(layout, True) def _import_virtools(file_name_: str, encodings_: tuple[str], resolver: UTIL_ioport_shared.ConflictResolver) -> None: # create temp folder diff --git a/bbp_ng/PROP_ballance_element.py b/bbp_ng/PROP_ballance_element.py index f3bcf00..dbc216e 100644 --- a/bbp_ng/PROP_ballance_element.py +++ b/bbp_ng/PROP_ballance_element.py @@ -97,12 +97,12 @@ class BBP_PG_ballance_element(bpy.types.PropertyGroup): element_id: bpy.props.IntProperty( name = "Element Id", default = 0 - ) + ) # type: ignore mesh_ptr: bpy.props.PointerProperty( name = "Mesh", type = bpy.types.Mesh - ) + ) # type: ignore def get_ballance_elements(scene: bpy.types.Scene) -> bpy.types.CollectionProperty: return scene.ballance_elements diff --git a/bbp_ng/PROP_bme_material.py b/bbp_ng/PROP_bme_material.py index 17191c5..3a8584a 100644 --- a/bbp_ng/PROP_bme_material.py +++ b/bbp_ng/PROP_bme_material.py @@ -73,12 +73,12 @@ class BBP_PG_bme_material(bpy.types.PropertyGroup): bme_material_name: bpy.props.StringProperty( name = "Name", default = "" - ) + ) # type: ignore material_ptr: bpy.props.PointerProperty( name = "Material", type = bpy.types.Material - ) + ) # type: ignore def get_bme_materials(scene: bpy.types.Scene) -> bpy.types.CollectionProperty: return scene.bme_materials diff --git a/bbp_ng/PROP_preferences.py b/bbp_ng/PROP_preferences.py index 3605af3..5982f59 100644 --- a/bbp_ng/PROP_preferences.py +++ b/bbp_ng/PROP_preferences.py @@ -24,13 +24,13 @@ class BBPPreferences(bpy.types.AddonPreferences): description = "The path to folder which will be used by this plugin to get external Ballance texture.", subtype='DIR_PATH', default = RawPreferences.cBallanceTextureFolder, - ) + ) # type: ignore no_component_collection: bpy.props.StringProperty( name = "No Component Collection", description = "(Import) The object which stored in this collectiion will not be saved as component. (Export) All forced no component objects will be stored in this collection", default = RawPreferences.cNoComponentCollection, - ) + ) # type: ignore def draw(self, context): layout = self.layout diff --git a/bbp_ng/PROP_ptrprop_resolver.py b/bbp_ng/PROP_ptrprop_resolver.py index 6173608..de99f3f 100644 --- a/bbp_ng/PROP_ptrprop_resolver.py +++ b/bbp_ng/PROP_ptrprop_resolver.py @@ -10,19 +10,19 @@ class BBP_PG_ptrprop_resolver(bpy.types.PropertyGroup): name = "Material", description = "The material used for rail", type = bpy.types.Material, - ) + ) # type: ignore export_collection: bpy.props.PointerProperty( type = bpy.types.Collection, name = "Collection", description = "The collection exported. Nested collections allowed." - ) + ) # type: ignore export_object: bpy.props.PointerProperty( type = bpy.types.Object, name = "Object", description = "The object exported" - ) + ) # type: ignore def get_ptrprop_resolver() -> BBP_PG_ptrprop_resolver: return bpy.context.scene.bbp_ptrprop_resolver diff --git a/bbp_ng/PROP_virtools_group.py b/bbp_ng/PROP_virtools_group.py index c183d62..e782abf 100644 --- a/bbp_ng/PROP_virtools_group.py +++ b/bbp_ng/PROP_virtools_group.py @@ -255,19 +255,19 @@ class SharedGroupNameInputProperties(): ('DEFINED', "Predefined", "Pre-defined group name."), ('CUSTOM', "Custom", "User specified group name."), ), - ) + ) # type: ignore preset_group_name: bpy.props.EnumProperty( name = "Group Name", description = "Pick vanilla Ballance group name.", items = _g_EnumHelper_Group.generate_items(), - ) + ) # type: ignore custom_group_name: bpy.props.StringProperty( name = "Custom Group Name", description = "Input your custom group name.", default = "", - ) + ) # type: ignore def draw_group_name_input(self, layout: bpy.types.UILayout) -> None: layout.prop(self, 'group_name_source', expand = True) diff --git a/bbp_ng/PROP_virtools_mesh.py b/bbp_ng/PROP_virtools_mesh.py index 25eb8c4..b3ff5b2 100644 --- a/bbp_ng/PROP_virtools_mesh.py +++ b/bbp_ng/PROP_virtools_mesh.py @@ -25,7 +25,7 @@ class BBP_PG_virtools_mesh(bpy.types.PropertyGroup): description = "Lighting mode of the mesh.", items = _g_Helper_VXMESH_LITMODE.generate_items(), default = _g_Helper_VXMESH_LITMODE.to_selection(RawVirtoolsMesh.cDefaultLitMode) - ) + ) # type: ignore # Getter Setter diff --git a/bbp_ng/PROP_virtools_texture.py b/bbp_ng/PROP_virtools_texture.py index dffcebe..07de7dd 100644 --- a/bbp_ng/PROP_virtools_texture.py +++ b/bbp_ng/PROP_virtools_texture.py @@ -30,14 +30,14 @@ class BBP_PG_virtools_texture(bpy.types.PropertyGroup): 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 = _g_Helper_CK_TEXTURE_SAVEOPTIONS.generate_items(), default = _g_Helper_CK_TEXTURE_SAVEOPTIONS.to_selection(RawVirtoolsTexture.cDefaultSaveOptions) - ) + ) # type: ignore video_format: bpy.props.EnumProperty( name = "Video Format", description = "The desired surface pixel format in video memory.", items = _g_Helper_VX_PIXELFORMAT.generate_items(), default = _g_Helper_VX_PIXELFORMAT.to_selection(RawVirtoolsTexture.cDefaultVideoFormat) - ) + ) # type: ignore #region Virtools Texture Getter Setter diff --git a/bbp_ng/UTIL_file_browser.py b/bbp_ng/UTIL_file_browser.py index 1009939..c0429dd 100644 --- a/bbp_ng/UTIL_file_browser.py +++ b/bbp_ng/UTIL_file_browser.py @@ -29,7 +29,7 @@ class ImportBallanceImage(bpy_extras.io_utils.ImportHelper): filter_glob: bpy.props.StringProperty( default = "*.bmp;*.tga", options = {'HIDDEN'} - ) + ) # type: ignore def general_set_filename(self, filename: str) -> None: self.filepath = filename @@ -44,7 +44,7 @@ class ImportBmxFile(bpy_extras.io_utils.ImportHelper): filter_glob: bpy.props.StringProperty( default = "*.bmx", options = {'HIDDEN'} - ) + ) # type: ignore def general_get_filename(self) -> str: return self.filepath @@ -56,7 +56,7 @@ class ExportBmxFile(bpy_extras.io_utils.ExportHelper): filter_glob: bpy.props.StringProperty( default = "*.bmx", options = {'HIDDEN'} - ) + ) # type: ignore def general_get_filename(self) -> str: return self.filepath @@ -68,7 +68,7 @@ class ImportVirtoolsFile(bpy_extras.io_utils.ImportHelper): filter_glob: bpy.props.StringProperty( default = "*.nmo;*.cmo;*.vmo", options = {'HIDDEN'} - ) + ) # type: ignore def general_get_filename(self) -> str: return self.filepath @@ -80,7 +80,7 @@ class ExportVirtoolsFile(bpy_extras.io_utils.ExportHelper): filter_glob: bpy.props.StringProperty( default = "*.nmo", options = {'HIDDEN'} - ) + ) # type: ignore def general_get_filename(self) -> str: return self.filepath @@ -94,7 +94,7 @@ class ImportDirectory(bpy_extras.io_utils.ImportHelper): filter_glob: bpy.props.StringProperty( default = "", options = {'HIDDEN'} - ) + ) # type: ignore def general_get_directory(self) -> str: return self.directory diff --git a/bbp_ng/UTIL_file_io.py b/bbp_ng/UTIL_file_io.py index a887d29..ecb94e5 100644 --- a/bbp_ng/UTIL_file_io.py +++ b/bbp_ng/UTIL_file_io.py @@ -2,6 +2,10 @@ import bpy, mathutils import struct, os, io, typing from . import UTIL_virtools_types +## MARK: +# This module may be deprecated because the host refering this module, +# BM file import and export is no longer existing. + _FileWriter_t = io.BufferedWriter _FileReader_t = io.BufferedReader @@ -31,10 +35,10 @@ def write_float(fs: _FileWriter_t, fl: float) -> None: fs.write(struct.pack(" None: - fs.write(struct.pack("<16f", *mat.to_tuple())) + fs.write(struct.pack("<16f", *mat.to_const())) def write_color(fs: _FileWriter_t, colors: UTIL_virtools_types.VxColor) -> None: - fs.write(struct.pack(" None: fs.write(struct.pack('<' + str(count) + 'I', *vals)) @@ -67,11 +71,11 @@ def read_string(fs: _FileReader_t) -> str: count = read_uint32(fs) return fs.read(count * 4).decode("utf_32_le") -def read_bool(fs: _FileReader_t) -> None: +def read_bool(fs: _FileReader_t) -> bool: return read_uint8(fs) != 0 def read_world_materix(fs: _FileReader_t, mat: UTIL_virtools_types.VxMatrix) -> None: - mat.from_tuple(struct.unpack("<16f", fs.read(16 * 4))) + mat.from_const(struct.unpack("<16f", fs.read(16 * 4))) def read_color(fs: _FileReader_t, target: UTIL_virtools_types.VxColor) -> None: target.from_const_rgb(struct.unpack("fff", fs.read(3 * 4))) diff --git a/bbp_ng/UTIL_ioport_shared.py b/bbp_ng/UTIL_ioport_shared.py index 5d18ece..7bc31ae 100644 --- a/bbp_ng/UTIL_ioport_shared.py +++ b/bbp_ng/UTIL_ioport_shared.py @@ -1,7 +1,7 @@ import bpy import enum, typing from . import UTIL_virtools_types, UTIL_functions -from . import PROP_ptrprop_resolver +from . import PROP_ptrprop_resolver, PROP_ballance_map_info ## Intent # Some importer or exporter may share same properties. @@ -152,14 +152,20 @@ class ImportParams(): ) # type: ignore def draw_import_params(self, layout: bpy.types.UILayout) -> None: - layout.label(text = 'Object Name Conflict') - layout.prop(self, 'object_conflict_strategy', text = '') - layout.label(text = 'Mesh Name Conflict') - layout.prop(self, 'mesh_conflict_strategy', text = '') - layout.label(text = 'Material Name Conflict') - layout.prop(self, 'material_conflict_strategy', text = '') - layout.label(text = 'Texture Name Conflict') - layout.prop(self, 'texture_conflict_strategy', text = '') + header: bpy.types.UILayout + body: bpy.types.UILayout + header, body = layout.panel("BBP_PT_ioport_shared_import_params", default_closed=False) + header.label(text = 'Import Parameters') + if body is None: return + + body.label(text = 'Object Name Conflict') + body.prop(self, 'object_conflict_strategy', text = '') + body.label(text = 'Mesh Name Conflict') + body.prop(self, 'mesh_conflict_strategy', text = '') + body.label(text = 'Material Name Conflict') + body.prop(self, 'material_conflict_strategy', text = '') + body.label(text = 'Texture Name Conflict') + body.prop(self, 'texture_conflict_strategy', text = '') def general_get_texture_conflict_strategy(self) -> ConflictStrategy: return _g_EnumHelper_ConflictStrategy.get_selection(self.texture_conflict_strategy) @@ -191,16 +197,22 @@ class ExportParams(): ) # type: ignore def draw_export_params(self, layout: bpy.types.UILayout) -> None: + header: bpy.types.UILayout + body: bpy.types.UILayout + header, body = layout.panel("BBP_PT_ioport_shared_export_params", default_closed=False) + header.label(text = 'Export Parameters') + if body is None: return + # make prop expand horizontaly, not vertical. - sublayout = layout.row() + horizon_body = body.row() # draw switch - sublayout.prop(self, "export_mode", expand = True) + horizon_body.prop(self, "export_mode", expand = True) # draw picker if self.export_mode == 'COLLECTION': - PROP_ptrprop_resolver.draw_export_collection(layout) + PROP_ptrprop_resolver.draw_export_collection(body) elif self.export_mode == 'OBJECT': - PROP_ptrprop_resolver.draw_export_object(layout) + PROP_ptrprop_resolver.draw_export_object(body) def general_get_export_objects(self) -> tuple[bpy.types.Object] | None: """ @@ -216,6 +228,9 @@ class ExportParams(): if obj is None: return None else: return (obj, ) +# 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 VirtoolsParams(): vt_encodings: bpy.props.StringProperty( name = "Encodings", @@ -223,11 +238,95 @@ class VirtoolsParams(): default = UTIL_virtools_types.g_PyBMapDefaultEncoding ) # type: ignore - def draw_virtools_params(self, layout: bpy.types.UILayout) -> None: - layout.label(text = 'Encodings') - layout.prop(self, 'vt_encodings', text = '') + 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 = _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.generate_items(), + default = _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.to_selection(UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS.CKTEXTURE_EXTERNAL) + ) # type: ignore + + use_compress: bpy.props.BoolProperty( + name="Use Compress", + description = "Whether use ZLib to compress result when saving composition.", + default = True, + ) # type: ignore + + compress_level: bpy.props.IntProperty( + name = "Compress Level", + description = "The ZLib compress level used by Virtools Engine when saving composition.", + min = 1, max = 9, + default = 5, + ) # type: ignore + + def draw_virtools_params(self, layout: bpy.types.UILayout, is_importer: bool) -> None: + header: bpy.types.UILayout + body: bpy.types.UILayout + header, body = layout.panel("BBP_PT_ioport_shared_virtools_params", default_closed=False) + header.label(text = 'Virtools Parameters') + if body is None: return + + # draw encodings + body.label(text = 'Encodings') + body.prop(self, 'vt_encodings', text = '') + + # following field are only valid in exporter + if not is_importer: + body.separator() + body.label(text = 'Global Texture Save Options') + body.prop(self, 'texture_save_opt', text = '') + + body.separator() + body.prop(self, 'use_compress') + if self.use_compress: + body.prop(self, 'compress_level') + def general_get_vt_encodings(self) -> tuple[str]: # get encoding, split it by `;` and strip blank chars. encodings: str = self.vt_encodings return tuple(map(lambda x: x.strip(), encodings.split(';'))) + + def general_get_texture_save_opt(self) -> UTIL_virtools_types.CK_TEXTURE_SAVEOPTIONS: + return _g_EnumHelper_CK_TEXTURE_SAVEOPTIONS.get_selection(self.texture_save_opt) + + def general_get_use_compress(self) -> bool: + return self.use_compress + + def general_get_compress_level(self) -> int: + return self.compress_level + +class BallanceParams(): + successive_sector: bpy.props.BoolProperty( + name="Successive Sector", + description = "Whether order exporter to use document specified sector count to make sure sector is successive.", + default = True, + ) # type: ignore + + def draw_ballance_params(self, layout: bpy.types.UILayout, is_importer: bool) -> None: + # ballance params only presented in exporter. + # so if we are in impoerter, we skip the whole function + # because we don't want to create an empty panel. + if is_importer: return + + header: bpy.types.UILayout + body: bpy.types.UILayout + header, body = layout.panel("BBP_PT_ioport_shared_ballance_params", default_closed=False) + header.label(text = 'Ballance Parameters') + if body is None: return + + map_info: PROP_ballance_map_info.RawBallanceMapInfo = PROP_ballance_map_info.get_raw_ballance_map_info(bpy.context.scene) + body.prop(self, 'successive_sector') + body.label(text = f'Map Sectors: {map_info.mSectorCount}') + + def general_get_successive_sector(self) -> bool: + return self.successive_sector + + def general_get_successive_sector_count(self) -> int: + # if user do not pick successive sector, return a random int directly. + if not self.general_get_successive_sector(): + return 0 + + # otherwise fetch user specified sector number + map_info: PROP_ballance_map_info.RawBallanceMapInfo + map_info = PROP_ballance_map_info.get_raw_ballance_map_info(bpy.context.scene) + return map_info.mSectorCount