Просмотр исходного кода

Fix for shadow bias value truncation. Exposed shadow darkness in light panel.

rknopf 8 лет назад
Родитель
Сommit
94baa62a25

+ 12 - 1
Exporters/Blender/src/babylon-js/light_shadow.py

@@ -113,6 +113,7 @@ class ShadowGenerator:
         self.lightId = lamp.name
         self.mapSize = lamp.data.shadowMapSize
         self.shadowBias = lamp.data.shadowBias
+        self.shadowStrength = lamp.data.shadowStrength
 
         if lamp.data.shadowMap == ESM_SHADOWS:
             self.useExponentialShadowMap = True
@@ -133,7 +134,8 @@ class ShadowGenerator:
         file_handler.write('{')
         write_int(file_handler, 'mapSize', self.mapSize, True)
         write_string(file_handler, 'lightId', self.lightId)
-        write_float(file_handler, 'bias', self.shadowBias)
+        write_float(file_handler, 'bias', self.shadowBias, precision = 5)
+        write_float(file_handler, 'darkness', self.shadowDarkness)
 
         if hasattr(self, 'useExponentialShadowMap') :
             write_bool(file_handler, 'useExponentialShadowMap', self.useExponentialShadowMap)
@@ -195,6 +197,11 @@ bpy.types.Lamp.shadowBlurBoxOffset = bpy.props.IntProperty(
     description='Setting when using a Blur Variance shadow map',
     default = 0
 )
+bpy.types.Lamp.shadowDarkness = bpy.props.FloatProperty(
+    name='Shadow Darkness',
+    description='Shadow Darkness',
+    default = 1
+)
 #===============================================================================
 class LightPanel(bpy.types.Panel):
     bl_label = get_title()
@@ -220,6 +227,10 @@ class LightPanel(bpy.types.Panel):
         row = layout.row()
         row.enabled = usingShadows
         row.prop(ob.data, 'shadowBias')
+        
+        row = layout.row()
+        row.enabled = usingShadows
+        row.prop(ob.data, 'shadowDarkness')
 
         box = layout.box()
         box.label(text="Blur ESM Shadows")

+ 7 - 6
Exporters/Blender/src/babylon-js/package_level.py

@@ -4,8 +4,8 @@ from mathutils import Euler, Matrix
 
 from bpy import app
 from time import strftime
-MAX_FLOAT_PRECISION_INT = 4
-MAX_FLOAT_PRECISION = '%.' + str(MAX_FLOAT_PRECISION_INT) + 'f'
+FLOAT_PRECISION_DEFAULT = 4
+#MAX_FLOAT_PRECISION = '%.' + str(MAX_FLOAT_PRECISION_DEFAULT) + 'f'
 VERTEX_OUTPUT_PER_LINE = 50
 STRIP_LEADING_ZEROS_DEFAULT = False # false for .babylon
 #===============================================================================
@@ -92,8 +92,9 @@ def legal_js_identifier(input):
         out += '_' + prefix
     return out
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-def format_f(num, stripLeadingZero = STRIP_LEADING_ZEROS_DEFAULT):
-    s = MAX_FLOAT_PRECISION % num # rounds to N decimal places while changing to string
+def format_f(num, stripLeadingZero = STRIP_LEADING_ZEROS_DEFAULT, precision = FLOAT_PRECISION_DEFAULT):
+    fmt = '%.' + str(precision) + 'f'
+    s = fmt % num  # rounds to N decimal places
     s = s.rstrip('0') # strip trailing zeroes
     s = s.rstrip('.') # strip trailing .
     s = '0' if s == '-0' else s # nuke -0
@@ -267,8 +268,8 @@ def write_string(file_handler, name, string, noComma = False):
         file_handler.write(',')
     file_handler.write('"' + name + '":"' + string + '"')
 
-def write_float(file_handler, name, float):
-    file_handler.write(',"' + name + '":' + format_f(float))
+def write_float(file_handler, name, float, precision = FLOAT_PRECISION_DEFAULT):
+    file_handler.write(',"' + name + '":' + format_f(float, precision = precision))
 
 def write_int(file_handler, name, int, noComma = False):
     if noComma == False: