import os
class SceneExporter:
- def __init__(self):
- self.selected_only = False
- self.visible_only = True
- self.collection = True
- self.skip_existing = True
-
- def export_to_file(self, context, out_fn):
+ 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)
from .scene import create_scene_from_current
- scene = create_scene_from_current(context, selected_only=self.selected_only, visible_only=self.visible_only)
+ scene = create_scene_from_current(context, selected_only=selected_only, visible_only=visible_only)
resources = {}
self.export_scene_resources(context, scene, resources, progress)
path, base = os.path.split(out_fn)
base, ext = os.path.splitext(base)
- if self.collection:
+ if collection:
existing = None
- if self.skip_existing:
+ if skip_existing:
existing = lambda r: not os.path.exists(os.path.join(path, r.name))
scene_res.write_collection(out_fn, filter=existing)
else:
from .datafile import Resource, Statement, Token
scene_res = Resource(scene.name+".scene", "scene")
- scene_res.statements.append(Statement("type", Token(scene.scene_type.lower())))
+ scene_res.statements.append(Statement("type", Token("simple")))
for i in scene.instances:
obj_res = resources[i.prototype+".object"]
lighting_name = scene.name+".lightn"
if lighting_name not in resources:
lighting_res = Resource(lighting_name, "lighting")
+ lighting_res.statements.append(Statement("ambient", *tuple(scene.ambient_light)))
for l in lights:
lighting_res.statements.append(lighting_res.create_reference_statement("light", resources[l.name+".light"]))
resources[lighting_name] = lighting_res
def export_sequence(self, scene, resources):
- from .datafile import Resource, Statement
+ from .datafile import Resource, Statement, Token
seq_res = Resource(scene.name+".seq", "sequence")
+ if scene.use_hdr:
+ seq_res.statements.append(Statement("hdr", True))
+
content = scene
if scene.background_set:
content = resources[scene.name+".wrapper.scene"]
- ss = Statement("pass", "", "content")
- ss.sub.append(Statement("depth_test", "lequal"))
+ 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)
+
+ ss = Statement("step", "", "content")
+ ss.sub.append(Statement("depth_test", Token("LEQUAL")))
ss.sub.append(seq_res.create_reference_statement("lighting", resources[scene.name+".lightn"]))
ss.sub.append(seq_res.create_reference_statement("scene", content))
seq_res.statements.append(ss)
- # Add a colorcurve with linear response to convert into sRGB color space
- ss = Statement("colorcurve")
- ss.sub.append(Statement("brightness_response", 1.0))
- ss.sub.append(Statement("srgb"))
- seq_res.statements.append(ss)
+ if scene.use_ao:
+ ss = Statement("ambient_occlusion")
+ ss.sub.append(Statement("occlusion_radius", scene.ao_distance))
+ ss.sub.append(Statement("samples", scene.ao_samples))
+ seq_res.statements.append(ss)
+
+ if scene.use_hdr:
+ seq_res.statements.append(Statement("bloom"))
+ ss = Statement("colorcurve")
+ ss.sub.append(Statement("exposure_adjust", scene.exposure))
+ ss.sub.append(Statement("srgb"))
+ seq_res.statements.append(ss)
+ else:
+ # Add a colorcurve with linear response to convert into sRGB color space
+ ss = Statement("colorcurve")
+ ss.sub.append(Statement("brightness_response", 1.0))
+ ss.sub.append(Statement("srgb"))
+ seq_res.statements.append(ss)
return seq_res