Skip to content

Commit 01dcf7d

Browse files
committed
Current not wokring version (but mzd is now fixed)
1 parent 43071ac commit 01dcf7d

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

additional_file_formats/mzd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def readMZD_to_meshio(filepath):
2222

2323
with open(filepath, 'rb') as file:
2424
byte = file.read(24)
25+
# check if mzd file is empty
2526
if byte != head:
2627
return -4
2728
while 1:
@@ -49,7 +50,7 @@ def readMZD_to_meshio(filepath):
4950
if out_numVertices < 0:
5051
return -127
5152
if out_numVertices == 0:
52-
break
53+
return meshio.Mesh(points=np.array([]), cells={})
5354

5455
byte = file.read(12 * out_numVertices)
5556
out_vertPositions = np.frombuffer(byte, dtype=np.float32)

bseq/importer.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def update_mesh(meshio_mesh, mesh):
9494
n_loop = 0
9595
n_verts = len(mesh_vertices)
9696
if n_verts == 0:
97+
mesh.clear_geometry()
98+
mesh.update()
99+
mesh.validate()
97100
return
98101
faces_loop_start = np.array([], dtype=np.uint64)
99102
faces_loop_total = np.array([], dtype=np.uint64)
@@ -202,11 +205,14 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
202205
current_frame = bpy.context.scene.frame_current
203206
filepath = fileseq[current_frame % len(fileseq)]
204207

205-
if filepath.endswith(".obj"):
208+
#.obj sequences have to be handled differently
209+
isObj = filepath.endswith(".obj")
210+
if isObj:
206211
bpy.ops.import_scene.obj(filepath=filepath)
207212
object = bpy.context.selected_objects[-1]
208213
object.name = fileseq.basename() + "@" + fileseq.extension()
209-
enabled = False
214+
# object.data.name = fileseq.basename() + "@" + fileseq.extension()
215+
enabled = True
210216
else:
211217
meshio_mesh = None
212218
enabled = True
@@ -237,6 +243,8 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
237243
object.matrix_world = transform_matrix
238244
driver = object.driver_add("BSEQ.frame")
239245
driver.driver.expression = 'frame'
246+
if isObj:
247+
return
240248
if enabled:
241249
update_mesh(meshio_mesh, object.data)
242250
bpy.context.collection.objects.link(object)
@@ -249,6 +257,9 @@ def update_obj(scene, depsgraph=None):
249257
for obj in bpy.data.objects:
250258
start_time = time.perf_counter()
251259

260+
isObj = obj.BSEQ.pattern.endswith(".obj")
261+
print("isObj: ", isObj)
262+
252263
if obj.BSEQ.init == False:
253264
continue
254265
if obj.BSEQ.enabled == False:
@@ -305,14 +316,23 @@ def update_obj(scene, depsgraph=None):
305316
else:
306317
filepath = fs[current_frame % len(fs)]
307318
try:
308-
meshio_mesh = meshio.read(filepath)
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)
309329
except Exception as e:
310330
show_message_box("Error when reading: " + filepath + ",\n" + traceback.format_exc(),
311331
"Meshio Loading Error" + str(e),
312332
icon="ERROR")
313333
continue
314334

315-
if not isinstance(meshio_mesh, meshio.Mesh):
335+
if not isinstance(meshio_mesh, meshio.Mesh) or not isObj:
316336
show_message_box('function preprocess does not return meshio object', "ERROR")
317337
continue
318338
update_mesh(meshio_mesh, obj.data)

0 commit comments

Comments
 (0)