├── example ├── addons.make └── src │ ├── main.cpp │ ├── ofApp.h │ └── ofApp.cpp ├── .gitmodules ├── readme.md ├── addon_config.mk ├── license.md └── src └── ofxImGuizmo.h /example/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | ofxImGuizmo 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/ImGuizmo"] 2 | path = libs/ImGuizmo 3 | url = git@github.com:CedricGuillemet/ImGuizmo.git 4 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ofxImGuizmo 2 | 3 | an openFrameworks wrapper of [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo) 4 | 5 | ## setup 6 | 7 | 1. clone this repository 8 | 1. init and update submodule `git submodule update --init` 9 | 10 | ## dependencies 11 | 12 | ### [ofxImGui](https://github.com/jvcleave/ofxImGui) -------------------------------------------------------------------------------- /example/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | 4 | //======================================================================== 5 | int main( ){ 6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context 7 | 8 | // this kicks off the running of my app 9 | // can be OF_WINDOW or OF_FULLSCREEN 10 | // pass in width and height too: 11 | ofRunApp(new ofApp()); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | meta: 2 | ADDON_NAME = ofxImGuizmo 3 | ADDON_DESCRIPTION = openFrameworks wrapper for ImGuizmo 4 | ADDON_AUTHOR = Nariaki Iwatani 5 | ADDON_TAGS = "ImGui" "dear ImGui" "gizmo" "LibGizmo" "ImGuizmo" 6 | ADDON_URL = https://github.com/nariakiiwatani/ofxImGuizmo 7 | 8 | common: 9 | ADDON_INCLUDES_EXCLUDE = libs/ImGuizmo/example% 10 | ADDON_INCLUDES_EXCLUDE += libs/ImGuizmo/bin% 11 | ADDON_SOURCES_EXCLUDE = libs/ImGuizmo/example% 12 | ADDON_SOURCES_EXCLUDE += libs/ImGuizmo/bin% 13 | ADDON_SOURCES_EXCLUDE += libs/ImGuizmo/vcpkg-example% 14 | -------------------------------------------------------------------------------- /example/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | #include "ofxImGui.h" 5 | #include "ofxImGuizmo.h" 6 | 7 | class ofApp : public ofBaseApp{ 8 | 9 | public: 10 | void setup(); 11 | void update(); 12 | void draw(); 13 | 14 | void keyPressed(int key); 15 | void keyReleased(int key); 16 | void mouseMoved(int x, int y ); 17 | void mouseDragged(int x, int y, int button); 18 | void mousePressed(int x, int y, int button); 19 | void mouseReleased(int x, int y, int button); 20 | void mouseEntered(int x, int y); 21 | void mouseExited(int x, int y); 22 | void windowResized(int w, int h); 23 | void dragEvent(ofDragInfo dragInfo); 24 | void gotMessage(ofMessage msg); 25 | private: 26 | ofCamera cam_; 27 | ImGuizmo::OPERATION op_; 28 | ImGuizmo::MODE mode_; 29 | ofNode node_; 30 | ofxImGui::Gui gui_; 31 | }; 32 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | Copyright 2020 nariakiiwatani 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /example/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | #include 3 | 4 | 5 | //-------------------------------------------------------------- 6 | void ofApp::setup(){ 7 | gui_.setup(); 8 | cam_.setPosition({0,0,100}); 9 | cam_.lookAt({0,0,0}); 10 | } 11 | 12 | //-------------------------------------------------------------- 13 | void ofApp::update(){ 14 | 15 | } 16 | 17 | //-------------------------------------------------------------- 18 | void ofApp::draw(){ 19 | cam_.begin(); 20 | node_.draw(); 21 | cam_.end(); 22 | 23 | gui_.begin(); 24 | ImGuizmo::BeginFrame(); 25 | ImGuizmo::Manipulate(cam_, node_, op_, mode_); 26 | gui_.end(); 27 | } 28 | 29 | //-------------------------------------------------------------- 30 | void ofApp::keyPressed(int key){ 31 | switch(key) { 32 | case 'w': op_ = ImGuizmo::TRANSLATE; break; 33 | case 'e': op_ = ImGuizmo::SCALE; break; 34 | case 'r': op_ = ImGuizmo::ROTATE; break; 35 | case ' ': mode_ = mode_==ImGuizmo::LOCAL?ImGuizmo::WORLD:ImGuizmo::LOCAL; break; 36 | } 37 | } 38 | 39 | //-------------------------------------------------------------- 40 | void ofApp::keyReleased(int key){ 41 | 42 | } 43 | 44 | //-------------------------------------------------------------- 45 | void ofApp::mouseMoved(int x, int y ){ 46 | 47 | } 48 | 49 | //-------------------------------------------------------------- 50 | void ofApp::mouseDragged(int x, int y, int button){ 51 | 52 | } 53 | 54 | //-------------------------------------------------------------- 55 | void ofApp::mousePressed(int x, int y, int button){ 56 | 57 | } 58 | 59 | //-------------------------------------------------------------- 60 | void ofApp::mouseReleased(int x, int y, int button){ 61 | 62 | } 63 | 64 | //-------------------------------------------------------------- 65 | void ofApp::mouseEntered(int x, int y){ 66 | 67 | } 68 | 69 | //-------------------------------------------------------------- 70 | void ofApp::mouseExited(int x, int y){ 71 | 72 | } 73 | 74 | //-------------------------------------------------------------- 75 | void ofApp::windowResized(int w, int h){ 76 | 77 | } 78 | 79 | //-------------------------------------------------------------- 80 | void ofApp::gotMessage(ofMessage msg){ 81 | 82 | } 83 | 84 | //-------------------------------------------------------------- 85 | void ofApp::dragEvent(ofDragInfo dragInfo){ 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/ofxImGuizmo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxImGui.h" 4 | #include "ImGuizmo.h" 5 | #include "ofCamera.h" 6 | #include "ofNode.h" 7 | #include 8 | #include "imgui_internal.h" 9 | 10 | namespace { 11 | static void applyLocalTransformMatrix(ofNode &node, const glm::mat4 &mat) { 12 | glm::vec3 scale; 13 | glm::quat rotation; 14 | glm::vec3 translation; 15 | glm::vec3 skew; 16 | glm::vec4 perspective; 17 | glm::decompose(mat, scale, rotation, translation, skew, perspective); 18 | 19 | node.setPosition(translation); 20 | node.setOrientation(rotation); 21 | node.setScale(scale); 22 | } 23 | static void applyWorldTransformMatrix(ofNode &node, const glm::mat4 &mat) { 24 | glm::vec3 scale; 25 | glm::quat rotation; 26 | glm::vec3 translation; 27 | glm::vec3 skew; 28 | glm::vec4 perspective; 29 | glm::decompose(mat, scale, rotation, translation, skew, perspective); 30 | 31 | node.setGlobalPosition(translation); 32 | node.setGlobalOrientation(rotation); 33 | node.setScale(scale/(node.getParent()?node.getParent()->getGlobalScale():glm::vec3{1,1,1})); 34 | } 35 | static ofRectangle getViewport(const ofCamera &cam) { 36 | class MyCamera : public ofCamera { 37 | public: 38 | MyCamera(const ofCamera &cam):ofCamera(cam){} 39 | using ofCamera::getViewport; 40 | }; 41 | return MyCamera(cam).getViewport(); 42 | } 43 | } 44 | 45 | namespace ImGuizmo 46 | { 47 | static bool Manipulate(const ofCamera &camera, glm::mat4 &matrix, OPERATION operation, MODE mode, const ofRectangle *viewvolume=nullptr, glm::mat4 *delta_matrix=nullptr, const float *snap = nullptr, const float *localBounds = nullptr, const float *boundsSnap = nullptr) { 48 | auto viewport = viewvolume ? *viewvolume : getViewport(camera); 49 | ImGuizmo::SetRect(viewport.x, viewport.y, viewport.width, viewport.height); 50 | auto view = glm::inverse(camera.getGlobalTransformMatrix()); 51 | auto proj = camera.getProjectionMatrix(viewport); 52 | ImGuizmo::SetOrthographic(camera.getOrtho()); 53 | return ImGuizmo::Manipulate(&view[0][0], &proj[0][0], operation, mode, &matrix[0][0], delta_matrix?&((*delta_matrix)[0][0]):nullptr, snap, localBounds, boundsSnap); 54 | } 55 | static bool Manipulate(const ofCamera &camera, ofNode &node, OPERATION operation, MODE mode, const ofRectangle *viewvolume=nullptr, glm::mat4 *delta_matrix=nullptr, const float *snap = nullptr, const float *localBounds = nullptr, const float *boundsSnap = nullptr) { 56 | auto matrix = node.getGlobalTransformMatrix(); 57 | if(Manipulate(camera, matrix, operation, mode, viewvolume, delta_matrix, snap, localBounds, boundsSnap)) { 58 | applyWorldTransformMatrix(node, matrix); 59 | return true; 60 | } 61 | return false; 62 | } 63 | static bool ViewManipulate(ofNode &node, float eye_length, const ofRectangle &pos_size, const ofColor &bg_color) { 64 | auto view = glm::inverse(node.getGlobalTransformMatrix()); 65 | auto view_cache = view; 66 | auto colorToHex = [](const ofColor &color) -> ImU32 { 67 | return color.a<<24|color.getHex(); 68 | }; 69 | ViewManipulate(&view[0][0], eye_length, ImVec2(pos_size.x, pos_size.y), ImVec2(pos_size.width, pos_size.height), colorToHex(bg_color)); 70 | if(view != view_cache) { 71 | applyLocalTransformMatrix(node, glm::inverse(view)); 72 | return true; 73 | } 74 | return false; 75 | } 76 | } 77 | --------------------------------------------------------------------------------