added framework to figure out the input and output filenames and load the input file into an Assimp scene object

This commit is contained in:
gered 2011-04-27 09:42:06 -04:00
parent 61f67a9f34
commit 9e8b06fa9d
5 changed files with 82 additions and 1 deletions

View file

@ -81,6 +81,10 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\utils\fileutils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\utils\utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -18,5 +18,13 @@
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\utils\fileutils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\utils\utils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -1,7 +1,50 @@
#include <stdio.h>
#include <string>
#include <exception>
#include <assimp.hpp>
#include <aiScene.h>
#include <aiPostProcess.h>
#include "utils/utils.h"
int main(int argc, char *argv[])
{
printf("Hello world!\n");
printf("ASSIMP-to-MESH Converter.\n");
if (argc == 1)
{
printf("Usage: assimptomesh.exe [inputfile]\n\n");
return 0;
}
std::string file = argv[1];
std::string outputFile = GetMeshFilenameFromInput(file);
if (outputFile.length() == 0)
{
printf("Unable to determine output mesh filename from the input file name.\n\n");
return 1;
}
printf("Input file: %s\n", file.c_str());
printf("Output file: %s\n", outputFile.c_str());
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(file,
aiProcess_JoinIdenticalVertices |
aiProcess_Triangulate |
aiProcess_RemoveRedundantMaterials |
aiProcess_SortByPType |
aiProcess_OptimizeMeshes |
aiProcess_OptimizeGraph
);
if (!scene)
{
printf("Failed to load input file: %s\n\n", importer.GetErrorString());
return 1;
}
return 0;
}

View file

@ -0,0 +1,18 @@
#include "utils.h"
#include <stdio.h>
std::string GetMeshFilenameFromInput(const std::string &filename)
{
std::string meshFilename = "";
// strip off the existing extension, and replace it with ".mesh"
size_t extStart = filename.find_last_of('.');
if (extStart != std::string::npos)
{
meshFilename = filename.substr(0, extStart);
meshFilename += ".mesh";
}
return meshFilename;
}

View file

@ -0,0 +1,8 @@
#ifndef __UTILS_UTILS_H_INCLUDED__
#define __UTILS_UTILS_H_INCLUDED__
#include <string>
std::string GetMeshFilenameFromInput(const std::string &filename);
#endif