Add option to export Material as Spatial Material

This commit is contained in:
Jason0214
2019-08-31 18:11:15 -06:00
parent 9c4d1874a3
commit a55346d137
3 changed files with 39 additions and 12 deletions

View File

@@ -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 "

View File

@@ -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,16 @@ 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)
elif export_settings['material_mode'] == 'SPATIAL':
mat = export_as_spatial_material(material_rsc_name, material)
assert mat is not None
# make material-object tuple as an identifier, as uniforms is part of
# material and they are binded with object

View File

@@ -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,