cache.fetch_strip(strip)
faces_done += len(island)
- if progress:
- progress.set_progress(float(faces_done)/len(mesh.faces))
+ progress.set_progress(faces_done/len(mesh.faces))
# Collect any faces that weren't used in strips
loose += [f for f in island if not f.flag]
from .mesh import create_mesh_from_object
from .util import Progress
- if self.show_progress:
- if not progress:
- progress = Progress(context)
- progress.set_task("Preparing", 0.0, 0.0)
- else:
- progress = None
+ if not progress:
+ progress = Progress(self.show_progress and context)
+ progress.push_task("", 0.0, 0.65)
mesh = create_mesh_from_object(context, obj, progress)
strips = []
loose = mesh.faces
if self.use_strips:
- if progress:
- progress.set_task("Creating strips", 0.65, 0.95)
+ progress.set_task("Creating strips", 0.65, 0.95)
strips, loose = self.stripify(mesh, progress)
- if progress:
- progress.set_task("Writing file", 0.95, 1.0)
+ progress.set_task("Writing file", 0.95, 1.0)
from .outfile import open_output
out_file = open_output(out_file)
if mesh.winding_test:
out_file.write("winding", "COUNTERCLOCKWISE")
- if progress:
- progress.set_task("Done", 1.0, 1.0)
+ progress.pop_task()
return mesh
class SceneExporter:
def __init__(self):
self.resource_collection = True
+ self.show_progress = True
def export(self, context, out_file):
objs = context.selected_objects
object_prototypes[c.name] = o
from .util import Progress
- progress = Progress(context)
+ progress = Progress(self.show_progress and context)
+
if self.resource_collection:
res_out = open_output(os.path.join(path, base+"_resources.mdc"))
# TODO Export techniques as separate items in the collection
for i, o in enumerate(unique_objects):
res_out.begin("object", '"{}.object"'.format(o.name))
- progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
+ progress.push_task_slice(o.name, i, len(objs))
object_export.export(context, res_out, o, progress)
progress.pop_task()
res_out.end()
os.makedirs(res_dir)
for i, o in enumerate(unique_objects):
obj_out = open_output(os.path.join(res_dir, o.name+".object"))
- progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
+ progress.push_task_slice(o.name, i, len(objs))
object_export.export(context, obj_out, o, progress)
progress.pop_task()
self.lines += other.lines
- def prepare_smoothing(self, progress=None):
+ def prepare_smoothing(self, progress):
smooth_limit = -1
if self.smoothing=='NONE':
for f in self.faces:
for e in self.edges:
e.check_smooth(smooth_limit)
+ progress.push_task("Sharp edges", 0.0, 0.7)
self.split_vertices(self.find_smooth_group, progress)
if self.smoothing!='BLENDER':
- self.compute_normals()
+ progress.set_task("Updating normals", 0.7, 1.0)
+ self.compute_normals(progress)
+
+ progress.pop_task()
def prepare_vertex_groups(self, obj):
for v in self.vertices:
for g in v.groups:
g.group = group_index_map[g.group]
- def prepare_uv(self, obj, progress=None):
+ def prepare_uv(self, obj, progress):
if obj.material_tex and self.use_uv!='NONE':
layer = UvLayer("material_tex")
for u in self.uv_layers:
f.uvs.append([u.uvs[i] for i in f.loop_indices])
+ prog_count = len(self.uv_layers)
+ prog_step = 0
+
tbn_layer_index = -1
if self.tbn_vecs:
uv_names = [u.name for u in self.uv_layers]
if self.tbn_uvtex in uv_names:
+ prog_count += 1
tbn_layer_index = uv_names.index(self.tbn_uvtex)
- self.compute_tbn(tbn_layer_index)
+ progress.push_task_slice("Computing TBN", 0, prog_count)
+ self.compute_tbn(tbn_layer_index, progress)
+ progress.set_task_slice(self.tbn_uvtex, 1, prog_count)
self.split_vertices(self.find_uv_group, progress, tbn_layer_index)
+ progress.pop_task()
+ prog_step = 2
- for i in range(len(self.uv_layers)):
+ for i, u in enumerate(self.uv_layers):
+ if i==tbn_layer_index:
+ continue
+
+ progress.push_task_slice(u.name, prog_step, prog_count)
self.split_vertices(self.find_uv_group, progress, i)
+ progress.pop_task()
+ prog_step += 1
for v in self.vertices:
if v.faces:
groups.append(vg)
- if progress:
- progress.set_progress(i*0.5/len(self.vertices))
+ progress.set_progress(i*0.5/len(self.vertices))
for i in range(len(self.vertices)):
for g in groups[i][1:]:
f.vertices[f.vertices.index(self.vertices[i])] = v
v.faces.append(f)
- if progress:
- progress.set_progress(0.5+i*0.5/len(self.vertices))
+ progress.set_progress(0.5+i*0.5/len(self.vertices))
def find_smooth_group(self, vertex, face):
face.flag = True
return group
- def compute_normals(self):
- for v in self.vertices:
+ def compute_normals(self, progress):
+ for i, v in enumerate(self.vertices):
v.normal = mathutils.Vector()
for f in v.faces:
fv = f.pivot_vertices(v)
else:
v.normal = mathutils.Vector((0, 0, 1))
- def compute_tbn(self, index):
+ progress.set_progress(i/len(self.vertices))
+
+ def compute_tbn(self, index, progress):
layer_uvs = self.uv_layers[index].uvs
- for v in self.vertices:
+ for i, v in enumerate(self.vertices):
v.tan = mathutils.Vector()
v.bino = mathutils.Vector()
for f in v.faces:
if v.bino.length:
v.bino.normalize()
+ progress.set_progress(i/len(self.vertices))
+
def drop_references(self):
for v in self.vertices:
v._mvert = None
return result
-def create_mesh_from_object(context, obj, progress=None):
+def create_mesh_from_object(context, obj, progress):
if obj.type!="MESH":
raise Exception("Object is not a mesh")
+ progress.push_task("Preparing mesh", 0.0, 0.3)
+
objs = [(obj, mathutils.Matrix())]
i = 0
while i<len(objs):
else:
mesh = me
+ progress.set_task("Smoothing", 0.3, 0.6)
mesh.prepare_smoothing(progress)
+ progress.set_task("Vertex groups", 0.6, 0.7)
mesh.prepare_vertex_groups(obj)
+ progress.set_task("Preparing UVs", 0.7, 1.0)
mesh.prepare_uv(obj, progress)
mesh.drop_references()
for m in bmeshes:
bpy.data.meshes.remove(m)
+ progress.pop_task()
+
return mesh
self.delta = 1.0
self.last = 0.0
self.stack = []
- self.window_manager = context.window_manager
- self.window_manager.progress_begin(0.0, 1.0)
+ if context:
+ self.window_manager = context.window_manager
+ self.window_manager.progress_begin(0.0, 1.0)
+ else:
+ self.window_manager = None
def push_task(self, task, low, high):
- self.stack.append((task, low, high-low))
- self.set_task("init", 0.0, 0.0)
+ self.stack.append((self.task, self.start, self.delta))
+ self.set_task(task, low, high)
+
+ def push_task_slice(self, task, index, count):
+ self.push_task(task, index/count, (index+1)/count)
def pop_task(self):
- self.set_task("finish", 1.0, 1.0)
- self.stack.pop()
+ if not self.stack:
+ return
+
+ self.set_progress(1.0)
+ self.task, self.start, self.delta = self.stack.pop()
def set_task(self, task, low, high):
if self.stack:
- task = self.stack[-1][0]+": "+task
- low = self.stack[-1][1]+self.stack[-1][2]*low
- high = self.stack[-1][1]+self.stack[-1][2]*high
+ outer = self.stack[-1]
+ if outer[0]:
+ task = "{}: {}".format(outer[0], task)
+ low = outer[1]+low*outer[2]
+ high = outer[1]+high*outer[2]
self.task = task
self.start = low
self.delta = high-low
- self.set_progress(0)
+ self.set_progress(0.0)
+
+ def set_task_slice(self, task, index, count):
+ self.set_task(task, index/count, (index+1)/count)
def set_progress(self, value):
value = self.start+self.delta*value
if value>self.last+0.01:
- self.window_manager.progress_update(value)
+ if self.window_manager:
+ self.window_manager.progress_update(value)
self.last = value