[Closed] 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.
Thanks,
-Johan
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
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
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!
-Johan
hence the “where”
http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)
Don’t let the math scare you off
This is where Bobo’s DVD would come in really handy. He has a thorough tutorial on how to do this.
Oh but it does… it does… I didn’t skip “wiskunde B” for nothing, regret it every day though… 🙁
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.
Thanks,
-Johan
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 "%
" 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