fix virtools export fatal errors
This commit is contained in:
parent
70dd525315
commit
5c34bbad38
@ -89,7 +89,7 @@ def _export_virtools(file_name_: str, encodings_: tuple[str], compress_level_: i
|
|||||||
texture_crets: tuple[_TTexturePair, ...] = _export_virtools_materials(
|
texture_crets: tuple[_TTexturePair, ...] = _export_virtools_materials(
|
||||||
writer, progress, material_crets)
|
writer, progress, material_crets)
|
||||||
# export texture
|
# export texture
|
||||||
_export_virtools_textures(writer, progress, texture_crets)
|
_export_virtools_textures(writer, progress, vt_temp_folder, texture_crets)
|
||||||
|
|
||||||
# save document
|
# save document
|
||||||
_save_virtools_document(
|
_save_virtools_document(
|
||||||
@ -385,15 +385,12 @@ def _export_virtools_materials(
|
|||||||
def _export_virtools_textures(
|
def _export_virtools_textures(
|
||||||
writer: bmap.BMFileWriter,
|
writer: bmap.BMFileWriter,
|
||||||
progress: ProgressReport,
|
progress: ProgressReport,
|
||||||
|
vt_temp_folder: str,
|
||||||
texture_crets: tuple[_TTexturePair, ...]
|
texture_crets: tuple[_TTexturePair, ...]
|
||||||
) -> None:
|
) -> None:
|
||||||
# start saving
|
# start saving
|
||||||
progress.enter_substeps(len(texture_crets), "Saving Textures")
|
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:
|
for tex, vttexture in texture_crets:
|
||||||
# set name
|
# set name
|
||||||
vttexture.set_name(tex.name)
|
vttexture.set_name(tex.name)
|
||||||
@ -411,7 +408,7 @@ def _export_virtools_textures(
|
|||||||
UTIL_ballance_texture.get_texture_filepath(tex))
|
UTIL_ballance_texture.get_texture_filepath(tex))
|
||||||
if try_filepath is None:
|
if try_filepath is None:
|
||||||
# non-ballance file, save in temp and change file path to point to it.
|
# 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)
|
UTIL_ballance_texture.save_other_texture(tex, try_filepath)
|
||||||
# load into vt engine
|
# load into vt engine
|
||||||
vttexture.load_image(try_filepath)
|
vttexture.load_image(try_filepath)
|
||||||
|
@ -78,7 +78,7 @@ elif sys.platform.startswith('darwin'):
|
|||||||
else:
|
else:
|
||||||
_g_BMapLibName = "BMap.bin"
|
_g_BMapLibName = "BMap.bin"
|
||||||
|
|
||||||
_g_BMapModule: ctypes.CDLL = None
|
_g_BMapModule: ctypes.CDLL | None = None
|
||||||
try:
|
try:
|
||||||
_g_BMapModule = ctypes.cdll.LoadLibrary(
|
_g_BMapModule = ctypes.cdll.LoadLibrary(
|
||||||
os.path.join(os.path.dirname(__file__), _g_BMapLibName)
|
os.path.join(os.path.dirname(__file__), _g_BMapLibName)
|
||||||
|
@ -7,7 +7,7 @@ g_InvalidPtr: bmap.bm_void_p = bmap.bm_void_p(0)
|
|||||||
g_InvalidCKID: int = 0
|
g_InvalidCKID: int = 0
|
||||||
g_BMapEncoding: str = "utf-8"
|
g_BMapEncoding: str = "utf-8"
|
||||||
|
|
||||||
def python_callback(strl: bytes):
|
def _python_callback(strl: bytes):
|
||||||
"""
|
"""
|
||||||
The Python type callback for BMFile.
|
The Python type callback for BMFile.
|
||||||
Simply add a prefix when output.
|
Simply add a prefix when output.
|
||||||
@ -17,6 +17,7 @@ def python_callback(strl: bytes):
|
|||||||
# i think Python do a auto convertion here.
|
# i think Python do a auto convertion here.
|
||||||
if strl is not None:
|
if strl is not None:
|
||||||
print(f'[PyBMap] {strl.decode(g_BMapEncoding)}')
|
print(f'[PyBMap] {strl.decode(g_BMapEncoding)}')
|
||||||
|
_g_RawCallback: bmap.bm_callback = bmap.bm_callback(_python_callback)
|
||||||
|
|
||||||
class _AbstractPointer():
|
class _AbstractPointer():
|
||||||
__mRawPointer: int
|
__mRawPointer: int
|
||||||
@ -594,7 +595,6 @@ class BMFileReader(_AbstractPointer):
|
|||||||
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(g_BMapEncoding))
|
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))
|
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))
|
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_))
|
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
|
||||||
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
|
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
|
||||||
*(strl.encode(g_BMapEncoding) for strl in 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()
|
out_file: bmap.bm_void_p = bmap.bm_void_p()
|
||||||
# exec
|
# exec
|
||||||
bmap.BMFile_Load(
|
bmap.BMFile_Load(
|
||||||
file_name, temp_folder, texture_folder, raw_callback,
|
file_name, temp_folder, texture_folder, _g_RawCallback,
|
||||||
encoding_count, encodings,
|
encoding_count, encodings,
|
||||||
ctypes.byref(out_file)
|
ctypes.byref(out_file)
|
||||||
)
|
)
|
||||||
@ -693,7 +693,6 @@ class BMFileWriter(_AbstractPointer):
|
|||||||
# create param
|
# create param
|
||||||
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.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))
|
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_))
|
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
|
||||||
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
|
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
|
||||||
*(strl.encode(g_BMapEncoding) for strl in 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()
|
out_file: bmap.bm_void_p = bmap.bm_void_p()
|
||||||
# exec
|
# exec
|
||||||
bmap.BMFile_Create(
|
bmap.BMFile_Create(
|
||||||
temp_folder, texture_folder, raw_callback,
|
temp_folder, texture_folder, _g_RawCallback,
|
||||||
encoding_count, encodings,
|
encoding_count, encodings,
|
||||||
ctypes.byref(out_file)
|
ctypes.byref(out_file)
|
||||||
)
|
)
|
||||||
|
@ -350,6 +350,7 @@ def save_other_texture(tex: bpy.types.Image, filepath: str) -> None:
|
|||||||
@param tex[in] The saving texture
|
@param tex[in] The saving texture
|
||||||
@param filepath[in] The absolute path to saving file.
|
@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)
|
tex.save(filepath = filepath)
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user