I want to create myself soft body by makeTetMesh
.
Firstly, I use pygmsh
to generate a tetrahedron:
with pygmsh.occ.Geometry() as geom:
disk = geom.add_disk([0, 0, 0], 0.2, 0.2)
geom.extrude(disk, [0, 0, 3])
msh = geom.generate_mesh()
print('generation finish')
points = msh.points
tri = msh.cells_dict['triangle']
tet = msh.cells_dict['tetra']
I find there are two way to call makeTetMesh
:
make_tet_mesh(BulletSoftBodyWorldInfo info, PointerToArray points, PointerToArray indices, bool tetralinks)
make_tet_mesh(BulletSoftBodyWorldInfo info, str ele, str face, str node)
For the above points/tri/tet
, I can sucessfully call make_tet_mesh(BulletSoftBodyWorldInfo info, str ele, str face, str node)
but failed to call make_tet_mesh(BulletSoftBodyWorldInfo info, PointerToArray points, PointerToArray indices, bool tetralinks)
.
The complete code to test is:
from panda3d.core import Vec3, Point3
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletSoftBodyNode
import pygmsh
world = BulletWorld()
info = world.getWorldInfo()
with pygmsh.occ.Geometry() as geom:
disk = geom.add_disk([0, 0, 0], 0.2, 0.2)
geom.extrude(disk, [0, 0, 3])
msh = geom.generate_mesh()
print('generation finish')
points = msh.points
tri = msh.cells_dict['triangle']
tet = msh.cells_dict['tetra']
fixIds = []
node = '%d 3 0 0\n'%len(points)
for idx, p in enumerate(points):
node += '%d %f %f %f\n'%(idx, p[0], p[1], p[2])
if p[2] == 0:
fixIds.append(idx)
ele = '%d 4 0\n'%(len(tet))
for idx, e in enumerate(tet):
ele += '%d %d %d %d %d\n'%(idx, e[0], e[1], e[2], e[3])
face = '%d 0\n'%len(tri)
for idx, f in enumerate(tri):
face += '%d %d %d %d\n'%(idx, f[0], f[1], f[2])
node = BulletSoftBodyNode.makeTetMesh(info, ele, face, node)
print('success: make_tet_mesh(BulletSoftBodyWorldInfo info, str ele, str face, str node)')
points = [Point3(p[0], p[1], p[2])*3 for p in points]
elements = [(t[0], t[1], t[2], t[3]) for t in tet]
indices = sum([list(x) for x in elements], [])
node = BulletSoftBodyNode.makeTetMesh(info, points, indices, True)
print('success: make_tet_mesh(BulletSoftBodyWorldInfo info, PointerToArray points, PointerToArray indices, bool tetralinks)')