Rendering VTK files with Mantra ?

   3885   5   2
User Avatar
Member
301 posts
Joined: July 2005
Online
Hi,

Is there any project/solutions (open/close source) which is able to render VTK files natively in Mantra (preferably without having to convert the files to bgeo)?

Cheers
Nicholas Yue
User Avatar
Member
383 posts
Joined: June 2010
Offline
You can do it quite easily with a python sop. Read your vtk file , convert volume to numpy array and copy this numy array into a houdini volume .. I will search some sample code. I have lying around somewhere ..
www.woogieworks.at
User Avatar
Member
383 posts
Joined: June 2010
Offline
import numpy

# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()

# Add code to modify the contents of geo.
filePath = hou.Node.evalParm(hou.pwd(), “parmFilePath”)
infile = file(filePath,'r')
data = numpy.load(infile)
infile.close()
data = data.astype(numpy.float64)
dimensions = data.shape
xres = dimensions
yres = dimensions
zres = dimensions
volume_bbox = hou.BoundingBox(0, 0, 0,xres , yres, zres)
volume = geo.createVolume( xres, yres, zres, volume_bbox)
volume.setAllVoxels (data.flatten(order='F'))

This is the code to convert from numpy to houdini volume .. just insert before this the code to load the vtk file and copy it into a numpy array ..
I have the code to do that too somewhere, but I didnt find it just now ..
www.woogieworks.at
User Avatar
Member
17 posts
Joined: July 2018
Offline
Hi Dulo,

Thanks for sharing that code! That has been massively helpful for me. In the end I reduced it slightly, do let me know if I'm missing something by cutting out some of the extra sections:

import numpy

node = hou.pwd()
geo = node.geometry()

data = numpy.load(hou.evalParm('/obj/geo1/numpy_to_volume/numpyfile'))
xres, yres, zres = data.shape
volume_bbox = hou.BoundingBox(0, 0, 0, xres , yres, zres)
volume = geo.createVolume( xres, yres, zres, volume_bbox)
volume.setAllVoxels (data.flatten(order='F'))

(The hou.evalParm… is a file field that I added to the python node)


Ash
User Avatar
Member
8597 posts
Joined: July 2007
Offline
ashcic
(The hou.evalParm… is a file field that I added to the python node)
you better use node.evalParm(“numpyfile”) instead of specifying it using absolute path to the parm
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
17 posts
Joined: July 2018
Offline
Thanks Tomas!
  • Quick Links