@@ -80,8 +80,9 @@ def apply_transformation(meshio_mesh, obj, depsgraph):
80
80
81
81
# evaluate the rigid body transformations (only relevant for .bin format)
82
82
rigid_body_transformation = mathutils .Matrix .Identity (4 )
83
- if meshio_mesh .field_data .get ("transformation_matrix" ) is not None :
84
- rigid_body_transformation = meshio_mesh .field_data ["transformation_matrix" ]
83
+ if meshio_mesh is not None :
84
+ if meshio_mesh .field_data .get ("transformation_matrix" ) is not None :
85
+ rigid_body_transformation = meshio_mesh .field_data ["transformation_matrix" ]
85
86
86
87
# multiply everything together (with custom transform matrix)
87
88
obj .matrix_world = rigid_body_transformation @ eval_transform_matrix
@@ -94,6 +95,9 @@ def update_mesh(meshio_mesh, mesh):
94
95
n_loop = 0
95
96
n_verts = len (mesh_vertices )
96
97
if n_verts == 0 :
98
+ mesh .clear_geometry ()
99
+ mesh .update ()
100
+ mesh .validate ()
97
101
return
98
102
faces_loop_start = np .array ([], dtype = np .uint64 )
99
103
faces_loop_total = np .array ([], dtype = np .uint64 )
@@ -115,7 +119,7 @@ def update_mesh(meshio_mesh, mesh):
115
119
# Add a zero as first entry
116
120
faces_loop_start = np .roll (faces_loop_start , 1 )
117
121
faces_loop_start [0 ] = 0
118
-
122
+
119
123
if len (mesh .vertices ) == n_verts and len (mesh .polygons ) == n_poly and len (mesh .loops ) == n_loop :
120
124
pass
121
125
else :
@@ -130,6 +134,10 @@ def update_mesh(meshio_mesh, mesh):
130
134
mesh .polygons .foreach_set ("loop_total" , faces_loop_total )
131
135
mesh .polygons .foreach_set ("use_smooth" , [shade_scheme ] * len (faces_loop_total ))
132
136
137
+ # newer function but is about 4 times slower
138
+ # mesh.clear_geometry()
139
+ # mesh.from_pydata(mesh_vertices, [], data)
140
+
133
141
mesh .update ()
134
142
mesh .validate ()
135
143
@@ -180,7 +188,13 @@ def create_meshio_obj(filepath):
180
188
show_message_box ("Error when reading: " + filepath + ",\n " + traceback .format_exc (),
181
189
"Meshio Loading Error" + str (e ),
182
190
icon = "ERROR" )
183
-
191
+
192
+ # Do I need this for multi-loading?
193
+ if filepath .endswith (".obj" ):
194
+ bpy .ops .import_scene .obj (filepath = filepath )
195
+ obj = bpy .context .selected_objects [0 ]
196
+ obj .name = os .path .basename (filepath )
197
+ return
184
198
# create the object
185
199
name = os .path .basename (filepath )
186
200
mesh = bpy .data .meshes .new (name )
@@ -196,20 +210,36 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
196
210
current_frame = bpy .context .scene .frame_current
197
211
filepath = fileseq [current_frame % len (fileseq )]
198
212
199
- meshio_mesh = None
200
- enabled = True
201
- try :
202
- meshio_mesh = meshio .read (filepath )
203
- except Exception as e :
204
- show_message_box ("Error when reading: " + filepath + ",\n " + traceback .format_exc (),
205
- "Meshio Loading Error" + str (e ),
206
- icon = "ERROR" )
207
- enabled = False
213
+ #.obj sequences have to be handled differently
214
+ is_obj_seq = filepath .endswith (".obj" )
215
+ if is_obj_seq and bpy .context .scene .BSEQ .use_blender_obj_import :
216
+ bpy .ops .import_scene .obj (filepath = filepath )
217
+ enabled = True
218
+
219
+ tmp_obj = bpy .context .selected_objects [- 1 ]
220
+
221
+ name = fileseq .basename () + "@" + fileseq .extension ()
222
+ object = bpy .data .objects .new (name , tmp_obj .data )
223
+
224
+ tmp_obj .select_set (True )
225
+ bpy .ops .object .delete ()
226
+
227
+ else :
228
+ meshio_mesh = None
229
+ enabled = True
230
+ try :
231
+ meshio_mesh = meshio .read (filepath )
232
+ except Exception as e :
233
+ show_message_box ("Error when reading: " + filepath + ",\n " + traceback .format_exc (),
234
+ "Meshio Loading Error" + str (e ),
235
+ icon = "ERROR" )
236
+ enabled = False
237
+
238
+ name = fileseq .basename () + "@" + fileseq .extension ()
239
+ mesh = bpy .data .meshes .new (name )
240
+ object = bpy .data .objects .new (name , mesh )
208
241
209
242
# create the object
210
- name = fileseq .basename () + "@" + fileseq .extension ()
211
- mesh = bpy .data .meshes .new (name )
212
- object = bpy .data .objects .new (name , mesh )
213
243
object .BSEQ .use_relative = use_relative
214
244
if use_relative :
215
245
if root_path != "" :
@@ -224,7 +254,7 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
224
254
object .matrix_world = transform_matrix
225
255
driver = object .driver_add ("BSEQ.frame" )
226
256
driver .driver .expression = 'frame'
227
- if enabled :
257
+ if enabled and not is_obj_seq :
228
258
update_mesh (meshio_mesh , object .data )
229
259
bpy .context .collection .objects .link (object )
230
260
bpy .ops .object .select_all (action = "DESELECT" )
@@ -260,6 +290,23 @@ def update_obj(scene, depsgraph=None):
260
290
pattern = bpy .path .native_pathsep (pattern )
261
291
fs = fileseq .FileSequence (pattern )
262
292
293
+ if pattern .endswith (".obj" ) and scene .BSEQ .use_blender_obj_import :
294
+ filepath = fs [current_frame % len (fs )]
295
+
296
+ # Reload the object
297
+ bpy .ops .import_scene .obj (filepath = filepath )
298
+ tmp_obj = bpy .context .selected_objects [- 1 ]
299
+
300
+ obj .data = tmp_obj .data
301
+ tmp_obj .select_set (True )
302
+ bpy .ops .object .delete ()
303
+
304
+ apply_transformation (meshio_mesh , obj , depsgraph )
305
+
306
+ end_time = time .perf_counter ()
307
+ obj .BSEQ .last_benchmark = (end_time - start_time ) * 1000
308
+ continue
309
+
263
310
if obj .BSEQ .use_advance and obj .BSEQ .script_name :
264
311
script = bpy .data .texts [obj .BSEQ .script_name ]
265
312
try :
0 commit comments