@@ -12,15 +12,22 @@ struct Position {
1212};
1313
1414std::vector<Position> positions;
15+ std::vector<Position> normals;
1516std::vector<uint32_t > indices;
1617
1718void processMesh (aiMesh* mesh, const aiScene* scene) {
1819 for (unsigned int i = 0 ; i < mesh->mNumVertices ; i++) {
19- Position vertex;
20- vertex.x = mesh->mVertices [i].x ;
21- vertex.y = mesh->mVertices [i].y ;
22- vertex.z = mesh->mVertices [i].z ;
23- positions.push_back (vertex);
20+ Position position;
21+ position.x = mesh->mVertices [i].x ;
22+ position.y = mesh->mVertices [i].y ;
23+ position.z = mesh->mVertices [i].z ;
24+ positions.push_back (position);
25+
26+ Position normal;
27+ normal.x = mesh->mNormals [i].x ;
28+ normal.y = mesh->mNormals [i].y ;
29+ normal.z = mesh->mNormals [i].z ;
30+ normals.push_back (normal);
2431 }
2532
2633 for (unsigned int i = 0 ; i < mesh->mNumFaces ; i++) {
@@ -65,7 +72,7 @@ int main(int argc, char** argv) {
6572 }
6673
6774 Assimp::Importer importer;
68- const aiScene* scene = importer.ReadFile (argv[argc-1 ], aiProcess_Triangulate | aiProcess_OptimizeMeshes | aiProcess_OptimizeGraph | aiProcess_JoinIdenticalVertices | aiProcess_ImproveCacheLocality);
75+ const aiScene* scene = importer.ReadFile (argv[argc-1 ], aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_OptimizeMeshes | aiProcess_OptimizeGraph | aiProcess_JoinIdenticalVertices | aiProcess_ImproveCacheLocality);
6976 if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE, !scene->mRootNode ) {
7077 std::cout << " Error while loading model with assimp: " << importer.GetErrorString () << std::endl;
7178 return 1 ;
@@ -87,6 +94,10 @@ int main(int argc, char** argv) {
8794 output.write ((char *)&positions[i].x , sizeof (float ));
8895 output.write ((char *)&positions[i].y , sizeof (float ));
8996 output.write ((char *)&positions[i].z , sizeof (float ));
97+
98+ output.write ((char *)&normals[i].x , sizeof (float ));
99+ output.write ((char *)&normals[i].y , sizeof (float ));
100+ output.write ((char *)&normals[i].z , sizeof (float ));
90101 }
91102 for (uint64_t i = 0 ; i < numIndices; i++) {
92103 output.write ((char *)&indices[i], sizeof (uint32_t ));
0 commit comments