I am painting onto a mesh with the mouse. Wherever the user clicks, the current colour will be painted in a circular shape of about 32 pixels, centered around the click position. To find the position I have been using a Raycase:
which can be combined with
My problem is this:
I want to only change the colour for the pixels which lie on the triangle I have hit by the raycast. I realize I can get the triangle index from the
asked Feb 08 '11 at 10:18 PM
I just wrote my own barycentric calculation routine. It's not optimised and don't have error checking/handling, but it works great in my tests.
GetBarycentric just returns the same value you get from hit.barycentricCoordinate, but for any point you like. The point you offer have to be in uv coordinates. Just check every "pixel" you want to draw. If your "circular shape" is generated in pixels i guess that should work too but you have to use the pixelcoordinates instead of uvs for the 3 vertex positions.
InTriangle is not tested, but it should work. z don't have to be tested for lower 1 since it's calculated out of x and y.
I hope that helps a bit ;) It's a pity that Unity don't offers a barycentric conversion routine. I just adapted the wikipedia formular
answered Feb 09 '11 at 02:15 AM