]> git.tdb.fi Git - libs/gl.git/commitdiff
Export the scene's background color as ambient light color
authorMikko Rasa <tdb@tdb.fi>
Wed, 5 May 2021 12:29:05 +0000 (15:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 5 May 2021 12:30:30 +0000 (15:30 +0300)
blender/io_mspgl/export_scene.py
blender/io_mspgl/scene.py

index 39a7428e146652018c5db011f2e8007e08d0e06c..77755a65b7479353958f36ebee02c8f77635a1bd 100644 (file)
@@ -101,6 +101,7 @@ class SceneExporter:
                lighting_name = scene.name+".lightn"
                if lighting_name not in resources:
                        lighting_res = Resource(lighting_name, "lighting")
                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"]))
 
                        for l in lights:
                                lighting_res.statements.append(lighting_res.create_reference_statement("light", resources[l.name+".light"]))
 
index 21d54c7b25a1ea31cbd79acddd4e9a89e1f3fe91..7532f48ccdd82d88de86cafcef2b4fc9237d40d8 100644 (file)
@@ -1,3 +1,5 @@
+import mathutils
+
 def is_same_object(obj1, obj2):
        if obj1.data.name!=obj2.data.name:
                return False
 def is_same_object(obj1, obj2):
        if obj1.data.name!=obj2.data.name:
                return False
@@ -23,12 +25,23 @@ class Scene:
                self.prototypes = []
                self.instances = []
                self.lights = []
                self.prototypes = []
                self.instances = []
                self.lights = []
+               self.ambient_light = mathutils.Color((0.0, 0.0, 0.0))
                self.exposure = scene.view_settings.exposure
 
                self.use_hdr = False
                if scene.world:
                        self.use_hdr = scene.world.use_hdr
 
                self.exposure = scene.view_settings.exposure
 
                self.use_hdr = False
                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)
                if obj_filter:
                objects = scene.objects[:]
                objects.sort(key=lambda o:o.name)
                if obj_filter: