Przeglądaj źródła

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 8 lat temu
rodzic
commit
cb4c8e08c9

+ 14 - 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.shadowDarkness = lamp.data.shadowDarkness
 
         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,13 @@ 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,
+    min = 0, 
+    max = 1
+)
 #===============================================================================
 class LightPanel(bpy.types.Panel):
     bl_label = get_title()
@@ -220,6 +229,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:

+ 66 - 8
Exporters/Blender/src/babylon-js/world.py

@@ -2,12 +2,19 @@ from .logger import *
 from .package_level import *
 
 import bpy
+import mathutils
 
 # used in World constructor, defined in BABYLON.Scene
-#FOGMODE_NONE = 0
-#FOGMODE_EXP = 1
-#FOGMODE_EXP2 = 2
+FOGMODE_NONE = 0
+FOGMODE_EXP = 1
+FOGMODE_EXP2 = 2
 FOGMODE_LINEAR = 3
+
+eFOGMODE_NONE = "NONE"
+eFOGMODE_LINEAR = "LINEAR"
+eFOGMODE_EXP = "EXP"
+eFOGMODE_EXP2 = "EXP2"
+
 #===============================================================================
 class World:
     def __init__(self, scene):
@@ -23,12 +30,19 @@ class World:
         self.gravity = scene.gravity
 
         if world and world.mist_settings.use_mist:
-            self.fogMode = FOGMODE_LINEAR
+            if world.fogMode == eFOGMODE_LINEAR:
+                self.fogMode = FOGMODE_LINEAR
+            elif world.fogMode == eFOGMODE_EXP:
+                self.fogMode = FOGMODE_EXP
+            elif world.fogMode == eFOGMODE_EXP2:
+                self.fogMode = FOGMODE_EXP2
             self.fogColor = world.horizon_color
             self.fogStart = world.mist_settings.start
             self.fogEnd = world.mist_settings.depth
-            self.fogDensity = 0.1
-
+            self.fogDensity = world.fogDensity
+        else:
+            self.fogMode = FOGMODE_NONE
+        
         Logger.log('Python World class constructor completed')
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     def to_scene_file(self, file_handler, needPhysics):
@@ -40,9 +54,53 @@ class World:
         if needPhysics:
             write_bool(file_handler, 'physicsEnabled', True)
             
-        if hasattr(self, 'fogMode'):
+        if hasattr(self, 'fogMode') and (self.fogMode != FOGMODE_NONE):
             write_int(file_handler, 'fogMode', self.fogMode)
             write_color(file_handler, 'fogColor', self.fogColor)
             write_float(file_handler, 'fogStart', self.fogStart)
             write_float(file_handler, 'fogEnd', self.fogEnd)
-            write_float(file_handler, 'fogDensity', self.fogDensity)
+            write_float(file_handler, 'fogDensity', self.fogDensity)
+
+#===============================================================================
+
+bpy.types.World.fogMode = bpy.props.EnumProperty(
+    name='Fog Mode',
+    description='',
+    items = ((eFOGMODE_LINEAR   , 'Linear',             'Linear Fog'),
+             (eFOGMODE_EXP      , 'Exponential',        'Exponential Fog'),
+             (eFOGMODE_EXP2     , 'Exponential Squared','Exponential Squared Fog')
+            ),
+    default = eFOGMODE_LINEAR
+)
+
+bpy.types.World.fogDensity = bpy.props.FloatProperty(
+    name='Fog Density',
+    description='',
+    default = 0.3
+)
+
+#===============================================================================
+class WorldPanel(bpy.types.Panel):
+    bl_label = get_title()
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = 'world'
+
+    @classmethod
+    def poll(cls, context):
+        ob = context.world
+        #print(ob.data)
+        return ob is not None and isinstance(ob, bpy.types.World)
+
+    def draw(self, context):
+        ob = context.world
+        fogEnabled = ob.mist_settings.use_mist
+        layout = self.layout
+        row = layout.row()
+        row.enabled = fogEnabled
+        row.prop(ob, 'fogMode')
+        
+        row = layout.row()
+        row.enabled = fogEnabled
+        row.prop(ob, 'fogDensity')
+