How to get polygon vectors

   9936   17   1
User Avatar
Member
166 posts
Joined: 3月 2014
Offline
Hello,

I have an upright standing plane with four vertices (actually it's a mesh consisting of many such quads).

I now need two vectors. When looking at the front of the face, I need the vector that goes from bottom left to bottom right. And I need the vector that goes from bottom left to top left.

I have used three Sort SOPs with three Switch nodes + expressions to try and rotate the polygon vertices such that starting from the bottom left and going counter-clockwise, the order always comes out as: 0, 1, 2, 3. My desired vectors are then 0->1 and 0->3.

But on certain faces I have the problem that Houdini appears to have an unpredictable vertex order. When setting up the nodes described above, I assumed that the vertex order would always be counter-clockwise. But for example I have a face whose vertices in counter-clockwise order are given as:
0, 2, 1, 3

I have not found a way to sort these predictably. Can anybody shed some light on it? I'm sure there's a better way to do things anyhow than the one I described.
User Avatar
Member
7899 posts
Joined: 7月 2005
Offline
What about using nearpoint() hscript expressions to find your 3 points? Depending on your actual situation, you could try using nearpoint() with variations of $XMIN, $YMIN, $ZMIN, $XMAX, $YMAX, $ZMAX.
User Avatar
Member
166 posts
Joined: 3月 2014
Offline
Does $XMIN etc. work with polygons? They would have to be in the polygons' local space in order to work. I need to be able to loop over an entire mesh consisting of upright quads.

Imagine a box with the top and bottom blasted away. For every one of the four sides, I want two vectors going from bottom left point along bottom edge to the right and from bottom left point along left edge to the top.

Of course my mesh is not conveniently rotated such that all sides align with the world axes (except for Y).
User Avatar
Member
99 posts
Joined: 7月 2007
Offline
Hi, Chris_TC,
could you maybe share that mesh (or a part of it)? hip is always welcome too
User Avatar
Member
7899 posts
Joined: 7月 2005
Offline
Chris_TC
But on certain faces I have the problem that Houdini appears to have an unpredictable vertex order. When setting up the nodes described above, I assumed that the vertex order would always be counter-clockwise. But for example I have a face whose vertices in counter-clockwise order are given as:
0, 2, 1, 3

An idea on this, have you tried using a Facet SOP and telling it to Orient Polygons?
User Avatar
Member
11 posts
Joined: 3月 2014
Offline
Chris,

This is probably over-elaborate but if you partition your quad grid first you'll get independent quads which might have the same point order. From there you can foreach with an expression and construct your axes. Works in this simple scene but I don't know whether it's a universal solution i.e. I don't know what dictates the point order of the partitioned quads or whether you're going to run into the same anomalies although a sort after the each node for each poly might just fix it…

Attachments:
quad_axes.hipnc (66.4 KB)

User Avatar
Member
166 posts
Joined: 3月 2014
Offline
Thank you for the answers. I cannot check my scene file currently, but on Monday I will take a look at the suggestions and can also share a few example meshes if necessary.

edward
An idea on this, have you tried using a Facet SOP and telling it to Orient Polygons?
I believe I have, but I will check again.

Julian Johnson
This is probably over-elaborate but if you partition your quad grid first you'll get independent quads which might have the same point order.
Thank you. Can you or somebody else explain what exactly the partition node with the rule you used does? I've read the help file, but am not entirely clear on how the output of this node differs from the input.

Also, I will of course try this on my scenes.
User Avatar
Member
11 posts
Joined: 3月 2014
Offline
Hi Chris,

I should have been more accurate in my description of what I was doing. As I understand it, all Partition does is create an independent group for each polygon. The magic happens in the ForEach node. Here it iterates over each group (in this case each polygon) and as it is iterating it treats each polygon as an individual (non-attached) item i.e. each polygon only has four vertices numbered 0,1,2,3. It somehow ignores the overall point numbering from the grid itself and treats the quad as solo entity which is why referencing points 0 to 1 and 0 to 2 works consistently in the expression. All partition does is split your geometry into groups based on patterns etc. At the end of the ForEach cycle the geometry is merged back together and the original point order restored…..at least, that's how I think it works!
User Avatar
Member
99 posts
Joined: 7月 2007
Offline
Yes, partition sop separates geometry based on rules, in your case each face to its own group.

In for each you already have “per primitive/point”, so it doesn't use groups created with partition sop at all.
Also after “for each” you get 4 points in 1 spot since it doesn't fuse them back.

Example of a mesh would be really great (50 faces? ). Without it its like walking in the dark . With all that said, here are some attempts which hopefully will solve your problem.

I've stored vectors in question as tangentu and tangentv attributes.

Attachments:
orient_points_on_mesh.hipnc (169.7 KB)

User Avatar
Member
11 posts
Joined: 3月 2014
Offline
owlYzarc - thanks for pointing that out. It couldn't be more wrong! :-) Back to the drawing board with ForEach. @Chris - apologies for wasting your time on that one!
User Avatar
Member
166 posts
Joined: 3月 2014
Offline
Thank you everyone for the answers. So I have attached my actual scene file because I think it's easier to see what's going on.

Since I'm very new, a lot of the node connections may be far from perfect, so feel free to point this out. In fact, please do!

In the scene file, there is a “Kontrollobjekt” with a value that can be adjusted. The ForEach node is then supposed to subdivde the polygons. This works if the point orders of the polygons are “clean”, i.e. counter-clockwise. If you connect the Tube into the ForEach you can see that it works.

@owlYzarc: I have looked at your file, I don't think it fixes the point order the way I need but I will take a closer look when I have more time.

Attachments:
testmesh.rar (24.2 KB)

User Avatar
Member
99 posts
Joined: 7月 2007
Offline
it isn't supposed to fix point order, it should give you 2 vectors in desired directions
User Avatar
Member
166 posts
Joined: 3月 2014
Offline
owlYzarc
it isn't supposed to fix point order, it should give you 2 vectors in desired directions
I see, sorry about that. In that case I can probably make it work for what I need.
User Avatar
Member
99 posts
Joined: 7月 2007
Offline
I'm not sure but, is this what you were trying to achieve?

Attachments:
testmesh2.hipnc (276.9 KB)

User Avatar
Member
166 posts
Joined: 3月 2014
Offline
owlYzarc
it isn't supposed to fix point order, it should give you 2 vectors in desired directions
I have had a closer look at the file now.
I think I understand most of what's going on, and I think the important magic happens in the two nodes Attribute Create and Attribute Promote. The VTX attribute seems to give a predictable order, which is always clockwise.

However, in order for this to work for my situation, I must be able to put VTX 2 at a predictable location, otherwise the vectors you calculate are sometimes flipped and sometimes not (depending on where VTX 2 is situated in the polygon).

So basically I need VTX 2 to always be at the bottom left. The Sort+Switch nodes in my scene file already take care of this based on point number (they shift the point order until the bottom left point is correct). But I don't know how I can get a point based on its VTX number?

EDIT: My post overlapped with yours, I haven't looked at your new scene file yet.

EDIT2: Oh wow, thank you for fixing up my scene file, very cool! I will take a close look tomorrow and see how you did it. May have some more questions then
User Avatar
Member
166 posts
Joined: 3月 2014
Offline
So I've looked through the scene now. Using the two sorts is very cool and straightforward.

The only question I have are the two nodes that you've called “for vector preview”. I don't see any reference there to the tangentu and tangentv, so how are you previewing the vectors?
User Avatar
Member
99 posts
Joined: 7月 2007
Offline
in display options > markers
you can create/set up custom attributes to be displayed
these settings should be saved in hip file so just enable them
User Avatar
Member
166 posts
Joined: 3月 2014
Offline
Alright, thank you, you have been a huge help!
  • Quick Links