From 2fb07823f1b66b8f812d96a5b82d1cc69199f049 Mon Sep 17 00:00:00 2001 From: Calvin Hsu Date: Tue, 1 Oct 2013 13:21:26 -0700 Subject: [PATCH 1/2] Add basic light and camera support * Convert point and directional light * Convert perspective camera Not suppoted: * Spotlight, area lights * Perspective camera fov angle / focal length * Orthogonal camera --- code/BlenderLoader.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) 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(); } // ------------------------------------------------------------------------------------------------ From 4328636d145d304372327ebfa5be93dd00e1f063 Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Wed, 2 Oct 2013 17:54:30 -0700 Subject: [PATCH 2/2] Allow commandline-supplied model path for the SimpledTexturedOGL sample Currently, the path to the model in the sample is hardcoded. Allow the user to provide a model path via the command line for the sample, and remove a few redundant comments. --- .../src/model_loading.cpp | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) 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); }