From 9ab6b16ed2b739ea9c11cecc9b83a20b974e18fa Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 24 Jun 2016 15:58:06 -0400 Subject: [PATCH] Implement limited directional lights --- korman/exporter/rtlight.py | 8 ++++++++ korman/properties/prop_lamp.py | 6 ++++++ korman/ui/ui_lamp.py | 37 +++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/korman/exporter/rtlight.py b/korman/exporter/rtlight.py index ec7495c..01787e2 100644 --- a/korman/exporter/rtlight.py +++ b/korman/exporter/rtlight.py @@ -21,6 +21,7 @@ from .explosions import * from . import utils _BL2PL = { + "AREA": plLimitedDirLightInfo, "POINT": plOmniLightInfo, "SPOT": plSpotLightInfo, "SUN": plDirectionalLightInfo, @@ -32,6 +33,7 @@ class LightConverter: def __init__(self, exporter): self._exporter = weakref.ref(exporter) self._converter_funcs = { + "AREA": self._convert_area_lamp, "POINT": self._convert_point_lamp, "SPOT": self._convert_spot_lamp, "SUN": self._convert_sun_lamp, @@ -64,6 +66,12 @@ class LightConverter: else: raise BlenderOptionNotSupportedError(bl.falloff_type) + def _convert_area_lamp(self, bl, pl): + print(" [LimitedDirLightInfo '{}']".format(bl.name)) + + pl.width = bl.size + pl.depth = bl.size if bl.shape == "SQUARE" else bl.size_y + pl.height = bl.plasma_lamp.size_height def _convert_point_lamp(self, bl, pl): print(" [OmniLightInfo '{}']".format(bl.name)) diff --git a/korman/properties/prop_lamp.py b/korman/properties/prop_lamp.py index 56dea69..ada5ce5 100644 --- a/korman/properties/prop_lamp.py +++ b/korman/properties/prop_lamp.py @@ -32,3 +32,9 @@ class PlasmaLamp(bpy.types.PropertyGroup): soft_region = StringProperty(name="Soft Volume", description="Soft region this light is active inside", options=set()) + + # For LimitedDirLights + size_height = FloatProperty(name="Height", + description="Size of the area for the Area Lamp in the Z direction", + min=0.0, default=200.0, + options=set()) diff --git a/korman/ui/ui_lamp.py b/korman/ui/ui_lamp.py index 27b589e..7501cf1 100644 --- a/korman/ui/ui_lamp.py +++ b/korman/ui/ui_lamp.py @@ -31,7 +31,7 @@ class PlasmaLampPanel(LampButtonsPanel, bpy.types.Panel): def draw (self, context): layout = self.layout - rtlamp = context.object.data.plasma_lamp + rtlamp = context.lamp.plasma_lamp split = layout.split() col = split.column() @@ -45,3 +45,38 @@ class PlasmaLampPanel(LampButtonsPanel, bpy.types.Panel): if not context.object.plasma_modifiers.softvolume.enabled: layout.prop_search(rtlamp, "soft_region", bpy.data, "objects") + + +def _draw_area_lamp(self, context): + """Draw dispatch function for DATA_PT_area""" + if context.scene.render.engine == "PLASMA_GAME": + _plasma_draw_area_lamp(self, context) + else: + self._draw_blender(context) + + +def _plasma_draw_area_lamp(self, context): + """Draw function for DATA_PT_area when Korman is active""" + layout = self.layout + lamp = context.lamp + plasma_lamp = lamp.plasma_lamp + + col = layout.column() + col.row().prop(lamp, "shape", expand=True) + sub = col.row(align=True) + + if lamp.shape == "SQUARE": + sub.prop(lamp, "size") + sub.prop(plasma_lamp, "size_height") + elif lamp.shape == "RECTANGLE": + sub.prop(lamp, "size", text="W") + sub.prop(lamp, "size_y", text="D") + sub.prop(plasma_lamp, "size_height", text="H") + +# Swap out the draw functions for the standard Area Shape panel +# TODO: Maybe we should consider standardizing an interface for overriding +# standard Blender panels? This seems like a really useful approach. +from bl_ui import properties_data_lamp +properties_data_lamp.DATA_PT_area._draw_blender = properties_data_lamp.DATA_PT_area.draw +properties_data_lamp.DATA_PT_area.draw = _draw_area_lamp +del properties_data_lamp