Macha Posted June 20, 2014 Share Posted June 20, 2014 (edited) 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 June 20, 2014 by Macha Quote Link to comment Share on other sites More sharing options...
ClausKleber Posted June 24, 2014 Share Posted June 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
Macha Posted July 8, 2014 Author Share Posted July 8, 2014 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? Quote Link to comment Share on other sites More sharing options...
symek Posted July 8, 2014 Share Posted July 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.