View Full Version : UV coord to mapfaces

 JHN03-25-2009, 10:24 AMI have a UV(W) coordinate and I want to get all map faces that exist under that coord. How would I go about it, would I need to brute force loop over all faces, just to find which are or are there some better ways. Like rayshooting in UV space. In the end I want to use a uvmap to get worldcoordinates, but I think I can manage after the find face under coord part. Thanks, -Johan
PiXeL_MoNKeY
03-25-2009, 03:46 PM
I think your best bet may to use the getArea method of the Unwrap Modifier, which returns the UVW (area, X, Y, Width, and Height), as well as the Geometry (Area). From there you should be able to calculate what you need.

-Eric

JHN
03-25-2009, 04:19 PM
AreaGeom is a float value, what does it represent?
And the other stuff can be returned as well with getMapVert on all 3 verts of a mapFace I think... I don't see how this get's me to a XYZ value. Right now I'm trying to get the bary of a UVW face by the UV coord and then use that bary on the verts on the geoFace. But I'm not there yet...

-Johan

ZeBoxx2
03-25-2009, 05:49 PM
look up one of the algorithms for figuring out where, in a triangle, a point sits.

Alternatively, you could copy the UV coords to mesh using the channel operations and then do the intersectRayEx/etc. thing on that. Trick from another thread here somewhere :)

JHN
03-25-2009, 08:18 PM
Richard, I already have a function to find if a point is in a triangle, that works okay, I need to know what the bary (well I think I need that) is in the mapFace, and use the same bary for the geoVerts.. so much for the theory, but in practice I'm missing something.

To be continued...

Suggestions are welcome!

-Johan

ZeBoxx2
03-25-2009, 09:04 PM
hence the "where" ;)

http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)

Don't let the math scare you off :)

thatoneguy
03-25-2009, 11:56 PM
This is where Bobo's DVD would come in really handy. He has a thorough tutorial on how to do this.

JHN
03-26-2009, 08:45 AM
Don't let the math scare you off :)

Oh but it does... it does.. I didn't skip "wiskunde B" for nothing, regret it every day though.. :sad:

I'll keep my progress posted.

@Gavin: I know I should buy it, or even better let my boss buy it.

Thanks,
-Johan

Gravey
04-07-2009, 03:37 PM
did you ever find a solution for this? i'm now in need of this myself

JHN
04-08-2009, 07:10 AM
I was going in the right direction and then other stuff landed on my plate. So what I have now is this.

b = box mapcoords:on

-- Check if points point to the same side
fn sameSide p1 p2 a b =
(
cp1 = cross (b-a) (p1-a)
cp2 = cross (b-a) (p2-a)
if dot cp1 cp2 >= 0 then true
else false
)

-- Is point in the UV mapface
fn pointInTriangle p a b c=
(
if SameSide p a b c and SameSide p b a c and SameSide p c a b then
true
else
false
)

-- Get the worldspace coordinates
fn getMapFaceXYZfromUV obj face uv =
(
obj = obj.mesh
local theMapVerts = meshop.getMapFace obj 1 face
local theMapVertCoords = for vert = 1 to 3 collect meshop.getMapVert obj 1 theMapVerts[vert]
format "%\n" theMapVertCoords
if pointInTriangle [uv[1], uv[2], 0.] theMapVertCoords[1] theMapVertCoords[2] theMapVertCoords[3] then
(
local restoreMapPos = meshop.getMapVert obj 1 theMapVerts[1]
meshop.setMapVert obj 1 theMapVerts[1] [uv[1], uv[2], 0.]
local theCoords = meshop.getMapVert obj 1 theMapVerts[1]
meshop.setMapVert obj 1 theMapVerts[1] restoreMapPos
local uvw = [uv[1],uv[2],0]
local uvBary = [distance theMapVertCoords[1] uvw, distance theMapVertCoords[2] uvw, distance theMapVertCoords[3] uvw]
-- uvBary = normalize uvBary
-- local uvBary = theMapVertCoords[1]*uv[1] + theMapVertCoords[2]*uv[2] + theMapVertCoords[3]*0
local theMeshVerts = meshop.getVertsUsingFace obj face
local thePos = for vert in theMeshVerts collect meshop.getVert obj vert
uvBary = normalize uvBary
theBary = thePos[1]*uvBary[1] + thePos[2]*uvBary[2] + thePos[3]*uvBary[3]

-- meshop.getBaryCoords obj face [30.854,-47.385,0]
)
-- for vert in theMapVerts do
)

-- Place a null on the UV coord. function doesn't return proper coords yet.
point pos:(getMapFaceXYZfromUV b 4 [0.1,0.6])

I know it's badly documented, I have to dive into it too, but that's not going to happen anytime soon I'm afraid....
If you find a way I'd be very interrested, since mine is obviously not working yet.

Goodluck,
-Johan

CGTalk Moderation
04-08-2009, 07:10 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1