Because this is a projection from 3D down to 2D, it's not invertible. So we can't recover *the* triangle \$\triangle PMN\$ that was used to create the original projection. But we can find a member of a *family* of triangles that fits that bill.

For simplicity, let's choose the member of that family that lies in the same plane as our mesh triangle \$\triangle ABC\$. That means our points \$PMN\$ are linear combinations of the points \$ABC\$.

We can start with point \$P\$, which sits at the point in the plane where \$u = v = 0\$.

Let's define...

$$u_1 = U_b - U_a \quad u_2 = U_c - U_a\\
v_1 = V_b - V_a \quad v_2 = V_c - V_a$$

Now we'll solve...

$$\begin{align}
\begin{bmatrix}u_1 & u_2\\v_1 & v_2\end{bmatrix}
\begin{bmatrix}s\\t\end{bmatrix}
&=\begin{bmatrix}-U_a\\-V_a\end{bmatrix}\\
\begin{bmatrix}u_1 & u_2\\v_1 & v_2\end{bmatrix}^{-1}
\begin{bmatrix}u_1 & u_2\\v_1 & v_2\end{bmatrix}
\begin{bmatrix}s\\t\end{bmatrix}
&=\begin{bmatrix}u_1 & u_2\\v_1 & v_2\end{bmatrix}^{-1}\begin{bmatrix}-U_a\\-V_a\end{bmatrix}\\
\begin{bmatrix}s\\t\end{bmatrix}
&=\frac 1 {u_1v_2 - u_2v_1}
\begin{bmatrix}v_2 & -u_2\\-v_1 & u_1\end{bmatrix}
\begin{bmatrix}-U_a\\-V_a\end{bmatrix}
\end{align}$$

Now we have

$$P = A + s(B-A) + t(C-A)$$

Next we want to find the point where \$(u, v) = (1, 0)\$, which will give us point \$M\$, and \$(u, v) = (0, 1)\$, which gives us point \$N\$, completing our texture space basis. We can proceed the same way...

$$\begin{bmatrix}s\\t\end{bmatrix}
=\frac 1 {u_1v_2 - u_2v_1}
\begin{bmatrix}v_2 & -u_2\\-v_1 & u_1\end{bmatrix}
\begin{bmatrix}1 -U_a\\-V_a\end{bmatrix}\\
M = A + s(B - A) + t (C-A)$$


$$\begin{bmatrix}s\\t\end{bmatrix}
=\frac 1 {u_1v_2 - u_2v_1}
\begin{bmatrix}v_2 & -u_2\\-v_1 & u_1\end{bmatrix}
\begin{bmatrix}-U_a\\1 - V_a\end{bmatrix}\\
N = A + s(B - A) + t (C-A)$$

In my tests with random triangles, using single-precision floats throughout, this correctly reproduces the UV mapping to within 0.001, which I'd attribute to rounding errors along the way. If you have more sensible triangles, and use double-precision intermediates, you could probably reduce the deviation even further.