| 397 | } |
| 398 | |
| 399 | void PhysXSample::newMesh(const RAWMesh& data) |
| 400 | { |
| 401 | // PT: the mesh name should capture the scale value as well, to make sure different scales give birth to different cooked files |
| 402 | const PxU32 scaleTag = PX_IR(mScale); |
| 403 | |
| 404 | PX_ASSERT(mFilename); |
| 405 | char extension[256]; |
| 406 | sprintf(extension, "_%d_%x.cooked", mMeshTag, scaleTag); |
| 407 | |
| 408 | const char* filePathCooked = getSampleOutputFilePath(mFilename, extension); |
| 409 | PX_ASSERT(NULL != filePathCooked); |
| 410 | |
| 411 | bool ok = false; |
| 412 | if(!gRecook) |
| 413 | { |
| 414 | SampleFramework::File* fp = NULL; |
| 415 | PxToolkit::fopen_s(&fp, filePathCooked, "rb"); |
| 416 | if(fp) |
| 417 | { |
| 418 | fclose(fp); |
| 419 | ok = true; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | if(!ok) |
| 424 | { |
| 425 | PxTriangleMeshDesc meshDesc; |
| 426 | meshDesc.points.count = data.mNbVerts; |
| 427 | meshDesc.triangles.count = data.mNbFaces; |
| 428 | meshDesc.points.stride = 4*3; |
| 429 | meshDesc.triangles.stride = 4*3; |
| 430 | meshDesc.points.data = data.mVerts; |
| 431 | meshDesc.triangles.data = data.mIndices; |
| 432 | |
| 433 | // |
| 434 | shdfnd::printFormatted("Cooking object... %s",filePathCooked); |
| 435 | PxDefaultFileOutputStream stream(filePathCooked); |
| 436 | ok = mCooking->cookTriangleMesh(meshDesc, stream); |
| 437 | shdfnd::printFormatted(" - Done\n"); |
| 438 | } |
| 439 | |
| 440 | if(ok) |
| 441 | { |
| 442 | PxDefaultFileInputData stream(filePathCooked); |
| 443 | PxTriangleMesh* triangleMesh = mPhysics->createTriangleMesh(stream); |
| 444 | if(triangleMesh) |
| 445 | { |
| 446 | PxTriangleMeshGeometry triGeom; |
| 447 | triGeom.triangleMesh = triangleMesh; |
| 448 | PxRigidStatic* actor = mPhysics->createRigidStatic(data.mTransform); |
| 449 | PxShape* shape = PxRigidActorExt::createExclusiveShape(*actor, triGeom, *mMaterial); |
| 450 | PX_UNUSED(shape); |
| 451 | mScene->addActor(*actor); |
| 452 | addPhysicsActors(actor); |
| 453 | |
| 454 | if(0) |
| 455 | { |
| 456 | // Create render mesh from PhysX mesh |
no test coverage detected