Skip to content

Commit

Permalink
fix remaining instances of slow progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Feb 15, 2024
1 parent c707fee commit f3e6281
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
14 changes: 2 additions & 12 deletions io_ogre/ogre/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
14 changes: 2 additions & 12 deletions io_ogre/ogre/ogre_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 2 additions & 9 deletions io_ogre/ogre/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions io_ogre/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3e6281

Please sign in to comment.