import mathutils
class SceneExporter:
- def export_to_file(self, context, out_fn, *, selected_only=False, visible_only=True, collection=True, skip_existing=True):
- from .util import Progress
- progress = Progress(context)
-
+ def export_to_file(self, ctx, out_fn, *, selected_only=False, visible_only=True, collection=True, skip_existing=True):
from .scene import create_scene_from_current
- scene = create_scene_from_current(context, selected_only=selected_only, visible_only=visible_only)
+ task = ctx.task("Preparing scene", 0.1)
+ scene = create_scene_from_current(task, selected_only=selected_only, visible_only=visible_only)
resources = {}
- self.export_scene_resources(context, scene, resources, progress)
+ task = ctx.task("Exporting resources", 0.9)
+ self.export_scene_resources(task, scene, resources)
+ task = ctx.task(scene, 1.0)
scene_res = self.export_scene(scene, resources)
- progress.set_progress(1.0)
path, base = os.path.split(out_fn)
base, ext = os.path.splitext(base)
+ task = ctx.task("Writing files", 1.0)
if collection:
existing = None
if skip_existing:
for r in scene_res.collect_references():
r.write_to_file(os.path.join(path, r.name))
- def export_scene_resources(self, context, scene, resources, progress):
+ def export_scene_resources(self, ctx, scene, resources):
from .export import DataExporter
data_exporter = DataExporter()
- data_exporter.export_resources(context, scene.prototypes, resources, None, progress)
+ data_exporter.export_resources(ctx, [p.object for p in scene.prototypes], resources)
def export_scene(self, scene, resources):
from .datafile import Resource, Statement, Token
for i in instances:
obj_res = resources[i.prototype.name+".object"]
- st = scene_res.create_reference_statement("object", obj_res, i.name)
+ st = scene_res.create_reference_statement("object", obj_res)
+ if i.name:
+ st.append(i.name)
- ss = Statement("transform")
+ st.sub.append(self.create_transform_statement(i))
+ statements.append(st)
- loc = i.matrix_world.to_translation()
- ss.sub.append(Statement("position", *tuple(loc)))
+ def create_transform_statement(self, instance):
+ from .datafile import Statement
- quat = i.matrix_world.to_quaternion()
- if i.rotation_mode in ('XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'):
- angles = [a*180/math.pi for a in quat.to_euler()]
- ss.sub.append(Statement("euler", *angles));
- else:
- ss.sub.append(Statement("rotation", quat.angle*180/math.pi, *tuple(quat.axis)))
+ st = Statement("transform")
- scale = i.matrix_world.to_scale()
- ss.sub.append(Statement("scale", *tuple(scale)))
+ loc = instance.matrix_world.to_translation()
+ st.sub.append(Statement("position", *tuple(loc)))
- st.sub.append(ss)
- statements.append(st)
+ quat = instance.matrix_world.to_quaternion()
+ if instance.rotation_mode in ('XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'):
+ angles = [a*180/math.pi for a in quat.to_euler()]
+ st.sub.append(Statement("euler", *angles));
+ else:
+ st.sub.append(Statement("rotation", quat.angle*180/math.pi, *tuple(quat.axis)))
+
+ scale = instance.matrix_world.to_scale()
+ st.sub.append(Statement("scale", *tuple(scale)))
+
+ return st
def export_sequence_resources(self, scene, resources):
from .datafile import Resource, Statement, Token
use_shadow = True
shadowed_lights += [l.data for l in s.lights if l.data.use_shadow]
for i in itertools.chain(s.instances, s.blended_instances):
- p = i.prototype
- if p.material_slots and p.material_slots[0].material and p.material_slots[0].material.shadow_method!='NONE':
+ o = i.prototype.object
+ if o.material_slots and o.material_slots[0].material and o.material_slots[0].material.shadow_method!='NONE':
shadow_casters.append(i)
s = s.background_set
st = Statement("effect", "shadow_map")
st.sub.append(Statement("type", Token("shadow_map")))
+ st.sub.append(Statement("enable_for_method", "blended"))
st.sub.append(Statement("size", *self.compute_shadowmap_size(shadowed_lights)))
target, radius = self.compute_bounding_sphere(shadow_casters)
st.sub.append(Statement("target", *target))
def compute_bounding_sphere(self, instances):
points = []
for i in instances:
- points += [i.matrix_world@mathutils.Vector(c) for c in i.prototype.bound_box]
+ points += [i.matrix_world@mathutils.Vector(c) for c in i.prototype.object.bound_box]
from .util import compute_bounding_sphere
return compute_bounding_sphere(points)