About Store Forum Documentation Contact



Post Reply 
Mesh face index = mesh part index?
Author Message
cat555 Offline
Member

Post: #1
Mesh face index = mesh part index?
Hi,

The face index accessible throught PhysHit, is the same index of mesh parts?

In this case, i can use this to get mesh part?

Code:
MeshPart part = mesh->parts[face_index];

If not, how to get mesh part having just having face index information?

Thanks!
09-12-2014 05:44 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #2
RE: Mesh face index = mesh part index?
Hi again,

By making some more research in some key header files, i see that face are the quads and tris... Ok.

So, what i need is to get the MeshPart that is related to a face with index X. Is this possible? I've researched MeshPart, Mesh*, etc... and could not find a way to do it...

I see that Sweep method allows to get the hit_part, which is great for what i need, but unfortunately i saw some post where @Esenthel does not recommend it's use, due to poor performance.

So, if not actually possible to get MeshPart given a face index, i propose to @Esenthel adding (if viable, of course):
(1) add hit_part to PhysHit struct
AND/OR
(2) add a method to Mesh, where we can get MeshPart or part index, given a face index

Thanks!
09-13-2014 02:28 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Mesh face index = mesh part index?
Hi,

You'll need to:
create one MeshBase from your Mesh, (I recommend MeshBase.createPhys)
then create PhysBody/PhysPart from the MeshBase, and you will have direct mapping.
don't forget to set the function param for PhysPart creation that preserves face indexes.
09-13-2014 03:39 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #4
RE: Mesh face index = mesh part index?
Hi,

Ok, didn't knew that, but now i've done it like that so i can have a perfect match, which is very important on this - OK, thanks for the tip!

But now i can't figure it out, how to get the MeshPart, from which belongs a face with face index X. I've searched on MeshPart and could not find a way... is there already any method that will allow me to do this?

Thanks!
09-13-2014 05:42 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Mesh face index = mesh part index?
Hi,

Code:
MeshBase& create    (C MeshLod    &src ,           UInt flag_and=~0, Bool set_id_from_part_index=false); // create from 'src'      , 'flag_and'=MESH_BASE_FLAG
You can use this method with 'set_id_from_part_index'=set to true.
Then meshbase.tri.id and meshbase.quad.id point to the meshpart.
For next release I'll add set_id_from_part_index param to 'createPhys' method as well.
09-14-2014 04:26 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #6
RE: Mesh face index = mesh part index?
Hi,

So, creating MeshBase with set_id_from_part_index=true, will make the face_id index (Quad/Tri) = part_id index (MeshPart)?

Any way, meshbase.tri.id and meshbase.quad.id both return VecI2... how they point to MeshPart?

Quote:For next release I'll add set_id_from_part_index param to 'createPhys' method as well.

Nice, thanks!
(This post was last modified: 09-14-2014 06:15 PM by cat555.)
09-14-2014 06:14 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Mesh face index = mesh part index?
Hi,
both X and Y of the VecI2 should be the same values (mesh part index).
09-14-2014 11:25 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #8
RE: Mesh face index = mesh part index?
Hi,

I've made my last tests and it's working great smile

Much appreciated for your great help!
09-15-2014 10:50 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #9
RE: Mesh face index = mesh part index?
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!
(This post was last modified: 01-20-2015 04:03 AM by cat555.)
01-20-2015 02:26 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #10
RE: Mesh face index = mesh part index?
Hi, any help please?

Thanks!
01-22-2015 01:16 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
RE: Mesh face index = mesh part index?
Hello,

The face index gives you face index in a single MeshPart, it is not a mesh part index.
01-24-2015 10:41 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #12
RE: Mesh face index = mesh part index?
(01-24-2015 10:41 PM)Esenthel Wrote:  Hello,

The face index gives you face index in a single MeshPart, it is not a mesh part index.

Hi @Esenthel, thanks for your reply!

But, i'm using hit.face as tri index, to get the mesh part index:

Code:
int some_var = ((GroundObj*)hit.obj).base.tri.id(hit.face); // get mesh part index
...
Log(S + "Material part? = " + ((GroundObj*)hit.obj).mesh->parts[some_var].material().id().asCString() + "\n"); // log material uid, using meshpart index calculated above

I think this is what you are saying in this thread, some time ago - 09-14-2014 03:26 AM

Quote:Hi,
Quote:Code:
MeshBase& create (C MeshLod &src , UInt flag_and=~0, Bool set_id_from_part_index=false); // create from 'src' , 'flag_and'=MESH_BASE_FLAG
You can use this method with 'set_id_from_part_index'=set to true.
Then meshbase.tri.id and meshbase.quad.id point to the meshpart.
For next release I'll add set_id_from_part_index param to 'createPhys' method as well.

I may be confusing some of the concepts, but i can't figure out where i'm failing here... it seems that i'm following your indications above in this thread... :\

Thanks!
(This post was last modified: 01-24-2015 11:21 PM by cat555.)
01-24-2015 11:08 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #13
[SOLVED] RE: Mesh face index = mesh part index?
Ok, solved the issue... problem was related only with the creation of the object. Now i have:

Code:
class GroundObj : Game.Static
{
   MeshBase base;
      
   void create(Game.ObjParams &obj)
   {
super.create(obj);
      
base.createPhys(*T.mesh,  NULL, true);
PhysPart part;
part.createMesh(base, true);

actor.create(part);
actor.matrix(T.matrixScaled());
actor.group(AG_GROUND);
}

[...]

}

Need to do some more tests, but for now it's giving me consistent results smile

Thanks for the help @Esenthel!

Regards,
(This post was last modified: 01-25-2015 08:29 PM by cat555.)
01-25-2015 08:29 PM
Find all posts by this user Quote this message in a reply
Post Reply