PxShape* AttachShape_AssumesLocked(const PxGeometry& PGeom, const PxTransform& PLocalPose, const float ContactOffset, PxShapeFlags PShapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE) const { const PxMaterial* PMaterial = GetDefaultPhysMaterial(); PxShape* PNewShape = bShapeSharing ? GPhysXSDK->createShape(PGeom, *PMaterial, /*isExclusive =*/ false, PShapeFlags) : PDestActor->createShape(PGeom, *PMaterial, PShapeFlags); if (PNewShape) { PNewShape->setLocalPose(PLocalPose); if (NewShapes) { NewShapes->Add(PNewShape); } PNewShape->setContactOffset(ContactOffset); const bool bSyncFlags = bShapeSharing || SceneType == PST_Sync; const FShapeFilterData& Filters = ShapeData.FilterData; const bool bComplexShape = PNewShape->getGeometryType() == PxGeometryType::eTRIANGLEMESH; PNewShape->setQueryFilterData(bComplexShape ? Filters.QueryComplexFilter : Filters.QuerySimpleFilter); PNewShape->setFlags( (bSyncFlags ? ShapeData.SyncShapeFlags : ShapeData.AsyncShapeFlags) | (bComplexShape ? ShapeData.ComplexShapeFlags : ShapeData.SimpleShapeFlags)); PNewShape->setSimulationFilterData(Filters.SimFilter); FBodyInstance::ApplyMaterialToShape_AssumesLocked(PNewShape, SimpleMaterial, ComplexMaterials, bShapeSharing); if(bShapeSharing) { PDestActor->attachShape(*PNewShape); PNewShape->release(); } } return PNewShape; }
void SampleParticles::createDrain() { float lakeHeight = 5.5f; //Creates a drain plane for the particles. This is good practice to avoid unnecessary //spreading of particles, which is bad for performance. The drain represents a lake in this case. { PxRigidStatic* actor = getPhysics().createRigidStatic(PxTransform(PxVec3(0.0f, lakeHeight - 1.0f, 0.0f), PxQuat(PxHalfPi, PxVec3(0,0,1)))); runtimeAssert(actor, "PxPhysics::createRigidStatic returned NULL\n"); PxShape* shape = actor->createShape(PxPlaneGeometry(), getDefaultMaterial()); runtimeAssert(shape, "PxRigidStatic::createShape returned NULL\n"); shape->setSimulationFilterData(collisionGroupDrain); shape->setFlags(PxShapeFlag::ePARTICLE_DRAIN | PxShapeFlag::eSIMULATION_SHAPE); getActiveScene().addActor(*actor); mPhysicsActors.push_back(actor); } //Creates the surface of the lake (the particles actually just collide with the underlaying drain). { PxBoxGeometry bg; bg.halfExtents = PxVec3(130.0f, lakeHeight + 1.0f, 130.0f); PxRigidStatic* actor = getPhysics().createRigidStatic(PxTransform(PxVec3(0.0f, 0.0f, 0.0f), PxQuat::createIdentity())); runtimeAssert(actor, "PxPhysics::createRigidStatic returned NULL\n"); PxShape* shape = actor->createShape(bg, getDefaultMaterial()); runtimeAssert(shape, "PxRigidStatic::createShape returned NULL\n"); shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shape->setFlag(PxShapeFlag::eSCENE_QUERY_SHAPE, false); getActiveScene().addActor(*actor); mPhysicsActors.push_back(actor); createRenderObjectsFromActor(actor, getMaterial(MATERIAL_LAKE)); } }
FDUint BuildingSystem::newPoint(Vector3 point, PhysicsSystem& physics) { FDUint i = pointAuthor->newPoint(point); pointMesh->setSourceVertexData(pointAuthor->getVertexData()); PxMaterial* m = physics.genericMaterial; // Point actor is constructed on the fly because PhysX issues a warning // if you try to add a physical object to the scene with no initial // geometry. FDbool actorExistsAlready = pointActor != NULL; if (!actorExistsAlready) { pointActor = physics.physics->createRigidStatic( Transform(PxVec3(0, 0, 0))); } PxShape* shape = pointActor->createShape(PxSphereGeometry(0.2f), *m); shape->setFlags(PxShapeFlag::eSCENE_QUERY_SHAPE); shape->setLocalPose(Transform(Vector3(point))); shape->userData = (void*)i; if (!actorExistsAlready) { physics.scene->addActor(*pointActor); } return i; }
bool copyStaticProperties(PxRigidActor& to, const PxRigidActor& from,NxMirrorScene::MirrorFilter &mirrorFilter) { physx::shdfnd::InlineArray<PxShape*, 64> shapes; shapes.resize(from.getNbShapes()); PxU32 shapeCount = from.getNbShapes(); from.getShapes(shapes.begin(), shapeCount); physx::shdfnd::InlineArray<PxMaterial*, 64> materials; for(PxU32 i = 0; i < shapeCount; i++) { PxShape* s = shapes[i]; if ( mirrorFilter.shouldMirror(*s) ) { PxU32 materialCount = s->getNbMaterials(); materials.resize(materialCount); s->getMaterials(materials.begin(), materialCount); PxShape* shape = to.createShape(s->getGeometry().any(), materials.begin(), static_cast<physx::PxU16>(materialCount)); shape->setLocalPose( s->getLocalPose()); shape->setContactOffset(s->getContactOffset()); shape->setRestOffset(s->getRestOffset()); shape->setFlags(s->getFlags()); shape->setSimulationFilterData(s->getSimulationFilterData()); shape->setQueryFilterData(s->getQueryFilterData()); mirrorFilter.reviseMirrorShape(*shape); } } to.setActorFlags(from.getActorFlags()); to.setOwnerClient(from.getOwnerClient()); to.setDominanceGroup(from.getDominanceGroup()); if ( to.getNbShapes() ) { mirrorFilter.reviseMirrorActor(to); } return to.getNbShapes() != 0; }