]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
Bullet Shapes looking correct
authorPeter Schaefer <schaeferpm@gmail.com>
Tue, 16 Jun 2015 14:13:34 +0000 (16:13 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Tue, 16 Jun 2015 14:13:34 +0000 (16:13 +0200)
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/IMesh.h
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/IMetaMesh.h
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
Weave/Scene/Level.cpp

index c512cde4d7038da1b5033c0fbc3669e8a10b231c..8cf696e4dcab494e664d33506d1b5de82a70407f 100644 (file)
@@ -39,33 +39,27 @@ using std::array;
 //
 //}
 
-IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh")
+IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale, bool _isConvex) : modelpath("IMesh")
 {
        import(_mesh, numvertices, numfaces, vertex, uvs, normals, index, _scale);
 
-       btConvexHullShape* tmp_shape = new btConvexHullShape();
-       btTriangleMesh* tmp_mesh = new btTriangleMesh();
-
-       for (uint i = 0; i < numfaces * 3; i += 3)
-       {
-               tmp_mesh->addTriangle(
-                       btVector3(vertex[index[i]], vertex[index[i] + 1], vertex[index[i] + 2]),
-                       btVector3(vertex[index[i + 1]], vertex[index[i + 1] + 1], vertex[index[i + 1] + 2]),
-                       btVector3(vertex[index[i + 2]], vertex[index[i + 2] + 1], vertex[index[i + 2] + 2]),
-                       false);
-
-       }
-
-       //Message::info(std::to_string(tmp_mesh->getNumTriangles()));
-
-       for (uint i = 0; i < numvertices*3; i += 3)
-               tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));
-
-       //tmp_shape->recalcLocalAabb();
-       //bt_collision_shape = new btBvhTriangleMeshShape(tmp_mesh,true);
-       bt_collision_shape = new btConvexTriangleMeshShape(tmp_mesh,true);
-       //bt_collision_shape = tmp_shape;
-
+       btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();
+       btIndexedMesh part;
+       part.m_vertexBase = (const unsigned char*)vertex;
+       part.m_vertexStride = sizeof(float) * 3;
+       part.m_numVertices = numvertices;
+       part.m_triangleIndexBase = (const unsigned char*)index;
+       part.m_triangleIndexStride = sizeof(uint) * 3;
+       part.m_numTriangles = numfaces;
+       part.m_indexType = PHY_INTEGER;
+
+       meshInterface->addIndexedMesh(part, PHY_INTEGER);
+
+       if (_isConvex)
+               bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);
+       else
+               bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);
+       
        genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
        genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
        genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
index ce4f10ac7c89d828c7f2bc3f73bffece18de2d3b..573b0f418755685f233fe7a0bdbad7b49d79c7b1 100644 (file)
@@ -16,7 +16,7 @@ public:
        class Node;
 
 //     IMesh(const std::string& modelpath, uint index=0);
-       IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f));
+       IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f), bool isConvex=true);
 
        virtual ~IMesh();
 
index 8c7c9de873d58024dace924f992559ea8b409a49..ee47474fc51e491569943fc8b7538188917b87e5 100644 (file)
@@ -12,7 +12,7 @@
 
 using std::string;
 
-IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale) : modelpath(_modelpath)
+IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConvex) : modelpath(_modelpath)
 {
        Assimp::Importer importer;
 
@@ -41,7 +41,7 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale) : modelpath(_
                tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
                tmpModelMatClean = removeScale(tmpModelMat);
                tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
-               tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat));
+               tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat),_isConvex);
                models.push_back(std::pair<IMesh*,mat4>(tmpIMesh,tmpModelMatClean));
                tmp_shape->addChildShape(tmpModelMatBT,*tmpIMesh);
 
@@ -52,7 +52,7 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale) : modelpath(_
                        tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
                        tmpModelMatClean = removeScale(tmpModelMat);
                        tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
-                       tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat));
+                       tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);
                        models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));
 
                        tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);
index 2422aebbbab74cf18334c73bfe3219438c1f409f..50a2b1f11212e39d303639201e8b73816fdfb490 100644 (file)
@@ -14,7 +14,7 @@ class Texture;
 class IMetaMesh : public Model
 {
 public:
-       IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f));
+       IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f), bool isConvex = true);
        ~IMetaMesh();
 
        void bindShader(Shader* shader) override;
index dae550ca71b4bde0ba58582223dfd191bdc69133..c1244e0821e49b5fc6c0d9aab2f4b69725b0ab76 100644 (file)
@@ -253,12 +253,12 @@ Model* Model::getSkyBoxModel()
        return SkyBoxModel;
 }
 
-Model* Model::newIMetaModel(const string& _modelpath)
+Model* Model::newIMetaModel(const string& _modelpath, bool _isConvex)
 {
        Model*& ptr = IMetaModel[_modelpath];
        if (ptr == nullptr)
        {
-               ptr = new IMetaMesh(_modelpath);
+               ptr = new IMetaMesh(_modelpath,vec3(1.f),_isConvex);
                //ptr->bindShader(Graphix::shader_BBox);
        }
        ++IMetaModel_count[_modelpath];
index 356c478efbcb69c97392b795acdc6f204ac33333..499d2a1695d296ffdbde36d1a6b0e72083170971 100644 (file)
@@ -37,7 +37,7 @@ public:
 
        static Model* getBBoxModel();
        static Model* getSkyBoxModel();
-       static Model* newIMetaModel(const std::string& modelpath);
+       static Model* newIMetaModel(const std::string& modelpath,bool isConvex=true);
 
        static void deleteBBoxModel();
        static void deleteSkyBoxModel();
index 03f67a2bbc1f76be2060e5ffe14f08f681be6d67..e58d2a0ec07df6aaf33bc833b470843d9092523a 100644 (file)
@@ -7,7 +7,7 @@
 #include "../GLM.h"
 
 
-Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), _modelpath, _texturepath)
+Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath,false), _texturepath)
 {
        collide_group = COL_LEVEL;
        collide_with = COL_MARVIN | COL_ENEMY;