6 self.selected_only = False
7 self.visible_only = True
9 self.skip_existing = True
11 def export_to_file(self, context, out_fn):
12 from .util import Progress
13 progress = Progress(context)
15 from .scene import create_scene_from_current
16 scene = create_scene_from_current(context, selected_only=self.selected_only, visible_only=self.visible_only)
19 self.export_scene_resources(context, scene, resources, progress)
20 scene_res = self.export_scene(scene, resources)
21 progress.set_progress(1.0)
23 path, base = os.path.split(out_fn)
24 base, ext = os.path.splitext(base)
28 if self.skip_existing:
29 existing = lambda r: not os.path.exists(os.path.join(path, r.name))
30 scene_res.write_collection(out_fn, filter=existing)
32 scene_res.write_to_file(out_fn)
33 for r in scene_res.collect_references():
34 r.write_to_file(os.path.join(path, r.name))
36 def export_scene_resources(self, context, scene, resources, progress):
37 from .export import DataExporter
38 data_exporter = DataExporter()
40 data_exporter.export_resources(context, scene.prototypes, resources, None, progress)
42 def export_scene(self, scene, resources):
43 from .datafile import Resource, Statement, Token
44 scene_res = Resource(scene.name+".scene", "scene")
46 scene_res.statements.append(Statement("type", Token(scene.scene_type.lower())))
48 for i in scene.instances:
49 obj_res = resources[i.prototype+".object"]
50 st = scene_res.create_reference_statement("object", obj_res, i.name)
52 ss = Statement("transform")
54 loc = i.matrix_world.to_translation()
55 ss.sub.append(Statement("position", *tuple(loc)))
57 quat = i.matrix_world.to_quaternion()
58 if i.rotation_mode in ('XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'):
59 angles = [a*180/math.pi for a in quat.to_euler()]
60 ss.sub.append(Statement("euler", *angles));
62 ss.sub.append(Statement("rotation", quat.angle*180/math.pi, *tuple(quat.axis)))
64 scale = i.matrix_world.to_scale()
65 ss.sub.append(Statement("scale", *tuple(scale)))
68 scene_res.statements.append(st)
72 def export_sequence_resources(self, scene, resources):
73 from .datafile import Resource, Statement, Token
75 if scene.background_set:
76 wrapper_name = scene.name+".wrapper.scene"
77 if wrapper_name not in resources:
78 wrapper_res = Resource(wrapper_name, "scene")
79 wrapper_res.statements.append(Statement("type", Token("ordered")))
80 for s in scene.get_chain():
81 wrapper_res.statements.append(wrapper_res.create_reference_statement("scene", resources[s.name+".scene"]))
83 resources[wrapper_name] = wrapper_res
91 from .util import make_unique
92 lights = make_unique(lights)
94 from .export_light import LightExporter
95 light_exporter = LightExporter()
97 light_name = l.name+".light"
98 if light_name not in resources:
99 resources[light_name] = light_exporter.export_light(l)
101 lighting_name = scene.name+".lightn"
102 if lighting_name not in resources:
103 lighting_res = Resource(lighting_name, "lighting")
105 lighting_res.statements.append(lighting_res.create_reference_statement("light", resources[l.name+".light"]))
107 resources[lighting_name] = lighting_res
109 def export_sequence(self, scene, resources):
110 from .datafile import Resource, Statement
111 seq_res = Resource(scene.name+".seq", "sequence")
114 seq_res.statements.append(Statement("hdr", True))
117 if scene.background_set:
118 content = resources[scene.name+".wrapper.scene"]
120 ss = Statement("pass", "", "content")
121 ss.sub.append(Statement("depth_test", "lequal"))
122 ss.sub.append(seq_res.create_reference_statement("lighting", resources[scene.name+".lightn"]))
123 ss.sub.append(seq_res.create_reference_statement("scene", content))
124 seq_res.statements.append(ss)
127 seq_res.statements.append(Statement("bloom"))
128 ss = Statement("colorcurve")
129 ss.sub.append(Statement("exposure_adjust", scene.exposure))
130 ss.sub.append(Statement("srgb"))
131 seq_res.statements.append(ss)
133 # Add a colorcurve with linear response to convert into sRGB color space
134 ss = Statement("colorcurve")
135 ss.sub.append(Statement("brightness_response", 1.0))
136 ss.sub.append(Statement("srgb"))
137 seq_res.statements.append(ss)