| 1792 | |
| 1793 | |
| 1794 | RenderBaseActor* PhysXSample::createRenderObjectFromShape(PxRigidActor* actor, PxShape* shape, RenderMaterial* material) |
| 1795 | { |
| 1796 | PX_ASSERT(getRenderer()); |
| 1797 | |
| 1798 | RenderBaseActor* shapeRenderActor = NULL; |
| 1799 | Renderer& renderer = *getRenderer(); |
| 1800 | |
| 1801 | PxGeometryHolder geom = shape->getGeometry(); |
| 1802 | |
| 1803 | switch(geom.getType()) |
| 1804 | { |
| 1805 | case PxGeometryType::eSPHERE: |
| 1806 | shapeRenderActor = SAMPLE_NEW(RenderSphereActor)(renderer, geom.sphere().radius); |
| 1807 | break; |
| 1808 | case PxGeometryType::ePLANE: |
| 1809 | shapeRenderActor = SAMPLE_NEW(RenderGridActor)(renderer, 50, 1.f, PxShapeExt::getGlobalPose(*shape, *actor).q); |
| 1810 | break; |
| 1811 | case PxGeometryType::eCAPSULE: |
| 1812 | shapeRenderActor = SAMPLE_NEW(RenderCapsuleActor)(renderer, geom.capsule().radius, geom.capsule().halfHeight); |
| 1813 | break; |
| 1814 | case PxGeometryType::eBOX: |
| 1815 | shapeRenderActor = SAMPLE_NEW(RenderBoxActor)(renderer, geom.box().halfExtents); |
| 1816 | break; |
| 1817 | case PxGeometryType::eCONVEXMESH: |
| 1818 | { |
| 1819 | PxConvexMesh* convexMesh = geom.convexMesh().convexMesh; |
| 1820 | |
| 1821 | // ### doesn't support scale |
| 1822 | PxU32 nbVerts = convexMesh->getNbVertices(); |
| 1823 | PX_UNUSED(nbVerts); |
| 1824 | const PxVec3* convexVerts = convexMesh->getVertices(); |
| 1825 | const PxU8* indexBuffer = convexMesh->getIndexBuffer(); |
| 1826 | PxU32 nbPolygons = convexMesh->getNbPolygons(); |
| 1827 | |
| 1828 | PxU32 totalNbTris = 0; |
| 1829 | PxU32 totalNbVerts = 0; |
| 1830 | for(PxU32 i=0;i<nbPolygons;i++) |
| 1831 | { |
| 1832 | PxHullPolygon data; |
| 1833 | bool status = convexMesh->getPolygonData(i, data); |
| 1834 | PX_ASSERT(status); |
| 1835 | PX_UNUSED(status); |
| 1836 | totalNbVerts += data.mNbVerts; |
| 1837 | totalNbTris += data.mNbVerts - 2; |
| 1838 | } |
| 1839 | |
| 1840 | PxVec3Alloc* allocVerts = SAMPLE_NEW(PxVec3Alloc)[totalNbVerts]; |
| 1841 | PxVec3Alloc* allocNormals = SAMPLE_NEW(PxVec3Alloc)[totalNbVerts]; |
| 1842 | PxReal* UVs = (PxReal*)SAMPLE_ALLOC(sizeof(PxReal)*(totalNbVerts * 2)); |
| 1843 | PxU16* faces = (PxU16*)SAMPLE_ALLOC(sizeof(PxU16)*totalNbTris*3); |
| 1844 | |
| 1845 | PxU16* triangles = faces; |
| 1846 | PxVec3* vertices = allocVerts, |
| 1847 | * normals = allocNormals; |
| 1848 | |
| 1849 | PxU32 offset = 0; |
| 1850 | for(PxU32 i=0;i<nbPolygons;i++) |
| 1851 | { |
nothing calls this directly
no test coverage detected