Skip to content

Commit

Permalink
Add support for OgreMeshUpgrader '-optvtxcache' option
Browse files Browse the repository at this point in the history
  • Loading branch information
sercero committed Apr 9, 2024
1 parent 7fa2a44 commit 1584e9b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions io_ogre/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'GENERATE_TANGENTS' : '0',
'OPTIMISE_ANIMATIONS' : True,
'INTERFACE_TOGGLE': False,
'OPTIMISE_VERTEX_CACHE' : False,
'OPTIMISE_VERTEX_BUFFERS' : True,
'OPTIMISE_VERTEX_BUFFERS_OPTIONS' : 'puqs',

Expand Down
8 changes: 7 additions & 1 deletion io_ogre/ui/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def draw(self, context):
"Materials" : ["EX_MATERIALS", "EX_SEPARATE_MATERIALS", "EX_COPY_SHADER_PROGRAMS", "EX_USE_FFP_PARAMETERS"],
"Textures" : ["EX_DDS_MIPS", "EX_FORCE_IMAGE_FORMAT"],
"Armature" : ["EX_ARMATURE_ANIMATION", "EX_SHARED_ARMATURE", "EX_ONLY_KEYFRAMES", "EX_ONLY_DEFORMABLE_BONES", "EX_ONLY_KEYFRAMED_BONES", "EX_OGRE_INHERIT_SCALE", "EX_TRIM_BONE_WEIGHTS"],
"Mesh" : ["EX_MESH", "EX_MESH_OVERWRITE", "EX_ARRAY", "EX_V1_EXTREMITY_POINTS", "EX_Vx_GENERATE_EDGE_LISTS", "EX_GENERATE_TANGENTS", "EX_Vx_OPTIMISE_ANIMATIONS", "EX_V2_OPTIMISE_VERTEX_BUFFERS", "EX_V2_OPTIMISE_VERTEX_BUFFERS_OPTIONS"],
"Mesh" : ["EX_MESH", "EX_MESH_OVERWRITE", "EX_ARRAY", "EX_V1_EXTREMITY_POINTS", "EX_Vx_GENERATE_EDGE_LISTS", "EX_GENERATE_TANGENTS", "EX_Vx_OPTIMISE_ANIMATIONS", "EX_Vx_OPTIMISE_VERTEX_CACHE", "EX_V2_OPTIMISE_VERTEX_BUFFERS", "EX_V2_OPTIMISE_VERTEX_BUFFERS_OPTIONS"],
"LOD" : ["EX_LOD_GENERATION", "EX_LOD_LEVELS", "EX_LOD_DISTANCE", "EX_LOD_PERCENT"],
"Shape Animation" : ["EX_SHAPE_ANIMATIONS", "EX_SHAPE_NORMALS"],
"Logging" : ["EX_Vx_ENABLE_LOGGING", "EX_Vx_DEBUG_LOGGING"]
Expand Down Expand Up @@ -399,6 +399,12 @@ def execute(self, context):
name="Optimise Animations",
description="DON'T optimise out redundant tracks & keyframes",
default=config.get('OPTIMISE_ANIMATIONS')) = {}
EX_Vx_OPTIMISE_VERTEX_CACHE : BoolProperty(
name="Optimise Vertex Cache",
description="""This reorders the index buffer of the mesh such that triangles are rendered in order of proximity.
If enabled, the MeshUpgrader will print the change of the "average cache miss ratio (ACMR)" metric.
It measures the number of cache misses per triangle and thus ranges from 3.0 (all 3 vertices missed) to about 0.5 for an optimized mesh.""",
default=config.get('OPTIMISE_VERTEX_CACHE')) = {}
EX_V2_OPTIMISE_VERTEX_BUFFERS : BoolProperty(
name="Optimise Vertex Buffers For Shaders",
description="Optimise vertex buffers for shaders.\nSee Vertex Buffers Options for more settings",
Expand Down
31 changes: 30 additions & 1 deletion io_ogre/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ def mesh_upgrade_tool(infile):
# For Ogre v2.x we will use OgreMeshTool, which can perform the same operations
if detect_converter_type() != "OgreXMLConverter":
return


# Don't run 'OgreMeshUpgrader' unless we really need to
if config.get('LOD_GENERATION') != '0' and \
config.get('GENERATE_EDGE_LISTS') is False and \
config.get('OPTIMISE_VERTEX_CACHE') is False:
return

output_path, filename = os.path.split(infile)

if not os.path.exists(infile):
Expand All @@ -100,6 +106,9 @@ def mesh_upgrade_tool(infile):
if config.get('GENERATE_EDGE_LISTS') is True:
Report.warnings.append("OgreMeshUpgrader failed, Edge Lists will not be generated for this mesh: %s" % filename)

if config.get('OPTIMISE_VERTEX_CACHE') is True:
Report.warnings.append("OgreMeshUpgrader failed, Vertex Cache will not be optimized for this mesh: %s" % filename)

return

# Extract converter type from its output
Expand Down Expand Up @@ -132,6 +141,17 @@ def mesh_upgrade_tool(infile):
if config.get('GENERATE_EDGE_LISTS') is False:
cmd.append('-e')

# Vertex Cache Optimization
# https://www.ogre3d.org/2024/02/26/ogre-14-2-released#vertex-cache-optimization-in-meshupgrader

# Check to see if the option is available
if config.get('OPTIMISE_VERTEX_CACHE') is True:
if output.find("-optvtxcache") == -1:
logger.warn("Vertex Cache Optimization requested, but this version of OgreMeshUpgrader does not support it (OGRE >= 14.2)")
Report.warnings.append("Vertex Cache Optimization requested, but this version of OgreMeshUpgrader does not support it (OGRE >= 14.2)")
else:
cmd.append('-optvtxcache')

# Put logfile into output directory
use_logger = False
logfile = os.path.join(output_path, 'OgreMeshUpgrader.log')
Expand All @@ -151,6 +171,9 @@ def mesh_upgrade_tool(infile):
if config.get('GENERATE_EDGE_LISTS') is True:
logger.info("* Generating Edge Lists for mesh: %s" % filename)

if config.get('OPTIMISE_VERTEX_CACHE') is True:
logger.info("* Optimizing Vertex Cache for mesh: %s" % filename)

# First try to execute with the -log option
logger.debug("%s" % " ".join(cmd))
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
Expand All @@ -170,6 +193,9 @@ def mesh_upgrade_tool(infile):
if config.get('GENERATE_EDGE_LISTS') is True:
Report.warnings.append("OgreMeshUpgrader failed, Edge Lists will not be generated for this mesh: %s" % filename)

if config.get('OPTIMISE_VERTEX_CACHE') is True:
Report.warnings.append("OgreMeshUpgrader failed, Vertex Cache will not be optimized for this mesh: %s" % filename)

if error != None:
logger.error(error)
logger.warn(output)
Expand All @@ -180,6 +206,9 @@ def mesh_upgrade_tool(infile):
if config.get('GENERATE_EDGE_LISTS') is True:
logger.info("- Generated Edge Lists for mesh: %s" % filename)

if config.get('OPTIMISE_VERTEX_CACHE') is True and '-optvtxcache' in cmd:
logger.info("- Optimized Vertex Cache for mesh: %s" % filename)


def detect_converter_type():
# todo: executing the same exe twice might not be efficient but will do for now
Expand Down

0 comments on commit 1584e9b

Please sign in to comment.