Skip to content

Commit 3e3a921

Browse files
committed
add support for partio; some minor change
1 parent e48afd4 commit 3e3a921

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

simloader/importer.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,32 @@ def update_obj(scene, depsgraph=None):
153153
show_message_box(traceback.format_exc(), "running script: " + obj.SIMLOADER.script_name + " failed: " + str(e),
154154
"ERROR")
155155
continue
156-
156+
157157
if 'process' in locals():
158158
user_process = locals()['process']
159-
user_process(fs, current_frame, obj.data)
159+
try:
160+
user_process(fs, current_frame, obj.data)
161+
except Exception as e:
162+
show_message_box("Error when calling user process: " + traceback.format_exc(), icon="ERROR")
160163
continue
161164

162165
elif 'preprocess' in locals():
163166
user_preprocess = locals()['preprocess']
164-
meshio_mesh = user_preprocess(fs, current_frame)
167+
try:
168+
meshio_mesh = user_preprocess(fs, current_frame)
169+
except Exception as e:
170+
show_message_box("Error when calling user preprocess: " + traceback.format_exc(), icon="ERROR")
171+
continue
165172
else:
166173
filepath = fs[current_frame % len(fs)]
167174
try:
168175
meshio_mesh = meshio.read(filepath)
169176
except Exception as e:
170177
show_message_box("Error when reading: " + filepath + ",\n" + traceback.format_exc(),
171-
"Meshio Loading Error" + str(e),
172-
icon="ERROR")
178+
"Meshio Loading Error" + str(e),
179+
icon="ERROR")
173180
continue
174181

175-
176182
if not isinstance(meshio_mesh, meshio.Mesh):
177183
show_message_box('function preprocess does not return meshio object', "ERROR")
178184
continue

simloader/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def draw(self, context):
1313

1414
print("Information: ", title)
1515
print(message)
16+
print('End of simloader message box')
1617
print()
1718
stop_animation()
1819
bpy.context.window_manager.popup_menu(draw, title=title, icon=icon)

template/partio.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import meshio
2+
import fileseq
3+
import bpy
4+
import numpy as np
5+
6+
7+
def preprocess(fileseq: fileseq.FileSequence, frame_number: int) -> meshio.Mesh:
8+
# type the path to the partio binary file
9+
partio_pybind_path = ''
10+
# here is an example
11+
# partio_pybind_path = '/home/hui/Desktop/BlenderPartioTools/partio_extension_pybind/partio_pybind.cpython-39-x86_64-linux-gnu.so'
12+
13+
14+
# load partio_pybind module
15+
import importlib
16+
spec = importlib.util.spec_from_file_location('partio_pybind', partio_pybind_path)
17+
partio_pybind = importlib.util.module_from_spec(spec)
18+
19+
# read particle data from file
20+
frame_number = frame_number % len(fileseq)
21+
file = fileseq[frame_number]
22+
particle = partio_pybind.read(file)
23+
24+
25+
# construct meshio.mesh
26+
points = None
27+
n_particles = particle.numParticles()
28+
point_data = {}
29+
for i in range(particle.numAttributes()):
30+
attr = particle.attributeInfo(i)
31+
attr_data = np.array(particle.data_buffer(attr), copy=True)
32+
if attr.name == 'position':
33+
points = attr_data
34+
else:
35+
point_data[attr.name] = attr_data
36+
37+
38+
# release memory
39+
particle.release()
40+
41+
return meshio.Mesh(
42+
points,
43+
# the cells is not important here
44+
cells=[('vertex', [[x] for x in range(n_particles)])],
45+
point_data=point_data)

0 commit comments

Comments
 (0)