| 473 | /////////////////////////////////////////////////////////////////////////////// |
| 474 | |
| 475 | NpShape* NpFactory::createShape(const PxGeometry& geometry, |
| 476 | PxShapeFlags shapeFlags, |
| 477 | PxMaterial*const* materials, |
| 478 | PxU16 materialCount, |
| 479 | bool isExclusive) |
| 480 | { |
| 481 | switch(geometry.getType()) |
| 482 | { |
| 483 | case PxGeometryType::eBOX: |
| 484 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxBoxGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 485 | break; |
| 486 | case PxGeometryType::eSPHERE: |
| 487 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxSphereGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 488 | break; |
| 489 | case PxGeometryType::eCAPSULE: |
| 490 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxCapsuleGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 491 | break; |
| 492 | case PxGeometryType::eCONVEXMESH: |
| 493 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxConvexMeshGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 494 | break; |
| 495 | case PxGeometryType::ePLANE: |
| 496 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxPlaneGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 497 | break; |
| 498 | case PxGeometryType::eHEIGHTFIELD: |
| 499 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxHeightFieldGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 500 | break; |
| 501 | case PxGeometryType::eTRIANGLEMESH: |
| 502 | PX_CHECK_AND_RETURN_NULL(static_cast<const PxTriangleMeshGeometry&>(geometry).isValid(), "Supplied PxGeometry is not valid. Shape creation method returns NULL."); |
| 503 | break; |
| 504 | case PxGeometryType::eGEOMETRY_COUNT: |
| 505 | case PxGeometryType::eINVALID: |
| 506 | PX_ASSERT(0); |
| 507 | } |
| 508 | |
| 509 | // |
| 510 | // Check for invalid material table setups |
| 511 | // |
| 512 | |
| 513 | #if PX_CHECKED |
| 514 | if (!NpShape::checkMaterialSetup(geometry, "Shape creation", materials, materialCount)) |
| 515 | return NULL; |
| 516 | #endif |
| 517 | |
| 518 | Ps::InlineArray<PxU16, 4> materialIndices("NpFactory::TmpMaterialIndexBuffer"); |
| 519 | materialIndices.resize(materialCount); |
| 520 | if(materialCount == 1) |
| 521 | materialIndices[0] = static_cast<NpMaterial*>(materials[0])->getHandle(); |
| 522 | else |
| 523 | NpMaterial::getMaterialIndices(materials, materialIndices.begin(), materialCount); |
| 524 | |
| 525 | NpShape* npShape; |
| 526 | { |
| 527 | Ps::Mutex::ScopedLock lock(mShapePoolLock); |
| 528 | PxU16* mi = materialIndices.begin(); // required to placate pool constructor arg passing |
| 529 | npShape = mShapePool.construct(geometry, shapeFlags, mi, materialCount, isExclusive); |
| 530 | } |
| 531 | |
| 532 | if(!npShape) |
no test coverage detected