]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/scene.py
Recognize transparent materials in Blender and export them accordingly
[libs/gl.git] / blender / io_mspgl / scene.py
index 21d54c7b25a1ea31cbd79acddd4e9a89e1f3fe91..8f4f285b195d3af543b1a2b64c9ef592a626b6d3 100644 (file)
@@ -1,3 +1,5 @@
+import mathutils
+
 def is_same_object(obj1, obj2):
        if obj1.data.name!=obj2.data.name:
                return False
@@ -16,18 +18,30 @@ class Instance:
 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.ambient_light = mathutils.Color((0.0, 0.0, 0.0))
                self.exposure = scene.view_settings.exposure
 
-               self.use_hdr = False
+               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:
-                       self.use_hdr = scene.world.use_hdr
+                       out_node = next((n for n in scene.world.node_tree.nodes if n.type=='OUTPUT_WORLD'), None)
+                       if out_node:
+                               from .util import get_linked_node_and_socket
+
+                               surface_node, _ = get_linked_node_and_socket(scene.world.node_tree, out_node.inputs["Surface"])
+                               if surface_node and surface_node.type=='BACKGROUND':
+                                       c = surface_node.inputs["Color"].default_value
+                                       s = surface_node.inputs["Strength"].default_value
+                                       self.ambient_light = mathutils.Color(c[:3])*s
 
                objects = scene.objects[:]
                objects.sort(key=lambda o:o.name)
@@ -42,8 +56,11 @@ 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 and o.material_slots[0].material.blend_method=='BLEND':
+                                       instance_list = self.blended_instances
                                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)