Hi,
I've made a lot of changes in my code and my meshes since last post, and now i'm facing a problem... can't get the correct mesh part, so i can check for material that is being raycasted. So, i'm raycasting ground object, that's being created like this, with keep_face_index = true:
Code:
class GroundObj : Game.Static
{
MeshBase base;
void create(Game.ObjParams &obj)
{
super.create(obj);
base.create(*T.mesh, ~0 , true);
mesh->setBase();
FREPD(i, mesh->parts.elms())
{
PhysPart part;
part.createMesh(mesh->parts[i].base, true);
phys->parts.add(part);
part.del();
}
actor.create(*phys);
actor.matrix(T.matrixScaled());
actor.group(AG_GROUND);
}
UInt drawPrepare()
{
if(mesh)if(Frustum(mesh->box, _matrix_scaled))
{
mesh->draw(_matrix_scaled);
}
return 0;
}
}
/******************************************************************************/
===========
Now, i do raycasts like this to try to get the mesh part that it's being hit, so i can check what material is being hit:
Code:
Vec start = body->skeleton()->getPoint(8"down1").pos*scaledMatrix();
Vec end = body->skeleton()->getPoint(8"down2").pos*scaledMatrix();
PhysHit hit;
if(Physics.ray(start, end-start, &hit))
{
if(hit.group == AG_GROUND)
{
Log(S + Time.appTime() + "\n");
Log(S + "Hit face = " + hit.face + "\n");
int triangle_id = ((GroundObj*)hit.obj).base.tri.id(hit.face); // get mesh part index
Log(S + "Triangle id? = " + triangle_id + "\n");
Log(S + "Material User Type? = " + ((GroundObj*)hit.obj).mesh->parts[triangle_id].material()->user_type + "\n");
Log(S + "Material part? = " + ((GroundObj*)hit.obj).mesh->parts[triangle_id].material().id().asCString() + "\n"); // log material uid
}
}
Problem is that, the mesh part being hit is really part of the object that is being hit, but it's not the correct mesh part.
Can it be some problem in the ground object creation?
Thanks!