void PhysXMeshCollider::setGeometry(const PxGeometry& geometry) { PxShape* shape = getInternal()->_getShape(); if (shape->getGeometryType() != geometry.getType()) { PxShape* newShape = gPhysX().getPhysX()->createShape(geometry, *gPhysX().getDefaultMaterial(), true); getInternal()->_setShape(newShape); } else getInternal()->_getShape()->setGeometry(geometry); }
void PhysXD6Joint::setLimitLinear(const LimitLinear& limit) { PxJointLinearLimit pxLimit(gPhysX().getScale(), limit.extent, limit.contactDist); pxLimit.stiffness = limit.spring.stiffness; pxLimit.damping = limit.spring.damping; pxLimit.restitution = limit.restitution; getInternal()->setLinearLimit(pxLimit); }
PhysXMeshCollider::PhysXMeshCollider(PxPhysics* physx, const Vector3& position, const Quaternion& rotation) { PxSphereGeometry geometry(0.01f); // Dummy PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true); shape->setLocalPose(toPxTransform(position, rotation)); shape->userData = this; mInternal = bs_new<FPhysXCollider>(shape); }
PhysXCharacterController::PhysXCharacterController(PxControllerManager* manager, const CHAR_CONTROLLER_DESC& desc) :CharacterController(desc) { PxCapsuleControllerDesc pxDesc = toPxDesc(desc); pxDesc.reportCallback = this; pxDesc.material = gPhysX().getDefaultMaterial(); mController = static_cast<PxCapsuleController*>(manager->createController(pxDesc)); mController->setUserData(this); }
PhysXSphereCollider::PhysXSphereCollider(PxPhysics* physx, const Vector3& position, const Quaternion& rotation, float radius) :mRadius(radius) { PxSphereGeometry geometry(radius); PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true); shape->setLocalPose(toPxTransform(position, rotation)); shape->userData = this; mInternal = bs_new<FPhysXCollider>(shape); applyGeometry(); }
void FPhysXMesh::initialize() { if (mCookedData != nullptr && mCookedDataSize > 0) { PxPhysics* physx = gPhysX().getPhysX(); PxDefaultMemoryInputData input(mCookedData, mCookedDataSize); if (mType == PhysicsMeshType::Convex) mConvexMesh = physx->createConvexMesh(input); else mTriangleMesh = physx->createTriangleMesh(input); } }
PhysXBoxCollider::PhysXBoxCollider(PxPhysics* physx, const Vector3& position, const Quaternion& rotation, const Vector3& extents) :mExtents(extents) { PxBoxGeometry geometry(extents.x, extents.y, extents.z); PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true); shape->setLocalPose(toPxTransform(position, rotation)); shape->userData = this; mInternal = bs_new<FPhysXCollider>(shape); applyGeometry(); }
/** * Attempts to cook a triangle or convex mesh from the provided mesh data. Will log a warning and return false if it is * unable to cook the mesh. If the method returns true the resulting convex mesh will be output in the @p data buffer, * and its size in @p size. The data buffer will be allocated used the generic allocator and is up to the caller to * free it. */ bool cookMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type, UINT8** data, UINT32& size) { if (meshData == nullptr) return false; PxCooking* cooking = gPhysX().getCooking(); if (cooking == nullptr) { LOGWRN("Attempting to cook a physics mesh but cooking is not enabled globally."); return false; } SPtr<VertexDataDesc> vertexDesc = meshData->getVertexDesc(); if (!vertexDesc->hasElement(VES_POSITION)) { LOGWRN("Provided PhysicsMesh mesh data has no vertex positions."); return false; } if (type == PhysicsMeshType::Convex) { if(!cookConvex(cooking, meshData, data, size)) { LOGWRN("Failed cooking a convex mesh. Perpahs it is too complex? Maximum number of convex vertices is 256."); return false; } } else { PxTriangleMeshDesc meshDesc; meshDesc.points.count = meshData->getNumVertices(); meshDesc.points.stride = vertexDesc->getVertexStride(); meshDesc.points.data = meshData->getElementData(VES_POSITION); meshDesc.triangles.count = meshData->getNumIndices() / 3; meshDesc.flags |= PxMeshFlag::eFLIPNORMALS; IndexType indexType = meshData->getIndexType(); if (indexType == IT_32BIT) { meshDesc.triangles.stride = 3 * sizeof(PxU32); meshDesc.triangles.data = meshData->getIndices32(); } else { meshDesc.triangles.stride = 3 * sizeof(PxU16); meshDesc.triangles.data = meshData->getIndices16(); meshDesc.flags |= PxMeshFlag::e16_BIT_INDICES; } PxDefaultMemoryOutputStream output; if (!cooking->cookTriangleMesh(meshDesc, output)) return false; size = output.getSize(); *data = (UINT8*)bs_alloc(size); memcpy(*data, output.getData(), size); } return true; }