Notifications
Clear all

[Closed] Aligning object to UV'd face?

Say I have a plane with a UV map on it, and for visual purposes, i’m using a texture of an arrow pointing up. How do I translate a faces UV “up vector” to world space so that I can align an item to it? What math is involved here?

The solutions I can think of require that the face is exactly square, which seems limiting.

6 Replies

I don’t know what you exacly need, but I can tell you how to access to UV data.

First you need to check is the UV channel you will use is exsists:
if( meshOp.getMapSupport object channel ) then
To get know map verts count for this channel:
meshOp.getNumMapFaces object channel

To get map face use:

meshOp.getMapFace object channel faceIdx

It returns Point3, that contains indices of three map verts that map face is using

To get map vert use:
meshOp.getMapVert object channel vertIdx

It returns Point3, where first two values are U and V

Hopefully this happy image explains it a bit more. Here’s a standard plane with 4×4 subdivisions. Each polygon is UV mapped and some are rotated.

For each polygon, I would like to get a vector based on its normal, and the direction of the textured arrow. So i’ve painted an axis gizmo on each some of the faces to show what I mean.

These would then be used to align objects to each.

I get it now.
Try get UV map verts for each vertex of polygon. Then compare they all to get two with most top position.
That you will know where the arrow is pointing.

I don’t know how to get faces that are one polygon (you will need it)

Actually I have another idea. I virtually push the vertices of each face along the faces normal, multiplied by that vertices V co-ordinate. Then I uh… look its 6:30 my brain is out of juice, but I think im on to something.

Another idea:
Get vector based on face center and first corner possitions. (normalize it?)
Do it in UV and in scene space. After sudivide (or something ;)) these two vectors you should get the face’s rotation in UV sapce.

I have to sasy I’m not good in vectors and matrixes

OK assuming your Polys are square…

Test each vert to find which way corner is 0,0 in Uv space and which is 1,1 you just then right a couple of case statements to work this out then pass the vert with 0,1 UV values and the vert with 0,0 UV values. Then you can use these vertices to define an edge, use getfacenormal on your face to get the 2nd axis of orientation, do a cross product between these 2 vectors and then you’ll get the 3rd orientation. Put these 3 into a matrix 3 value, set the position part to do be the centre of the face, then apply this as a transform to your object.

I covered most of this in my recent post with regards to aligning object to an edge.