Skip to content

Commit

Permalink
[ERA-0] blast toolset work
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuradov committed Aug 16, 2024
1 parent b1b3fb0 commit cfbb97a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
4 changes: 3 additions & 1 deletion modules/core/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ namespace era_engine
// addRaytracingComponentAsync(en, mesh);
//}



#if PX_BLAST_ENABLE

{
Expand All @@ -341,7 +343,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_bottom, seed, 50, defaultmat, defaultmat, 400.0f, 1.0f);
fracture.fractureGameObject(ref, px_blast_entt1, physics::anchor::anchor_bottom, seed, 10, defaultmat, defaultmat, 400.0f, 1.0f);
scene.deleteEntity(px_blast_entt1.handle);
}
}
Expand Down
14 changes: 11 additions & 3 deletions modules/core/src/px/blast/px_blast_destructions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023-present Eldar Muradov. All rights reserved.

#include "px/blast/px_blast_destructions.h"
#include "px/core/px_aggregate.h"

#if PX_BLAST_ENABLE

Expand Down Expand Up @@ -28,11 +29,14 @@ namespace era_engine::physics

mm->aabb = bounding_box::negativeInfinity();

float calculatedMass = volumeOfMesh(mesh.first);
std::cout << (std::to_string(calculatedMass).c_str()) << "\n";

eentity chunk = enttScene->createEntity(asset.name.c_str())
.addComponent<transform_component>(transform)
.addComponent<px_convex_mesh_collider_component>(&asset)
.addComponent<px_dynamic_body_component>()
.addComponent<nvmesh_chunk_component>(mesh.second)
.addComponent<nvmesh_chunk_component>(mesh.second, calculatedMass)
.addComponent<mesh_component>(mm);

mm->aabb.grow(aabb.minCorner);
Expand All @@ -47,9 +51,13 @@ namespace era_engine::physics
{
std::vector<entity_handle> handles;

//px_aggregate* aggregate = new px_aggregate(meshes.size(), false);

for (size_t i = 0; i < meshes.size(); ++i)
{
handles.push_back(buildChunk(transform, insideMaterial, outsideMaterial, meshes[i], chunkMass, generation).handle);
eentity entity = buildChunk(transform, insideMaterial, outsideMaterial, meshes[i], chunkMass, generation);
handles.push_back(entity.handle);
//aggregate->addActor(entity.getComponent<px_dynamic_body_component>().getRigidActor());
}

return handles;
Expand Down Expand Up @@ -190,7 +198,7 @@ namespace era_engine::physics
auto dyn = rb.getRigidDynamic();
dyn->setMaxDepenetrationVelocity(3.0f);
dyn->setSolverIterationCounts(16);
rb.updateMassAndInertia(rb.getMass());
rb.updateMassAndInertia(renderEntity.getComponent<nvmesh_chunk_component>().mass);

if (rb.isKinematicBody())
isKinematic = true;
Expand Down
8 changes: 4 additions & 4 deletions modules/core/src/px/blast/px_blast_fracture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ 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 @@ -206,9 +209,6 @@ 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 @@ -383,7 +383,7 @@ namespace era_engine::physics
std::vector<PxFilterData> fd1 = getFilterData(rb.getRigidActor());
std::vector<PxFilterData> fd2 = getFilterData(rbOverlap.getRigidActor());

body.addComponent<px_fixed_joint_component>(jointBreakForce);
body.addComponent<px_fixed_joint_component>(jointBreakForce * rbOverlap.getMass() * rb.getMass());
auto& joint = body.getComponent<px_fixed_joint_component>();
joint.setPair(rbOverlap.getRigidActor(), rb.getRigidActor());

Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/px/blast/px_nvmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ namespace era_engine::physics
struct nvmesh_chunk_component : px_physics_component_base
{
nvmesh_chunk_component() = default;
nvmesh_chunk_component(uint32 handle, ref<nvmesh> inputMesh) : px_physics_component_base(handle), mesh(inputMesh) {}
nvmesh_chunk_component(uint32 handle, ref<nvmesh> inputMesh, float chunkMass) : px_physics_component_base(handle), mesh(inputMesh), mass(chunkMass) {}
~nvmesh_chunk_component() {}

virtual void release(bool release = false) override { PX_RELEASE(mesh) }

ref<nvmesh> mesh = nullptr;
float mass = 1.0f;
};
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/px/core/px_aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace era_engine
{
physics::px_aggregate::px_aggregate(uint8 nb, bool sc) : nbActors(nb), selfCollisions(sc)
{
aggregate = physics_holder::physicsRef->getPhysics()->createAggregate(nbActors, selfCollisions, PxAggregateFilterHint());
aggregate = physics_holder::physicsRef->getPhysics()->createAggregate(nbActors, nbActors, PxGetAggregateFilterHint(PxAggregateType::eGENERIC, true));
physics_holder::physicsRef->getScene()->addAggregate(*aggregate);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/px/physics/px_joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace era_engine::physics
joint->userData = this;
type = px_joint_type::joint_type_fixed;
auto jInstance = joint->is<PxFixedJoint>();
jInstance->setConstraintFlag(PxConstraintFlag::eCOLLISION_ENABLED, false);
jInstance->setConstraintFlag(PxConstraintFlag::eCOLLISION_ENABLED, true);
jInstance->setBreakForce(desc.forceThreshold, desc.torqueThreshold);
}

Expand Down

0 comments on commit cfbb97a

Please sign in to comment.