diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index a3e95c68c0..4256f0be03 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -130,7 +130,7 @@ protected: void evalVertexStream(); }; -typedef std::shared_ptr< Mesh > MeshPointer; +using MeshPointer = std::shared_ptr< Mesh >; class Geometry { diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt index b734c9ac2e..7733c019e0 100644 --- a/libraries/physics/CMakeLists.txt +++ b/libraries/physics/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME physics) setup_hifi_library() -link_hifi_libraries(shared fbx entities) +link_hifi_libraries(shared fbx entities model) target_bullet() diff --git a/libraries/physics/src/CollisionRenderMeshCache.cpp b/libraries/physics/src/CollisionRenderMeshCache.cpp index 14d02951a1..e563c05e90 100644 --- a/libraries/physics/src/CollisionRenderMeshCache.cpp +++ b/libraries/physics/src/CollisionRenderMeshCache.cpp @@ -9,16 +9,31 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "CollisionRenderMeshCache.h" + #include //#include //#include "ShapeFactory.h" -#include "CollisionRenderMeshCache.h" +#include -int foo = 0; -MeshPointer createMeshFromShape(CollisionRenderMeshCache::Key key) { - return std::make_shared(++foo); +model::MeshPointer createMeshFromShape(const btCollisionShape* shape) { + if (!shape) { + return std::make_shared(); + } + int32_t shapeType = shape->getShapeType(); + if (shapeType == (int32_t)COMPOUND_SHAPE_PROXYTYPE) { + const btCompoundShape* compoundShape = static_cast(shape); + int32_t numSubShapes = compoundShape->getNumChildShapes(); + for (int i = 0; i < numSubShapes; ++i) { + const btCollisionShape* childShape = compoundShape->getChildShape(i); + std::cout << "adebug " << i << " " << (void*)(childShape) << std::endl; // adebug + } + } else if (shape->isConvex()) { + std::cout << "adebug " << (void*)(shape)<< std::endl; // adebug + } + return std::make_shared(); } CollisionRenderMeshCache::CollisionRenderMeshCache() { @@ -29,21 +44,19 @@ CollisionRenderMeshCache::~CollisionRenderMeshCache() { _pendingGarbage.clear(); } -MeshPointer CollisionRenderMeshCache::getMesh(CollisionRenderMeshCache::Key key) { - if (!key) { - return MeshPointer(); - } - MeshPointer geometry = 0; - - CollisionMeshMap::const_iterator itr = _geometryMap.find(key); - if (itr != _geometryMap.end()) { - // make geometry and add it to map - geometry = createMeshFromShape(key); - if (geometry) { - _geometryMap.insert(std::make_pair(key, geometry)); +model::MeshPointer CollisionRenderMeshCache::getMesh(CollisionRenderMeshCache::Key key) { + model::MeshPointer mesh; + if (key) { + CollisionMeshMap::const_iterator itr = _geometryMap.find(key); + if (itr != _geometryMap.end()) { + // make mesh and add it to map + mesh = createMeshFromShape(key); + if (mesh) { + _geometryMap.insert(std::make_pair(key, mesh)); + } } } - return geometry; + return mesh; } bool CollisionRenderMeshCache::releaseMesh(CollisionRenderMeshCache::Key key) { diff --git a/libraries/physics/src/CollisionRenderMeshCache.h b/libraries/physics/src/CollisionRenderMeshCache.h index 3b39ef80f8..03083048d8 100644 --- a/libraries/physics/src/CollisionRenderMeshCache.h +++ b/libraries/physics/src/CollisionRenderMeshCache.h @@ -16,11 +16,9 @@ #include #include -class btCollisionShape; +#include -// BEGIN TEST HACK -using MeshPointer = std::shared_ptr; -// END TEST HACK +class btCollisionShape; namespace std { template <> @@ -39,7 +37,7 @@ public: ~CollisionRenderMeshCache(); /// \return pointer to geometry - MeshPointer getMesh(Key key); + model::MeshPointer getMesh(Key key); /// \return true if geometry was found and released bool releaseMesh(Key key); @@ -52,7 +50,7 @@ public: bool hasMesh(Key key) const { return _geometryMap.find(key) == _geometryMap.end(); } private: - using CollisionMeshMap = std::unordered_map; + using CollisionMeshMap = std::unordered_map; CollisionMeshMap _geometryMap; std::vector _pendingGarbage; };