Skip to content

Commit fc4165f

Browse files
committed
added support for modifiers
1 parent e7f624e commit fc4165f

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

__init__.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,30 @@ class ExportDatasmith(bpy.types.Operator, ExportHelper):
4242
filename_ext = ".udatasmith"
4343
filter_glob: StringProperty(default="*.udatasmith", options={'HIDDEN'})
4444

45-
use_logging: BoolProperty(
46-
name="Enable logging",
47-
description="Enable logging to Window > System console",
48-
default=False,
49-
)
45+
5046
export_selected: BoolProperty(
5147
name="Export selected objects",
5248
description="Exports only the selected objects",
5349
default=False,
54-
)
50+
)
51+
apply_modifiers: BoolProperty(
52+
name="Apply modifiers",
53+
description="Applies geometry modifiers when exporting. "
54+
"(This may break mesh instancing)",
55+
default=False,
56+
)
57+
use_logging: BoolProperty(
58+
name="Enable logging",
59+
description="Enable logging to Window > System console",
60+
default=False,
61+
)
5562
experimental_tex_mode: BoolProperty(
5663
name="Use experimental texture mode mask",
5764
description="Exports non-color textures in an unofficial mode to "
5865
"keep non-srgb flag in custom UE4 engine builds, "
5966
"check readme for more info",
6067
default=False,
61-
)
68+
)
6269

6370
def execute(self, context):
6471
keywords = self.as_keywords(ignore=("filter_glob",))

export_datasmith.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,10 @@ def mesh_copy_triangulated(bl_mesh):
933933

934934

935935

936-
def collect_mesh(bl_mesh):
936+
def collect_mesh(bl_mesh, mesh_name):
937937

938938
# when using linked libraries, some meshes can have the same name
939-
mesh_name = sanitize_name(bl_mesh.name)
939+
mesh_name = sanitize_name(mesh_name)
940940
if bl_mesh.library:
941941
#import pdb; pdb.set_trace()
942942
lib_path = bpy.path.clean_name(bl_mesh.library.filepath)
@@ -1032,7 +1032,12 @@ def node_transform(mat):
10321032
n['sz'] = f(scale.z)
10331033
return n
10341034

1035-
def collect_object(bl_obj, name_override=None, instance_matrix=None, selected_only=False):
1035+
def collect_object(bl_obj,
1036+
name_override=None,
1037+
instance_matrix=None,
1038+
selected_only=False,
1039+
apply_modifiers=False
1040+
):
10361041

10371042
n = Node('Actor')
10381043

@@ -1058,7 +1063,7 @@ def collect_object(bl_obj, name_override=None, instance_matrix=None, selected_on
10581063
child_nodes = []
10591064

10601065
for child in bl_obj.children:
1061-
new_obj = collect_object(child, selected_only=selected_only)
1066+
new_obj = collect_object(child, selected_only=selected_only, apply_modifiers=apply_modifiers)
10621067
if new_obj:
10631068
child_nodes.append(new_obj)
10641069

@@ -1078,10 +1083,12 @@ def collect_object(bl_obj, name_override=None, instance_matrix=None, selected_on
10781083

10791084
if write_all_data:
10801085
# TODO: use instanced static meshes
1086+
1087+
depsgraph = datasmith_context["depsgraph"]
1088+
10811089
if bl_obj.is_instancer:
10821090
dups = []
10831091
dup_idx = 0
1084-
depsgraph = datasmith_context["depsgraph"]
10851092
for dup in depsgraph.object_instances:
10861093
if dup.parent and dup.parent.original == bl_obj:
10871094
dup_name = '%s_%s' % (dup.instance_object.original.name, dup_idx)
@@ -1090,25 +1097,31 @@ def collect_object(bl_obj, name_override=None, instance_matrix=None, selected_on
10901097
dup.instance_object.original,
10911098
instance_matrix=dup.matrix_world.copy(),
10921099
name_override=dup_name,
1093-
selected_only=selected_only)
1100+
selected_only=False, # if is instancer, maybe all child want to be instanced
1101+
apply_modifiers=False, # if is instancer, applying modifiers may end in a lot of meshes
1102+
)
10941103
child_nodes.append(new_obj)
10951104
#dups.append((dup.instance_object.original, dup.matrix_world.copy()))
10961105
dup_idx += 1
10971106

10981107

1099-
1100-
11011108
if bl_obj.type == 'EMPTY':
11021109
pass
11031110
elif bl_obj.type == 'MESH':
11041111
bl_mesh = bl_obj.data
1112+
bl_mesh_name = bl_mesh.name
1113+
1114+
if bl_obj.modifiers and apply_modifiers:
1115+
bl_mesh = bl_obj.evaluated_get(depsgraph).to_mesh()
1116+
bl_mesh_name = "%s__%s" % (bl_obj.name, bl_mesh.name)
1117+
11051118
if len(bl_mesh.polygons) > 0:
11061119
n.name = 'ActorMesh'
11071120
material_list = datasmith_context["materials"]
11081121
for slot in bl_obj.material_slots:
11091122
material_list.append(slot.material)
11101123

1111-
umesh = collect_mesh(bl_mesh)
1124+
umesh = collect_mesh(bl_mesh, bl_mesh_name)
11121125
n.push(Node('mesh', {'name': umesh.name}))
11131126

11141127
for idx, slot in enumerate(bl_obj.material_slots):
@@ -1325,8 +1338,9 @@ def collect_and_save(context, args, save_path):
13251338
objects = []
13261339

13271340
selected_only = args["export_selected"]
1341+
apply_modifiers = args["apply_modifiers"]
13281342
for obj in root_objects:
1329-
uobj = collect_object(obj, selected_only=selected_only)
1343+
uobj = collect_object(obj, selected_only=selected_only, apply_modifiers=apply_modifiers)
13301344
if uobj:
13311345
objects.append(uobj)
13321346

0 commit comments

Comments
 (0)