# GET Point3 XYZ world coordinates out of UVW´s

 01 January 2008 kutsche Frequenter   portfolio Andre Kutscherauer 3D Designer www.ak3d.de Munich, Germany GET Point3 XYZ world coordinates out of UVW´s Hello, image you have object with uvw´s assigned with a bitmap in material that uses this uv´s. How can I get the XYZ Point3 Values out of the UVW´s from a special pixel in World Space. (for example UV [3,5,0] is currently on Point [5,2,9] in wold coordinates. Basically I like know where exactly on my object a special pixel of the bitmap is projected. I need the information in world coordinates. I hope this is not too difficult to achieve... __________________ andré kutscherauer 3d design www.ak3d.de share quote
 01 January 2008 Haamu Frequenter portfolio Antton Tapani Finland Nah, not too complex. You need to use barycentric coordinates for this. meshop.getBaryCoords does this for mesh faces but I don't think there's any command for UV faces. You can make a temporary mesh corresponding the UV layout and use the meshop command or you can do it by hand, which is lucky for us because maths is know to be fun. This is a variant of a function Bobo posted here long ago. If you search you can probably find it and all explanations how it works. This particular one assumes you know in which face your point is. Bobo's version returns right values when the point is outside the face, mine doesn't (think it ran too slowly for me so dropped it). More below. `````` fn buildbary mes ind p = --mes=trimesh; ind=face index; p=point in uv space ( uvf=gettvface mes ind --vertex indices of the texture face ---UV vertex coordinates local a=gettvert mes uvf.x local b=gettvert mes uvf.y local c=gettvert mes uvf.z v1 = p-a v2 = p-b v3 = p-c a1= (length(cross v2 v3))/2 a2= (length(cross v3 v1))/2 a3= (length(cross v1 v2))/2 ta= a1+a2+a3 [a1/ta, a2/ta, a3/ta] )`````` This method returns poin2 value. Slightly different method, explained in here http://www.blackpawn.com/texts/pointinpoly/default.html. Returns False if point is outside the face. Think I had many reasons why I used this method. It works just fine with position values but you can't interpolate stuff like vertex colors or normals like this, you'll need the poin3 coordinates) ``````fn ifintri mes ind cor = --mes=trimesh; ind=face index; cor=point3 UV coordinate ( uvf=gettvface mes ind local a=gettvert mes uvf.x local b=gettvert mes uvf.y local c=gettvert mes uvf.z v1 = c-a v2 = b-a cor.z=0 --only interested in the 2d plane v3 = cor-a dot11 = dot v1 v1 dot12 = dot v1 v2 dot13 = dot v1 v3 dot22 = dot v2 v2 dot23 = dot v2 v3 div = 1 / (dot11 * dot22 - dot12 * dot12) u = (dot22 * dot13 - dot12 * dot23) * div v = (dot11 * dot23 - dot12 * dot13) * div if (u > 0) and (v > 0) and (u + v <= 1) then [u,v] else false )`````` once you have the coordinates you just need to interpolate your target face. This one is from maxscript help: Quote: Barycentric coordinates are the coordinates relative to the triangular face. The barycentric coordinates of a point p relative to a triangle describe that point as a weighted sum of the vertices of the triangle. If the barycentric coordinates are b0, b1, and b2, then: p = b0*p0 + b1*p1 + b2*p2; where p0, p1, and p2 are the positions of the vertices of the triangle. The Point3 returned by this method has the barycentric coordinate stored in its three component values. The coordinate is relative to the triangular face that was intersected. Barycentric coordinates can also be used to interpolate any quantity whose value is known at the vertices of the triangle. This doesn't work for the poin2 values, check the link for proper way to apply. Hope this is helpful share quote
 01 January 2008 kutsche Frequenter   portfolio Andre Kutscherauer 3D Designer www.ak3d.de Munich, Germany Thank you very much! This sounds very complicated. I will try that. Why has it always to be so complicated. Basically it is a simple task. The textures are viewable in realtime in the viewport of 3dsmax it should easy be accessible.... __________________ andré kutscherauer 3d design www.ak3d.de share quote
 01 January 2008 JHN maxscript/c# lover   Johan Boekhoven Technical Artist Freelance TD/Generalist Netherlands Well there is a really easy method! You know the map channel info tool. You can simply copy your map channel and paste it in the mesh channel.. voila your unwrap. it's scale will be small, so an xform to scale it to usable proportions is usefull. You can store the mesh channel temporay to an uv channel and paste if back when done with the layout.... just swapping channels! Incredibly usefull tool! -Johan N.B. Looks like its exposed to maxscript as well. Wouldn't be too hard writing a script to swap UV and mesh channels. __________________ Online: LinkedIn Last edited by JHN : 01 January 2008 at 03:59 PM. share quote
 01 January 2008 mrapelje Scholar   Matt Rapelje 3D Game Artist... Max Seattle, US http://www.polyleaf.com/MattRapelje_UVWXYZswap.zip <-- here is a swaper that I wrote awhile ago. Used this as a cheat to add modifiers to my UVs. share quote
 01 January 2008 kutsche Frequenter   portfolio Andre Kutscherauer 3D Designer www.ak3d.de Munich, Germany Thank you. Now i got a lot of stuff to think about. Basically I like to do it backwards than most of the examples I´ve read until now: I like to go through every pixel of a assigned 2d texture and get the current Point3 Coordinates in Wold Space back from this script. This should be independed from the meshvertices or faces. The consequence of that script would be that I would sometimes get more than just one Point3 Coordinate back. (Because of the possibility that a texture picel is mapped more than just once onto the object) Imagine a simple cube Dimension 10,10,10. This cube is currently on position [0,0,0] and has a uvw modificator on it with box mapping. Theres a texture applied to channel 1 with a bitmap that has exactly 9 pixels. What i like to do now is: A scripted loop that samples every pixel from this bitmap and puts out the current Point3 World Coordinates where this Pixel actually is projected. Shorter: In the above example I like to input to the script: Pixel [2,2,0] (The black pixel in the middle) and script should output: [0,0,5] [5,0,0] [0,5,0] [0,-5,0] [-5,0,0] [0,0,-5] How can I do that? Maybe someone has a simple code that would do that. Basically is the opposite of the Painter Tutorial in the Maxscript Reference... __________________ andré kutscherauer 3d design www.ak3d.de share quote
 01 January 2008 PiXeL_MoNKeY Expert   Eric Craft Dallas, USA I would guess you would need to get every face that covers that pixel in the UV Coordinates. Then get the location of that pixel on the face. From there return the WS space location. Just a thought, -Eric __________________ "The Evil Monkey hiding in your closet." share quote
 01 January 2008 kutsche Frequenter   portfolio Andre Kutscherauer 3D Designer www.ak3d.de Munich, Germany Maybe Bobo does know something about it.... ;-) __________________ andré kutscherauer 3d design www.ak3d.de share quote
 01 January 2008 CGTalk Moderation Expert Thread automatically closed 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. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.