Skip to content

Commit

Permalink
Blast toolset work
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuradov committed Jul 31, 2024
1 parent 76e2ed6 commit 2a22149
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 32 deletions.
23 changes: 12 additions & 11 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>().setCCD(true);
//px_sphere_entt.getComponent<physics::px_dynamic_body_component>().setFilterMask(1, 2);
sphere = px_sphere_entt.handle;

Expand Down Expand Up @@ -339,7 +340,7 @@ namespace era_engine
physics::fracture fracture;
auto ref = make_ref<submesh_asset>(ass.meshes[0].submeshes[0]);
unsigned int seed = 7249U;
fracture.fractureGameObject(ref, px_blast_entt1, physics::anchor::anchor_none, seed, 15, defaultmat, defaultmat, 100.0f, 3.0f);
fracture.fractureGameObject(ref, px_blast_entt1, physics::anchor::anchor_bottom, seed, 50, defaultmat, defaultmat, 2500.0f, 1.0f);
scene.deleteEntity(px_blast_entt1.handle);
}
}
Expand Down Expand Up @@ -612,7 +613,7 @@ namespace era_engine
eentity sphereEntity{ sphere, &scene.registry };
if (input.keyboard['G'].pressEvent)
{
sphereEntity.getComponent<physics::px_dynamic_body_component>().addForce(vec3(20.0f, 1.0f, 0.0f), physics::px_force_mode::force_mode_impulse);
sphereEntity.getComponent<physics::px_dynamic_body_component>().addForce(vec3(200.0f, 1.0f, 0.0f), physics::px_force_mode::force_mode_impulse);
}
}
}
Expand Down Expand Up @@ -679,15 +680,15 @@ namespace era_engine
}

#endif

//{
// CPU_PROFILE_BLOCK("PhysX blast chuncks");
// for (auto [entityHandle, cgm, _] : scene.group(component_group<physics::chunk_graph_manager, transform_component>).each())
// {
// cgm.update();
// }
//}

#if PX_BLAST_ENABLE
{
CPU_PROFILE_BLOCK("PhysX blast chuncks");
for (auto [entityHandle, cgm, _] : scene.group(component_group<physics::chunk_graph_manager, transform_component>).each())
{
cgm.update();
}
}
#endif
updateTestScene(dt, scene, input);

#ifndef ERA_RUNTIME
Expand Down
22 changes: 11 additions & 11 deletions modules/core/src/px/blast/px_blast_destructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace era_engine::physics

