const char * NxuPhysicsExport::Write(NxClothMesh *clothMesh,const char *id)
{
	const char *ret = 0;

	if ( clothMesh )
	{

		for (NxU32 i=0; i<mCollection->mClothMeshes.size(); i++)
		{
			NxClothMeshDesc *c = mCollection->mClothMeshes[i];
			if ( c->mInstance == clothMesh )
			{
				ret = c->mId;
				break;
			}
		}

		if ( !ret )
		{

			::NxClothMeshDesc desc;
 			clothMesh->saveToDesc(desc);
			NxU32	numMesh	=	mCollection->mClothMeshes.size();
    	NxClothMeshDesc *cMesh	=	new NxClothMeshDesc;

      if ( id )
      {
      	cMesh->mId = id;
      }
      else
      {
  			char tempString[512];
  			sprintf(tempString,	"ClothMesh_%d", numMesh);
      	cMesh->mId = getGlobalString(tempString);
      }

    	CustomCopy cc(mCollection,0);

      cMesh->copyFrom(desc,cc);

			cMesh->mInstance = clothMesh;

			mCollection->mClothMeshes.pushBack(cMesh);

			ret = cMesh->mId;
		}

	}
	return ret;
}
Exemple #2
0
bool PhysXCloth::cookMesh(NxClothMeshDesc &desc)
{
    assert(desc.isValid());

    MemoryWriteBuffer wb;
    if (!NxCookClothMesh(desc, wb))
        return false;
    MemoryReadBuffer rb(wb.data);
    mClothMesh = mScene->getPhysicsSDK().createClothMesh(rb);

    return true;
}
Exemple #3
0
// -----------------------------------------------------------------------
bool MyCloth::cookMesh(NxClothMeshDesc& desc)
{
	// Store correct number to detect tearing mesh in time
	mLastNumVertices = desc.numVertices;

	// we cook the mesh on the fly through a memory stream
	MemoryWriteBuffer wb;
	assert(desc.isValid());
	bool success = CookClothMesh(desc, wb);

	if (!success) 
		return false;

	MemoryReadBuffer rb(wb.data);
	mClothMesh = mScene->getPhysicsSDK().createClothMesh(rb);
	return true;
}
Exemple #4
0
bool PhysXCloth::saveMeshDesc(NxClothMeshDesc &desc, ObjMeshExt* objMesh)
{
    int vertexCount = objMesh->getNumVertices();
    if (vertexCount == 0)
        return false;

    NxVec3* verts = (NxVec3*)malloc(sizeof(NxVec3) * vertexCount);
    NxU32*  faces = (NxU32*) malloc(sizeof(NxU32)  * mNumTriangles * 3);

    for (int i = 0; i < vertexCount; i++)
    {
        NxVec3 vertex = objMesh->getVertex(i);
        verts[i].x = vertex.x;
        verts[i].y = vertex.y;
        verts[i].z = vertex.z;
    }
    for (int i = 0; i < mNumTriangles; i++)
    {
        ObjMeshTriangle tri = objMesh->getTriangle(i);
        faces[i * 3]     = tri.vertexNr[0];
        faces[i * 3 + 1] = tri.vertexNr[1];
        faces[i * 3 + 2] = tri.vertexNr[2];
    }

    desc.setToDefault();
    desc.numVertices           = vertexCount;
    desc.numTriangles          = mNumTriangles;
    desc.pointStrideBytes      = sizeof(NxVec3);
    desc.triangleStrideBytes   = 3 * sizeof(NxU32);
    desc.points                = verts;
    desc.triangles             = faces;
    desc.flags                 = 0;
    desc.flags                |= NX_CLOTH_MESH_WELD_VERTICES;
    desc.weldingDistance       = 0.5f;

    return true;
}