Mesh module API
Accessing meshes
The number of meshes being passed into the node can be found:
num= pfpy.getNumMeshes()
print("node is reading", num, "meshes")
A reference to an existing mesh can be obtained as follows:
m= pfpy.getMeshRef(index)
where index is an integer indicating which mesh to read in the range 0 and N-1 inclusive, where N is the number of meshes returned by pfpy.getNumMeshes().
By calling the Mesh API functions described below, mesh data can be modified before being passed down-stream. The internal mesh can be copied and freed as follows:
m= pfpy.getMeshRef(index)
mm= m.copy()
# do stuff
mm.freeCopy()
Copying a mesh in this way allows original mesh data to be read from the copy, regardless of how the actual mesh is then modified by the script. An example of this copying process in action for trackers (the process is the same for meshes) is given in the filterTracks.py example script.
Creating new meshes
To create a new mesh, use the new function:
m= pfpy.Mesh.new(name)
This will create a new mesh with the specified name ready to be modified in the script and then passed down-stream.
API functions
Examples of these functions in use are provided by the python scripts available in the exports, macros and nodes installation folders.
isDeformable()
Parameters:
none
Description:
Returns True if the mesh is a deformable object
Example:
m= pfpy.getMeshRef(0)
print("Mesh is deformable: ", m.isDeformable())
Parameters:
none
Description:
Returns true if the mesh has been flagged for export by an Export node. Note that meshes are flagged for export by default.
Example:
m= pfpy.getMeshRef(0)
print("Export mesh: ", m.getExport())
Parameters:
boolean state
Description:
Flag the mesh for export or not. Note that meshes are flagged for export by default.
Example:
m= pfpy.getMeshRef(0)
m.setExport(False)
loadOBJ(name, coord, up)
Parameters:
string filename
string coordinate system ('left' or 'right')
string up direction ('y' or 'z')
Description:
Loads an OBJ object from the filename and converts into a left/y coordinate system from the specified coordinate system.
Example:
m= pfpy.Mesh.new("myMesh")
# Load a right/y obj from the file and convert into left/y
m.loadOBJ('/path/to/myMesh.obj', 'right', 'y')
saveOBJ(objFilename, mtlFilename, frame)
Parameters:
string objFilename
optional string mtlFilename
optional integer frame number
Description:
Saved the mesh as an OBJ file with objFilename. If mtlFilename is provided, the material file will be saved using that filename, otherwise it will be saved by changing the obj extension of objFilename to mtl. If frame number is provided, the OBJ file will be saved with animation baked for that frame.
Example:
m= pfpy.getMeshRef(0)
m.save('/path/to/myMesh.obj')
m.save('/path/to/myMesh.obj', '/path/to/myMeshMaterial.mtl')
m.save('/path/to/myMesh.10.obj', '/path/to/myMesh.mtl', 10)
save3DS(filename)
Parameters:
string filename
Description:
Saves the mesh as a 3DS file with the given filename
Example:
m= pfpy.getMeshRef(0)
m.save3DS('/path/to/mymesh.3ds')
saveLWO(filename)
Parameters:
string filename
Description:
Saves the mesh as a LWO file with the given filename
Example:
m= pfpy.getMeshRef(0)
m.saveLWO('/path/to/mymesh.lwo)
removeKeys(frame)
Parameters:
optional frame number
Description:
Removes all animation keys (from the given frame only, if frame is provided)
Example:
m= pfpy.getMeshRef(0)
m.removeKeys(10)
m.removeKeys()
fixRotationFlips()
Parameters:
none
Description:
Prevents Euler angles flipping by +/- 360 degrees
Example:
m= pfpy.getMeshRef(0)
m.fixRotationFlips()
isKeyed(frame)
Parameters:
integer frame number
Description:
Returns True if the mesh is keyframed at the given frame.
Example:
m= pfpy.getMeshRef(0)
if m.isKeyed(10) :
# do something
isTracked(frame)
Parameters:
integer frame number
Description:
Returns True if the mesh is tracked at the given frame.
Example:
m= pfpy.getMeshRef(0)
if m.isKeyed(10) :
# do something
hasAnimatedVertices()
Parameters:
none
Description:
Returns True if the mesh contains independently animated vertices, such as those created when using the Trackers primitive in the Image Modelling node, or when tracking deformable geometry.
Example:
m= pfpy.getMeshRef(0)
if m.hasAnimatedVertices() :
# do something
getAnimatedVerticesInPoint()
Parameters:
none
Description:
Returns the in-point of all independently animated vertices.
Example:
m= pfpy.getMeshRef(0)
if m.hasAnimatedVertices() :
inp= m.getAnimatedVerticesInPoint()
outp= m.getAnimatedVerticesOutPoint()
# do something
getAnimatedVerticesOutPoint()
Parameters:
none
Description:
Returns the out-point of all independently animated vertices.
Example:
m= pfpy.getMeshRef(0)
if m.hasAnimatedVertices() :
inp= m.getAnimatedVerticesInPoint()
outp= m.getAnimatedVerticesOutPoint()
# do something
getName()
Parameters:
none
Description:
Returns the mesh name
Example:
m= pfpy.getMeshRef(0)
print("Mesh is named", m.getName())
setName(name)
Parameters:
string mesh name
Description:
Sets the mesh name to the string
Example:
m= pfpy.getMeshRef(0)
m.setName("myName")
getInPoint()
Parameters:
none
Description:
Returns the frame number for the tracker in-point.
Example:
m= pfpy.getMeshRef(0)
print("Tracker in/out is ", m.getInPoint(), m.getOutPoint())
setInPoint(frame)
Parameters:
integer frame number
Description:
Set the tracker in-point to the specified frame number
Example:
m= pfpy.getMeshRef(0)
m.setInPoint(1)
m.setOutPoint(20)
getOutPoint()
Parameters:
none
Description:
Returns the frame number for the mesh out-point.
Example:
m= pfpy.getMeshRef(0)
print("Mesh in/out is ", m.getInPoint(), m.getOutPoint())
setOutPoint(frame)
Parameters:
integer frame number
Description:
Set the mesh out-point to the specified frame number
Example:
m= pfpy.getMeshRef(0)
m.setInPoint(1)
m.setOutPoint(20)
getScale(frame)
Parameters:
integer frame number
Description:
Returns the mesh scale transformation at the frame
Example:
m= pfpy.getMeshRef(0)
print("scale at frame 20 is", m.getScale(20))
setScale(frame, value)
Parameters:
integer frame number
floating point value
Description:
Sets the mesh scale at the frame to the desired value
Example:
m= pfpy.getMeshRef(0)
m.setScale(20, 0.5)
getTranslation(frame)
Parameters:
integer frame number
Description:
Returns the X, Y, Z mesh translation at the frame
Example:
m= pfpy.getMeshRef(0)
t= m.getTranslation(20)
print("translation at frame 20 is", t[0], t[1], t[2])
setTranslation(frame, value)
Parameters:
integer frame number
floating point tuple of values
Description:
Sets the X, Y, Z mesh translation at the frame.
Example:
m= pfpy.getMeshRef(0)
m.setScale(10, 1.0)
m.setTranslation(10, 0.5, 0.7, -0.3)
m.setEulerRotation(10, 0.0, 0.0, 20.0, 'zxy')
getEulerRotation(frame, order)
Parameters:
integer frame number
string order, 'xyz', 'zxy' or 'yxz'
Description:
Returns the X, Y, Z mesh Euler rotations (in degrees and in the specified axis order) at the frame
Example:
m= pfpy.getMeshRef(0)
e= m.getEulerRotation(20, 'xyz')
print("euler rotation at frame 20 is", e[0], e[1], e[2])
setEulerRotation(frame, value, order)
Parameters:
integer frame number
floating point tuple of values
string order, 'xyz', 'zxy' or 'yxz'
Description:
Sets the X, Y, Z mesh Euler rotations (in degrees and in the specified axis order) at the frame.
Example:
m= pfpy.getMeshRef(0)
m.setScale(10, 1.0)
m.setTranslation(10, 0.5, 0.7, -0.3)
m.setEulerRotation(10, 0.0, 0.0, 20.0, 'zxy')
getQuaternionRotation(frame)
Parameters:
integer frame number
Description:
Returns the X, Y, Z, W mesh quaternion rotation at the frame
Example:
m= pfpy.getMeshRef(0)
q= m.getQuaternionRotation(20)
print("quaternion at frame 20 is", q[0], q[1], q[2], q[3])
setQuaternionRotation(frame, value)
Parameters:
integer frame number
floating point quad of values
Description:
Sets the X, Y, Z, W mesh quaternion rotation at the frame.
Example:
m= pfpy.getMeshRef(0)
m.setScale(10, 1.0)
m.setTranslation(10, 0.5, 0.7, -0.3)
m.setQuaternionRotation(10, 0.0, 0.0, 0.0, 1.0)
scale(value)
Parameters:
floating point value
Description:
Scales the entire mesh around the origin point
Example:
m= pfpy.getMeshRef(0)
m.scale(10.0)
rotateEuler(value, order)
Parameters:
floating point tuple of values
string order, 'xyz', 'zxy' or 'yxz'
Description:
Rotates the entire mesh around the origin point
Example:
m= pfpy.getMeshRef(0)
# rotate by 10 degrees around X, 20 degrees around Y and 30 degrees around Z using 'xyz' rotation order
m.rotate(10.0, 20.0, 30.0, 'xyz')
rotateQuaternion(value)
Parameters:
floating point tuple of values
Description:
Rotates the entire mesh around the origin point
Example:
m= pfpy.getMeshRef(0)
m.rotate(qx, qy, qz, qw)
translate(value)
Parameters:
floating point tuple of values
Description:
Translates the entire mesh
Example:
m= pfpy.getMeshRef(0)
# translate by 1.0 along X, 2.0 along Y and 3.0 along Z
m.translate(1.0, 2.0, 3.0)
flipNormals()
Parameters:
none
Description:
Flips the direction of all surface normals
Example:
m= pfpy.getMeshRef(0)
m.flipNormals()
centreOrigin()
Parameters:
none
Description:
Moves the transformation origin to the centre of the mesh's bounding box
Example:
m= pfpy.getMeshRef(0)
m.centreOrigin()
updateBound()
Parameters:
none
Description:
Recalculates the bounding box and centre point of the mesh
Example:
m= pfpy.getMeshRef(0)
m.updateBound()
getNumVertices()
Parameters:
none
Description:
Returns the number of vertices in the mesh
Example:
m= pfpy.getMeshRef(0)
print("Vertex count= ", m.getNumVertices())
print("Triangle count= ", m.getNumTriangles())
print("Material count= ", m.getNumMaterials())
getNumTriangle()
Parameters:
none
Description:
Returns the number of triangles in the mesh
Example:
m= pfpy.getMeshRef(0)
print("Vertex count= ", m.getNumVertices())
print("Triangle count= ", m.getNumTriangles())
print("Material count= ", m.getNumMaterials())
getNumMaterials()
Parameters:
none
Description:
Returns the number of materials in the mesh
Example:
m= pfpy.getMeshRef(0)
print("Vertex count= ", m.getNumVertices())
print("Triangle count= ", m.getNumTriangles())
print("Material count= ", m.getNumMaterials())
getVertexPos(frame, index)
Parameters:
integer frame number
integer vertex index number
Description:
Returns the position of the specified vertex in the specified frame
Example:
m= pfpy.getMeshRef(0)
print("Vertex0 pos in frame 100= ",m.getVertexPos(100, 0))
getRawVertexPos(index)
Parameters:
integer vertex index number
Description:
Returns the position of the specified vertex without applying any of the mesh transformations
Example:
m= pfpy.getMeshRef(0)
print("Raw vertex0 pos= ",m.getRawVertexPos(0))
getTriVertex(index, corner)
Parameters:
integer triangle index number
integer corner number
Description:
Returns vertex index associated with a corner (in the range 0..2 inclusive) for the specified triangle
Example:
m= pfpy.getMeshRef(0)
print("Triangle 100, corner 0= ",m.getTriVertex(100, 0))
print("Triangle 100, corner 1= ",m.getTriVertex(100, 1))
print("Triangle 100, corner 2= ",m.getTriVertex(100, 2))
getTriVertexNormal(frame, index, corner)
Parameters:
integer frame number
integer triangle index number
integer corner number
Description:
Returns the vertex normal associated with the specified corner (in the range 0..2 inclusive) for the specified triangle in the desired frame
Example:
m= pfpy.getMeshRef(0)
print("Frame 50, Triangle 100, corner normal 0= ",m.getTriVertexNormal(50, 100, 0))
print("Frame 50, Triangle 100, corner normal 1= ",m.getTriVertexNormal(50, 100, 1))
print("Frame 50, Triangle 100, corner normal 2= ",m.getTriVertexNormal(50, 100, 2))
getTriSurfaceNormal(frame, index)
Parameters:
integer frame number
integer triangle index number
Description:
Returns the triangle normal for the specified triangle in the desired frame
Example:
m= pfpy.getMeshRef(0)
print("Frame 50, Triangle 100, normal= ",m.getTriSurfaceNormal(50, 100))
getRawTriVertexNormal(index, corner)
Parameters:
integer triangle index number
integer corner number
Description:
Returns the vertex normal associated with the specified corner (in the range 0..2 inclusive) for the specified triangle without any mesh transformations applied.
Example:
m= pfpy.getMeshRef(0)
print("Triangle 100, raw corner normal 0= ",m.getRawTriVertexNormal(100, 0))
print("Triangle 100, raw corner normal 1= ",m.getRawTriVertexNormal(100, 1))
print("Triangle 100, raw corner normal 2= ",m.getRawTriVertexNormal(100, 2))
getRawTriSurfaceNormal(index)
Parameters:
integer triangle index number
Description:
Returns the triangle normal for the specified triangle without any mesh transformations applied.
Example:
m= pfpy.getMeshRef(0)
print("Triangle 100, raw normal= ",m.getRawTriSurfaceNormal(100))
hasTextureClip()
Parameters:
none
Description:
Returns True if the mesh has a texture clip associated with it
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
# do something
textureClipIsQuicktime()
Parameters:
none
Description:
Returns True if the texture clip associated with the mesh is a Quicktime movie
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
if m.textureClipIdQuicktime():
# do something
else :
# do something else
getTextureClipFilename()
Parameters:
none
Description:
Returns the filename associated with the texture clip associated with the mesh
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
print('filename= ', m.getTextureClipFilename())
getTextureClipFilenamePadding()
Parameters:
none
Description:
Returns the number padding for the texture clip associated with the mesh
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
print('filename= ', m.getTextureClipFilename())
print('number padding= ', m.getTextureClipFilenamePadding())
getTextureClipInPoint()
Parameters:
none
Description:
Returns the in-point (first frame) of the texture clip associated with the mesh
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
print('filename= ', m.getTextureClipFilename())
print('in= ', m.getTextureClipInPoint())
print('out= ', m.getTextureClipOutPoint())
Command:
getTextureClipOutPoint()
Parameters:
none
Description:
Returns the out-point (last frame) of the texture clip associated with the mesh
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
print('filename= ', m.getTextureClipFilename())
print('in= ', m.getTextureClipInPoint())
print('out= ', m.getTextureClipOutPoint())
getTextureClipWidth()
Parameters:
none
Description:
Returns the width (in pixels) of the texture clip associated with the mesh
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
print('filename= ', m.getTextureClipFilename())
print('width= ', m.getTextureClipWidth())
print('height= ', m.getTextureClipHeight())
getTextureClipHeight()
Parameters:
none
Description:
Returns the height (in pixels) of the texture clip associated with the mesh
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
print('filename= ', m.getTextureClipFilename())
print('width= ', m.getTextureClipWidth())
print('height= ', m.getTextureClipHeight())
getTriVertexTexCoord(tindex, cindex)
Parameters:
integer triangle number
integer corner number
Description:
Returns the texture coordinates associated with the specified corner (in the range 0..2 inclusive) for the specified triangle
Example:
m= pfpy.getMeshRef(0)
if m.hasTextureClip() :
# fetch the texture coordinated for the corner 0 in triangle 100
uv= m.getTriVertexTexCoord(100, 0)
print('u= ', uv[0])
print('v= ', uv[1])