It mostly comes down to a pointintriangle() function. Something like this...
Function TFormTextureCoords(u#,v#,mesh) For s=1 To CountSurfaces(mesh) surf=GetSurface(mesh,1) For t=0 To CountTriangles(surf)-1 a=TriangleVertex(surf,t,0) b=TriangleVertex(surf,t,1) c=TriangleVertex(surf,t,2) au#=VertexU(surf,a) av#=VertexV(surf,a) bu#=VertexU(surf,b) bv#=VertexV(surf,b) cu#=VertexU(surf,c) cv#=VertexV(surf,c) If PointInTriangle(u,v,au,av,bu,bv,cu,cv) TFormPoint x#,y#,z#,0,0 Return True EndIf Next Next Return False End Function Function PointInTriangle(x#,y#,Ax#,Ay#,Bx#,By#,Cx#,Cy#) End Function