importvtk 1.1.0 : VTK Import Plugin for Mayaź
importvtk is a Maya plugin written in C++ that provides MEL and Python commands to import VTK files (binary or ASCII) containing a vtkDataSet or a live (in memory) VTK Python object. Other generic 3D converters either supported ASCII files only (inefficient for large datasets) or lacked certain contexts such as scalars, vectors, tensors and lookup tables.
importvtk currently imports vtkDataSets in the following ways:
2008-05-26 Added support for live python objects and MS VCEE 9 2008.
2008-04-28 Added options for normals, version, and debug messages.
2008-04-24 Added UV texture and vertex normals import for polydata.
2008-04-23 Updated Makefile and code for Linux and Maya 2008.
2006-08-11 Project hosted by SourceForge.
Project files: importvtk-1.1.0.tar.gz
Example VTK files: 1.0-examples.tar.gz
Latest development files: CVS instructions
Within Maya's command line or script editor, load the plugin with this MEL command:
loadPlugin "importvtk"; # Or with explicit path (Windows example). loadPlugin "c:/rsz/projects/maya/plugins/importvtk.mll";or with the GUI, browse to that location through the Maya menu Windows | Settings/Preferences | Plugin Manager ....
unloadPlugin "importvtk";
For Python, copy "importvtk.py" to a directory listed in your PYTHONPATH. You don't want "importvtk.py" in the same directory as your "importvtk.mll" or "importvtk.so" file, because Python may complain upon import that "Error: dynamic module does not define init function (initimportvtk)" since it tries to load the DLL/SO before the python script.
Several test files are built by and ship with the project. Your own tests should reproduce the images below.
# MEL version. importvtk -f "c:/rsz/projects/maya/plugins/importvtk/test/tmp-sgrid.vtk" -s "opacityPP"; addAttr -is true -ln "radius" -at "float" -min 0 -max 20 -dv .1 "particleShape1"; setAttr "particleShape1.radius" .75; # Python version. from importvtk import importvtk importvtk(f="/net2/rsz/i686/importvtk/dev/importvtk-1.1.0/test/tmp-sgrid.vtk", s="opacityPP") import maya maya.cmds.addAttr("particleShape1", internalSet=True, ln="radius", at="float", min=0, max=20, dv=.1) maya.cmds.setAttr("particleShape1.radius", .75)The images below compare what is seen in VTK and in Maya.
vtkStructuredGrid points in VTK Opacities: Red = .1, Green =.5, Blue = .9 |
Converted to Maya Particle System |
# MEL version. importvtk -f "c:/rsz/projects/maya/plugins/importvtk/test/tmp-img.vtk" -s "density"; # Python version. from importvtk import importvtk importvtk(f="/net2/rsz/i686/importvtk/dev/importvtk-1.1.0/test/tmp-img.vtk", s="density")
vtkImageData points in VTK Opacities: Red = .1, Green =.5, Blue = .9 |
Converted to Maya Fluid |
# MEL version. importvtk -f "c:/rsz/projects/maya/plugins/importvtk/test/tmp-polyspt.vtk"; # Python version. from importvtk import importvtk importvtk(f="/net2/rsz/i686/importvtk/dev/importvtk-1.1.0/test/tmp-polyspt.vtk")You'll then need to add a material, such as Blinn and enable color-per-vertex shaded display from the menu Display | Polygons | Custom Polygon Display | Color in Shaded Display.
vtkPolyData polygon surface in VTK Opacity and colors mapped to Z coordinates |
Converted to Maya Mesh |
# MEL version. importvtk -f "c:/rsz/projects/maya/plugins/importvtk/test/tmp-polyslines.vtk"; # Python version. from importvtk import importvtk importvtk(f="/net2/rsz/i686/importvtk/dev/importvtk-1.1.0/test/tmp-polyslines.vtk")Each line is created as its own nurbs curve.
vtkPolyData lines in VTK (with colormapped scalars) |
Converted to Nurbs Curves |
# MEL version. importvtk -f "c:/rsz/projects/maya/plugins/importvtk/test/tmp-polytextured.vtk"; # Python version. from importvtk import importvtk importvtk(f="/net2/rsz/i686/importvtk/dev/importvtk-1.1.0/test/tmp-polytextured.vtk")To see the effect, you'll need to add a material, such as Blinn, and apply a texture to the color channel via a 2D Textures "File" render node. The default uvSet name "map1" is used.
vtkPolyData polygon normals in VTK with PNG texture "uvgrid.png" |
Converted to Maya Mesh |
# MEL version. importvtk -normals -f "c:/rsz/projects/maya/plugins/importvtk/test/tmp-polynormals.vtk"; # Python version. from importvtk import importvtk importvtk(f="/net2/rsz/i686/importvtk/dev/importvtk-1.1.0/test/tmp-polynormals.vtk")To see the effect, you'll need to select the new Maya object's polySurfaceShape in the Attribute Editor, expand the Mesh Component Display section and Display Normal and use the "vtx" Normal Type.
vtkPolyData normals in VTK | Converted to Maya Mesh |
import vtk c = vtk.vtkConeSource() c.Update() p = c.GetOutput() from importvtk import importvtk # Three ways to import the polydata. importvtk('p') importvtk(r=p.__this__) importvtk(reference=p.__this__)
loadPlugin "importvtk";
importvtk -f "file.vtk" -s "array1" "radiusPP" -s "array2" "opacityPP"