Get UV of point in triangle with UVW and bary



  • On 27/06/2013 at 16:57, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R13+ 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    This is driving me crazy.  Google isn't getting me results based on my inputs.

    A ray hits a triangle in a mesh.  My code gets the UVW coordinates for each point of the triangle in question from the UVWTag and UVWStruct (using the GeRayColResult.face_id).  I have the Barycentric coordinates of the hit point relative to the triangle from GeRayCollider/GeRayColResult.  How do I go about interpolating to the UVW coordinate in UVW space (not triangle space, i.e.: not barycentric) of the hit point given the triangle's three UVW coordinates and the hit point's Barycentric coordinate?

    To add, I have these two options (the only two so far) :

    // GetUVFromBarycentric  
    // - Given the Texture vertices of a triangle (UVW space) and the Barycentric coordinate of a point (P) within, return P's Texture coordinate  
    //*---------------------------------------------------------------------------*  
    Vector GetUVFromBarycentric(const Vector& vAUV, const Vector& vBUV, const Vector& vCUV, const Vector& vPBary)  
    //*---------------------------------------------------------------------------*  
    {  
      return    vAUV*vPBary.x + vBUV*vPBary.y + vCUV*vPBary.z;  
      //return    Vector(b0 * vA.x + vP.x * vB.x + vP.y * vC.x, b0 * vA.y + vP.x * vB.y + vP.y * vC.y, 0.0);  
    }
    

    I have not tried either yet but will soon.



  • On 27/06/2013 at 18:14, xxxxxxxx wrote:

    The current UV calculation appears to be working.  Nice.


Log in to reply