// Fordere mindestens prozentuelles gleichgewicht .1 = 10%
#define HEAP_SCALE_BOUND .1f
-IMesh::IMesh(const string& _modelpath, uint _mindex) : modelpath(_modelpath), root(nullptr)
+//IMesh::IMesh(const string& _modelpath, uint _mindex) : modelpath(_modelpath), root(nullptr)
+//{
+//
+// import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
+//
+// btConvexHullShape* tmp_shape = new btConvexHullShape();
+//
+// for (uint i = 0; i < numvertices; i += 3)
+// tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));
+//
+// bt_collision_shape = tmp_shape;
+//
+//#ifdef COMPARE_MTREE
+// root = buildMeshTree(mat4(1.f), numvertices, numfaces, vertex, normals, index);
+//
+// vec3 min, max;
+// setBB(*root);
+//#else
+// setBB(numvertices, vertex);
+//#endif
+//
+// genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+// genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
+// genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
+// genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
+//
+//}
+
+IMesh::IMesh(const aiMesh* _mesh, const mat4& _transformation, const vec3& _scale) : modelMat(removeScale(_transformation)), modelpath("IMesh"), root(nullptr)
{
- import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
+ import(_mesh, numvertices, numfaces, vertex, uvs, normals, index, _scale * getScale(_transformation));
btConvexHullShape* tmp_shape = new btConvexHullShape();
- for (int i = 0; i < numvertices; i += 3)
+ for (uint i = 0; i < numvertices; i += 3)
tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));
+ //tmp_shape->recalcLocalAabb();
bt_collision_shape = tmp_shape;
-#ifdef COMPARE_MTREE
- root = buildMeshTree(mat4(1.f), numvertices, numfaces, vertex, normals, index);
-
- vec3 min, max;
- setBB(*root);
-#else
- setBB(numvertices, vertex);
-#endif
-
- genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
- genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
- genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
- genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-}
-
-IMesh::IMesh(const aiMesh* _mesh, const mat4& _transformation) : modelMat(_transformation), modelpath("IMesh"), root(nullptr)
-{
-
- import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
-
- btConvexHullShape* tmp_shape = new btConvexHullShape();
+ btVector3 minB,maxB;
+ btTransform t;
- for (int i = 0; i < numvertices; i += 3)
- tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));
+ tmp_shape->getAabb(t, minB, maxB);
- bt_collision_shape = tmp_shape;
+ minB = t(minB);
+ maxB = t(maxB);
- btVector3 min,max;
- btTransform t;
+ vec3 min = (vec3)(modelMat * vec4(minB.getX(), minB.getY(), minB.getZ(),0.f));
+ vec3 max = (vec3)(modelMat * vec4(maxB.getX(), maxB.getY(), maxB.getZ(), 0.f));
- bt_collision_shape->getAabb(t,min,max);
+ vec3 size = (max - min) * .5f;
+ vec3 center = (max + min) * .5f;
#ifdef COMPARE_MTREE
root = buildMeshTree(_transformation, numvertices, numfaces, vertex, normals, index);
public:
class Node;
- IMesh(const std::string& modelpath, uint index=0);
- IMesh(const aiMesh* mesh, const mat4& transformation);
+// IMesh(const std::string& modelpath, uint index=0);
+ IMesh(const aiMesh* mesh, const mat4& transformation, const vec3& scale = vec3(1.f));
virtual ~IMesh();
using std::string;
-IMetaMesh::IMetaMesh(const string& _modelpath) : modelpath(_modelpath)
+IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale) : 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);
- tmpIMesh = new IMesh(scene->mMeshes[0], tmpModelMat);
+ tmpIMesh = new IMesh(scene->mMeshes[0], tmpModelMat, _scale);
models.push_back(tmpIMesh);
setBB(tmpIMesh->getBBox());
aimat = &(root->mChildren[i]->mTransformation);
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);
- tmpIMesh = new IMesh(scene->mMeshes[i], tmpModelMat);
+ tmpIMesh = new IMesh(scene->mMeshes[i], tmpModelMat,_scale);
models.push_back(tmpIMesh);
updateBB(tmpIMesh->getBBox());
class IMetaMesh : public Model
{
public:
- IMetaMesh(const std::string& modelpath);
+ IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f));
~IMetaMesh();
void bindShader(Shader* shader) override;
if (tmp >= 0)
glUniform4fv(tmp, 1, value_ptr(_color));
Graphix::getGlError();
+
+ btVector3 min, max;
+ btTransform trans;
+ bt_collision_shape->getAabb(trans, min, max);
+
+ btVector3 size = (max - min) * .5f;
+ btVector3 center = trans((max + min) * .5f);
+
getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(box.center())*glm::scale(box.size()*2.f));
}
return import(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index);
}
-bool Model::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index)
+bool Model::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, const vec3& _scale)
{
numvertices = mesh->mNumVertices;
//load vertices from Mesh
for (uint i = 0; i < numvertices; i++)
{
- vertex[3 * i] = mesh->mVertices[i].x;
- vertex[3 * i + 1] = mesh->mVertices[i].y;
- vertex[3 * i + 2] = mesh->mVertices[i].z;
+ vertex[3 * i] = _scale.x * mesh->mVertices[i].x;
+ vertex[3 * i + 1] = _scale.y * mesh->mVertices[i].y;
+ vertex[3 * i + 2] = _scale.z * mesh->mVertices[i].z;
}
//load UVs from Mesh
//load normals from Mesh
for (uint i = 0; i < numvertices; i++)
{
- normals[3 * i] = mesh->mNormals[i].x;
- normals[3 * i + 1] = mesh->mNormals[i].y;
- normals[3 * i + 2] = mesh->mNormals[i].z;
+ normals[3 * i] = mesh->mNormals[i].x / _scale.x;
+ normals[3 * i + 1] = mesh->mNormals[i].y / _scale.y;
+ normals[3 * i + 2] = mesh->mNormals[i].z / _scale.z;
}
return true;
// Mesh Speichern?
static bool import(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint mindex = 0);
- static bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index);
+ static bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, const vec3& scale = vec3(1.f));
protected:
Model();