Get point indices in prims with Python

   4322   2   0
User Avatar
Member
9 posts
Joined: 4月 2015
Offline
Hi,
I am trying to access the point indices prims are made up of in Python.

Currently I am doing this with:

for k in geo.prims():
MyCurrentFace = k
NumVertsCurrentFace = MyCurrentFace.numVertices()

for Verts in MyCurrentFace.vertices():
VertsCurrentFace = Verts.point().number()
print VertsCurrentFace




It works but it is relatively slow.
In another thread where I asked how to access point positions I was told that it would be very fast with using:

hou.Geometry.pointFloatAttribValues(geo,“P”)

That worked very fast.
So my question is, is it possible to get the point indices of individual faces in a similar way?

I have so far tried to create relevant Attributs with nodes such as the attribcreate node, but I wasn´t sucessful.
I did some other tests and manged to create Attributes such as Normals and similar things with nodes which I was then able to access with Python. But I have so far not managed to create Attributes for point index per prim.
User Avatar
Member
183 posts
Joined: 11月 2008
Offline
No other way. If need particular prim, or range of prims, better use generator (iterPrims):

points_ids = [vtx.point().number() for vtx in geo.iterPrims().vertices()]


If you'r iterating over all prims there is no big difference in speed between prims() and iterPrims() other than more memory consumption.
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
60 posts
Joined: 4月 2006
Offline
Hi,
This is what I use to avoid looping over the geometry in python (my example is strictly for triangles but you can modify it)

First add a string prim attribute with the vertices per primitve:
i[]@face_idx = primpoints(0, @primnum);
s@face_indices = string(itoa(i[]@face_idx[0]) + "," + itoa(i[]@face_idx[1]) + "," + itoa(i[]@face_idx[2]));

Then after that in a python geo node:
face_indices = np.array(geo.primStringAttribValues("face_indices"))
flat_list = ','.join(face_indices).split(',')
face_indices = np.array(flat_list, dtype=np.int32).reshape(-1,3)
Edited by perpen - 2024年5月23日 19:07:56
  • Quick Links