Skip to content

Commit

Permalink
Physics
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuradov committed Jul 29, 2024
1 parent 0a75046 commit 5078a71
Show file tree
Hide file tree
Showing 4,596 changed files with 63 additions and 1,121,254 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions modules/core/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ namespace era_engine
.addComponent<physics::px_sphere_collider_component>(1.0f)
.addComponent<physics::px_dynamic_body_component>();
px_sphere_entt.getComponent<physics::px_dynamic_body_component>().setMass(1000.f);
//px_sphere_entt.getComponent<physics::px_dynamic_body_component>().setFilterMask(1, 2);
sphere = px_sphere_entt.handle;

auto px_sphere1 = &scene.createEntity("SpherePX1", (entity_handle)59)
Expand All @@ -310,7 +311,9 @@ namespace era_engine
.addComponent<physics::px_sphere_collider_component>(5.0f)
.addComponent<physics::px_dynamic_body_component>();
px_sphere1->getComponent<physics::px_dynamic_body_component>().setMass(500.0f);
//px_sphere1->getComponent<physics::px_dynamic_body_component>().setFilterMask(2, 1 | 3);

//px_sphere1->getComponent<physics::px_dynamic_body_component>().setFilterMask(3, 1);
//if (auto mesh = loadAnimatedMeshFromFileAsync(getAssetPath("/resources/assets/veribot/source/VERIBOT_final.fbx")))
//{
// auto& en = scene.createEntity("Veribot", (entity_handle)15)
Expand Down
23 changes: 13 additions & 10 deletions modules/core/src/px/core/px_physics_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ namespace era_engine
return physx::PxFilterFlag::eDEFAULT;
}

pairFlags = physx::PxPairFlag::eCONTACT_DEFAULT;
pairFlags |= physx::PxPairFlag::eDETECT_CCD_CONTACT;
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_FOUND;
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_LOST;
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_PERSISTS;
pairFlags |= physx::PxPairFlag::ePOST_SOLVER_VELOCITY;
pairFlags |= physx::PxPairFlag::eNOTIFY_CONTACT_POINTS;
pairFlags |= physx::PxPairFlag::eSOLVE_CONTACT;
pairFlags |= physx::PxPairFlag::eDETECT_DISCRETE_CONTACT;

if ((filterData0.word0 & filterData1.word1) && (filterData1.word0 & filterData0.word1))
{
pairFlags = physx::PxPairFlag::eCONTACT_DEFAULT;
pairFlags |= physx::PxPairFlag::eDETECT_CCD_CONTACT;
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_FOUND;
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_LOST;
pairFlags |= physx::PxPairFlag::eNOTIFY_TOUCH_PERSISTS;
pairFlags |= physx::PxPairFlag::ePOST_SOLVER_VELOCITY;
pairFlags |= physx::PxPairFlag::eNOTIFY_CONTACT_POINTS;
pairFlags |= physx::PxPairFlag::eSOLVE_CONTACT;
pairFlags |= physx::PxPairFlag::eDETECT_DISCRETE_CONTACT;
}

return physx::PxFilterFlag::eDEFAULT;
}

Expand Down
13 changes: 12 additions & 1 deletion modules/core/src/px/physics/px_collider_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ namespace era_engine::physics
return true;
}

void setupFiltering(PxShape* shape, PxU32 filterGroup, PxU32 filterMask)
{
PxFilterData filterData;
filterData.word0 = filterGroup; // word0 = own ID
filterData.word1 = filterMask; // word1 = ID mask to filter pairs that trigger a contact callback
shape->setSimulationFilterData(filterData);
shape->setQueryFilterData(filterData);
}

