View Full Version : UV coord to mapfaces
I 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.
03-25-2009, 04: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.
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...
03-25-2009, 06: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 :)
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!
03-25-2009, 10:04 PM
hence the "where" ;)
Don't let the math scare you off :)
03-26-2009, 12:56 AM
This is where Bobo's DVD would come in really handy. He has a thorough tutorial on how to do this.
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 found a thread here: http://forums.cgsociety.org/showthread.php?t=275372 that holds some answers for me.
I'll keep my progress posted.
@Gavin: I know I should buy it, or even better let my boss buy it.
04-07-2009, 04:37 PM
did you ever find a solution for this? i'm now in need of this myself
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
-- 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
-- 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, uv, 0.] theMapVertCoords theMapVertCoords theMapVertCoords then
local restoreMapPos = meshop.getMapVert obj 1 theMapVerts
meshop.setMapVert obj 1 theMapVerts [uv, uv, 0.]
local theCoords = meshop.getMapVert obj 1 theMapVerts
meshop.setMapVert obj 1 theMapVerts restoreMapPos
local uvw = [uv,uv,0]
local uvBary = [distance theMapVertCoords uvw, distance theMapVertCoords uvw, distance theMapVertCoords uvw]
-- uvBary = normalize uvBary
-- local uvBary = theMapVertCoords*uv + theMapVertCoords*uv + theMapVertCoords*0
local theMeshVerts = meshop.getVertsUsingFace obj face
local thePos = for vert in theMeshVerts collect meshop.getVert obj vert
uvBary = normalize uvBary
theBary = thePos*uvBary + thePos*uvBary + thePos*uvBary
-- 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.
04-08-2009, 08: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.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.