From f3e628176f06c8f46e53ec985a5a571ece45a848 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Thu, 15 Feb 2024 20:43:13 +0100 Subject: [PATCH] fix remaining instances of slow progress reporting --- io_ogre/ogre/mesh.py | 14 ++------------ io_ogre/ogre/ogre_import.py | 14 ++------------ io_ogre/ogre/skeleton.py | 11 ++--------- io_ogre/util.py | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/io_ogre/ogre/mesh.py b/io_ogre/ogre/mesh.py index c464ded..050f220 100644 --- a/io_ogre/ogre/mesh.py +++ b/io_ogre/ogre/mesh.py @@ -248,21 +248,11 @@ def dot_mesh(ob, path, force_name=None, ignore_shape_animation=False, normals=Tr # calc_tangents() already calculates split normals for us mesh.calc_normals_split() - progressScale = 1.0 / len(mesh.polygons) - bpy.context.window_manager.progress_begin(0, 100) - - step = max(1, int(len(mesh.polygons) / 100)) + progressbar = util.ProgressBar("Faces", len(mesh.polygons)) # Process mesh after triangulation for F in mesh.polygons: - if F.index % step == 0: - # Update progress in console - percent = (F.index + 1) * progressScale - sys.stdout.write( "\r + Faces [" + '=' * int(percent * 50) + '>' + '.' * int(50 - percent * 50) + "] " + str(round(percent * 100)) + "% ") - sys.stdout.flush() - - # Update progress through Blender cursor - bpy.context.window_manager.progress_update(percent) + progressbar.update(F.index) tri = (F.vertices[0], F.vertices[1], F.vertices[2]) face = [] diff --git a/io_ogre/ogre/ogre_import.py b/io_ogre/ogre/ogre_import.py index 7084910..ea5d807 100644 --- a/io_ogre/ogre/ogre_import.py +++ b/io_ogre/ogre/ogre_import.py @@ -203,21 +203,11 @@ def xCollectVertexData(data): for vb in data.childNodes: if vb.localName == 'vertexbuffer': if vb.hasAttribute('positions'): - - progressScale = 1.0 / len(vb.getElementsByTagName('vertex')) - bpy.context.window_manager.progress_begin(0, 100) + progressbar = util.ProgressBar("Vertices", len(vb.getElementsByTagName('vertex'))) index = 0 for vertex in vb.getElementsByTagName('vertex'): - - # Update progress in console - percent = (index + 1) * progressScale - sys.stdout.write( "\r + Vertices [" + '=' * int(percent * 50) + '>' + '.' * int(50 - percent * 50) + "] " + str(int(percent * 10000) / 100.0) + "% ") - sys.stdout.flush() - - # Update progress through Blender cursor - bpy.context.window_manager.progress_update(percent) - + progressbar.update(index) index = index + 1 for vp in vertex.childNodes: diff --git a/io_ogre/ogre/skeleton.py b/io_ogre/ogre/skeleton.py index d5cd308..0bd3946 100644 --- a/io_ogre/ogre/skeleton.py +++ b/io_ogre/ogre/skeleton.py @@ -417,18 +417,11 @@ def write_animation( self, arm, actionName, frameBegin, frameEnd, doc, parentEle logger.info(" - Exporting action: %s" % actionName) - # Initialize progress through Blender cursor - progressScale = 1.0 / len(frame_range) - bpy.context.window_manager.progress_begin(0, 100) + progressbar = util.ProgressBar("Frames", len(frame_range) ) # Add keyframes to export for frame in frame_range: - percent = (frame - frameBegin + 1) * progressScale - sys.stdout.write( "\r + Frames [" + '=' * int(percent * 50) + '>' + '.' * int(50 - percent * 50) + "] " + str(int(percent * 10000) / 100.0) + "% ") - sys.stdout.flush() - - # Update progress through Blender cursor - bpy.context.window_manager.progress_update(percent) + progressbar.update( frame - frameBegin ) bpy.context.scene.frame_set(frame) for bone in self.roots: diff --git a/io_ogre/util.py b/io_ogre/util.py index 7c63579..de9f36b 100644 --- a/io_ogre/util.py +++ b/io_ogre/util.py @@ -15,6 +15,27 @@ logger = logging.getLogger('util') +class ProgressBar: + def __init__(self, name, total): + self.name = name + self.progressScale = 1.0 / total + self.step = max(1, int(total / 100)) + + # Initialize progress through Blender cursor + bpy.context.window_manager.progress_begin(0, 100) + + def update(self, value): + if value % self.step != 0: + return + + # Update progress in console + percent = (value + 1) * self.progressScale + sys.stdout.write( "\r + "+self.name+" [" + '=' * int(percent * 50) + '>' + '.' * int(50 - percent * 50) + "] " + str(round(percent * 100)) + "% ") + sys.stdout.flush() + + # Update progress through Blender cursor + bpy.context.window_manager.progress_update(percent) + def xml_converter_parameters(): """ Return the name of the ogre converter