Jump to content
Macha

Evaluating textures at hitpoints

Recommended Posts

I shoot rays from gdp to gdp2 and check if they intersect. If they do intersect then I would like to evaluate a texture map on gdp2.

 

I can get the hit positions, but how would I get the values of the texturemap at those points?

 

This is what I have to get the hit positions:

GA_FOR_ALL_PTOFF(gdp, ptoff)

{
// searchdir attribs
UT_Vector3 searchdir;
tupleN->get(hN.getAttribute(), ptoff, searchdir.data(), 3);

GU_RayIntersect *myCollision = new GU_RayIntersect;
myCollision->init(gdp2);
GU_RayInfo hitInfo(searchdir.normalize());
hitInfo.reset();


UT_Vector4 pos(gdp->getPos3(ptoff));
int hitNum = myCollision->sendRay(pos, searchdir, hitInfo);


if(hitNum)
{
const GEO_Primitive *hitPrim = hitInfo.myPrim;
fpreal32 hitU = hitInfo.myU;
fpreal32 hitV = hitInfo.myV;
//get pos of hit
UT_Vector4 hitPos;
hitPrim->evaluateInteriorPoint(hitPos, hitU, hitV);
}


delete myCollision;
}//GA_FOR_ALL_PTOFF
Edited by Macha

Share this post


Link to post
Share on other sites

Hi,

 
i had a similar problem and i've written my own function evaluateUVPoint(...). I would be very interested too if someone knows an already existing HDK function to get the texture point.
Anyway, this is my method which returns the texture UV coordinate of a hit position on a triangle.
UT_Vector3D evaluateUVPoint(GA_Offset primOff, float u, float v, float w = 0)
{
    UT_Vector3D uv = 0;
    GA_Primitive* prim = myGdp->getPrimitiveList().get(primOff);
    if (prim)
    {
        UT_Vector3D pt0, pt1, pt2;
        GA_ROHandleV3 primUV;
        primUV = myGdp->findPointAttribute(GEO_STD_ATTRIB_TEXTURE); // or findVertexAttribute(...)
        if (primUV.isValid())
        {
            pt0 = primUV.get(prim->getPointOffset(0)); // or getVertexOffset(...)
            pt1 = primUV.get(prim->getPointOffset(1));
            pt2 = primUV.get(prim->getPointOffset(2));
		
            uv  = (pt1 - pt0) * u;
            uv += (pt2 - pt0) * v;
            uv += pt0;
        }
    }
    return uv;
}

This works only for triangles. If someone knows a solution for quads i would be very gratefull.

 

Share this post


Link to post
Share on other sites

Thanks Claus, that works quite well. I've only come back to this now.

 

I'm thinking of using the uvs I get from the hitpoints to read pixels from an image.I don't see anything obvious in the HDK about images and uvs.

 

Is anybody aware of a sample code somewhere?

Share this post


Link to post
Share on other sites

I'm thinking of using the uvs I get from the hitpoints to read pixels from an image.I don't see anything obvious in the HDK about images and uvs.

 

Is anybody aware of a sample code somewhere?

 

Hi Macha, take a look at TIL_TextureMap.h for this.

 

cheers,

skk.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×