@@ -933,10 +933,10 @@ def mesh_copy_triangulated(bl_mesh):
933
933
934
934
935
935
936
- def collect_mesh (bl_mesh ):
936
+ def collect_mesh (bl_mesh , mesh_name ):
937
937
938
938
# 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 )
940
940
if bl_mesh .library :
941
941
#import pdb; pdb.set_trace()
942
942
lib_path = bpy .path .clean_name (bl_mesh .library .filepath )
@@ -1032,7 +1032,12 @@ def node_transform(mat):
1032
1032
n ['sz' ] = f (scale .z )
1033
1033
return n
1034
1034
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
+ ):
1036
1041
1037
1042
n = Node ('Actor' )
1038
1043
@@ -1058,7 +1063,7 @@ def collect_object(bl_obj, name_override=None, instance_matrix=None, selected_on
1058
1063
child_nodes = []
1059
1064
1060
1065
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 )
1062
1067
if new_obj :
1063
1068
child_nodes .append (new_obj )
1064
1069
@@ -1078,10 +1083,12 @@ def collect_object(bl_obj, name_override=None, instance_matrix=None, selected_on
1078
1083
1079
1084
if write_all_data :
1080
1085
# TODO: use instanced static meshes
1086
+
1087
+ depsgraph = datasmith_context ["depsgraph" ]
1088
+
1081
1089
if bl_obj .is_instancer :
1082
1090
dups = []
1083
1091
dup_idx = 0
1084
- depsgraph = datasmith_context ["depsgraph" ]
1085
1092
for dup in depsgraph .object_instances :
1086
1093
if dup .parent and dup .parent .original == bl_obj :
1087
1094
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
1090
1097
dup .instance_object .original ,
1091
1098
instance_matrix = dup .matrix_world .copy (),
1092
1099
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
+ )
1094
1103
child_nodes .append (new_obj )
1095
1104
#dups.append((dup.instance_object.original, dup.matrix_world.copy()))
1096
1105
dup_idx += 1
1097
1106
1098
1107
1099
-
1100
-
1101
1108
if bl_obj .type == 'EMPTY' :
1102
1109
pass
1103
1110
elif bl_obj .type == 'MESH' :
1104
1111
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
+
1105
1118
if len (bl_mesh .polygons ) > 0 :
1106
1119
n .name = 'ActorMesh'
1107
1120
material_list = datasmith_context ["materials" ]
1108
1121
for slot in bl_obj .material_slots :
1109
1122
material_list .append (slot .material )
1110
1123
1111
- umesh = collect_mesh (bl_mesh )
1124
+ umesh = collect_mesh (bl_mesh , bl_mesh_name )
1112
1125
n .push (Node ('mesh' , {'name' : umesh .name }))
1113
1126
1114
1127
for idx , slot in enumerate (bl_obj .material_slots ):
@@ -1325,8 +1338,9 @@ def collect_and_save(context, args, save_path):
1325
1338
objects = []
1326
1339
1327
1340
selected_only = args ["export_selected" ]
1341
+ apply_modifiers = args ["apply_modifiers" ]
1328
1342
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 )
1330
1344
if uobj :
1331
1345
objects .append (uobj )
1332
1346
0 commit comments