Skip to content

Commit f13ecb0

Browse files
committed
Add default material to meshes without material
1 parent 829adbe commit f13ecb0

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

export_datasmith.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ def exp_vector(value, exp_list):
4141
})
4242
return exp_list.push(n)
4343

44-
def exp_color(value, exp_list, name=""):
44+
def exp_color(value, exp_list, name=None):
4545
n = Node("Color", {
46-
"Name": name,
4746
"constant": "(R=%.6f,G=%.6f,B=%.6f,A=%.6f)"%tuple(value)
4847
})
48+
if name:
49+
n["Name"] = name
4950
return exp_list.push(n)
5051

5152
def exp_scalar(value, exp_list):
@@ -1382,9 +1383,10 @@ def pbr_default_material():
13821383
n = Node("UEPbrMaterial")
13831384
n["name"] = "DefaultMaterial"
13841385
exp_list = Node("Expressions")
1385-
1386-
basecolor_idx = exp_color((0.8, 0.8, 0.8, 1.0), exp_list)
1387-
roughness_idx = exp_scalar(0.5, exp_list)
1386+
grey = 0.906332
1387+
basecolor_idx = exp_color((grey, grey, grey, 1.0), exp_list)
1388+
roughness_idx = exp_scalar(0.4, exp_list)
1389+
n.push(exp_list)
13881390
n.push(Node("BaseColor", {
13891391
"expression": basecolor_idx,
13901392
"OutputIndex": "0"
@@ -1461,9 +1463,11 @@ def fill_umesh(umesh, bl_mesh):
14611463
m.calc_normals_split()
14621464

14631465
#finish inline mesh_copy_triangulate
1464-
1465-
for idx, mat in enumerate(bl_mesh.materials):
1466-
umesh.materials[idx] = sanitize_name(getattr(mat, 'name', 'DefaultMaterial'))
1466+
if len(bl_mesh.materials) == 0:
1467+
umesh.materials[0] = 'DefaultMaterial'
1468+
else:
1469+
for idx, mat in enumerate(bl_mesh.materials):
1470+
umesh.materials[idx] = sanitize_name(getattr(mat, 'name', 'DefaultMaterial'))
14671471

14681472
polygons = m.polygons
14691473
num_polygons = len(polygons)
@@ -1686,8 +1690,11 @@ def collect_object_custom_data(bl_obj, n, apply_modifiers, obj_mat, depsgraph):
16861690
collect_object_metadata(n["name"], "StaticMesh", bl_mesh)
16871691

16881692
material_list = datasmith_context["materials"]
1689-
for slot in bl_obj.material_slots:
1690-
material_list.append((slot.material, bl_obj))
1693+
if len(bl_obj.material_slots) == 0:
1694+
material_list.append((None, bl_obj))
1695+
else:
1696+
for slot in bl_obj.material_slots:
1697+
material_list.append((slot.material, bl_obj))
16911698

16921699
if umesh:
16931700
n.name = 'ActorMesh'
@@ -1722,12 +1729,15 @@ def collect_object_custom_data(bl_obj, n, apply_modifiers, obj_mat, depsgraph):
17221729
n.name = 'ActorMesh'
17231730
n.push(Node('mesh', {'name': umesh.name}))
17241731

1725-
for idx, slot in enumerate(bl_obj.material_slots):
1726-
material_list.append((slot.material, bl_obj))
1727-
if slot.link == 'OBJECT':
1728-
#collect_materials([slot.material], uscene)
1729-
safe_name = sanitize_name(slot.material.name)
1730-
n.push(Node('material', {'id':idx, 'name':safe_name}))
1732+
if len(bl_obj.material_slots) == 0:
1733+
material_list.append((None, bl_obj))
1734+
else:
1735+
for idx, slot in enumerate(bl_obj.material_slots):
1736+
material_list.append((slot.material, bl_obj))
1737+
if slot.link == 'OBJECT':
1738+
#collect_materials([slot.material], uscene)
1739+
safe_name = sanitize_name(slot.material.name)
1740+
n.push(Node('material', {'id':idx, 'name':safe_name}))
17311741

17321742
elif bl_obj.type == 'CAMERA':
17331743

0 commit comments

Comments
 (0)