diff --git a/include/assimp/types.h b/include/assimp/types.h index a41363b8a..be2aad18b 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -57,6 +57,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#ifdef ASSIMP_USE_HUNTER +#include +#else +#include "../contrib/utf8cpp/source/utf8.h" +#endif + // Our compile configuration #include diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp index 7f0d0c84e..4da5820a1 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp @@ -13,6 +13,8 @@ // Written by IAS. :) // --------------------------------------------------------------------------- +#include + #include #include #include @@ -21,11 +23,7 @@ #include #include #include -#ifdef ASSIMP_USE_HUNTER -#include -#else -#include "../contrib/utf8cpp/source/utf8.h" -#endif + #include "ModelLoader.h" #include "SafeRelease.hpp" @@ -53,10 +51,10 @@ struct ConstantBuffer { // ------------------------------------------------------------ // Window Variables // ------------------------------------------------------------ -#define SCREEN_WIDTH 800 -#define SCREEN_HEIGHT 600 +static constexpr uint32_t SCREEN_WIDTH = 800; +static constexpr uint32_t SCREEN_HEIGHT = 600; -const char g_szClassName[] = "directxWindowClass"; +constexpr char g_szClassName[] = "directxWindowClass"; static std::string g_ModelPath; diff --git a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp index 48066f189..2eb73b403 100644 --- a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp +++ b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp @@ -41,15 +41,14 @@ #include #include #include -#include "UTFConverter.h" // The default hard-coded path. Can be overridden by supplying a path through the command line. static std::string modelpath = "../../test/models/OBJ/spider.obj"; -HGLRC hRC=nullptr; // Permanent Rendering Context -HDC hDC=nullptr; // Private GDI Device Context -HWND g_hWnd=nullptr; // Holds Window Handle -HINSTANCE g_hInstance=nullptr; // Holds The Instance Of The Application +HGLRC hRC = nullptr; // Permanent Rendering Context +HDC hDC = nullptr; // Private GDI Device Context +HWND g_hWnd = nullptr; // Holds Window Handle +HINSTANCE g_hInstance = nullptr; // Holds The Instance Of The Application bool keys[256]; // Array used for Keyboard Routine; bool active=TRUE; // Window Active Flag Set To TRUE by Default @@ -69,8 +68,6 @@ GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat LightPosition[]= { 0.0f, 0.0f, 15.0f, 1.0f }; - - // the global Assimp scene object const aiScene* g_scene = nullptr; GLuint scene_list = 0; @@ -83,12 +80,8 @@ GLuint* textureIds; // pointer to texture Array // Create an instance of the Importer class Assimp::Importer importer; -using namespace AssimpSamples::SharedCode; - -void createAILogger() -{ - // Change this line to normal if you not want to analyse the import process - //Assimp::Logger::LogSeverity severity = Assimp::Logger::NORMAL; +void createAILogger() { + // Change this line to normal if you not want to analyze the import process Assimp::Logger::LogSeverity severity = Assimp::Logger::VERBOSE; // Create a logger instance for Console Output @@ -101,62 +94,52 @@ void createAILogger() Assimp::DefaultLogger::get()->info("this is my info-call"); } -void destroyAILogger() -{ - // Kill it after the work is done +void destroyAILogger() { Assimp::DefaultLogger::kill(); } -void logInfo(std::string logString) -{ - // Will add message to File with "info" Tag +void logInfo(const std::string &logString) { Assimp::DefaultLogger::get()->info(logString.c_str()); } -void logDebug(const char* logString) -{ - // Will add message to File with "debug" Tag +void logDebug(const char* logString) { Assimp::DefaultLogger::get()->debug(logString); } -bool Import3DFromFile( const std::string& pFile) -{ +bool Import3DFromFile( const std::string &filename) { // Check if file exists - std::ifstream fin(pFile.c_str()); - if(!fin.fail()) - { - fin.close(); + std::ifstream fin(filename.c_str()); + if(fin.fail()) { + std::string message = "Couldn't open file: " + filename; + std::wstring targetMessage; + //utf8::utf8to16(message.c_str(), message.c_str() + message.size(), targetMessage); + ::MessageBox(nullptr, targetMessage.c_str(), L"Error", MB_OK | MB_ICONEXCLAMATION); + logInfo(importer.GetErrorString()); + return false; } - else - { - MessageBox(nullptr, UTFConverter("Couldn't open file: " + pFile).c_wstr() , TEXT("ERROR"), MB_OK | MB_ICONEXCLAMATION); - logInfo( importer.GetErrorString()); - return false; - } - - g_scene = importer.ReadFile(pFile, aiProcessPreset_TargetRealtime_Quality); + + fin.close(); + + g_scene = importer.ReadFile(filename, aiProcessPreset_TargetRealtime_Quality); // If the import failed, report it - if(!g_scene) - { + if (g_scene == nullptr) { logInfo( importer.GetErrorString()); return false; } // Now we can access the file's contents. - logInfo("Import of scene " + pFile + " succeeded."); + logInfo("Import of scene " + filename + " succeeded."); // We're done. Everything will be cleaned up by the importer destructor return true; } // Resize And Initialize The GL Window -void ReSizeGLScene(GLsizei width, GLsizei height) -{ +void ReSizeGLScene(GLsizei width, GLsizei height) { // Prevent A Divide By Zero By - if (height==0) - { + if (height == 0) { // Making Height Equal One height=1; } @@ -174,43 +157,26 @@ void ReSizeGLScene(GLsizei width, GLsizei height) } -std::string getBasePath(const std::string& path) -{ +std::string getBasePath(const std::string& path) { size_t pos = path.find_last_of("\\/"); return (std::string::npos == pos) ? "" : path.substr(0, pos + 1); } -void freeTextureIds() -{ - textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) +void freeTextureIds() { + // no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) + textureIdMap.clear(); - if (textureIds) - { + if (textureIds) { delete[] textureIds; textureIds = nullptr; } } -int LoadGLTextures(const aiScene* scene) -{ +int LoadGLTextures(const aiScene* scene) { freeTextureIds(); - //ILboolean success; - - /* Before calling ilInit() version should be checked. */ - /*if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) - { - /// wrong DevIL version /// - std::string err_msg = "Wrong DevIL version. Old devil.dll in system32/SysWow64?"; - char* cErr_msg = (char *) err_msg.c_str(); - abortGLInit(cErr_msg); - return -1; - }*/ - - //ilInit(); /* Initialization of DevIL */ - - if (scene->HasTextures()) return 1; - //abortGLInit("Support for meshes with embedded textures is not implemented"); + if (scene->HasTextures()) + return 1; /* getTexture Filenames and Numb of Textures */ for (unsigned int m=0; mmNumMaterials; m++) @@ -230,14 +196,6 @@ int LoadGLTextures(const aiScene* scene) const size_t numTextures = textureIdMap.size(); - - /* array with DevIL image IDs */ - //ILuint* imageIds = NULL; -// imageIds = new ILuint[numTextures]; - - /* generate DevIL Image IDs */ -// ilGenImages(numTextures, imageIds); /* Generation of numTextures image names */ - /* create and fill array with GL texture ids */ textureIds = new GLuint[numTextures]; glGenTextures(static_cast(numTextures), textureIds); /* Texture name generation */ @@ -248,29 +206,17 @@ int LoadGLTextures(const aiScene* scene) std::string basepath = getBasePath(modelpath); for (size_t i=0; i 1) { std::wstring modelpathW(argv[1]); - modelpath = UTFConverter(modelpathW).str(); + utf8::utf16to8(modelpathW.c_str(), modelpathW.c_str() + modelpathW.size(), back_inserter(modelpath)); } if (!Import3DFromFile(modelpath))