import mathutils
class ObjectExporter:
- def compute_bounding_sphere(self, obj):
- p1 = max(((v.co, v.co.length) for v in obj.data.vertices), key=lambda x:x[1])[0]
- p2 = max(((v.co, (v.co-p1).length) for v in obj.data.vertices), key=lambda x:x[1])[0]
- center = (p1+p2)/2
- radius = (p1-p2).length/2
- for v in obj.data.vertices:
- d = v.co-center
- if d.length>radius:
- center += d*(1-radius/d.length)/2
- radius = (radius+d.length)/2
-
- return center, radius
-
def collect_object_lods(self, obj):
lods = [obj]
lods += sorted([c for c in obj.children if c.lod_for_parent], key=(lambda l: l.lod_index))
obj_res = Resource(obj.name+".object", "object")
statements = obj_res.statements
- center, radius = self.compute_bounding_sphere(obj)
+ from .util import compute_bounding_sphere
+ center, radius = compute_bounding_sphere([v.co for v in obj.data.vertices])
statements.append(Statement("bounding_sphere_hint", *center, radius))
prev_mesh = None
if scene.use_hdr:
seq_res.statements.append(Statement("hdr", True))
- ss = Statement("clear")
- ss.sub.append(Statement("color", 0.0, 0.0, 0.0, 0.0))
- ss.sub.append(Statement("depth", 1.0))
- seq_res.statements.append(ss)
+ self.add_clear(seq_res.statements, (0.0, 0.0, 0.0, 0.0), 1.0)
scene_res = resources[scene.name+".scene"]
seq_res.statements.append(seq_res.create_reference_statement("renderable", "content", scene_res))
any_blended = True
s = s.background_set
- if any_opaque:
- ss = Statement("step", "", "content")
- ss.sub.append(Statement("depth_test", Token("LEQUAL")))
- ss.sub.append(seq_res.create_reference_statement("lighting", lighting_res))
- seq_res.statements.append(ss)
+ main_tags = []
+ if any_opaque:
+ main_tags.append("")
if any_blended:
- ss = Statement("step", "blended", "content")
- ss.sub.append(Statement("depth_test", Token("LEQUAL")))
- ss.sub.append(seq_res.create_reference_statement("lighting", lighting_res))
- seq_res.statements.append(ss)
+
+ self.add_content_steps(seq_res, "content", lighting_res, main_tags)
if scene.use_ao:
ss = Statement("postprocessor")
seq_res.statements.append(ss)
return seq_res
+
+ def add_clear(self, statements, color, depth):
+ from .datafile import Statement
+
+ st = Statement("clear")
+ if color is not None:
+ st.sub.append(Statement("color", *color))
+ if depth is not None:
+ st.sub.append(Statement("depth", depth))
+ statements.append(st)
+
+ def add_content_steps(self, seq_res, renderable, lighting, tags):
+ from .datafile import Statement, Token
+
+ for t in tags:
+ st = Statement("step", t, renderable)
+ st.sub.append(Statement("depth_test", Token("LEQUAL")))
+ if lighting:
+ st.sub.append(seq_res.create_reference_statement("lighting", lighting))
+ seq_res.statements.append(st)
elif socket==l.from_socket:
return (l.to_node, l.to_socket)
return (None, None)
+
+def compute_bounding_sphere(points):
+ p1 = max(((p, p.length) for p in points), key=lambda x:x[1])[0]
+ p2 = max(((p, (p-p1).length) for p in points), key=lambda x:x[1])[0]
+ center = (p1+p2)/2
+ radius = (p1-p2).length/2
+ for p in points:
+ d = p-center
+ if d.length>radius:
+ center += d*(1-radius/d.length)/2
+ radius = (radius+d.length)/2
+
+ return center, radius