void Mesh::Init(std::string filename)
{
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(filename,aiProcessPreset_TargetRealtime_Fast);//aiProcessPreset_TargetRealtime_Fast has the configs you'll need
aiMesh *mesh = scene->mMeshes[0]; //assuming you only want the first mesh
numVerts = mesh->mNumFaces*3;
vArray = new Vertex[mesh->mNumVertices];
Bone *bones = new Bone[mesh->mNumBones];
for (unsigned int i = 0; i<mesh->mNumFaces; i++)
{
const aiFace& face = mesh->mFaces[i];
for (int j = 0; j < 3; j++)
{
aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
vArray[i].uv[0] = uv.x;
vArray[i].uv[1] = uv.y;
std::cout << vArray[i].uv[0] << " : " << vArray[i].uv[1] << " : " << vArray[i].uv[2] << std::endl;
}
/*for (int j = 0; j<3; j++)
{
aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
memcpy(uvArray, &uv, sizeof(float) * 2);
uvArray += 2;
aiVector3D normal = mesh->mNormals[face.mIndices[j]];
memcpy(normalArray, &normal, sizeof(float) * 3);
normalArray += 3;
aiVector3D pos = mesh->mVertices[face.mIndices[j]];
memcpy(vertexArray, &pos, sizeof(float) * 3);
vertexArray += 3;
aiVector3D colour = aiVector3D(m_Colour[0], m_Colour[1], m_Colour[2]);//mesh->mVertices[face.mIndices[j]];
memcpy(colourArray, &colour, sizeof(float) * 3);
colourArray += 3;
}*/
}
for (unsigned int boneIndex = 0; boneIndex < mesh->mNumBones; boneIndex++)
{
aiBone *ai_bone = mesh->mBones[boneIndex];
bones[boneIndex].name = StringCopy(ai_bone->mName.C_Str());
bones[boneIndex].inverse_bone_matrix = toMat4(&ai_bone->mOffsetMatrix);
for (int weightindex = 0; weightindex < mesh->mBones[boneIndex]->mNumWeights; weightindex++)
{
aiVertexWeight *ai_weight = &ai_bone->mWeights[weightindex];
for (int j = 0; j < 4; j++)
{
if (vArray[ai_weight->mVertexId].weights[j] == 0.0)
{
vArray[ai_weight->mVertexId].bone_id[j] = boneIndex;
vArray[ai_weight->mVertexId].weights[j] = ai_weight->mWeight;
break;
}
}
}
}
}
char* Mesh::StringCopy(const char* name)
{
return (char*)name;
}