瀏覽代碼

Merge pull request #276 from Jason0214/optional_mat

Add option to export Material as Spatial Material
Lu Jiacheng 6 年之前
父節點
當前提交
2617236404

+ 22 - 5
io_scene_godot/__init__.py

@@ -98,11 +98,6 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
                     "own AnimationPlayer holding its actions",
         default=True,
     )
-    use_export_material: BoolProperty(
-        name="Export Material",
-        description="Export all the material associated with mesh surfaces",
-        default=True,
-    )
     use_export_shape_key: BoolProperty(
         name="Export Shape Key",
         description="Export all the shape keys in mesh objects",
@@ -151,6 +146,28 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
             )
         )
     )
+    material_mode: EnumProperty(
+        name="Material Mode",
+        description="Configuration of how mesh surface Material being "
+                    "exported.",
+        default="SCRIPT_SHADER",
+        items=(
+            (
+                "NONE", "None",
+                "Do not export any materials"
+            ),
+            (
+                "SPATIAL", "Spatial Material",
+                "Export all eligible materials as Spatial Material"
+            ),
+            (
+                "SCRIPT_SHADER", "Script Shader Material",
+                "Export all eligible materials as Shader Material "
+                "with Script Shader"
+            )
+        )
+
+    )
     material_search_paths: EnumProperty(
         name="Material Search Paths",
         description="Search for existing Godot materials with names that "

+ 13 - 6
io_scene_godot/converters/material/material.py

@@ -55,6 +55,13 @@ def export_material(escn_file, export_settings, bl_object, material):
     return "SubResource({})".format(resource_id)
 
 
+def export_as_spatial_material(material_rsc_name, material):
+    """Export a Blender Material as Godot Spatial Material"""
+    mat = InternalResource("SpatialMaterial", material_rsc_name)
+    mat['albedo_color'] = gamma_correct(material.diffuse_color)
+    return mat
+
+
 def generate_material_resource(escn_file, export_settings, bl_object,
                                material):
     """Export blender material as an internal resource"""
@@ -68,7 +75,8 @@ def generate_material_resource(escn_file, export_settings, bl_object,
         # to convert material to external file
         material_rsc_name = ''
 
-    if (engine in ('CYCLES', 'BLENDER_EEVEE') and
+    if (export_settings['material_mode'] == 'SCRIPT_SHADER' and
+            engine in ('CYCLES', 'BLENDER_EEVEE') and
             material.node_tree is not None):
         mat = InternalResource("ShaderMaterial", material_rsc_name)
         try:
@@ -76,14 +84,13 @@ def generate_material_resource(escn_file, export_settings, bl_object,
                 escn_file, export_settings, bl_object, material, mat
             )
         except ValidationError as exception:
-            mat = None  # revert to SpatialMaterial
+            # fallback to SpatialMaterial
+            mat = export_as_spatial_material(material_rsc_name, material)
             logging.error(
                 "%s, in material '%s'", str(exception), material.name
             )
-
-    if mat is None:
-        mat = InternalResource("SpatialMaterial", material_rsc_name)
-        mat['albedo_color'] = gamma_correct(material.diffuse_color)
+    else:  # Spatial Material
+        mat = export_as_spatial_material(material_rsc_name, material)
 
     # make material-object tuple as an identifier, as uniforms is part of
     # material and they are binded with object

+ 2 - 2
io_scene_godot/converters/mesh.py

@@ -98,7 +98,7 @@ def export_object_link_material(escn_file, export_settings, mesh_object,
         if slot.link == 'OBJECT' and slot.material is not None:
             surface_id = mesh_resource.get_surface_id(index)
             if (surface_id is not None and
-                    export_settings['use_export_material']):
+                    export_settings['material_mode'] != 'NONE'):
                 gd_node['material/{}'.format(surface_id)] = export_material(
                     escn_file,
                     export_settings,
@@ -280,7 +280,7 @@ class ArrayMeshResourceExporter:
                 if mesh.materials:
                     mat = mesh.materials[face.material_index]
                     if (mat is not None and
-                            export_settings['use_export_material']):
+                            export_settings['material_mode'] != 'NONE'):
                         surface.material = export_material(
                             escn_file,
                             export_settings,

+ 4 - 10
tests/install_blender.sh

@@ -2,26 +2,20 @@
 
 set -e
 
-# hack, may be removed after find a stable blender2.8 build
-BLENDER_ORG_HOMEPAGE="https://builder.blender.org"
-DOWNLOAD_PAGE_HTML="`wget -qO- ${BLENDER_ORG_HOMEPAGE}/download`"
-DAILY_BUILD_REGEX_PATTERN='href="([^"]+)" title="Download Dev Linux 64 bit master"'
-[[ ${DOWNLOAD_PAGE_HTML} =~ ${DAILY_BUILD_REGEX_PATTERN} ]]
-BLENDER_28_LINUX_64_PATH=${BASH_REMATCH[1]}
+BLENDER_28_LINUX_64_URL="https://mirror.clarkson.edu/blender/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2"
 
-BLENDER_DIRNAME_REGEX_PATTERN='/download/(.+)\.tar\.bz2$'
-[[ ${BLENDER_28_LINUX_64_PATH} =~ ${BLENDER_DIRNAME_REGEX_PATTERN} ]]
+BLENDER_DIRNAME_REGEX_PATTERN='/Blender2\.80/(.+)\.tar\.bz2$'
+[[ ${BLENDER_28_LINUX_64_URL} =~ ${BLENDER_DIRNAME_REGEX_PATTERN} ]]
 NAME=${BASH_REMATCH[1]}
 
 VERSION=2.80
 CACHE="${HOME}/.blender-cache"
 TAR="${CACHE}/${NAME}.tar.bz2"
-URL="${BLENDER_ORG_HOMEPAGE}/${BLENDER_28_LINUX_64_PATH}"
 
 echo "Installing Blender ${VERSION}"
 mkdir -p $CACHE
 if [ ! -f $TAR ]; then
-    wget -O $TAR $URL
+    wget -O $TAR $BLENDER_28_LINUX_64_URL
 fi
 tar -xjf $TAR -C $HOME