How to get UV attribute indices sorted as to draw them

I'm tryng to draw the uv's of a mesh, in a way similar to the common UV Editors of any DCC's
For that, I'm getting the vertex indices of each polygon with "GetPolygonAttributeIndex". Then I use these indices to get the UV 2d coordinates from the array returned with a "Attributes > GetValueArry", with mode "Per Face Corner".
Once I have the 2d positions, I can draw lines in order to "see" them.

But ... the problem is that those indices are not ordered, and I don't know how to draw the lines so they don't cross each other, as you can see in some polygons in the attached image.
Is there a way to know the order of those indices?

Maybe, if I use the order of the associated vertex index, they could be correctly drawn?
But still, the splitted attribute indices cannot be correlated to the vertex indices ...

Any solution for these?

Or maybe there is a more direct way of displaying the UVs?

Comments

  • jcgagnonjcgagnon Fabric Employee Posts: 122 Fabric Employee
    edited February 15

    Hi Gabriel,

    I don't know exactly the existing Canvas nodes to do this, but it should be easy to do directly in KL (if you write a custom function node). You basically need to loop for all PolygonMeshTopology.getPolygonSize( Size polygon ) elements, and get the index from PolygonMesh.getPolygonAttributeIndex?( Size polygon, Size polygonPointIndex ) to index the value into the attribute. You can then draw the edges in polygon order.

    Jerome

  • GabrielRoyGabrielRoy Posts: 42

    Well, that's what I'm doing, but the order is not always correct, as you can see in the image.

  • jcgagnonjcgagnon Fabric Employee Posts: 122 Fabric Employee

    From what you wrote, you are using "Attributes > GetValueArry", with mode "Per Face Corner", which might not be the same behavior. The ordering should definitively be good in what I propose, as it is similar to what is used to create the 3D drawn polygons.

  • jcgagnonjcgagnon Fabric Employee Posts: 122 Fabric Employee

    What is also possible is that some code along the way is assuming per-point values, while in fact these UVs have seams and are not the same around vertices.

  • GabrielRoyGabrielRoy Posts: 42
    edited February 15

    I've set up an example where the issue can be seen. Find it attached.
    There is a Size node, at the left, where you can set the polygon index you want to see.
    The logic part of the graph is inside the node "getPolygonPointPositions"

    Inside a loop, I'm using, as you suggested, getPolygonAttributeIndex, to get the indexes of the vertexes of a polygon. These indices are "PolygonMesh Attribute indices" and not "PolygonMesh Polygon indices". The amount is different, as some vertexes have unshared values (splits).

    As these are only indices, and not 2d coordinates, I need to get those 2d coordinate values using Attribute>GetValueArray, with Face Corner mode, as otherwise I don't get the correct amount of values including splits. That node returns an array of coordinates of all the indices. From these, using the indices I got before, I get the uv 2d coordinates I need.

    But, as it seems, sometimes the order of the indices, as they were returned by "getPolygonAttributeIndex" is not the desired one.

  • jcgagnonjcgagnon Fabric Employee Posts: 122 Fabric Employee

    Thanks Gabriel, I'll have a look when I have time.

    Jerome

  • jcgagnonjcgagnon Fabric Employee Posts: 122 Fabric Employee

    Hi Gabriel,

    Finally I took the time to look at your sample. At first I suspected a very bad bug, but finally it's what we could call either a user error or bad documentation.

    Basically, the GetValueArray node, with "Per Face Corner" mode, returns the values ordered as

    [ Poly0.corner0, Poly0.corner1, , Poly0.corner2, , Poly0.corner4, Poly1.corner0, ... ]

    This order isn't the same as the "attribute index" order. The "attribute index" is a direct index to the attribute values, and these are not ordered by polygons, but by point then unshared values.

    So, basically, if you use this node (didn't find an out-of-the-box one) instead of GetValueArray, it works:

    dfgEntry {
    Vec2Attribute attr = geom.getAttributes().getAttribute("uvs0");
    uvs = attr.values;
    }

    where "geom" is an input of type Geometry, and "uvs" is an output of type Vec2[ ].

    Hope this helps,

    Jerome Couture-Gagnon

  • GabrielRoyGabrielRoy Posts: 42

    Thanks a lot Jerome,
    that was very helpful. Indeed I was understanding it incorrectly.

  • s_tkcms_tkcm Posts: 24

    Hi GabrielRoy,

    I maked node that create mesh from UV.
    https://github.com/TKCM/TKCM_Exts/tree/master/DFG/PolygonMesh

    Will this help you?

  • GabrielRoyGabrielRoy Posts: 42

    For sure it will!
    Thanks a lot for sharing.
    I'll have a look!

Sign In or Register to comment.