void chunk_graph_manager::chunk_node::update()
{
if (frozen)
if (frozen && !isKinematic)
{
auto enttScene = globalApp.getCurrentScene();

Expand Down Expand Up @@ -160,9 +160,6 @@ namespace era_engine::physics
{
auto body = jointToChunk[link];

link->joint->setInvInertiaScale0(0.0f);
link->joint->setInvInertiaScale1(0.0f);

jointToChunk.erase(link);
chunkToJoint.erase(body);

Expand All @@ -186,31 +183,34 @@ namespace era_engine::physics

auto& rb = renderEntity.getComponent<px_dynamic_body_component>();

constexpr float chunkMass = 3.0f;
constexpr float chunkMass = 1.0f;

rb.setMaxAngularVelosity(100.0f);
rb.setAngularDamping(0.01f);
rb.setLinearDamping(0.01f);

auto dyn = rb.getRigidDynamic();
dyn->setSolverIterationCounts(4, 4);
dyn->setMaxDepenetrationVelocity(3.0f);
dyn->setMaxContactImpulse(1000.0f);

rb.updateMassAndInertia(chunkMass);

if (rb.isKinematicBody())
isKinematic = true;
}

void chunk_graph_manager::chunk_node::unfreeze()
{
frozen = false;

auto enttScene = globalApp.getCurrentScene();

eentity renderEntity{ handle, &enttScene->registry };
auto& rb = renderEntity.getComponent<physics::px_dynamic_body_component>();
if (rb.isKinematicBody())
return;
rb.setConstraints(0);
rb.setGravity(true);
rb.setFilterMask(-1, -1);

frozen = false;
}

void chunk_graph_manager::chunk_node::freeze()
Expand Down Expand Up @@ -284,7 +284,7 @@ namespace era_engine::physics

eentity renderEntity{ node, &enttScene->registry };
auto nodeComponent = renderEntity.getComponentIfExists<chunk_node>();

nodeComponent->update();
if (nodeComponent->hasBrokenLinks)
{
nodeComponent->cleanBrokenLinks();
Expand Down Expand Up @@ -335,7 +335,7 @@ namespace era_engine::physics
}
for (auto sub : search)
{
sub->addToUnfreezeQueue();
sub->unfreeze();
}
}

Expand Down
12 changes: 6 additions & 6 deletions modules/core/src/px/blast/px_blast_fracture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ namespace era_engine::physics
float chunkMass = volumeOfMesh(meshAsset) * density / totalChunks;
auto chunks = buildChunks(gameObject.getComponent<transform_component>(), insideMaterial, outsideMaterial, meshes, chunkMass);

// Graph manager freezes/unfreezes blocks depending on whether they are connected to the graph or not
graphManager.setup(chunks);

// Connect blocks that are touching with fixed joints
for (size_t i = 0; i < chunks.size(); i++)
{
Expand All @@ -209,6 +206,9 @@ namespace era_engine::physics

anchorChunks(gameObject.handle, anchor);

// Graph manager freezes/unfreezes blocks depending on whether they are connected to the graph or not
graphManager.setup(chunks);

return fractureGameObject.handle;
}

Expand Down Expand Up @@ -384,15 +384,15 @@ namespace era_engine::physics
auto& joint = body.getComponent<px_fixed_joint_component>();
joint.setPair(rbOverlap.getRigidActor(), rb.getRigidActor());

if (manager.joints.contains(chunk))
if (manager.joints.contains(overlap))
{
manager.joints[chunk].push_back(joint.getJoint());
manager.joints[overlap].push_back(joint.getJoint());
}
else
{
std::vector<px_fixed_joint*> jointVec;
jointVec.push_back(joint.getJoint());
manager.joints.emplace(chunk, jointVec);
manager.joints.emplace(overlap, jointVec);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/core/src/px/core/px_physics_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ namespace era_engine
{
simulationEventCallback->sendCollisionEvents();
simulationEventCallback->sendTriggerEvents();
simulationEventCallback->sendJointEvents();

simulationEventCallback->clear();
}
Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/px/physics/px_joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ namespace era_engine::physics
#if PX_GPU_BROAD_PHASE
jInstance->setConstraintFlag(PxConstraintFlag::eGPU_COMPATIBLE, true);
#endif
//jInstance->setConstraintFlag(PxConstraintFlag::eALWAYS_UPDATE, true);
jInstance->setConstraintFlag(PxConstraintFlag::eCOLLISION_ENABLED, false);
jInstance->setConstraintFlag(PxConstraintFlag::eVISUALIZATION, true);
jInstance->setBreakForce(desc.forceThreshold, desc.torqueThreshold);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/px/physics/px_joint_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace era_engine::physics

void px_fixed_joint_component::setPair(PxRigidActor* f, PxRigidActor* s)
{
joint = new px_fixed_joint(px_fixed_joint_desc{10.0f, 10.0f, jointBreakForce, jointBreakForce}, f, s);
joint = new px_fixed_joint(px_fixed_joint_desc{10.0f, 10.0f, jointBreakForce, jointBreakForce * 2.0f}, f, s);
}

void px_fixed_joint_component::release(bool releaseActor)
Expand Down
6 changes: 4 additions & 2 deletions modules/core/src/px/physics/px_rigidbody_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ namespace era_engine::physics
{
physics_lock_write lock{};

actor->setGlobalPose(PxTransform(createPxVec3(pos), createPxQuat(rot)));

if (auto dyn = actor->is<PxRigidDynamic>())
{
if (dyn->getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC)
return;
dyn->setAngularVelocity(PxVec3(0.0f));
dyn->setLinearVelocity(PxVec3(0.0f));
}

actor->setGlobalPose(PxTransform(createPxVec3(pos), createPxQuat(rot)));
}

uint32 px_body_component::getFilterMask() const
Expand Down

0 comments on commit 2a22149

Please sign in to comment.