void enableShapeVisualization(PxShape* shape)
{
ASSERT(shape != nullptr);
Expand Down Expand Up @@ -304,7 +313,9 @@ namespace era_engine::physics

material = physics->createMaterial(0.5f, 0.5f, 0.6f);
plane = PxCreatePlane(*physics, PxPlane(createPxVec3(position), createPxVec3(normal)), *material);

PxShape* buffer[1];
plane->getShapes(buffer, 1);
setupFiltering(buffer[0], -1, -1);
physics_holder::physicsRef->getScene()->addActor(*plane);

return true;
Expand Down
8 changes: 5 additions & 3 deletions modules/core/src/px/physics/px_collider_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace era_engine::physics
NODISCARD PxConvexMesh* buildMesh(mesh_asset* asset, const vec3& size);
};

void setupFiltering(PxShape* shape, PxU32 filterGroup, PxU32 filterMask);

void enableShapeVisualization(PxShape* shape);
void disableShapeVisualization(PxShape* shape);

Expand All @@ -60,14 +62,14 @@ namespace era_engine::physics
px_collider_component_base() = default;
virtual ~px_collider_component_base();

NODISCARD PxGeometry* getGeometry() const { return geometry; }
NODISCARD PxShape* getShape() const { return shape; }
PxGeometry* getGeometry() const { return geometry; }
PxShape* getShape() const { return shape; }
void setShape(PxShape* newShape) { shape = newShape; }

virtual bool createGeometry() { return false; }

template<typename T, IsColliderType<T> = true>
NODISCARD T* is()
T* is()
{
return static_cast<const T*>(this);
}
Expand Down
27 changes: 27 additions & 0 deletions modules/core/src/px/physics/px_rigidbody_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ namespace era_engine::physics
actor->setGlobalPose(PxTransform(createPxVec3(pos), createPxQuat(rot)));
}

uint32 px_body_component::getFilterMask() const
{
return filterMask;
}

void px_body_component::setFilterMask(uint32 group, uint32 mask)
{
auto& physicsRef = physics_holder::physicsRef;

filterMask = mask;
filterGroup = group;
auto& colliders = physicsRef->collidersMap[entityHandle];

for (auto& collider : colliders)
{
setupFiltering(collider->getShape(), filterGroup, filterMask);
}
}

void px_body_component::onCollisionEnter(px_body_component* collision) const
{
}
Expand Down Expand Up @@ -90,8 +109,12 @@ namespace era_engine::physics
PxShape* shape = PxRigidActorExt::createExclusiveShape(*actor, *coll->getGeometry(), *material);
enableShapeVisualization(shape);
shape->userData = userData;

coll->setShape(shape);
}

setFilterMask(filterGroup, filterMask);

physicsRef->addActor(this, actor, addToScene);
}

Expand Down Expand Up @@ -363,8 +386,12 @@ namespace era_engine::physics
PxShape* shape = PxRigidActorExt::createExclusiveShape(*actor, *coll->getGeometry(), *material);
enableShapeVisualization(shape);
shape->userData = userData;

coll->setShape(shape);
}

setFilterMask(filterGroup, filterMask);

physicsRef->addActor(this, actor, addToScene);
}

Expand Down
3 changes: 3 additions & 0 deletions modules/core/src/px/physics/px_rigidbody_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ namespace era_engine::physics

void setPhysicsPositionAndRotation(const vec3& pos, const quat& rot);

uint32 getFilterMask() const;
void setFilterMask(uint32 group, uint32 mask);

void onCollisionEnter(px_body_component* collision) const;
void onCollisionExit(px_body_component* collision) const;
void onCollisionStay(px_body_component* collision) const;
Expand Down
Binary file removed tools/Cmake/doc/cmake/CMake.qch
Binary file not shown.
136 changes: 0 additions & 136 deletions tools/Cmake/doc/cmake/Copyright.txt

This file was deleted.

7 changes: 0 additions & 7 deletions tools/Cmake/doc/cmake/cmake.org.html

This file was deleted.

5 changes: 0 additions & 5 deletions tools/Cmake/doc/cmake/cmcppdap/NOTICE

This file was deleted.

22 changes: 0 additions & 22 deletions tools/Cmake/doc/cmake/cmcurl/COPYING

This file was deleted.

Loading

0 comments on commit 5078a71

Please sign in to comment.