group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
TriMeshCollision.cpp File Reference

BVH builder, edge-welding cooker, and runtime triangle-mesh queries. More...

#include "TriMeshCollision.hpp"
#include "ecs/physics/DebugCollisionDraw.hpp"
#include "ecs/physics/PhaseDiagnostic.hpp"
#include "ecs/physics/PhysicsPerfStats.hpp"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <glm/geometric.hpp>
#include <limits>
#include <unordered_map>
Include dependency graph for TriMeshCollision.cpp:

Namespaces

namespace  physics
 Pure physics math — no ECS types, no registry.

Functions

void physics::buildTriMeshBVH (WorldTriMesh &mesh)
 Build the BVH for a WorldTriMesh.
void physics::weldTriMesh (WorldTriMesh &mesh, float coplanarTolerance=0.0349065850f)
 Compute face normals + active edge / vertex flags for a triangle mesh.
TriMeshValidationReport physics::validateTriMesh (const WorldTriMesh &mesh, float positionEpsilon=1e-4f)
 Validate authored collision mesh topology before/after cooking.
TriMeshValidationTotals physics::validateTriMeshes (std::span< const WorldTriMesh > meshes, float positionEpsilon=1e-4f)
 Validate every triangle mesh in an authored collision set.
TriMeshCookStats physics::collectTriMeshCookStats (std::span< const WorldTriMesh > meshes)
 Collect aggregate map-cooking diagnostics for already-cooked meshes.
HitResult physics::sweepAABBvsTriMesh (glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldTriMesh &mesh)
 Sweep an AABB against a triangle mesh using Voronoi-clipped per-triangle tests.
void physics::depenetrateAABBvsTriMesh (glm::vec3 &pos, glm::vec3 &vel, glm::vec3 halfExtents, const WorldTriMesh &mesh, float pushback=0.03125f)
 Push an AABB out of a triangle mesh using Voronoi-clipped face-normal MTVs.
HitResult physics::sweepCapsuleVsTriMesh (CapsuleShape capsule, glm::vec3 start, glm::vec3 end, const WorldTriMesh &mesh)
 Sweep a capsule against a triangle mesh.
DepenContact physics::deepestCapsuleContactVsTriMesh (CapsuleShape capsule, glm::vec3 pos, glm::vec3 vel, const WorldTriMesh &mesh)
 Single deepest surface contact of a capsule against any triangle in this mesh.
ClosestPointOnMeshResult physics::closestPointOnMesh (glm::vec3 segA, glm::vec3 segB, float maxDist, const WorldTriMesh &mesh)
 Find the closest point on the mesh's surface to a query segment, considering only points within maxDist.
ClosestPointOnMeshResult physics::closestPointOnMesh (CapsuleShape capsule, glm::vec3 center, float maxDist, const WorldTriMesh &mesh)
 Convenience overload — uses the capsule's inner axis as the query segment at the given centre position.
ClosestPointOnMeshResult physics::closestPointOnMeshTriangle (CapsuleShape capsule, glm::vec3 center, float maxDist, const WorldTriMesh &mesh, uint32_t triId)
 Closest point from a capsule axis to one specific cooked triangle.
ClearanceResult physics::clearanceCapsuleVsTriMesh (CapsuleShape capsule, glm::vec3 pos, float maxReach, const WorldTriMesh &mesh)
 Capsule-vs-trimesh clearance.
GroundProbeResult physics::groundProbeCapsuleVsTriMesh (CapsuleShape capsule, glm::vec3 pos, float maxDistance, float minWalkableDot, const WorldTriMesh &mesh)
 Downward ground probe against walkable triangle faces only.

Detailed Description

BVH builder, edge-welding cooker, and runtime triangle-mesh queries.

Phase 2 of the physics roadmap. Replaces the older SAT-MTV per-triangle path (which produced "ghost contacts" on internal edges of triangulated flat surfaces, requiring multi-pass MTV averaging to mask the noise) with:

  1. A cook-time welding pass (weldTriMesh) that classifies every shared edge as convex / concave / coplanar, marking only convex edges and their incident vertices as "active".
  2. Legacy AABB primitives that use Voronoi feature clipping for debug geometry.
  3. Capsule primitives that treat authored map triangles as two-sided blocking surfaces and solve against bounded face / edge / vertex features via segment-triangle closest points.