Browse Source

add decayExponent support to lights.

Ben Houston 9 years ago
parent
commit
d848e13d34

+ 2 - 0
utils/exporters/blender/addons/io_three/constants.py

@@ -113,6 +113,7 @@ ERROR = 'error'
 WARNING = 'warning'
 WARNING = 'warning'
 INFO = 'info'
 INFO = 'info'
 DEBUG = 'debug'
 DEBUG = 'debug'
+DISABLED = 'disabled'
 
 
 NONE = 'None'
 NONE = 'None'
 MSGPACK = 'msgpack'
 MSGPACK = 'msgpack'
@@ -338,6 +339,7 @@ INTENSITY = 'intensity'
 DISTANCE = 'distance'
 DISTANCE = 'distance'
 ASPECT = 'aspect'
 ASPECT = 'aspect'
 ANGLE = 'angle'
 ANGLE = 'angle'
+DECAY = 'decayExponent'
 
 
 FOV = 'fov'
 FOV = 'fov'
 ASPECT = 'aspect'
 ASPECT = 'aspect'

+ 20 - 0
utils/exporters/blender/addons/io_three/exporter/api/light.py

@@ -75,3 +75,23 @@ def intensity(lamp):
     """
     """
     logger.debug("light.intensity(%s)", lamp)
     logger.debug("light.intensity(%s)", lamp)
     return round(lamp.energy, 2)
     return round(lamp.energy, 2)
+
+# mapping enum values to decay exponent
+__FALLOFF_TO_EXP = {
+    'CONSTANT': 0,
+    'INVERSE_LINEAR': 1,
+    'INVERSE_SQUARE': 2,
+    'CUSTOM_CURVE': 0,
+    'LINEAR_QUADRATIC_WEIGHTED': 2
+}
+
+@_lamp
+def falloff(lamp):
+    """
+
+    :param lamp:
+    :rtype: float
+
+    """
+    logger.debug("light.falloff(%s)", lamp)
+    return __FALLOFF_TO_EXP[lamp.falloff_type]

+ 5 - 1
utils/exporters/blender/addons/io_three/exporter/object.py

@@ -51,8 +51,12 @@ class Object(base_classes.BaseNode):
         #    self[constants.DISTANCE] = api.light.distance(self.data)
         #    self[constants.DISTANCE] = api.light.distance(self.data)
         self[constants.DISTANCE] = 0;
         self[constants.DISTANCE] = 0;
 
 
-        if self[constants.TYPE] == constants.SPOT_LIGHT:
+        lightType = self[constants.TYPE]
+        if lightType == constants.SPOT_LIGHT:
             self[constants.ANGLE] = api.light.angle(self.data)
             self[constants.ANGLE] = api.light.angle(self.data)
+            self[constants.DECAY] = api.light.falloff(self.data)
+        elif lightType == constants.POINT_LIGHT:
+            self[constants.DECAY] = api.light.falloff(self.data)
 
 
     def _init_mesh(self):
     def _init_mesh(self):
         """Initialize mesh attributes"""
         """Initialize mesh attributes"""