From: Mikko Rasa Date: Wed, 5 May 2021 12:29:05 +0000 (+0300) Subject: Export the scene's background color as ambient light color X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7d8c187f036a7c91f9073ca0071a20807c0f1aa5;p=libs%2Fgl.git Export the scene's background color as ambient light color --- diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index 39a7428e..77755a65 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -101,6 +101,7 @@ class SceneExporter: 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"])) diff --git a/blender/io_mspgl/scene.py b/blender/io_mspgl/scene.py index 21d54c7b..7532f48c 100644 --- a/blender/io_mspgl/scene.py +++ b/blender/io_mspgl/scene.py @@ -1,3 +1,5 @@ +import mathutils + 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.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 + 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: