Skip to content

Commit c38a8c6

Browse files
committed
Better (not working) obj loader
1 parent 01dcf7d commit c38a8c6

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

bseq/importer.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def apply_transformation(meshio_mesh, obj, depsgraph):
8080

8181
# evaluate the rigid body transformations (only relevant for .bin format)
8282
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"]
8586

8687
# multiply everything together (with custom transform matrix)
8788
obj.matrix_world = rigid_body_transformation @ eval_transform_matrix
@@ -256,9 +257,6 @@ def update_obj(scene, depsgraph=None):
256257

257258
for obj in bpy.data.objects:
258259
start_time = time.perf_counter()
259-
260-
isObj = obj.BSEQ.pattern.endswith(".obj")
261-
print("isObj: ", isObj)
262260

263261
if obj.BSEQ.init == False:
264262
continue
@@ -284,6 +282,24 @@ def update_obj(scene, depsgraph=None):
284282
pattern = bpy.path.native_pathsep(pattern)
285283
fs = fileseq.FileSequence(pattern)
286284

285+
if pattern.endswith(".obj"):
286+
filepath = fs[current_frame % len(fs)]
287+
288+
# Reload the object
289+
tmp_transform = obj.matrix_world
290+
obj.select_set(True)
291+
bpy.ops.object.delete()
292+
bpy.ops.import_scene.obj(filepath=filepath)
293+
obj = bpy.context.selected_objects[-1]
294+
obj.name = fs.basename() + "@" + fs.extension()
295+
obj.data.name = fs.basename() + "@" + fs.extension()
296+
obj.matrix_world = tmp_transform
297+
apply_transformation(meshio_mesh, obj, depsgraph)
298+
299+
end_time = time.perf_counter()
300+
obj.BSEQ.last_benchmark = (end_time - start_time) * 1000
301+
return
302+
287303
if obj.BSEQ.use_advance and obj.BSEQ.script_name:
288304
script = bpy.data.texts[obj.BSEQ.script_name]
289305
try:
@@ -316,23 +332,14 @@ def update_obj(scene, depsgraph=None):
316332
else:
317333
filepath = fs[current_frame % len(fs)]
318334
try:
319-
if filepath.endswith(".obj"):
320-
# Reload the object
321-
obj.select_set(True)
322-
bpy.ops.object.delete()
323-
# bpy.ops.import_scene.obj(filepath=filepath)
324-
# object = bpy.context.selected_objects[-1]
325-
# object.name = fileseq.basename() + "@" + fileseq.extension()
326-
# object.data.name = fileseq.basename() + "@" + fileseq.extension()
327-
else:
328-
meshio_mesh = meshio.read(filepath)
335+
meshio_mesh = meshio.read(filepath)
329336
except Exception as e:
330337
show_message_box("Error when reading: " + filepath + ",\n" + traceback.format_exc(),
331338
"Meshio Loading Error" + str(e),
332339
icon="ERROR")
333340
continue
334341

335-
if not isinstance(meshio_mesh, meshio.Mesh) or not isObj:
342+
if not isinstance(meshio_mesh, meshio.Mesh):
336343
show_message_box('function preprocess does not return meshio object', "ERROR")
337344
continue
338345
update_mesh(meshio_mesh, obj.data)

0 commit comments

Comments
 (0)