@michael I recall it was saving on math, but not 100% sure, its been a while since I've dived in this
@John If your hit is along the edge of a UV it doesn't return a value. I use another way in prebaker and normalmapgeneration, at least for a part of the code to prevent these problems. Tho its not 100% full proof, just ok enough for bitmapdata purpose. Corner to point distance to edge/line intersect test, which gives me 3 dist percentages, all added giving me not more than 1 (added 0.02 to it tho, because due to roundings it was failing sometimes) from these I simply interpolate between vertex values, either uv's or color I set at vertexes. so in a way very similar, except it came out very handy for my code. There are more ways to retreive uv's, using the rect defined by the uv's for instance. Made few tests in that direction but as they were resulting in "star" like at corners when combined with gradients, I've let them go. Might be the way that I was doing that was wrong tho. Note en passant: the BarycentricTest class was updated last summer, not its concepts but formating, all Vector based, its obviously more complex to follow, but it should be faster and low on memory than in its previous form. Added optional uvholder as well. Fabrice On Nov 23, 2010, at 4:56 PM, Michael Iv wrote: > Fabrice that is ok , I recall you told me ,you used to work alot with > barycentric space . I looked through several techniques for UV picking and > found that each of them is pretty different from another. Like that one I > posted above is different from one in Away3D BaryCentricTest class. One thing > I don't undestand in BaryCentricTest getUVs(0 is why you invert the > denominator? is it for simplifying math calculations or it must be done for > some other reason.? > > On Tue, Nov 23, 2010 at 5:34 PM, Fabrice3D <[email protected]> wrote: >> Also Ask Fabrice he told once he is a barycentric GURU :)) > Can't recall that! Truth is far away from that. I needed other ways to > retreive uvs than I was doing previously for the raytracer I was working on, > and came across a version of this principle I liked. Credits due are in the > class as its basically a 1/1 copy of this publication. > In its first version/first commit, It was a variation of it, using away face > order, which turned out be wrong, was easyer fix the raytracer and set it back > and be able use the class for more cases. Such as the HitTest class for BSP. > > Pretty much all we need has been done, it's a matter of adaptation. No guru, > no voodoo, no magic and certainly not me! > > Fabrice > > > On Nov 23, 2010, at 2:34 PM, Michael Iv wrote: > >> Ok here is a quick way to get UVs from ray-triangle intersection point: >> >> >> >> A;B;C vectors of triangle vertices >> P intersection vector >> uA uB uC- U coords of A B C >> vA vB vC -V coords of A B C >> >> First, you compute distances from P to A, B and C: >> >> dA = distance from A to P >> dB = distance from B to P >> dC = distance from C to B >> >> sum = dA + dB + dC >> coefA = dA / sum >> coefB = dB / sum >> coefC = dC / sum >> >> So, the texture coordinate at point P is : >> >> uP = uA * coefA + uB * coefB + uC * coefC >> vP = vA * coefA + vB * coefB + vC * coefC >> >> Read it in one of 3d math forums ,have not tested yet. But it is expressed >> exactly as barycentric formulas are formulated in math. >> Good Luck :)) >> >> On Tue, Nov 23, 2010 at 2:23 PM, Michael Iv <[email protected]> wrote: >> You should transform these coords to barycentric . I am too stuffed to write >> a showcase on this.But there is a lot of materia on this in the web.Also Ask >> Fabrice he told once he is a barycentric GURU :)) >> >> But it seems to me that transform material should contain such an example as >> it projects texture based on vector. >> >> >> On Tue, Nov 23, 2010 at 2:19 PM, John Brookes <[email protected]> wrote: >> Nice. >> So whats the UV position of the hit ;) >> >> >> >> >> -- >> Michael Ivanov ,Programmer >> Neurotech Solutions Ltd. >> Flex|Air |3D|Unity| >> www.neurotechresearch.com >> http://blog.alladvanced.net >> http://www.meetup.com/GO3D-Games-Opensource-3D/ >> Tel:054-4962254 >> [email protected] >> [email protected] >> >> >> >> >> -- >> Michael Ivanov ,Programmer >> Neurotech Solutions Ltd. >> Flex|Air |3D|Unity| >> www.neurotechresearch.com >> http://blog.alladvanced.net >> http://www.meetup.com/GO3D-Games-Opensource-3D/ >> Tel:054-4962254 >> [email protected] >> [email protected] >> > > > > > -- > Michael Ivanov ,Programmer > Neurotech Solutions Ltd. > Flex|Air |3D|Unity| > www.neurotechresearch.com > http://blog.alladvanced.net > http://www.meetup.com/GO3D-Games-Opensource-3D/ > Tel:054-4962254 > [email protected] > [email protected] >
