|
@@ -68,6 +68,24 @@ def export_camera_node(escn_file, export_settings, node, parent_gd_node):
|
|
|
return cam_node
|
|
|
|
|
|
|
|
|
+def find_shader_node(node_tree, name):
|
|
|
+ """Find the shader node from the tree with the given name."""
|
|
|
+ for node in node_tree.nodes:
|
|
|
+ if node.bl_idname == name:
|
|
|
+ return node
|
|
|
+ logging.warning("%s node not found", name)
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
+def node_input(node, name):
|
|
|
+ """Get the named input value from the shader node."""
|
|
|
+ for inp in node.inputs:
|
|
|
+ if inp.name == name:
|
|
|
+ return inp.default_value
|
|
|
+ logging.warning("%s input not found in %s", name, node.bl_idname)
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
class LightNode(NodeTemplate):
|
|
|
"""Base class for godot light node"""
|
|
|
_light_attr_conv = [
|
|
@@ -104,14 +122,16 @@ class LightNode(NodeTemplate):
|
|
|
def export_light_node(escn_file, export_settings, node, parent_gd_node):
|
|
|
"""Exports lights - well, the ones it knows about. Other light types
|
|
|
just throw a warning"""
|
|
|
- light = node.data
|
|
|
+ bl_light_to_gd_light = {
|
|
|
+ "POINT": "OmniLight",
|
|
|
+ "SPOT": "SpotLight",
|
|
|
+ "SUN": "DirectionalLight",
|
|
|
+ }
|
|
|
|
|
|
- if light.type == "POINT":
|
|
|
- light_node = LightNode(node.name, 'OmniLight', parent_gd_node)
|
|
|
- elif light.type == "SPOT":
|
|
|
- light_node = LightNode(node.name, 'SpotLight', parent_gd_node)
|
|
|
- elif light.type == "SUN":
|
|
|
- light_node = LightNode(node.name, 'DirectionalLight', parent_gd_node)
|
|
|
+ light = node.data
|
|
|
+ if light.type in bl_light_to_gd_light:
|
|
|
+ light_node = LightNode(
|
|
|
+ node.name, bl_light_to_gd_light[light.type], parent_gd_node)
|
|
|
else:
|
|
|
light_node = None
|
|
|
logging.warning(
|
|
@@ -123,9 +143,26 @@ def export_light_node(escn_file, export_settings, node, parent_gd_node):
|
|
|
bl_attr, gd_attr, converter = item
|
|
|
light_node[gd_attr] = converter(getattr(light, bl_attr))
|
|
|
|
|
|
- # Properties cannot handled by a converter function
|
|
|
+ # Properties common to all lights
|
|
|
+ # These cannot be set via AttributeConvertInfo as it will not handle
|
|
|
+ # animations correctly
|
|
|
light_node['transform'] = fix_directional_transform(node.matrix_local)
|
|
|
- light_node['shadow_enabled'] = light.use_shadow
|
|
|
+ if light.use_nodes:
|
|
|
+ emission = find_shader_node(light.node_tree, 'ShaderNodeEmission')
|
|
|
+ if emission:
|
|
|
+ strength = node_input(emission, 'Strength') or 100
|
|
|
+ color = node_input(emission, 'Color') or [1, 1, 1]
|
|
|
+ # we don't have an easy way to get these in cycles
|
|
|
+ # don't set them and let godot use its defaults
|
|
|
+ del light_node['light_specular']
|
|
|
+ del light_node['shadow_color']
|
|
|
+ # strength=100 in cycles is roughly equivalent to energy=1
|
|
|
+ light_node['light_energy'] = abs(strength / 100.0)
|
|
|
+ light_node['light_color'] = gamma_correct(color)
|
|
|
+ light_node['shadow_enabled'] = light.cycles.cast_shadow
|
|
|
+ light_node['light_negative'] = strength < 0
|
|
|
+ else:
|
|
|
+ light_node['shadow_enabled'] = light.use_shadow
|
|
|
|
|
|
escn_file.add_node(light_node)
|
|
|
|