blender: make progress report work consistent
This commit is contained in:
parent
5e6f3d243b
commit
416f5aef69
@ -31,7 +31,19 @@ class Library(object):
|
||||
|
||||
return (coord[0] * fact, coord[1] * fact)
|
||||
|
||||
def link_refs(self, progress_callback=None):
|
||||
def link_refs(self, root, progress_callback=None):
|
||||
for ref in root.references:
|
||||
if isinstance(ref.structure, str):
|
||||
try:
|
||||
element.structure = self.structures[ref.structure]
|
||||
except KeyError:
|
||||
err = LinkError("dangeling sref (structure {} is not defined in library)".format(ref.structure))
|
||||
err.element = root
|
||||
raise err
|
||||
|
||||
return root
|
||||
|
||||
def link_all_refs(self, progress_callback=None):
|
||||
class Progress(ProgressGetter):
|
||||
total = 0
|
||||
current = 0
|
||||
|
@ -98,11 +98,14 @@ class SceneInserter(object):
|
||||
def link(self, obj):
|
||||
self.context.scene.objects.link(obj)
|
||||
|
||||
def build_object(self, structure):
|
||||
def build_object(self, structure, progress=None):
|
||||
# is the object already existent => return new instance
|
||||
if structure.name in bpy.data.objects:
|
||||
return self.new_instance(bpy.data.objects[structure.name])
|
||||
|
||||
if progress:
|
||||
progress.total += 1 + len(structure.references)
|
||||
|
||||
verts = {}
|
||||
faces = {}
|
||||
|
||||
@ -149,10 +152,21 @@ class SceneInserter(object):
|
||||
self.layers[layer].link(obj)
|
||||
obj.parent = root
|
||||
|
||||
if progress:
|
||||
progress.inc()
|
||||
|
||||
# handle all references
|
||||
# build tree depth first
|
||||
for reference in structure.references:
|
||||
obj = self.build_object(reference.structure)
|
||||
if isinstance(reference.structure, str):
|
||||
if reference.structure not in self.lib.structures:
|
||||
progress.inc()
|
||||
continue
|
||||
|
||||
# resolve structure
|
||||
reference.structure = self.lib.structures[reference.structure]
|
||||
|
||||
obj = self.build_object(reference.structure, progress=progress)
|
||||
|
||||
if hasattr(reference, "size"):
|
||||
def add(a,b):
|
||||
@ -209,6 +223,9 @@ class SceneInserter(object):
|
||||
obj.rotation_euler.z = math.radians(trans.rotation)
|
||||
obj.scale = (trans.zoom, trans.zoom, 1)
|
||||
|
||||
if progress:
|
||||
progress.inc()
|
||||
|
||||
return root
|
||||
|
||||
def new_instance(self, obj):
|
||||
@ -230,7 +247,7 @@ class SceneInserter(object):
|
||||
|
||||
def __call__(self, progress=None):
|
||||
class ProgressTracker:
|
||||
def __init__(self, total, callback):
|
||||
def __init__(self, callback, total=0):
|
||||
self.total = total
|
||||
self.current = 0
|
||||
self.callback = callback
|
||||
@ -245,12 +262,18 @@ class SceneInserter(object):
|
||||
if self.top_cell:
|
||||
if self.top_cell not in self.lib.structures:
|
||||
return None
|
||||
s = self.lib.structures[self.top_cell]
|
||||
|
||||
progressTracker = ProgressTracker(progress, 1+len(s.references))
|
||||
self.build_object(s,progress=progressTracker)
|
||||
|
||||
self.build_object(self.lib.structures[self.top_cell])
|
||||
return True
|
||||
|
||||
# build all structures in object
|
||||
progressTracker = ProgressTracker(2*(len(self.lib.structures)-len(self.ignore_structures)), progress)
|
||||
progressTracker = ProgressTracker(progress)
|
||||
progressTracker.total = len(self.lib.structures)
|
||||
|
||||
# self.link_all_refs(progressTracker)
|
||||
|
||||
# build all structures first
|
||||
# since references could reference unknown objects otherwise
|
||||
for name, value in self.lib.structures.items():
|
||||
@ -258,8 +281,7 @@ class SceneInserter(object):
|
||||
if name in self.ignore_structures:
|
||||
continue
|
||||
|
||||
self.build_object(value)
|
||||
progressTracker.total += len(value.references)
|
||||
self.build_object(value, progress=progressTracker)
|
||||
|
||||
|
||||
return True
|
||||
@ -285,11 +307,6 @@ def load(context,
|
||||
progress.step("linking references")
|
||||
prog.end()
|
||||
|
||||
lib.link_refs(prog)
|
||||
|
||||
progress.step("inserting structures into scene")
|
||||
prog.end()
|
||||
|
||||
if not SceneInserter(context=context, lib=lib, top_cell=top_cell_name)(prog):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user