Skip to content

Commit

Permalink
Separate deletion of XML files between importer and exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
sercero committed Mar 10, 2024
1 parent 80e1410 commit 22df672
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
7 changes: 5 additions & 2 deletions io_ogre/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

_CONFIG_DEFAULTS_ALL = {
# General
'SWAP_AXIS' : 'xyz', # ogre standard is 'xz-y', but swapping is currently broken
'SWAP_AXIS' : 'xz-y',
'MESH_TOOL_VERSION' : 'v2',
'XML_DELETE' : True,
'EXPORT_XML_DELETE' : True,

# Scene
'SCENE' : True,
Expand Down Expand Up @@ -96,6 +96,7 @@
#'SHOW_LOG_NAME' : False,

# Import
'IMPORT_XML_DELETE' : False,
'IMPORT_NORMALS' : True,
'MERGE_SUBMESHES' : True,
'IMPORT_ANIMATIONS' : True,
Expand Down Expand Up @@ -202,6 +203,8 @@ def get(name, default=None):
global CONFIG
if name in CONFIG:
return CONFIG[name]
else:
logger.error("Config option %s does not exist!" % name)
return default

def update(**kwargs):
Expand Down
3 changes: 2 additions & 1 deletion io_ogre/ogre/ogre_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,8 @@ def load(filepath):
# Create skeleton (if any) and mesh from parsed data
bCreateMesh(meshData, folder, onlyName, pathMeshXml)
bCreateAnimations(meshData)
if config.get('XML_DELETE'):

if config.get('IMPORT_XML_DELETE') == True:
# Cleanup by deleting the XML file we created
os.unlink("%s" % pathMeshXml)
if 'skeleton' in meshData:
Expand Down
14 changes: 7 additions & 7 deletions io_ogre/ui/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def draw(self, context):

# Options associated with each section
section_options = {
"General" : ["EX_SWAP_AXIS", "EX_V2_MESH_TOOL_VERSION", "EX_XML_DELETE"],
"General" : ["EX_SWAP_AXIS", "EX_V2_MESH_TOOL_VERSION", "EX_EXPORT_XML_DELETE"],
"Scene" : ["EX_SCENE", "EX_SELECTED_ONLY", "EX_EXPORT_HIDDEN", "EX_FORCE_CAMERA", "EX_FORCE_LAMPS", "EX_NODE_ANIMATION"],
"Materials" : ["EX_MATERIALS", "EX_SEPARATE_MATERIALS", "EX_COPY_SHADER_PROGRAMS", "EX_USE_FFP_PARAMETERS"],
"Textures" : ["EX_DDS_MIPS", "EX_FORCE_IMAGE_FORMAT"],
Expand Down Expand Up @@ -253,15 +253,15 @@ def execute(self, context):
name='Mesh Export Version',
description='Specify Ogre version format to write',
default=config.get('MESH_TOOL_VERSION')) = {}
EX_XML_DELETE : BoolProperty(
name="Clean up xml files",
description="Remove the generated xml files after binary conversion. \n(The removal will only happen if OgreXMLConverter/OgreMeshTool finishes successfully)",
default=config.get('XML_DELETE')) = {}
EX_EXPORT_XML_DELETE : BoolProperty(
name="Clean up XML files",
description="Remove the generated XML files after binary conversion. \n(The removal will only happen if OgreXMLConverter/OgreMeshTool finishes successfully)",
default=config.get('EXPORT_XML_DELETE')) = {}

# Scene
EX_SCENE : BoolProperty(
name="Export Scene",
description="Export current scene (OgreDotScene xml file)",
description="Export current scene (OgreDotScene XML file)",
default=config.get('SCENE')) = {}
EX_SELECTED_ONLY : BoolProperty(
name="Export Selected Only",
Expand Down
14 changes: 7 additions & 7 deletions io_ogre/ui/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def invoke(self, context, event):

wm = context.window_manager
fs = wm.fileselect_add(self)

return {'RUNNING_MODAL'}

def draw(self, context):
Expand All @@ -77,16 +77,16 @@ def draw(self, context):
section_icons = {
"General" : "WORLD", "Armature" : "ARMATURE_DATA", "Mesh" : "MESH_DATA", "Shape Keys" : "ANIM_DATA", "Logging" : "TEXT"
}

# Options associated with each section
section_options = {
"General" : ["IM_SWAP_AXIS", "IM_V2_MESH_TOOL_VERSION", "IM_XML_DELETE"],
"General" : ["IM_SWAP_AXIS", "IM_V2_MESH_TOOL_VERSION", "IM_IMPORT_XML_DELETE"],
"Armature" : ["IM_IMPORT_ANIMATIONS", "IM_ROUND_FRAMES", "IM_USE_SELECTED_SKELETON"],
"Mesh" : ["IM_IMPORT_NORMALS", "IM_MERGE_SUBMESHES"],
"Shape Keys" : ["IM_IMPORT_SHAPEKEYS"],
"Logging" : ["IM_Vx_ENABLE_LOGGING"]
}

for section in sections:
row = layout.row()
box = row.box()
Expand All @@ -103,7 +103,7 @@ def draw(self, context):
box.prop(self, prop)
elif prop.startswith('IM_'):
box.prop(self, prop)

def execute(self, context):
# Add warinng about missing XML converter
Report.reset()
Expand Down Expand Up @@ -236,10 +236,10 @@ def execute(self, context):
description='Specify Ogre version format to read',
default=config.get('MESH_TOOL_VERSION')) = {}

IM_XML_DELETE : BoolProperty(
IM_IMPORT_XML_DELETE : BoolProperty(
name="Clean up XML files",
description="Remove the generated XML files after binary conversion. \n(The removal will only happen if OgreXMLConverter/OgreMeshTool finishes successfully)",
default=config.get('XML_DELETE')) = {}
default=config.get('IMPORT_XML_DELETE')) = {}

# Mesh
IM_IMPORT_NORMALS : BoolProperty(
Expand Down
10 changes: 5 additions & 5 deletions io_ogre/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ def xml_convert(infile, has_uvs=False):
logger.error("OgreXMLConverter returned with non-zero status, check OgreXMLConverter.log")
logger.info(" ".join(cmd))
Report.errors.append("OgreXMLConverter finished with non-zero status converting mesh: (%s), it might not have been properly generated" % name)

# Clean up .xml file after successful conversion
if proc.returncode == 0 and config.get('XML_DELETE') == True:
if proc.returncode == 0 and config.get('EXPORT_XML_DELETE') == True:
logger.info("Removing generated xml file after conversion: %s" % infile)
os.remove(infile)

else:
# Convert to v2 format if required
cmd.append('-%s' %config.get('MESH_TOOL_VERSION'))
Expand Down Expand Up @@ -390,7 +390,7 @@ def xml_convert(infile, has_uvs=False):
if config.get('ENABLE_LOGGING'):
logfile_path, name = os.path.split(infile)
logfile = os.path.join(logfile_path, 'OgreMeshTool.log')

with open(logfile, 'w') as log:
log.write(output)

Expand All @@ -401,7 +401,7 @@ def xml_convert(infile, has_uvs=False):
Report.errors.append("OgreMeshTool finished with non-zero status converting mesh: (%s), it might not have been properly generated" % name)

# Clean up .xml file after successful conversion
if proc.returncode == 0 and config.get('XML_DELETE') == True:
if proc.returncode == 0 and config.get('EXPORT_XML_DELETE') == True:
logger.info("Removing generated xml file after conversion: %s" % infile)
os.remove(infile)

Expand Down

0 comments on commit 22df672

Please sign in to comment.