From 4df0cca212a3ab243c0422f88e0a103da88cfa85 Mon Sep 17 00:00:00 2001 From: Nodrev Date: Tue, 2 Jun 2015 22:37:22 +0200 Subject: [PATCH 1/3] Fixing geometryc for meshes exported without uv coordinates --- tools/geometryc/geometryc.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index ccf6a580..d55d4a2e 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -510,8 +510,8 @@ int main(int _argc, const char* _argv[]) for (uint32_t edge = 0, numEdges = argc-1; edge < numEdges; ++edge) { Index3 index; - index.m_texcoord = 0; - index.m_normal = 0; + index.m_texcoord = -1; + index.m_normal = -1; index.m_vertexIndex = -1; char* vertex = argv[edge+1]; @@ -528,8 +528,12 @@ int main(int _argc, const char* _argv[]) index.m_normal = (nn < 0) ? nn+numNormals : nn-1; } - const int tex = atoi(texcoord); - index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1; + // https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vertex_Normal_Indices_Without_Texture_Coordinate_Indices + if(*texcoord != '\0') + { + const int tex = atoi(texcoord); + index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1; + } } const int pos = atoi(vertex); @@ -716,8 +720,8 @@ int main(int _argc, const char* _argv[]) bool hasTexcoord; { Index3Map::const_iterator it = indexMap.begin(); - hasNormal = 0 != it->second.m_normal; - hasTexcoord = 0 != it->second.m_texcoord; + hasNormal = -1 != it->second.m_normal; + hasTexcoord = -1 != it->second.m_texcoord; if (!hasTexcoord && texcoords.size() == positions.size() ) From aa99fe13139d76bade39203c26b430f172efb8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 2 Jun 2015 14:28:22 -0700 Subject: [PATCH 2/3] Added ocornut-imgui key mapping. --- examples/common/entry/input.cpp | 20 +++++++++++++---- examples/common/entry/input.h | 3 +++ examples/common/imgui/ocornut_imgui.cpp | 29 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/examples/common/entry/input.cpp b/examples/common/entry/input.cpp index 2ee3b516..2f6933fd 100644 --- a/examples/common/entry/input.cpp +++ b/examples/common/entry/input.cpp @@ -89,10 +89,10 @@ struct Keyboard return state; } - static void decodeKeyState(uint32_t _state, uint8_t& _modifiers, bool& _down) + static bool decodeKeyState(uint32_t _state, uint8_t& _modifiers) { _modifiers = (_state>>16)&0xff; - _down = 0 != ( (_state>>8)&0xff); + return 0 != ( (_state>> 8)&0xff); } void setKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down) @@ -101,6 +101,14 @@ struct Keyboard m_once[_key] = false; } + bool getKeyState(entry::Key::Enum _key, uint8_t* _modifiers) + { + uint8_t modifiers; + _modifiers = NULL == _modifiers ? &modifiers : _modifiers; + + return decodeKeyState(m_key[_key], *_modifiers); + } + void pushChar(uint8_t _len, const uint8_t _char[4]) { for (uint32_t len = m_ring.reserve(4) @@ -196,8 +204,7 @@ struct Input for (const InputBinding* binding = _bindings; binding->m_key != entry::Key::None; ++binding) { uint8_t modifiers; - bool down; - Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers, down); + bool down = Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers); if (binding->m_flags == 1) { @@ -302,6 +309,11 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down) s_input->m_keyboard.setKeyState(_key, _modifiers, _down); } +bool inputGetKeyState(entry::Key::Enum _key, uint8_t* _modifiers) +{ + return s_input->m_keyboard.getKeyState(_key, _modifiers); +} + void inputChar(uint8_t _len, const uint8_t _char[4]) { s_input->m_keyboard.pushChar(_len, _char); diff --git a/examples/common/entry/input.h b/examples/common/entry/input.h index c3f7ef18..f18b899b 100644 --- a/examples/common/entry/input.h +++ b/examples/common/entry/input.h @@ -39,6 +39,9 @@ void inputProcess(); /// void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down); +/// +bool inputGetKeyState(entry::Key::Enum _key, uint8_t* _modifiers = NULL); + /// Adds single UTF-8 encoded character into input buffer. void inputChar(uint8_t _len, const uint8_t _char[4]); diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index 820cbc3c..7cc6448b 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "../entry/input.h" #include "imgui.h" #include "ocornut_imgui.h" #include @@ -61,6 +62,11 @@ struct OcornutImguiContext uint32_t vtx_offset = 0; for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++) { + if (0 == pcmd->vtx_count) + { + continue; + } + bgfx::setState(0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE @@ -105,6 +111,11 @@ struct OcornutImguiContext io.IniFilename = NULL; // io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? -0.5f : 0.0f; + for (uint32_t ii = 0; ii < ImGuiKey_COUNT; ++ii) + { + io.KeyMap[ii] = ImGuiKey_(ii); + } + const bgfx::Memory* vsmem; const bgfx::Memory* fsmem; @@ -182,6 +193,24 @@ struct OcornutImguiContext io.MousePos = ImVec2((float)_mx, (float)_my); io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT); + io.KeysDown[ImGuiKey_Tab] = inputGetKeyState(entry::Key::Tab); + io.KeysDown[ImGuiKey_LeftArrow] = inputGetKeyState(entry::Key::Left); + io.KeysDown[ImGuiKey_RightArrow] = inputGetKeyState(entry::Key::Right); + io.KeysDown[ImGuiKey_UpArrow] = inputGetKeyState(entry::Key::Up); + io.KeysDown[ImGuiKey_DownArrow] = inputGetKeyState(entry::Key::Down); + io.KeysDown[ImGuiKey_Home] = inputGetKeyState(entry::Key::Home); + io.KeysDown[ImGuiKey_End] = inputGetKeyState(entry::Key::End); + io.KeysDown[ImGuiKey_Delete] = inputGetKeyState(entry::Key::Delete); + io.KeysDown[ImGuiKey_Backspace] = inputGetKeyState(entry::Key::Backspace); + io.KeysDown[ImGuiKey_Enter] = inputGetKeyState(entry::Key::Return); + io.KeysDown[ImGuiKey_Escape] = inputGetKeyState(entry::Key::Esc); + io.KeysDown[ImGuiKey_A] = inputGetKeyState(entry::Key::KeyA); + io.KeysDown[ImGuiKey_C] = inputGetKeyState(entry::Key::KeyC); + io.KeysDown[ImGuiKey_V] = inputGetKeyState(entry::Key::KeyV); + io.KeysDown[ImGuiKey_X] = inputGetKeyState(entry::Key::KeyX); + io.KeysDown[ImGuiKey_Y] = inputGetKeyState(entry::Key::KeyY); + io.KeysDown[ImGuiKey_Z] = inputGetKeyState(entry::Key::KeyZ); + ImGui::NewFrame(); //ImGui::ShowTestWindow(); //Debug only. From 32750a682499db7689f88a61b0ee279842900c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 2 Jun 2015 19:25:37 -0700 Subject: [PATCH 3/3] Removed imgui dependency on input. --- examples/common/imgui/ocornut_imgui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index 7cc6448b..aab12370 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -7,7 +7,6 @@ #include #include #include -#include "../entry/input.h" #include "imgui.h" #include "ocornut_imgui.h" #include @@ -193,6 +192,7 @@ struct OcornutImguiContext io.MousePos = ImVec2((float)_mx, (float)_my); io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT); +#if 0 io.KeysDown[ImGuiKey_Tab] = inputGetKeyState(entry::Key::Tab); io.KeysDown[ImGuiKey_LeftArrow] = inputGetKeyState(entry::Key::Left); io.KeysDown[ImGuiKey_RightArrow] = inputGetKeyState(entry::Key::Right); @@ -210,6 +210,7 @@ struct OcornutImguiContext io.KeysDown[ImGuiKey_X] = inputGetKeyState(entry::Key::KeyX); io.KeysDown[ImGuiKey_Y] = inputGetKeyState(entry::Key::KeyY); io.KeysDown[ImGuiKey_Z] = inputGetKeyState(entry::Key::KeyZ); +#endif // 0 ImGui::NewFrame();