This tutorial assumes that you have already installed FrostPy onto your computer, and that you have configured your license.
[size=150]Start Python[/size]
Linux
Open a bash shell and make these four calls:
export PYTHONPATH=/pathto/FrostPy/
export LD_LIBRARY_PATH=/pathto/FrostPy/
cd /pathto/FrostPy/
python26
Windows
Open a command prompt and make these three calls:
set PYTHONPATH=C:\pathto\FrostPy
cd C:\pathto\FrostPy
python
[size=150]Load Frost[/size]
Now that we’re in Python, we load the Frost library:
>>> import frost
[size=150]Load Particles[/size]
Next we load the particles that we want to mesh. Particles are stored using the frost.ParticleArray class. To load particles from a file, we use the frost.ParticleArray.ReadFromFile() method:
>>> pa = frost.ParticleArray.ReadFromFile( 'two_particles.prt' )
[size=150]Create a Mesh[/size]
Next we create a mesh from the particles. There are four different functions for doing so. Each makes a different shape of mesh:
- frost.mesh_union_of_spheres
- frost.mesh_metaballs
- frost.mesh_zhu_bridson
- frost.mesh_anisotropic
Let’s create a mesh using frost.mesh_metaballs(). The particles in ‘two_particles.prt’ do not have a Radius channel, so we must specify the radius here:
>>> m = frost.mesh_metaballs( pa, radius=0.6 )
[size=150]Save a Mesh[/size]
Meshes are stored in the frost.Trimesh3 class. To save a mesh to a file, we use the WriteToFile() method:
>>> m.WriteToFile( 'two_particles.xmesh' )
To save a Wavefront .obj file instead, we change the filename extension to ‘.obj’:
>>> m.WriteToFile( 'two_particles.obj' )
This produces the following mesh:
We see that the mesh has low resolution, with large faces.
[size=150]Change the Mesh Resolution[/size]
Now let’s make a higher-resolution mesh. To change the mesh resolution, we use the voxelLength parameter. When the voxelLength is None (the default value), the voxelLength is set to 0.5 * the maximum particle radius, or 0.5 * 0.6 = 0.3 in this example. Smaller values produce a higher-resolution mesh.
[code]>>> m = frost.mesh_metaballs( pa, voxelLength=0.1, radius=0.6 )
m.WriteToFile( ‘two_particles_hires.xmesh’ )[/code]
This produces the following mesh:
[size=150]Create Mesh Channels[/size]
Frost can create mesh channels from the particle channels. We call pa.GetChannelDict() to find the available particle channels:
>>> pa.GetChannelDict()
{'Color': 'float32[3]', 'Position': 'float32[3]', 'TextureCoord': 'float32[3]', 'Velocity': 'float32[3]'}
Let’s create a mesh that includes the ‘Color’ and ‘Velocity’ channels. We specify these channels using the vertexChannels parameter:
[code]>>> m = frost.mesh_metaballs( pa, voxelLength=0.1, radius=0.6, vertexChannels=[‘Color’, ‘Velocity’] )
m.WriteToFile( ‘two_particles_with_channels.xmesh’ )[/code]
This produces the following mesh:
We see that the mesh is colored according to the particles, and we have applied motion blur from the Velocity channel.