Importing from Blender as tetrahedral Soft Bodies

Preparation

You will need the following programs:

Optionally, you can also download TetView, a tool to visualise the mesh generated by TetGen.

TetGen compilation

TetGen does not provide directly the executable, only the sources. It also provides a Makefile and CMakeLists.txt, thus you can compile it with make (or mingw32-make), or via CMake if it does not work. If you use CMake, the process is like when compiling Bullet. Generate the Makefile with CMake then use make (or mingw32-make) command to compile it.

In Blender

In Blender, build a mesh. As an example, you can just add an icosphere with the Add menu, Mesh, Icosphere.

Export it in ASCII STL format with the commands File, Export, Stl (.stl), and make sure Ascii is checked on the left panel. This file will then be used with TetGen.

TetGen

To generate the tetrahedral mesh from the STL file with TetGen, open a terminal, cd to the tetgen executable and use the command:

./tetgen -z stl_file.stl

The -z argument is required because TetGen by default generate a vertex indices starting by 1. However, Bullet use zero-based indices. The argument make TetGen produce a zero-based output.

The command produces 5 files in the same directory of the STL file. If you have python, you can use the script below which produces the output in a separate folder.

import os
import sys
import string

###########
# Configuration

# tetgen program
tetgen_path = ‘D:\\Documents\\Kent\\Project\\TetGen\\tetgen1.5.0-build\\tetgen.exe’

# tetgen args
tetgen_args = ‘-zq1.414’



####################
# Execute TetGen
# ASCII format of STL is only supported by tetgen, not binary

if len(sys.argv) != 2 or not sys.argv[1].endswith(‘.stl’):
    print “Usage: python tetgen.py <stl file (ascii)>”
    sys.exit()

file_name = sys.argv[1]
output_dir = file_name[:file_name.rfind(‘.’)]

# create folder and copy file temporarily into it
os.mkdir(output_dir)
os.system(‘copy ‘ + file_name + ‘ ‘ + output_dir)
os.chdir(output_dir)

# execute tetgen
os.system(tetgen_path + ‘ ‘ + tetgen_args + ‘ ‘ + file_name)

# remove temporary file
os.remove(file_name)

The only files that Bullet will use are the .ele and .node files.

In Bullet

The static method of btSoftBodyHelpers used to import TetGen files is:

static btSoftBody*      CreateFromTetGenData(   btSoftBodyWorldInfo& worldInfo,
                                                const char* ele,
                                                const char* face,
                                                const char* node,
                                                bool bfacelinks,
                                                bool btetralinks,
                                                bool bfacesfromtetras);

Although it takes face, bfacelinks and bfacesfromtetras as arguments, they are not implemented in the code.