How to get polygon vectors
9919 17 1- Digipiction
- Member
- 166 posts
- Joined: March 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.
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.
- edward
- Member
- 7899 posts
- Joined: July 2005
- Offline
- Digipiction
- Member
- 166 posts
- Joined: March 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).
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).
- Platon
- Member
- 99 posts
- Joined: July 2007
- Offline
- edward
- Member
- 7899 posts
- Joined: July 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?
- Julian Johnson
- Member
- 11 posts
- Joined: March 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…
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…
- Digipiction
- Member
- 166 posts
- Joined: March 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.
Also, I will of course try this on my scenes.
edwardI believe I have, but I will check again.
An idea on this, have you tried using a Facet SOP and telling it to Orient Polygons?
Julian JohnsonThank 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.
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.
Also, I will of course try this on my scenes.
- Julian Johnson
- Member
- 11 posts
- Joined: March 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!
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!
- Platon
- Member
- 99 posts
- Joined: July 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.
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.
- Julian Johnson
- Member
- 11 posts
- Joined: March 2014
- Offline
- Digipiction
- Member
- 166 posts
- Joined: March 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.
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.
- Platon
- Member
- 99 posts
- Joined: July 2007
- Offline
- Digipiction
- Member
- 166 posts
- Joined: March 2014
- Offline
- Platon
- Member
- 99 posts
- Joined: July 2007
- Offline
- Digipiction
- Member
- 166 posts
- Joined: March 2014
- Offline
owlYzarcI have had a closer look at the file now.
it isn't supposed to fix point order, it should give you 2 vectors in desired directions
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
- Digipiction
- Member
- 166 posts
- Joined: March 2014
- Offline
- Platon
- Member
- 99 posts
- Joined: July 2007
- Offline
- Digipiction
- Member
- 166 posts
- Joined: March 2014
- Offline
-
- Quick Links