import(_mesh, numvertices, numfaces, vertex, uvs, normals, index, _scale);
btConvexHullShape* tmp_shape = new btConvexHullShape();
+ btTriangleMesh* tmp_mesh = new btTriangleMesh();
- 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;
+ 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);
- btVector3 minB,maxB;
- btTransform t;
- t.setIdentity();
+ }
- tmp_shape->getAabb(t, minB, maxB);
+ //Message::info(std::to_string(tmp_mesh->getNumTriangles()));
- //minB = t(minB);
- //maxB = t(maxB);
-
- vec3 min = (vec3)(vec4(minB.getX(), minB.getY(), minB.getZ(), 0.f));
- vec3 max = (vec3)(vec4(maxB.getX(), maxB.getY(), maxB.getZ(), 0.f));
+ for (uint i = 0; i < numvertices*3; i += 3)
+ tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));
- vec3 size = (max - min) * .5f;
- vec3 center = (max + min) * .5f;
+ //tmp_shape->recalcLocalAabb();
+ //bt_collision_shape = new btBvhTriangleMeshShape(tmp_mesh,true);
+ bt_collision_shape = new btConvexTriangleMeshShape(tmp_mesh,true);
+ //bt_collision_shape = tmp_shape;
setBB(numvertices, vertex);
//load normals from Mesh
for (uint i = 0; i < numvertices; i++)
{
- 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;
+ 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;