//
//}
-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);
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();
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;
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);
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);
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;
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];
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();
#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;