]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/scene.py
Redesign progress and error reporting in the Blender exporter
[libs/gl.git] / blender / io_mspgl / scene.py
index 50ccb7c2d694fd91632ea6e36eeacdb93a1fd80f..70dbc8c9a7178d19470c5ba3d0ae5e1c2e142250 100644 (file)
@@ -13,22 +13,27 @@ class Instance:
                self.name = obj.name
                self.matrix_world = obj.matrix_world
                self.rotation_mode = obj.rotation_mode
-               self.prototype = prototype.name
+               self.prototype = prototype
 
 class Scene:
        def __init__(self, scene, obj_filter=None):
                self.name = scene.name
-               self.scene_type = scene.scene_type
                self.export_disposition = scene.export_disposition
                self.background_set = None
                self.camera = scene.camera
                self.prototypes = []
                self.instances = []
+               self.blended_instances = []
                self.lights = []
+               self.realtime_sky = False
+               self.sun_light = None
                self.ambient_light = mathutils.Color((0.0, 0.0, 0.0))
                self.exposure = scene.view_settings.exposure
 
                self.use_hdr = scene.use_hdr
+               self.use_ao = scene.eevee.use_gtao
+               self.ao_distance = scene.eevee.gtao_distance
+               self.ao_samples = scene.ao_samples
                if scene.world:
                        out_node = next((n for n in scene.world.node_tree.nodes if n.type=='OUTPUT_WORLD'), None)
                        if out_node:
@@ -40,6 +45,12 @@ class Scene:
                                        s = surface_node.inputs["Strength"].default_value
                                        self.ambient_light = mathutils.Color(c[:3])*s
 
+                       self.use_sky = scene.world.use_sky and scene.world.sun_light
+                       self.sun_light = scene.world.sun_light
+
+               self.use_shadow = False
+               self.use_ibl = False
+
                objects = scene.objects[:]
                objects.sort(key=lambda o:o.name)
                if obj_filter:
@@ -53,11 +64,20 @@ class Scene:
                        if o.type=='MESH':
                                clones = [c for c in objects if is_same_object(o, c)]
                                self.prototypes.append(o)
+                               instance_list = self.instances
+                               if o.material_slots and o.material_slots[0].material:
+                                       mat = o.material_slots[0].material
+                                       if mat.blend_method=='BLEND':
+                                               instance_list = self.blended_instances
+                                       if mat.image_based_lighting:
+                                               self.use_ibl = True
                                for c in clones:
-                                       self.instances.append(Instance(c, o))
+                                       instance_list.append(Instance(c, o))
                                        processed.add(c.name)
                        elif o.type=='LIGHT':
                                self.lights.append(o)
+                               if o.data.use_shadow:
+                                       self.use_shadow = True
 
        def get_chain(self):
                result = []
@@ -72,7 +92,7 @@ def get_all_collections(collection):
                result += get_all_collections(c)
        return result
 
-def create_scene_from_current(context, *, selected_only=False, visible_only=True):
+def create_scene_from_current(ctx, *, selected_only=False, visible_only=True):
        obj_filters = []
 
        if selected_only:
@@ -80,7 +100,7 @@ def create_scene_from_current(context, *, selected_only=False, visible_only=True
 
        if visible_only:
                visible_names = set()
-               for c in get_all_collections(context.view_layer.layer_collection):
+               for c in get_all_collections(ctx.context.view_layer.layer_collection):
                        if not c.hide_viewport and not c.collection.hide_viewport:
                                visible_names.update(o.name for o in c.collection.objects)
                obj_filters.append(lambda o: o.name in visible_names)
@@ -91,7 +111,7 @@ def create_scene_from_current(context, *, selected_only=False, visible_only=True
        if obj_filters:
                obj_filter = lambda o: all(f(o) for f in obj_filters)
 
-       return Scene(context.scene, obj_filter)
+       return Scene(ctx.context.scene, obj_filter)
 
 def create_scene(scene, *, visible_only=True):
        obj_filter = None