diff --git a/bin/data/entities/prop.json b/bin/data/entities/prop.json index 98623d6b..2186f06f 100644 --- a/bin/data/entities/prop.json +++ b/bin/data/entities/prop.json @@ -6,7 +6,7 @@ "metadata": { "holdable": true, "physics": { - "mass": 0, + "mass": 5, "type": "bounding box" // "type": "mesh" } diff --git a/engine/src/utils/math/physics/bvh.inl b/engine/src/utils/math/physics/bvh.inl index 98140a53..6b9e26e8 100644 --- a/engine/src/utils/math/physics/bvh.inl +++ b/engine/src/utils/math/physics/bvh.inl @@ -348,7 +348,7 @@ namespace { if ( bvh.nodes.empty() ) return; // update leaf bounds - #pragma omp parallel for + //#pragma omp parallel for for ( auto i = 0; i < bvh.nodes.size(); i++ ) { auto& node = bvh.nodes[i]; if ( node.getCount() == 0 ) continue; diff --git a/engine/src/utils/math/physics/impl.cpp b/engine/src/utils/math/physics/impl.cpp index 550ba950..2c2068f5 100644 --- a/engine/src/utils/math/physics/impl.cpp +++ b/engine/src/utils/math/physics/impl.cpp @@ -13,8 +13,8 @@ namespace { uint32_t substeps = 0; // number of substeps per frame tick uint32_t reserveCount = 32; // amount of elements to reserve for vectors used in this system, to-do: have it tie to a memory pool allocator - // increasing these make things lag for reasons I can imagine why (having to test more triangles over just more boxes) - uint32_t broadphaseBvhCapacity = 4; // number of bodies per leaf node + // increasing these make things lag for reasons I can imagine why + uint32_t broadphaseBvhCapacity = 1; // number of bodies per leaf node uint32_t meshBvhCapacity = 1; // number of triangles per leaf node // additionally flattens a BVH for linear iteration, rather than a recursive / stack-based traversal diff --git a/engine/src/utils/math/physics/triangle.inl b/engine/src/utils/math/physics/triangle.inl index 219fe85b..70d71a84 100644 --- a/engine/src/utils/math/physics/triangle.inl +++ b/engine/src/utils/math/physics/triangle.inl @@ -92,7 +92,9 @@ namespace { } pod::TriangleWithNormal fetchTriangle( const uf::Mesh& mesh, size_t triID ) { - auto views = mesh.makeViews({"position", "normal"}); + static thread_local uf::stl::unordered_map> cachedViews; + if ( cachedViews.count(&mesh) == 0 ) cachedViews[&mesh] = mesh.makeViews({"position"}); + auto& views = cachedViews[&mesh]; UF_ASSERT(!views.empty()); // find which view contains this triangle index. @@ -110,7 +112,6 @@ namespace { UF_ASSERT( view ); auto& positions = (*view)["position"]; - auto& normals = (*view)["normal"]; auto& indices = (*view)["index"]; pod::TriangleWithNormal tri = { ::fetchTriangle( *view, indices, positions, triID ) }; @@ -122,6 +123,7 @@ namespace { // if body is a mesh, apply its transform to the triangles, else reorient the normal with respect to the body pod::TriangleWithNormal fetchTriangle( const uf::Mesh& mesh, size_t triID, const pod::PhysicsBody& body, bool fast = false ) { auto tri = ::fetchTriangle( mesh, triID ); + auto transform = ::getTransform( body ); if ( body.collider.type == pod::ShapeType::MESH ) {