fork download
  1. void Mesh::Init(std::string filename)
  2. {
  3. Assimp::Importer importer;
  4. const aiScene *scene = importer.ReadFile(filename,aiProcessPreset_TargetRealtime_Fast);//aiProcessPreset_TargetRealtime_Fast has the configs you'll need
  5.  
  6. aiMesh *mesh = scene->mMeshes[0]; //assuming you only want the first mesh
  7.  
  8. numVerts = mesh->mNumFaces*3;
  9.  
  10. vArray = new Vertex[mesh->mNumVertices];
  11. Bone *bones = new Bone[mesh->mNumBones];
  12.  
  13. for (unsigned int i = 0; i<mesh->mNumFaces; i++)
  14. {
  15. const aiFace& face = mesh->mFaces[i];
  16.  
  17. for (int j = 0; j < 3; j++)
  18. {
  19. aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
  20. vArray[i].uv[0] = uv.x;
  21. vArray[i].uv[1] = uv.y;
  22.  
  23. std::cout << vArray[i].uv[0] << " : " << vArray[i].uv[1] << " : " << vArray[i].uv[2] << std::endl;
  24.  
  25. }
  26.  
  27. /*for (int j = 0; j<3; j++)
  28. {
  29. aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
  30. memcpy(uvArray, &uv, sizeof(float) * 2);
  31. uvArray += 2;
  32.  
  33. aiVector3D normal = mesh->mNormals[face.mIndices[j]];
  34. memcpy(normalArray, &normal, sizeof(float) * 3);
  35. normalArray += 3;
  36.  
  37. aiVector3D pos = mesh->mVertices[face.mIndices[j]];
  38. memcpy(vertexArray, &pos, sizeof(float) * 3);
  39. vertexArray += 3;
  40.  
  41. aiVector3D colour = aiVector3D(m_Colour[0], m_Colour[1], m_Colour[2]);//mesh->mVertices[face.mIndices[j]];
  42. memcpy(colourArray, &colour, sizeof(float) * 3);
  43. colourArray += 3;
  44. }*/
  45. }
  46.  
  47.  
  48. for (unsigned int boneIndex = 0; boneIndex < mesh->mNumBones; boneIndex++)
  49. {
  50. aiBone *ai_bone = mesh->mBones[boneIndex];
  51. bones[boneIndex].name = StringCopy(ai_bone->mName.C_Str());
  52. bones[boneIndex].inverse_bone_matrix = toMat4(&ai_bone->mOffsetMatrix);
  53.  
  54. for (int weightindex = 0; weightindex < mesh->mBones[boneIndex]->mNumWeights; weightindex++)
  55. {
  56. aiVertexWeight *ai_weight = &ai_bone->mWeights[weightindex];
  57.  
  58. for (int j = 0; j < 4; j++)
  59. {
  60. if (vArray[ai_weight->mVertexId].weights[j] == 0.0)
  61. {
  62. vArray[ai_weight->mVertexId].bone_id[j] = boneIndex;
  63. vArray[ai_weight->mVertexId].weights[j] = ai_weight->mWeight;
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. }
  70.  
  71. char* Mesh::StringCopy(const char* name)
  72. {
  73. return (char*)name;
  74. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:6: error: 'Mesh' has not been declared
 void Mesh::Init(std::string filename)
      ^
prog.cpp:1:22: error: variable or field 'Init' declared void
 void Mesh::Init(std::string filename)
                      ^
prog.cpp:1:17: error: 'string' is not a member of 'std'
 void Mesh::Init(std::string filename)
                 ^
stdout
Standard output is empty