@@ -120,6 +120,8 @@ def update_mesh(meshio_mesh, mesh):
120
120
faces_loop_start = np .roll (faces_loop_start , 1 )
121
121
faces_loop_start [0 ] = 0
122
122
123
+ start_time = time .perf_counter ()
124
+
123
125
if len (mesh .vertices ) == n_verts and len (mesh .polygons ) == n_poly and len (mesh .loops ) == n_loop :
124
126
pass
125
127
else :
@@ -128,12 +130,20 @@ def update_mesh(meshio_mesh, mesh):
128
130
mesh .loops .add (n_loop )
129
131
mesh .polygons .add (n_poly )
130
132
133
+
131
134
mesh .vertices .foreach_set ("co" , mesh_vertices .ravel ())
132
135
mesh .loops .foreach_set ("vertex_index" , loops_vert_idx )
133
136
mesh .polygons .foreach_set ("loop_start" , faces_loop_start )
134
137
mesh .polygons .foreach_set ("loop_total" , faces_loop_total )
135
138
mesh .polygons .foreach_set ("use_smooth" , [shade_scheme ] * len (faces_loop_total ))
136
139
140
+ # mesh.clear_geometry()
141
+ # mesh.from_pydata(mesh_vertices, [], data)
142
+
143
+ end_time = time .perf_counter ()
144
+ print ("foreach_set time: " , end_time - start_time )
145
+
146
+
137
147
mesh .update ()
138
148
mesh .validate ()
139
149
@@ -208,13 +218,19 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
208
218
209
219
#.obj sequences have to be handled differently
210
220
isObj = filepath .endswith (".obj" )
211
- if isObj :
221
+ if isObj and bpy . context . scene . BSEQ . use_blender_obj_import :
212
222
print (str (filepath ))
213
223
bpy .ops .import_scene .obj (filepath = filepath )
214
- object = bpy .context .selected_objects [- 1 ]
215
- object .name = fileseq .basename () + "@" + fileseq .extension ()
216
- # object.data.name = fileseq.basename() + "@" + fileseq.extension()
217
224
enabled = True
225
+
226
+ tmp_obj = bpy .context .selected_objects [- 1 ]
227
+
228
+ name = fileseq .basename () + "@" + fileseq .extension ()
229
+ object = bpy .data .objects .new (name , tmp_obj .data )
230
+
231
+ tmp_obj .select_set (True )
232
+ bpy .ops .object .delete ()
233
+
218
234
else :
219
235
meshio_mesh = None
220
236
enabled = True
@@ -245,9 +261,7 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
245
261
object .matrix_world = transform_matrix
246
262
driver = object .driver_add ("BSEQ.frame" )
247
263
driver .driver .expression = 'frame'
248
- if isObj :
249
- return
250
- if enabled :
264
+ if enabled and not isObj :
251
265
update_mesh (meshio_mesh , object .data )
252
266
bpy .context .collection .objects .link (object )
253
267
bpy .ops .object .select_all (action = "DESELECT" )
@@ -283,21 +297,20 @@ def update_obj(scene, depsgraph=None):
283
297
pattern = bpy .path .native_pathsep (pattern )
284
298
fs = fileseq .FileSequence (pattern )
285
299
286
- if pattern .endswith (".obj" ):
300
+ if pattern .endswith (".obj" ) and scene . BSEQ . use_blender_obj_import :
287
301
filepath = fs [current_frame % len (fs )]
288
302
289
303
# Reload the object
290
- tmp_transform = obj .matrix_world
291
- obj .select_set (True )
292
- bpy .ops .object .delete ()
293
304
bpy .ops .import_scene .obj (filepath = filepath )
294
- obj = bpy .context .selected_objects [- 1 ]
305
+ tmp_obj = bpy .context .selected_objects [- 1 ]
295
306
print (str (filepath ))
296
307
print (current_frame % len (fs ))
297
308
print (obj .name )
298
- obj .name = fs .basename () + "@" + fs .extension ()
299
- obj .data .name = fs .basename () + "@" + fs .extension ()
300
- obj .matrix_world = tmp_transform
309
+
310
+ obj .data = tmp_obj .data
311
+ tmp_obj .select_set (True )
312
+ bpy .ops .object .delete ()
313
+
301
314
apply_transformation (meshio_mesh , obj , depsgraph )
302
315
303
316
end_time = time .perf_counter ()
0 commit comments