diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index 4bad638e2..3a8bb868e 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -958,19 +958,41 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co } // ------------------------------------------------------------------------------------------------ -aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* /*obj*/, const Camera* /*mesh*/, ConversionData& /*conv_data*/) +aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, const Camera* camera, ConversionData& /*conv_data*/) { ScopeGuard out(new aiCamera()); - - return NULL ; //out.dismiss(); + out->mName = obj->id.name+2; + out->mPosition = aiVector3D(0.f, 0.f, 0.f); + out->mUp = aiVector3D(0.f, 1.f, 0.f); + out->mLookAt = aiVector3D(0.f, 0.f, -1.f); + return out.dismiss(); } // ------------------------------------------------------------------------------------------------ -aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* /*obj*/, const Lamp* /*mesh*/, ConversionData& /*conv_data*/) +aiLight* BlenderImporter::ConvertLight(const Scene& in, const Object* obj, const Lamp* lamp, ConversionData& conv_data) { ScopeGuard out(new aiLight()); + out->mName = obj->id.name+2; - return NULL ; //out.dismiss(); + switch (lamp->type) + { + case Lamp::Type_Local: + out->mType = aiLightSource_POINT; + break; + case Lamp::Type_Sun: + out->mType = aiLightSource_DIRECTIONAL; + + // blender orients directional lights as facing toward -z + out->mDirection = aiVector3D(0.f, 0.f, -1.f); + break; + default: + break; + } + + out->mColorAmbient = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; + out->mColorSpecular = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; + out->mColorDiffuse = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; + return out.dismiss(); } // ------------------------------------------------------------------------------------------------ diff --git a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp index 83d47795f..42f468ea1 100644 --- a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp +++ b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp @@ -36,9 +36,8 @@ #include "assimp/LogStream.hpp" -// currently these are hardcoded -static const std::string basepath = "../../test/models/OBJ/"; -static const std::string modelname = "spider.obj"; +// The default hardcoded path. Can be overridden by supplying a path through the commandline. +static std::string modelpath = "../../test/models/OBJ/spider.obj"; HGLRC hRC=NULL; // Permanent Rendering Context @@ -165,6 +164,11 @@ void ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize Th } +std::string getBasePath(const std::string& path) +{ + size_t pos = path.find_last_of("\\/"); + return (std::string::npos == pos) ? "" : path.substr(0, pos + 1); +} int LoadGLTextures(const aiScene* scene) { @@ -220,6 +224,7 @@ int LoadGLTextures(const aiScene* scene) /* get iterator */ std::map::iterator itr = textureIdMap.begin(); + std::string basepath = getBasePath(modelpath); for (int i=0; i 1) + { + std::wstring modelpathW(argv[1]); + modelpath = std::string(modelpathW.begin(), modelpathW.end()); + } - if (!Import3DFromFile(basepath+modelname)) return 0; + if (!Import3DFromFile(modelpath)) return 0; logInfo("=============== Post Import ===================="); - - // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL, "Would You Like To Run In Fullscreen Mode?", "Start Fullscreen?", MB_YESNO|MB_ICONEXCLAMATION)==IDNO) { - fullscreen=FALSE; // Windowed Mode + fullscreen=FALSE; } - // Create Our OpenGL Window (also calls GLinit und LoadGLTextures) if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { return 0; } - - - while(!done) // Game Loop { - if (PeekMessage(&msg, NULL, 0,0, PM_REMOVE)) // Is There A Message Waiting + if (PeekMessage(&msg, NULL, 0,0, PM_REMOVE)) { - if (msg.message==WM_QUIT) // Have we received A Quit Message? + if (msg.message==WM_QUIT) { - done=TRUE; // If So done=TRUE + done=TRUE; } else { - TranslateMessage(&msg); // Translate The Message - DispatchMessage(&msg); // Dispatch The Message + TranslateMessage(&msg); + DispatchMessage(&msg); } } else @@ -852,26 +857,25 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance // Draw The Scene. Watch For ESC Key And Quit Messaged From DrawGLScene() if (active) { - if (keys[VK_ESCAPE]) // Was ESC pressed? + if (keys[VK_ESCAPE]) { - done=TRUE; // ESC signalled A quit + done=TRUE; } else { - DrawGLScene(); // Draw The Scene - SwapBuffers(hDC); // Swap Buffers (Double Buffering) + DrawGLScene(); + SwapBuffers(hDC); } } - if (keys[VK_F1]) // Is F1 Being Pressed? + if (keys[VK_F1]) { - keys[VK_F1]=FALSE; // If so make Key FALSE - KillGLWindow(); // Kill Our Current Window - fullscreen=!fullscreen; // Toggle Fullscreen - //recreate Our OpenGL Window + keys[VK_F1]=FALSE; + KillGLWindow(); + fullscreen=!fullscreen; if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { - return 0; // Quit if Window Was Not Created + return 0; } } } @@ -879,10 +883,8 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance // *** cleanup *** - // clear map textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) - // clear texture ids if (textureIds) { delete[] textureIds; @@ -891,8 +893,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance // *** cleanup end *** - // Shutdown destroyAILogger(); KillGLWindow(); - return (msg.wParam); // Exit The Program + return (msg.wParam); }