geometry get all attributes in one query (Python Module)

   6547   4   2
User Avatar
Member
36 posts
Joined: Sept. 2014
Offline
Hello! I am attempting to write a custom data writer using python, but I have run into an interesting problem

the larger the mesh, the longer each query to a mesh can take, so I am trying to reduce my queries and do everything in memory

my question: is there a way to query all of a node's geo data and attributes in a single query?

or do I have the “fastest” option currently where I pre-allocate my list and then query each attribute in a for loop


numberOfPoints = len(objG.points()) + 1
vertPos = *numberOfPoints
uvPos = *numberOfPoints
vertColor = *numberOfPoints

for point in objG.points():
pointNumber = point.number()
vertPos = point.position()
uvPos = point.attribValue('uv')
vertColor = point.attribValue('Cd')
todo: add signature
User Avatar
Member
624 posts
Joined: Aug. 2008
Offline
wrangle node, vex instead python will be faster.
User Avatar
Member
36 posts
Joined: Sept. 2014
Offline
ohh shiny! I have not actually tried to use vex in Houdini yet

do you know a good resource on how to use it to write data to an external file?
todo: add signature
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
You should also take a look at hou.Geometry.pointFloatAttribValues(). This function will return a single list of all the values for all the points on your geometry in a very fast manner.
vertPos = objG.pointFloatAttribValues(“P”)
This however returns a flat list instead of a list of 3 sized tuples. You can use the numpy module to reshape that list (which I think there should be examples of in the help for that function, or one similar to it).
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
36 posts
Joined: Sept. 2014
Offline
Thanks! this was exactly what I was looking for!

and I will also add in-case anyone else ever has a similar question to mine

I then got stuck on how to query the points.numbers() to a primitive or point group

groupPoints = geo.globPoints('groupName')


I think I am finally starting to get a grasp on the built in help files
todo: add signature
  • Quick Links