Skip to content

Commit

Permalink
Update PerfC mesh exchange system
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravbug committed Jun 17, 2024
1 parent 2eac5b9 commit 64f02af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
28 changes: 23 additions & 5 deletions Samples/Perf_Draw/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <RavEngine/Utilities.hpp>
#include <RavEngine/RenderEngine.hpp>
#include "CustomMaterials.hpp"
#include <RavEngine/MeshCollection.hpp>

using namespace std;
using namespace RavEngine;
Expand All @@ -20,7 +21,7 @@ static constexpr uint32_t num_entities =
#endif

struct InstanceEntity : public RavEngine::GameObject {
void Create(Ref<RavEngine::MeshAsset> mesh, Ref<InstanceColorMatInstance> matinst) {
void Create(Ref<RavEngine::MeshCollectionStatic> mesh, Ref<InstanceColorMatInstance> matinst) {
GameObject::Create();
auto& ism = EmplaceComponent<RavEngine::StaticMesh>(mesh, LitMeshMaterialInstance(matinst));
}
Expand All @@ -45,21 +46,20 @@ PerfB_World::PerfB_World() {

Debug::Log("Loading Assets");
matinst = RavEngine::New<InstanceColorMatInstance>(Material::Manager::Get<InstanceColorMat>());
currentMesh = RavEngine::New<MeshAsset>();
cube = RavEngine::MeshAsset::Manager::Get("cube.obj");
cone = RavEngine::MeshAsset::Manager::Get("cone.obj");
sphere = RavEngine::MeshAsset::Manager::Get("sphere.obj");
cylinder = RavEngine::MeshAsset::Manager::Get("cylinder.obj");
currentMesh->Exchange(cube);
currentMesh->destroyOnDestruction = false;

// spawn demo entities

int32_t range = 200;

meshCollection = New<MeshCollectionStatic>(cube);

Debug::Log("Spawning {} instances",num_entities);
for (uint32_t i = 0; i < num_entities; i++) {
auto e = Instantiate<InstanceEntity>(currentMesh, matinst);
auto e = Instantiate<InstanceEntity>(meshCollection, matinst);
auto& transform = e.GetTransform();

vector3 pos;
Expand Down Expand Up @@ -132,6 +132,24 @@ PerfB_World::PerfB_World() {
EmplaceTimedSystem<MetricsSystem>(std::chrono::seconds(1));
}

void PerfB_World::SwitchMesh(meshes nextMesh)
{
switch (nextMesh) {
case meshes::cube:
meshCollection->SetMeshForLOD(0, cube);
break;
case meshes::cone:
meshCollection->SetMeshForLOD(0, cone);
break;
case meshes::cylinder:
meshCollection->SetMeshForLOD(0, cylinder);
break;
case meshes::sphere:
meshCollection->SetMeshForLOD(0, sphere);
break;
}
}

void PerfB_World::PreTick(float fpsscale)
{
auto time = GetApp()->GetCurrentTime();
Expand Down
36 changes: 3 additions & 33 deletions Samples/Perf_Draw/Level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,10 @@ struct PerfB_World : public RavEngine::World {
sphere
} prevMesh = meshes::cube;

void SwitchMesh(meshes nextMesh){
switch (prevMesh){
case meshes::cube:
cube->Exchange(currentMesh,false);
break;
case meshes::cone:
cone->Exchange(currentMesh,false);
break;
case meshes::cylinder:
cylinder->Exchange(currentMesh,false);
break;
case meshes::sphere:
sphere->Exchange(currentMesh,false);
break;
}
prevMesh = nextMesh;

switch(nextMesh){
case meshes::cube:
currentMesh->Exchange(cube,false);
break;
case meshes::cone:
currentMesh->Exchange(cone,false);
break;
case meshes::cylinder:
currentMesh->Exchange(cylinder,false);
break;
case meshes::sphere:
currentMesh->Exchange(sphere,false);
break;
}
}
void SwitchMesh(meshes nextMesh);
private:
Ref<RavEngine::MeshAsset> currentMesh, cube, cone, cylinder, sphere;
Ref<RavEngine::MeshAsset> cube, cone, cylinder, sphere;
Ref<RavEngine::MeshCollectionStatic> meshCollection;
Ref<struct InstanceColorMatInstance> matinst;
void PreTick(float fpsscale) override;
};

0 comments on commit 64f02af

Please sign in to comment.