Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to hide high-vertex-count drawables #2092

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,7 @@ void ResourceManager::addComponent(

gfx::Drawable::Flags meshAttributeFlags{};
const auto& meshData = meshes_.at(meshID)->getMeshData();
Mn::Range3D* pbb = nullptr;
if (meshData != Cr::Containers::NullOpt) {
if (meshData->hasAttribute(Mn::Trade::MeshAttribute::Tangent)) {
meshAttributeFlags |= gfx::Drawable::Flag::HasTangent;
Expand All @@ -3229,22 +3230,64 @@ void ResourceManager::addComponent(
if (meshData->hasAttribute(Mn::Trade::MeshAttribute::Color)) {
meshAttributeFlags |= gfx::Drawable::Flag::HasVertexColor;
}

GenericMeshData& gltfMeshData =
dynamic_cast<GenericMeshData&>(*meshes_.at(meshID).get());
pbb = &gltfMeshData.BB;
}

bool doUsePlaceholderMesh = false;
if (mesh) {
static int numRequestedDrawables = 0;
static int numHidDrawables = 0;
numRequestedDrawables++;

constexpr float halfSize = 0.1f;
Mn::Range3D defaultBB({-halfSize, -halfSize, -halfSize},
{halfSize, halfSize, halfSize});
if (!pbb) {
pbb = &defaultBB;
}

// float bbArea = (bb.sizeX() * bb.sizeY()) + (bb.sizeX() * bb.sizeZ())
// + (bb.sizeY() * bb.sizeZ());
// const CollisionMeshData& meshData =
// gltfMeshData.getCollisionMeshData();
int numVerts = mesh->count();
constexpr int threshold = 5000; // todo: expose to Python as tuning var
// if (float(numVerts) / bbArea > threshold)
if (numVerts > threshold) {
const auto& bb = *pbb;
Magnum::Vector3 scale = bb.size() / 2.0;
auto& bbNode = node.createChild();
bbNode.MagnumObject::setScaling(scale);
bbNode.MagnumObject::setTranslation(bb.center());
addPrimitiveToDrawables(0, bbNode, drawables);
doUsePlaceholderMesh = true;
numHidDrawables++;
ESP_WARNING() << "hid " << std::to_string(numHidDrawables) << "/"
<< std::to_string(numRequestedDrawables) << " drawables";
}
}

createDrawable(mesh, // render mesh
meshAttributeFlags, // mesh attribute flags
node, // scene node
lightSetupKey, // lightSetup Key
materialKey, // material key
drawables, // drawable group
skinData); // instance skinning data
if (!doUsePlaceholderMesh) {
createDrawable(mesh, // render mesh
meshAttributeFlags, // mesh attribute flags
node, // scene node
lightSetupKey, // lightSetup Key
materialKey, // material key
drawables, // drawable group
skinData); // instance skinning data
}

// compute the bounding box for the mesh we are adding
if (computeAbsoluteAABBs) {
staticDrawableInfo.emplace_back(StaticDrawableInfo{node, meshID});
}
BaseMesh* meshBB = meshes_.at(meshID).get();
node.setMeshBB(computeMeshBB(meshBB));
auto bb = computeMeshBB(meshBB);
CORRADE_INTERNAL_ASSERT(!pbb || *pbb == bb);
node.setMeshBB(bb);
}

// Recursively add children
Expand Down
2 changes: 2 additions & 0 deletions src/esp/sim/ClassicReplayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ClassicReplayRenderer::ClassicReplayRenderer(
resourceManager_->getShaderManager().setFallback(
esp::gfx::getDefaultLights());

resourceManager_->initDefaultPrimAttributes(); // needed for wireframeCube

sceneManager_ = scene::SceneManager::create_unique();

class SceneGraphPlayerImplementation
Expand Down