Skip to content

Commit

Permalink
Add option to pack normals into INT_10_10_10_2 format
Browse files Browse the repository at this point in the history
  • Loading branch information
sercero committed Apr 10, 2024
1 parent d34ee21 commit 5de911f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions io_ogre/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
'EXTREMITY_POINTS' : 0,
'GENERATE_EDGE_LISTS' : False,
'GENERATE_TANGENTS' : '0',
'PACK_INT_10_10_10_2': False,
'OPTIMISE_ANIMATIONS' : True,
'INTERFACE_TOGGLE': False,
'OPTIMISE_VERTEX_CACHE' : False,
Expand Down
4 changes: 3 additions & 1 deletion io_ogre/ogre/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ def replaceInplace(f,searchExp,replaceExp):

# If requested by the user, generate LOD levels / Edge Lists / Vertex buffer optimization through OgreMeshUpgrader
if ((config.get('LOD_LEVELS') > 0 and config.get('LOD_GENERATION') == '0') or
(config.get('GENERATE_EDGE_LISTS') is True)):
(config.get('GENERATE_EDGE_LISTS') is True) or
(config.get('PACK_INT_10_10_10_2') is True) or
(config.get('OPTIMISE_VERTEX_CACHE') is True)):
target_mesh_file = os.path.join(path, '%s.mesh' % obj_name )
util.mesh_upgrade_tool(target_mesh_file)

Expand Down
19 changes: 14 additions & 5 deletions 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_Vx_OPTIMISE_VERTEX_CACHE", "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_PACK_INT_10_10_10_2", "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 @@ -265,7 +265,8 @@ def execute(self, context):
default=config.get('MESH_TOOL_VERSION')) = {}
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)",
description="""Remove the generated XML files after binary conversion.
(The removal will only happen if OgreXMLConverter/OgreMeshTool finishes successfully)""",
default=config.get('EXPORT_XML_DELETE')) = {}

# Scene
Expand All @@ -275,7 +276,7 @@ def execute(self, context):
default=config.get('SCENE')) = {}
EX_SELECTED_ONLY : BoolProperty(
name="Export Selected Only",
description="Export only selected objects\nTurn on to avoid exporting non-selected stuff",
description="Export only selected objects.\nTurn on to avoid exporting non-selected stuff",
default=config.get('SELECTED_ONLY')) = {}
EX_EXPORT_HIDDEN : BoolProperty(
name="Export Hidden Also",
Expand Down Expand Up @@ -342,7 +343,9 @@ def execute(self, context):
default=config.get('ARMATURE_ANIMATION')) = {}
EX_SHARED_ARMATURE : BoolProperty(
name="Shared Armature",
description="Export a single .skeleton file for objects that have the same Armature parent (useful for: shareSkeletonInstanceWith())\nNOTE: The name of the .skeleton file will be that of the Armature",
description="""Export a single .skeleton file for objects that have the same Armature parent
(useful for: shareSkeletonInstanceWith())
NOTE: The name of the .skeleton file will be that of the Armature""",
default=config.get('SHARED_ARMATURE')) = {}
EX_ONLY_KEYFRAMES : BoolProperty(
name="Only Keyframes",
Expand Down Expand Up @@ -395,6 +398,12 @@ def execute(self, context):
name="Tangents",
description="Export tangents generated by Blender",
default=config.get('GENERATE_TANGENTS')) = {}
EX_Vx_PACK_INT_10_10_10_2 : BoolProperty(
name="Pack into 'INT_10_10_10_2' format",
description="""Ogre now supports normalized INT_10_10_10_2 as the normal format.
This packs 3 signed values with 10bit precision and a fourth 2bit value into 4 bytes; the size of a single float.
If you are using normal-maps, you will notice how this format is perfect to store a tangent with parity, while only requiring 25% of storage compared to 4 floats""",
default=config.get('PACK_INT_10_10_10_2')) = {}
EX_Vx_OPTIMISE_ANIMATIONS : BoolProperty(
name="Optimise Animations",
description="DON'T optimise out redundant tracks & keyframes",
Expand All @@ -403,7 +412,7 @@ def execute(self, context):
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.""",
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",
Expand Down
20 changes: 20 additions & 0 deletions io_ogre/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def mesh_upgrade_tool(infile):
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 config.get('PACK_INT_10_10_10_2') is True:
Report.warnings.append("OgreMeshUpgrader failed, Normals won't be packed for this mesh: %s" % filename)

return

# Extract converter type from its output
Expand Down Expand Up @@ -155,6 +158,15 @@ def mesh_upgrade_tool(infile):
else:
cmd.append('-optvtxcache')

# Normal Packing
# https://www.ogre3d.org/2022/06/07/ogre-13-4-released#vetint1010102norm-support-added
if config.get('PACK_INT_10_10_10_2') is True:
if output.find("-pack") == -1:
logger.warn("Normal Packing requested, but this version of OgreMeshUpgrader does not support it (OGRE >= 13.4)")
Report.warnings.append("Normal Packing requested, but this version of OgreMeshUpgrader does not support it (OGRE >= 13.4)")
else:
cmd.append('-pack')

# Put logfile into output directory
use_logger = False
logfile = os.path.join(output_path, 'OgreMeshUpgrader.log')
Expand All @@ -177,6 +189,9 @@ def mesh_upgrade_tool(infile):
if config.get('OPTIMISE_VERTEX_CACHE') is True and '-optvtxcache' in cmd:
logger.info("* Optimizing Vertex Cache for mesh: %s" % filename)

if config.get('PACK_INT_10_10_10_2') is True and '-pack' in cmd:
logger.info("* Packing Normals 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 @@ -199,6 +214,9 @@ def mesh_upgrade_tool(infile):
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 config.get('PACK_INT_10_10_10_2') is True:
Report.warnings.append("OgreMeshUpgrader failed, Normals won't be packed for this mesh: %s" % filename)

if error != None:
logger.error(error)
logger.warn(output)
Expand All @@ -212,6 +230,8 @@ def mesh_upgrade_tool(infile):
if config.get('OPTIMISE_VERTEX_CACHE') is True and '-optvtxcache' in cmd:
logger.info("- Optimized Vertex Cache for mesh: %s" % filename)

if config.get('PACK_INT_10_10_10_2') is True and '-pack' in cmd:
logger.info("- Packed Normals 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 5de911f

Please sign in to comment.