Created
March 28, 2020 21:46
-
-
Save PcChip/6609166512a0747cb013aa8d7f03e8c8 to your computer and use it in GitHub Desktop.
load mesh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool teMesh::MeshEntry::LoadDataToMemory(aiMesh *mesh) | |
{ | |
//std::cout << "MeshEntry::LoadDataToMemory()\n"; | |
vbo[VERTEX_BUFFER] = NULL; | |
vbo[TEXCOORD_BUFFER] = NULL; | |
vbo[NORMAL_BUFFER] = NULL; | |
vbo[INDEX_BUFFER] = NULL; | |
vbo[INSTANCE_BUFFER] = NULL; | |
elementCount = mesh->mNumFaces * 3; | |
btConvexHullShape* tempConvexHullShape = new btConvexHullShape(); | |
if (mesh->HasPositions()) | |
{ | |
vertices.resize(mesh->mNumVertices * 3); | |
for (int i = 0; i < mesh->mNumVertices; ++i) | |
{ | |
vertices[i * 3 + 0] = mesh->mVertices[i].x; | |
vertices[i * 3 + 1] = mesh->mVertices[i].y; | |
vertices[i * 3 + 2] = mesh->mVertices[i].z; | |
tempConvexHullShape->addPoint(btVector3(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z), false); | |
} | |
btShapeHull* temphull = new btShapeHull(tempConvexHullShape); | |
btScalar margin = tempConvexHullShape->getMargin(); | |
temphull->buildHull(0.0); | |
convexHullShape = new btConvexHullShape((btScalar*)temphull->getVertexPointer(), temphull->numVertices()); | |
convexHullShape->optimizeConvexHull(); | |
convexHullShape->initializePolyhedralFeatures(); | |
btVector3 center; | |
btScalar radius; | |
convexHullShape->getBoundingSphere(center, radius); | |
centerOfMesh = glm::vec3(center.getX(), center.getY(), center.getZ()); | |
delete temphull; | |
delete tempConvexHullShape; | |
} | |
if (mesh->HasTextureCoords(0)) | |
{ | |
texCoords.resize(mesh->mNumVertices * 2); | |
for (int i = 0; i < mesh->mNumVertices; ++i) | |
{ | |
texCoords[i * 2] = mesh->mTextureCoords[0][i].x; | |
texCoords[i * 2 + 1] = mesh->mTextureCoords[0][i].y; | |
} | |
} | |
if (mesh->HasNormals()) | |
{ | |
normals.resize(mesh->mNumVertices * 3); | |
for (int i = 0; i < mesh->mNumVertices; ++i) | |
{ | |
normals[i * 3] = mesh->mNormals[i].x; | |
normals[i * 3 + 1] = mesh->mNormals[i].y; | |
normals[i * 3 + 2] = mesh->mNormals[i].z; | |
} | |
} | |
if (mesh->HasFaces()) | |
{ | |
indices.resize(mesh->mNumFaces * 3); | |
for (int i = 0; i < mesh->mNumFaces; ++i) | |
{ | |
indices[i * 3] = mesh->mFaces[i].mIndices[0]; | |
indices[i * 3 + 1] = mesh->mFaces[i].mIndices[1]; | |
indices[i * 3 + 2] = mesh->mFaces[i].mIndices[2]; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment