Skip to content

Commit

Permalink
[ERA-1] ragdoll (without skinning)
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuradov committed Aug 26, 2024
1 parent 5d46074 commit 334c9fb
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 44 deletions.
4 changes: 3 additions & 1 deletion modules/core/src/animation/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ namespace era_engine::animation
relTime += dt / targetLength;
relTime = fmodf(relTime, 1.f);


trs* totalLocalTransforms = (trs*)alloca(sizeof(trs) * skeleton.joints.size() * 2);
trs* localTransforms1 = totalLocalTransforms;
trs* localTransforms2 = totalLocalTransforms + skeleton.joints.size();
Expand Down Expand Up @@ -687,6 +686,9 @@ namespace era_engine::animation

controller = make_ref<animation_controller>();

if (clips.empty())
return;

animation_blackboard startBlackboard = { &clips[startIndex] };
controller->stateMachine.set_state(state, startBlackboard);

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,6 @@ namespace era_engine::animation
trs* currentGlobalTransforms = 0;

float timeScale = 1.f;
bool drawSceleton = false;
bool drawSceleton = true;
};
}
41 changes: 35 additions & 6 deletions modules/core/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ namespace era_engine
}

static entity_handle sphere{};
static entity_handle ragdoll{};

static void initTestScene(escene& scene)
{
Expand Down Expand Up @@ -328,6 +329,19 @@ namespace era_engine
// addRaytracingComponentAsync(en, mesh);
//}

if (auto mesh = loadAnimatedMeshFromFileAsync(getAssetPath("/resources/assets/resident-evil-tyrant/source/UmodelExport.fbx")))
{
auto& en = scene.createEntity("Tiran")
.addComponent<transform_component>(vec3(0.0f), quat::identity, vec3(0.1f))
.addComponent<animation::animation_component>()
.addComponent<dynamic_transform_component>()
.addComponent<mesh_component>(mesh)
.addComponent<physics::px_ragdoll_component>(vec3(0.0f));
initializeAnimationComponentAsync(en, mesh);
addRaytracingComponentAsync(en, mesh);

ragdoll = en.handle;
}


#if PX_BLAST_ENABLE
Expand Down Expand Up @@ -364,11 +378,11 @@ namespace era_engine
// scene.deleteEntity(px_sphere_entt1.handle);
//}

auto& vehicle = scene.createEntity("Vehicle")
.addComponent<transform_component>(vec3(2.f), quat::identity, vec3(1.f))
.addComponent<physics::px_4_wheels_vehicle_component>(vec3(2.f));
//auto& vehicle = scene.createEntity("Vehicle")
// .addComponent<transform_component>(vec3(2.f), quat::identity, vec3(1.f))
// .addComponent<physics::px_4_wheels_vehicle_component>(vec3(2.f));

vehicle.getComponent<physics::px_4_wheels_vehicle_component>().setupVehicle();
//vehicle.getComponent<physics::px_4_wheels_vehicle_component>().setupVehicle();

//auto soft_body = &scene.createEntity("SoftBody")
// .addComponent<transform_component>(vec3(0.f), quat::identity, vec3(1.f))
Expand Down Expand Up @@ -406,8 +420,8 @@ namespace era_engine
// .addComponent<physics::px_cloth_component>(100, 100, vec3(0.f, 15.0f, 0.0f));

scene.createEntity("Platform")
.addComponent<transform_component>(vec3(10, -7.f, 0.f), quat(vec3(1.f, 0.f, 0.f), deg2rad(0.f)))
.addComponent<physics::px_plane_collider_component>(vec3(0.f, -3.0, 0.0f))
.addComponent<transform_component>(vec3(10, -9.f, 0.f), quat(vec3(1.f, 0.f, 0.f), deg2rad(0.f)))
.addComponent<physics::px_plane_collider_component>(vec3(0.f, -5.0, 0.0f))
.addComponent<mesh_component>(groundMesh);

auto chainMesh = make_ref<multi_mesh>();
Expand Down Expand Up @@ -904,6 +918,21 @@ namespace era_engine
renderer->setSun(sun);
renderer->setCamera(camera);

if (ImGui::Begin("Ragdoll"))
{
static bool init = false;

if (ImGui::Checkbox("Build", &init))
{
init = false;

eentity rag{ ragdoll, &scene.registry };

rag.getComponent<physics::px_ragdoll_component>().initRagdoll(make_ref<animation::animation_skeleton>(rag.getComponent<mesh_component>().mesh->skeleton));
}
ImGui::End();
}

//if (running)
// physics::physics_holder::physicsRef->endSimulation(dt);
#ifndef ERA_RUNTIME
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace era_engine

system_info systemInfo;

bool renderPhysicsShapes = false;
bool renderPhysicsShapes = true;

friend struct selection_undo;
friend struct application;
Expand Down
Loading

0 comments on commit 334c9fb

Please sign in to comment.