fix virtools export fatal errors

This commit is contained in:
yyc12345 2023-12-03 18:14:20 +08:00
parent 70dd525315
commit 5c34bbad38
4 changed files with 29 additions and 32 deletions

View File

@ -89,7 +89,7 @@ def _export_virtools(file_name_: str, encodings_: tuple[str], compress_level_: i
texture_crets: tuple[_TTexturePair, ...] = _export_virtools_materials(
writer, progress, material_crets)
# export texture
_export_virtools_textures(writer, progress, texture_crets)
_export_virtools_textures(writer, progress, vt_temp_folder, texture_crets)
# save document
_save_virtools_document(
@ -385,15 +385,12 @@ def _export_virtools_materials(
def _export_virtools_textures(
writer: bmap.BMFileWriter,
progress: ProgressReport,
vt_temp_folder: str,
texture_crets: tuple[_TTexturePair, ...]
) -> None:
# start saving
progress.enter_substeps(len(texture_crets), "Saving Textures")
# create another temp folder for non-ballance texture saving
with tempfile.TemporaryDirectory() as nonballance_temp:
print(f'Non-Ballance Texture Temp: {nonballance_temp}')
for tex, vttexture in texture_crets:
# set name
vttexture.set_name(tex.name)
@ -411,7 +408,7 @@ def _export_virtools_textures(
UTIL_ballance_texture.get_texture_filepath(tex))
if try_filepath is None:
# non-ballance file, save in temp and change file path to point to it.
try_filepath = UTIL_ballance_texture.generate_other_texture_save_path(tex, nonballance_temp)
try_filepath = UTIL_ballance_texture.generate_other_texture_save_path(tex, vt_temp_folder)
UTIL_ballance_texture.save_other_texture(tex, try_filepath)
# load into vt engine
vttexture.load_image(try_filepath)

View File

@ -78,7 +78,7 @@ elif sys.platform.startswith('darwin'):
else:
_g_BMapLibName = "BMap.bin"
_g_BMapModule: ctypes.CDLL = None
_g_BMapModule: ctypes.CDLL | None = None
try:
_g_BMapModule = ctypes.cdll.LoadLibrary(
os.path.join(os.path.dirname(__file__), _g_BMapLibName)

View File

@ -7,7 +7,7 @@ g_InvalidPtr: bmap.bm_void_p = bmap.bm_void_p(0)
g_InvalidCKID: int = 0
g_BMapEncoding: str = "utf-8"
def python_callback(strl: bytes):
def _python_callback(strl: bytes):
"""
The Python type callback for BMFile.
Simply add a prefix when output.
@ -17,6 +17,7 @@ def python_callback(strl: bytes):
# i think Python do a auto convertion here.
if strl is not None:
print(f'[PyBMap] {strl.decode(g_BMapEncoding)}')
_g_RawCallback: bmap.bm_callback = bmap.bm_callback(_python_callback)
class _AbstractPointer():
__mRawPointer: int
@ -594,7 +595,6 @@ class BMFileReader(_AbstractPointer):
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(g_BMapEncoding))
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(g_BMapEncoding))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(g_BMapEncoding))
raw_callback: bmap.bm_callback = bmap.bm_callback(python_callback)
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(g_BMapEncoding) for strl in encodings_)
@ -602,7 +602,7 @@ class BMFileReader(_AbstractPointer):
out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec
bmap.BMFile_Load(
file_name, temp_folder, texture_folder, raw_callback,
file_name, temp_folder, texture_folder, _g_RawCallback,
encoding_count, encodings,
ctypes.byref(out_file)
)
@ -693,7 +693,6 @@ class BMFileWriter(_AbstractPointer):
# create param
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(g_BMapEncoding))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(g_BMapEncoding))
raw_callback: bmap.bm_callback = bmap.bm_callback(python_callback)
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(g_BMapEncoding) for strl in encodings_)
@ -701,7 +700,7 @@ class BMFileWriter(_AbstractPointer):
out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec
bmap.BMFile_Create(
temp_folder, texture_folder, raw_callback,
temp_folder, texture_folder, _g_RawCallback,
encoding_count, encodings,
ctypes.byref(out_file)
)

View File

@ -350,6 +350,7 @@ def save_other_texture(tex: bpy.types.Image, filepath: str) -> None:
@param tex[in] The saving texture
@param filepath[in] The absolute path to saving file.
"""
# MARK: must use keyword to assign param otherwise blender will throw error.
tex.save(filepath = filepath)
#endregion