Game Development Community

Object mesh points and Torque collision

by Gustavo Boni · in Torque Game Engine · 03/09/2007 (12:42 pm) · 2 replies

Hey guys,

Im trying to integrate Newton Dynamics in Torque and i need to know how can i get mesh points of a dts. In addition, i would like to know how should i use newton collision instead torque collision.

Any help would be really appreciated.

Thanks

#1
03/09/2007 (2:03 pm)
This is the rough gist of it:

Resource<TSShape> shape;
   shape = ResourceManager->load(filename);
   if(shape.isNull())
      false;
	
   TSShapeInstance *shapeinst = new TSShapeInstance(shape, true);
      if(!shapeinst)
         return false;

   // Now grab the collision meshes
   for (U32 i = 0; i < shapeinst->getShape()->details.size(); i++)
   {
      const TSDetail * detail = &shapeinst->getShape()->details[i];

      char* name = (char*)shapeinst->getShape()->names[detail->nameIndex];

      if (dStrstr(dStrlwr(name), "collision-"))
      {
         shapeinst->animate(i);
         shapeinst->setCurrentDetail(i);
         shapeinst->setStatics(i);

         S32 ss = detail->subShapeNum;
         S32 od = detail->objectDetailNum;

         S32 start = shapeinst->getShape()->subShapeFirstObject[ss];
         S32 end   = shapeinst->getShape()->subShapeNumObjects[ss] + start;
         if (start < end)
         {
            // Run through objects and collide
            for (S32 j = start; j < end; j++)
            {
               TSShapeInstance::MeshObjectInstance * mesh = &shapeinst->mMeshObjects[j];

               if (od >= mesh->object->numMeshes)
                  continue;

               ConcretePolyList polys;

               // Get a valid transform for the polylist
               MatrixF* mat = mesh->getTransform();

               MatrixF m;
               if(mat)
                  m = *mat;
               else
                  m.identity();

               polys.setTransform(&m, Point3F(1.0f, 1.0f, 1.0f));

               // collide...
               U32 surfaceKey = 0;
               mesh->buildPolyList(od, &polys, surfaceKey);

               if (polys.mPolyList.size() == 0)
                  continue;

               // Note that TSMesh returns a list of triangles that you will need
               // to merge in order to create a convex. It also may repeat vertices.
               for (U32 k = 0; k < polys.mPolyList.size(); k++)
               {
                  ConcretePolyList::Poly& srcPoly = polys.mPolyList[k];

                  for (U32 m = 0; m < srcPoly.vertexCount; m++)
                  {
                     U32 srcIndex = polys.mIndexList[srcPoly.vertexStart + m];
                     Point3F& pt = polys.mVertexList[srcIndex];

                     Con::errorf("pt[%d](%g, %g, %g)", m, pt.x, pt.y, pt.z);
                  }
               }
            }
         }
      }
   }

   shapeinst->clearStatics();

   delete shapeinst;
#2
03/09/2007 (8:33 pm)
Thanks Matt, i'll give it a try.