mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-06 22:47:32 -06:00
QoL: 3D navigator (#4181)
* Initial integration of ImGuizmo * Fix mouse capture * Fix frame update * Update face color * Show current camera rotation * Fix coord mapping * Update camera rotation from 3d navigator * Use orthographic * Render axis * Make the axis color lighter if at back * Show axis label * Fix linux build * Move to separate method * Refine * Add option to show/hide 3d navigator * Add license info * Handle dpi scaling --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
parent
4991a3d312
commit
bf4d59a676
15 changed files with 3695 additions and 1 deletions
|
@ -26,6 +26,7 @@ add_subdirectory(libslic3r)
|
||||||
|
|
||||||
if (SLIC3R_GUI)
|
if (SLIC3R_GUI)
|
||||||
add_subdirectory(imgui)
|
add_subdirectory(imgui)
|
||||||
|
add_subdirectory(imguizmo)
|
||||||
add_subdirectory(hidapi)
|
add_subdirectory(hidapi)
|
||||||
include_directories(hidapi/include)
|
include_directories(hidapi/include)
|
||||||
|
|
||||||
|
|
9
src/imguizmo/CMakeLists.txt
Normal file
9
src/imguizmo/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
project(imguizmo)
|
||||||
|
|
||||||
|
add_library(imguizmo STATIC
|
||||||
|
ImGuizmo.h
|
||||||
|
ImGuizmo.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(imguizmo PRIVATE imgui)
|
3093
src/imguizmo/ImGuizmo.cpp
Normal file
3093
src/imguizmo/ImGuizmo.cpp
Normal file
File diff suppressed because it is too large
Load diff
282
src/imguizmo/ImGuizmo.h
Normal file
282
src/imguizmo/ImGuizmo.h
Normal file
|
@ -0,0 +1,282 @@
|
||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v 1.89 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// 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 :
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// History :
|
||||||
|
// 2019/11/03 View gizmo
|
||||||
|
// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode.
|
||||||
|
// 2016/09/09 Hatched negative axis. Snapping. Documentation update.
|
||||||
|
// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved
|
||||||
|
// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results.
|
||||||
|
// 2016/08/31 First version
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Future (no order):
|
||||||
|
//
|
||||||
|
// - Multi view
|
||||||
|
// - display rotation/translation/scale infos in local/world space and not only local
|
||||||
|
// - finish local/world matrix application
|
||||||
|
// - OPERATION as bitmask
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Example
|
||||||
|
#if 0
|
||||||
|
void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||||
|
{
|
||||||
|
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||||
|
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||||
|
if (ImGui::IsKeyPressed(90))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
if (ImGui::IsKeyPressed(69))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
if (ImGui::IsKeyPressed(82)) // r Key
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||||
|
|
||||||
|
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||||
|
{
|
||||||
|
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||||
|
}
|
||||||
|
static bool useSnap(false);
|
||||||
|
if (ImGui::IsKeyPressed(83))
|
||||||
|
useSnap = !useSnap;
|
||||||
|
ImGui::Checkbox("", &useSnap);
|
||||||
|
ImGui::SameLine();
|
||||||
|
vec_t snap;
|
||||||
|
switch (mCurrentGizmoOperation)
|
||||||
|
{
|
||||||
|
case ImGuizmo::TRANSLATE:
|
||||||
|
snap = config.mSnapTranslation;
|
||||||
|
ImGui::InputFloat3("Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::ROTATE:
|
||||||
|
snap = config.mSnapRotation;
|
||||||
|
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::SCALE:
|
||||||
|
snap = config.mSnapScale;
|
||||||
|
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||||
|
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef USE_IMGUI_API
|
||||||
|
#include "imconfig.h"
|
||||||
|
#endif
|
||||||
|
#ifndef IMGUI_API
|
||||||
|
#define IMGUI_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IMGUIZMO_NAMESPACE
|
||||||
|
#define IMGUIZMO_NAMESPACE ImGuizmo
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace IMGUIZMO_NAMESPACE
|
||||||
|
{
|
||||||
|
// call inside your own window and before Manipulate() in order to draw gizmo to that window.
|
||||||
|
// Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()).
|
||||||
|
IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr);
|
||||||
|
|
||||||
|
// call BeginFrame right after ImGui_XXXX_NewFrame();
|
||||||
|
IMGUI_API void BeginFrame();
|
||||||
|
|
||||||
|
// this is necessary because when imguizmo is compiled into a dll, and imgui into another
|
||||||
|
// globals are not shared between them.
|
||||||
|
// More details at https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam
|
||||||
|
// expose method to set imgui context
|
||||||
|
IMGUI_API void SetImGuiContext(ImGuiContext* ctx);
|
||||||
|
|
||||||
|
// return true if mouse cursor is over any gizmo control (axis, plan or screen component)
|
||||||
|
IMGUI_API bool IsOver();
|
||||||
|
|
||||||
|
// return true if mouse IsOver or if the gizmo is in moving state
|
||||||
|
IMGUI_API bool IsUsing();
|
||||||
|
|
||||||
|
// return true if any gizmo is in moving state
|
||||||
|
IMGUI_API bool IsUsingAny();
|
||||||
|
|
||||||
|
// enable/disable the gizmo. Stay in the state until next call to Enable.
|
||||||
|
// gizmo is rendered with gray half transparent color when disabled
|
||||||
|
IMGUI_API void Enable(bool enable);
|
||||||
|
|
||||||
|
// helper functions for manualy editing translation/rotation/scale with an input float
|
||||||
|
// translation, rotation and scale float points to 3 floats each
|
||||||
|
// Angles are in degrees (more suitable for human editing)
|
||||||
|
// example:
|
||||||
|
// float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
// ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
// ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
// ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
// ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
// ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
|
||||||
|
//
|
||||||
|
// These functions have some numerical stability issues for now. Use with caution.
|
||||||
|
IMGUI_API void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale);
|
||||||
|
IMGUI_API void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix);
|
||||||
|
|
||||||
|
IMGUI_API void SetRect(float x, float y, float width, float height);
|
||||||
|
// default is false
|
||||||
|
IMGUI_API void SetOrthographic(bool isOrthographic);
|
||||||
|
|
||||||
|
// Render a cube with face color corresponding to face normal. Usefull for debug/tests
|
||||||
|
IMGUI_API void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount);
|
||||||
|
IMGUI_API void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize);
|
||||||
|
|
||||||
|
// call it when you want a gizmo
|
||||||
|
// Needs view and projection matrices.
|
||||||
|
// matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional
|
||||||
|
// translation is applied in world space
|
||||||
|
enum OPERATION
|
||||||
|
{
|
||||||
|
TRANSLATE_X = (1u << 0),
|
||||||
|
TRANSLATE_Y = (1u << 1),
|
||||||
|
TRANSLATE_Z = (1u << 2),
|
||||||
|
ROTATE_X = (1u << 3),
|
||||||
|
ROTATE_Y = (1u << 4),
|
||||||
|
ROTATE_Z = (1u << 5),
|
||||||
|
ROTATE_SCREEN = (1u << 6),
|
||||||
|
SCALE_X = (1u << 7),
|
||||||
|
SCALE_Y = (1u << 8),
|
||||||
|
SCALE_Z = (1u << 9),
|
||||||
|
BOUNDS = (1u << 10),
|
||||||
|
SCALE_XU = (1u << 11),
|
||||||
|
SCALE_YU = (1u << 12),
|
||||||
|
SCALE_ZU = (1u << 13),
|
||||||
|
|
||||||
|
TRANSLATE = TRANSLATE_X | TRANSLATE_Y | TRANSLATE_Z,
|
||||||
|
ROTATE = ROTATE_X | ROTATE_Y | ROTATE_Z | ROTATE_SCREEN,
|
||||||
|
SCALE = SCALE_X | SCALE_Y | SCALE_Z,
|
||||||
|
SCALEU = SCALE_XU | SCALE_YU | SCALE_ZU, // universal
|
||||||
|
UNIVERSAL = TRANSLATE | ROTATE | SCALEU
|
||||||
|
};
|
||||||
|
|
||||||
|
inline OPERATION operator|(OPERATION lhs, OPERATION rhs)
|
||||||
|
{
|
||||||
|
return static_cast<OPERATION>(static_cast<int>(lhs) | static_cast<int>(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
enum MODE
|
||||||
|
{
|
||||||
|
LOCAL,
|
||||||
|
WORLD
|
||||||
|
};
|
||||||
|
|
||||||
|
IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL);
|
||||||
|
//
|
||||||
|
// Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
|
||||||
|
// It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
|
||||||
|
// other software are using the same mechanics. But just in case, you are now warned!
|
||||||
|
//
|
||||||
|
IMGUI_API bool ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
|
||||||
|
|
||||||
|
// use this version if you did not call Manipulate before and you are just using ViewManipulate
|
||||||
|
IMGUI_API bool ViewManipulate(float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
|
||||||
|
|
||||||
|
IMGUI_API void SetID(int id);
|
||||||
|
|
||||||
|
// return true if the cursor is over the operation's gizmo
|
||||||
|
IMGUI_API bool IsOver(OPERATION op);
|
||||||
|
IMGUI_API void SetGizmoSizeClipSpace(float value);
|
||||||
|
|
||||||
|
// Allow axis to flip
|
||||||
|
// When true (default), the guizmo axis flip for better visibility
|
||||||
|
// When false, they always stay along the positive world/local axis
|
||||||
|
IMGUI_API void AllowAxisFlip(bool value);
|
||||||
|
|
||||||
|
// Configure the limit where axis are hidden
|
||||||
|
IMGUI_API void SetAxisLimit(float value);
|
||||||
|
// Configure the limit where planes are hiden
|
||||||
|
IMGUI_API void SetPlaneLimit(float value);
|
||||||
|
|
||||||
|
enum COLOR
|
||||||
|
{
|
||||||
|
DIRECTION_X, // directionColor[0]
|
||||||
|
DIRECTION_Y, // directionColor[1]
|
||||||
|
DIRECTION_Z, // directionColor[2]
|
||||||
|
PLANE_X, // planeColor[0]
|
||||||
|
PLANE_Y, // planeColor[1]
|
||||||
|
PLANE_Z, // planeColor[2]
|
||||||
|
SELECTION, // selectionColor
|
||||||
|
INACTIVE, // inactiveColor
|
||||||
|
TRANSLATION_LINE, // translationLineColor
|
||||||
|
SCALE_LINE,
|
||||||
|
ROTATION_USING_BORDER,
|
||||||
|
ROTATION_USING_FILL,
|
||||||
|
HATCHED_AXIS_LINES,
|
||||||
|
TEXT,
|
||||||
|
TEXT_SHADOW,
|
||||||
|
COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Axis
|
||||||
|
{
|
||||||
|
Axis_X,
|
||||||
|
Axis_Y,
|
||||||
|
Axis_Z,
|
||||||
|
Axis_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Style
|
||||||
|
{
|
||||||
|
IMGUI_API Style();
|
||||||
|
|
||||||
|
float TranslationLineThickness; // Thickness of lines for translation gizmo
|
||||||
|
float TranslationLineArrowSize; // Size of arrow at the end of lines for translation gizmo
|
||||||
|
float RotationLineThickness; // Thickness of lines for rotation gizmo
|
||||||
|
float RotationOuterLineThickness; // Thickness of line surrounding the rotation gizmo
|
||||||
|
float ScaleLineThickness; // Thickness of lines for scale gizmo
|
||||||
|
float ScaleLineCircleSize; // Size of circle at the end of lines for scale gizmo
|
||||||
|
float HatchedAxisLineThickness; // Thickness of hatched axis lines
|
||||||
|
float CenterCircleSize; // Size of circle at the center of the translate/scale gizmo
|
||||||
|
|
||||||
|
ImVec4 Colors[COLOR::COUNT];
|
||||||
|
|
||||||
|
char AxisLabels[Axis::Axis_COUNT][32];
|
||||||
|
};
|
||||||
|
|
||||||
|
IMGUI_API Style& GetStyle();
|
||||||
|
}
|
21
src/imguizmo/LICENSE
Normal file
21
src/imguizmo/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Cedric Guillemet
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
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.
|
192
src/imguizmo/README.md
Normal file
192
src/imguizmo/README.md
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
# ImGuizmo
|
||||||
|
|
||||||
|
Latest stable tagged version is 1.83. Current master version is 1.84 WIP.
|
||||||
|
|
||||||
|
What started with the gizmo is now a collection of dear imgui widgets and more advanced controls.
|
||||||
|
|
||||||
|
## Guizmos
|
||||||
|
|
||||||
|
### ImViewGizmo
|
||||||
|
|
||||||
|
Manipulate view orientation with 1 single line of code
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### ImGuizmo
|
||||||
|
|
||||||
|
ImGizmo is a small (.h and .cpp) library built ontop of Dear ImGui that allow you to manipulate(Rotate & translate at the moment) 4x4 float matrices. No other dependancies. Coded with Immediate Mode (IM) philosophy in mind.
|
||||||
|
|
||||||
|
Built against DearImgui 1.53WIP
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
There is now a sample for Win32/OpenGL ! With a binary in bin directory.
|
||||||
|

|
||||||
|
|
||||||
|
### ImSequencer
|
||||||
|
|
||||||
|
A WIP little sequencer used to edit frame start/end for different events in a timeline.
|
||||||
|

|
||||||
|
Check the sample for the documentation. More to come...
|
||||||
|
|
||||||
|
### Graph Editor
|
||||||
|
|
||||||
|
Nodes + connections. Custom draw inside nodes is possible with the delegate system in place.
|
||||||
|

|
||||||
|
|
||||||
|
### API doc
|
||||||
|
|
||||||
|
Call BeginFrame right after ImGui_XXXX_NewFrame();
|
||||||
|
|
||||||
|
```C++
|
||||||
|
void BeginFrame();
|
||||||
|
```
|
||||||
|
|
||||||
|
return true if mouse cursor is over any gizmo control (axis, plan or screen component)
|
||||||
|
|
||||||
|
```C++
|
||||||
|
bool IsOver();**
|
||||||
|
```
|
||||||
|
|
||||||
|
return true if mouse IsOver or if the gizmo is in moving state
|
||||||
|
|
||||||
|
```C++
|
||||||
|
bool IsUsing();**
|
||||||
|
```
|
||||||
|
|
||||||
|
enable/disable the gizmo. Stay in the state until next call to Enable. gizmo is rendered with gray half transparent color when disabled
|
||||||
|
|
||||||
|
```C++
|
||||||
|
void Enable(bool enable);**
|
||||||
|
```
|
||||||
|
|
||||||
|
helper functions for manualy editing translation/rotation/scale with an input float
|
||||||
|
translation, rotation and scale float points to 3 floats each
|
||||||
|
Angles are in degrees (more suitable for human editing)
|
||||||
|
example:
|
||||||
|
|
||||||
|
```C++
|
||||||
|
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
|
||||||
|
```
|
||||||
|
|
||||||
|
These functions have some numerical stability issues for now. Use with caution.
|
||||||
|
|
||||||
|
```C++
|
||||||
|
void DecomposeMatrixToComponents(const float *matrix, float *translation, float *rotation, float *scale);
|
||||||
|
void RecomposeMatrixFromComponents(const float *translation, const float *rotation, const float *scale, float *matrix);**
|
||||||
|
```
|
||||||
|
|
||||||
|
Render a cube with face color corresponding to face normal. Usefull for debug/test
|
||||||
|
|
||||||
|
```C++
|
||||||
|
void DrawCube(const float *view, const float *projection, float *matrix);**
|
||||||
|
```
|
||||||
|
|
||||||
|
Call it when you want a gizmo
|
||||||
|
Needs view and projection matrices.
|
||||||
|
Matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional. snap points to a float[3] for translation and to a single float for scale or rotation. Snap angle is in Euler Degrees.
|
||||||
|
|
||||||
|
```C++
|
||||||
|
enum OPERATION
|
||||||
|
{
|
||||||
|
TRANSLATE,
|
||||||
|
ROTATE,
|
||||||
|
SCALE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MODE
|
||||||
|
{
|
||||||
|
LOCAL,
|
||||||
|
WORLD
|
||||||
|
};
|
||||||
|
|
||||||
|
void Manipulate(const float *view, const float *projection, OPERATION operation, MODE mode, float *matrix, float *deltaMatrix = 0, float *snap = 0);**
|
||||||
|
```
|
||||||
|
|
||||||
|
### ImGui Example
|
||||||
|
|
||||||
|
Code for :
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```C++
|
||||||
|
void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||||
|
{
|
||||||
|
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||||
|
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||||
|
if (ImGui::IsKeyPressed(90))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
if (ImGui::IsKeyPressed(69))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
if (ImGui::IsKeyPressed(82)) // r Key
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||||
|
|
||||||
|
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||||
|
{
|
||||||
|
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||||
|
}
|
||||||
|
static bool useSnap(false);
|
||||||
|
if (ImGui::IsKeyPressed(83))
|
||||||
|
useSnap = !useSnap;
|
||||||
|
ImGui::Checkbox("", &useSnap);
|
||||||
|
ImGui::SameLine();
|
||||||
|
vec_t snap;
|
||||||
|
switch (mCurrentGizmoOperation)
|
||||||
|
{
|
||||||
|
case ImGuizmo::TRANSLATE:
|
||||||
|
snap = config.mSnapTranslation;
|
||||||
|
ImGui::InputFloat3("Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::ROTATE:
|
||||||
|
snap = config.mSnapRotation;
|
||||||
|
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::SCALE:
|
||||||
|
snap = config.mSnapScale;
|
||||||
|
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||||
|
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
ImGuizmo can be installed via [vcpkg](https://github.com/microsoft/vcpkg) and used cmake
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vcpkg install imguizmo
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [vcpkg example](/vcpkg-example) for more details
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
ImGuizmo is licensed under the MIT License, see [LICENSE](/LICENSE) for more information.
|
|
@ -189,6 +189,9 @@ void AppConfig::set_defaults()
|
||||||
if (get("show_gcode_window").empty())
|
if (get("show_gcode_window").empty())
|
||||||
set_bool("show_gcode_window", true);
|
set_bool("show_gcode_window", true);
|
||||||
|
|
||||||
|
if (get("show_3d_navigator").empty())
|
||||||
|
set_bool("show_3d_navigator", true);
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
|
|
@ -573,7 +573,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SLIC3R_GUI_SOURCES})
|
||||||
|
|
||||||
encoding_check(libslic3r_gui)
|
encoding_check(libslic3r_gui)
|
||||||
|
|
||||||
target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui minilzo GLEW::GLEW OpenGL::GL hidapi ${wxWidgets_LIBRARIES} glfw libcurl OpenSSL::SSL OpenSSL::Crypto)
|
target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui imguizmo minilzo GLEW::GLEW OpenGL::GL hidapi ${wxWidgets_LIBRARIES} glfw libcurl OpenSSL::SSL OpenSSL::Crypto)
|
||||||
#target_link_libraries(libslic3r_gui libslic3r cereal imgui minilzo GLEW::GLEW OpenGL::GL hidapi libcurl OpenSSL::SSL OpenSSL::Crypto ${wxWidgets_LIBRARIES} glfw)
|
#target_link_libraries(libslic3r_gui libslic3r cereal imgui minilzo GLEW::GLEW OpenGL::GL hidapi libcurl OpenSSL::SSL OpenSSL::Crypto ${wxWidgets_LIBRARIES} glfw)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
|
|
@ -100,6 +100,7 @@ void CopyrightsDialog::fill_entries()
|
||||||
{ "GLFW", "", "https://www.glfw.org" },
|
{ "GLFW", "", "https://www.glfw.org" },
|
||||||
{ "GNU gettext", "", "https://www.gnu.org/software/gettext" },
|
{ "GNU gettext", "", "https://www.gnu.org/software/gettext" },
|
||||||
{ "ImGUI", "", "https://github.com/ocornut/imgui" },
|
{ "ImGUI", "", "https://github.com/ocornut/imgui" },
|
||||||
|
{ "ImGuizmo", "", "https://github.com/CedricGuillemet/ImGuizmo" },
|
||||||
{ "Libigl", "", "https://libigl.github.io" },
|
{ "Libigl", "", "https://libigl.github.io" },
|
||||||
{ "libnest2d", "", "https://github.com/tamasmeszaros/libnest2d" },
|
{ "libnest2d", "", "https://github.com/tamasmeszaros/libnest2d" },
|
||||||
{ "lib_fts", "", "https://www.forrestthewoods.com" },
|
{ "lib_fts", "", "https://www.forrestthewoods.com" },
|
||||||
|
|
|
@ -419,6 +419,15 @@ void Camera::rotate_local_around_target(const Vec3d& rotation_rad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Camera::set_rotation(const Transform3d& rotation)
|
||||||
|
{
|
||||||
|
const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target;
|
||||||
|
m_view_rotation = Eigen::Quaterniond(rotation.matrix().template block<3, 3>(0, 0));
|
||||||
|
m_view_rotation.normalize();
|
||||||
|
m_view_matrix.fromPositionOrientationScale(m_view_rotation * (-m_target) + translation, m_view_rotation, Vec3d(1., 1., 1.));
|
||||||
|
update_zenit();
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box)
|
std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box)
|
||||||
{
|
{
|
||||||
std::pair<double, double> ret;
|
std::pair<double, double> ret;
|
||||||
|
|
|
@ -146,6 +146,8 @@ public:
|
||||||
// rotate the camera around three axes parallel to the camera local axes and passing through m_target
|
// rotate the camera around three axes parallel to the camera local axes and passing through m_target
|
||||||
void rotate_local_around_target(const Vec3d& rotation_rad);
|
void rotate_local_around_target(const Vec3d& rotation_rad);
|
||||||
|
|
||||||
|
void set_rotation(const Transform3d& rotation);
|
||||||
|
|
||||||
// returns true if the camera z axis (forward) is pointing in the negative direction of the world z axis
|
// returns true if the camera z axis (forward) is pointing in the negative direction of the world z axis
|
||||||
bool is_looking_downward() const { return get_dir_forward().dot(Vec3d::UnitZ()) < 0.0; }
|
bool is_looking_downward() const { return get_dir_forward().dot(Vec3d::UnitZ()) < 0.0; }
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,8 @@
|
||||||
#endif
|
#endif
|
||||||
#include <imgui/imgui_internal.h>
|
#include <imgui/imgui_internal.h>
|
||||||
|
|
||||||
|
#include <imguizmo/ImGuizmo.h>
|
||||||
|
|
||||||
static constexpr const float TRACKBALLSIZE = 0.8f;
|
static constexpr const float TRACKBALLSIZE = 0.8f;
|
||||||
|
|
||||||
static Slic3r::ColorRGBA DEFAULT_BG_LIGHT_COLOR = { 0.906f, 0.906f, 0.906f, 1.0f };
|
static Slic3r::ColorRGBA DEFAULT_BG_LIGHT_COLOR = { 0.906f, 0.906f, 0.906f, 1.0f };
|
||||||
|
@ -5535,6 +5537,70 @@ bool GLCanvas3D::_render_arrange_menu(float left, float right, float bottom, flo
|
||||||
return settings_changed;
|
return settings_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float identityMatrix[16] = {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f};
|
||||||
|
static const float cameraProjection[16] = {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f};
|
||||||
|
|
||||||
|
void GLCanvas3D::_render_3d_navigator()
|
||||||
|
{
|
||||||
|
if (!wxGetApp().show_3d_navigator()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGuizmo::BeginFrame();
|
||||||
|
ImGuizmo::AllowAxisFlip(false);
|
||||||
|
|
||||||
|
auto& style = ImGuizmo::GetStyle();
|
||||||
|
style.Colors[ImGuizmo::COLOR::DIRECTION_X] = ImGuiWrapper::to_ImVec4(ColorRGBA::Y());
|
||||||
|
style.Colors[ImGuizmo::COLOR::DIRECTION_Y] = ImGuiWrapper::to_ImVec4(ColorRGBA::Z());
|
||||||
|
style.Colors[ImGuizmo::COLOR::DIRECTION_Z] = ImGuiWrapper::to_ImVec4(ColorRGBA::X());
|
||||||
|
strcpy(style.AxisLabels[ImGuizmo::Axis::Axis_X], "y");
|
||||||
|
strcpy(style.AxisLabels[ImGuizmo::Axis::Axis_Y], "z");
|
||||||
|
strcpy(style.AxisLabels[ImGuizmo::Axis::Axis_Z], "x");
|
||||||
|
|
||||||
|
float sc = get_scale();
|
||||||
|
#ifdef WIN32
|
||||||
|
const int dpi = get_dpi_for_window(wxGetApp().GetTopWindow());
|
||||||
|
sc *= (float) dpi / (float) DPI_DEFAULT;
|
||||||
|
#endif // WIN32
|
||||||
|
|
||||||
|
const ImGuiIO& io = ImGui::GetIO();
|
||||||
|
const float viewManipulateLeft = 0;
|
||||||
|
const float viewManipulateTop = io.DisplaySize.y;
|
||||||
|
const float camDistance = 8.f;
|
||||||
|
ImGuizmo::SetID(0);
|
||||||
|
|
||||||
|
Camera& camera = wxGetApp().plater()->get_camera();
|
||||||
|
Transform3d m = Transform3d::Identity();
|
||||||
|
m.matrix().block(0, 0, 3, 3) = camera.get_view_rotation().toRotationMatrix();
|
||||||
|
// Rotate along X and Z axis for 90 degrees to have Y-up
|
||||||
|
const auto coord_mapping_transform = Geometry::rotation_transform(Vec3d(0.5 * PI, 0, 0.5 * PI));
|
||||||
|
m = m * coord_mapping_transform;
|
||||||
|
float cameraView[16];
|
||||||
|
for (unsigned int c = 0; c < 4; ++c) {
|
||||||
|
for (unsigned int r = 0; r < 4; ++r) {
|
||||||
|
cameraView[c * 4 + r] = m(r, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const float size = 128 * sc;
|
||||||
|
const bool dirty = ImGuizmo::ViewManipulate(cameraView, cameraProjection, ImGuizmo::OPERATION::ROTATE, ImGuizmo::MODE::WORLD,
|
||||||
|
identityMatrix, camDistance, ImVec2(viewManipulateLeft, viewManipulateTop - size),
|
||||||
|
ImVec2(size, size), 0x10101010);
|
||||||
|
|
||||||
|
if (dirty) {
|
||||||
|
for (unsigned int c = 0; c < 4; ++c) {
|
||||||
|
for (unsigned int r = 0; r < 4; ++r) {
|
||||||
|
m(r, c) = cameraView[c * 4 + r];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Rotate back
|
||||||
|
m = m * (coord_mapping_transform.inverse());
|
||||||
|
camera.set_rotation(m);
|
||||||
|
|
||||||
|
request_extra_frame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT 0
|
#define ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT 0
|
||||||
#if ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT
|
#if ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT
|
||||||
static void debug_output_thumbnail(const ThumbnailData& thumbnail_data)
|
static void debug_output_thumbnail(const ThumbnailData& thumbnail_data)
|
||||||
|
@ -7324,6 +7390,8 @@ void GLCanvas3D::_render_overlays()
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
m_labels.render(sorted_instances);
|
m_labels.render(sorted_instances);
|
||||||
|
|
||||||
|
_render_3d_navigator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3D::_render_style_editor()
|
void GLCanvas3D::_render_style_editor()
|
||||||
|
|
|
@ -1181,6 +1181,7 @@ private:
|
||||||
//BBS: GUI refactor: adjust main toolbar position
|
//BBS: GUI refactor: adjust main toolbar position
|
||||||
bool _render_orient_menu(float left, float right, float bottom, float top);
|
bool _render_orient_menu(float left, float right, float bottom, float top);
|
||||||
bool _render_arrange_menu(float left, float right, float bottom, float top);
|
bool _render_arrange_menu(float left, float right, float bottom, float top);
|
||||||
|
void _render_3d_navigator();
|
||||||
// render thumbnail using the default framebuffer
|
// render thumbnail using the default framebuffer
|
||||||
void render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params, PartPlateList& partplate_list, ModelObjectPtrs& model_objects, const GLVolumeCollection& volumes, std::vector<ColorRGBA>& extruder_colors, GLShaderProgram* shader, Camera::EType camera_type);
|
void render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params, PartPlateList& partplate_list, ModelObjectPtrs& model_objects, const GLVolumeCollection& volumes, std::vector<ColorRGBA>& extruder_colors, GLShaderProgram* shader, Camera::EType camera_type);
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,9 @@ private:
|
||||||
bool show_gcode_window() const { return m_show_gcode_window; }
|
bool show_gcode_window() const { return m_show_gcode_window; }
|
||||||
void toggle_show_gcode_window();
|
void toggle_show_gcode_window();
|
||||||
|
|
||||||
|
bool show_3d_navigator() const { return app_config->get_bool("show_3d_navigator"); }
|
||||||
|
void toggle_show_3d_navigator() const { app_config->set_bool("show_3d_navigator", !show_3d_navigator()); }
|
||||||
|
|
||||||
wxString get_inf_dialog_contect () {return m_info_dialog_content;};
|
wxString get_inf_dialog_contect () {return m_info_dialog_content;};
|
||||||
|
|
||||||
std::vector<std::string> split_str(std::string src, std::string separator);
|
std::vector<std::string> split_str(std::string src, std::string separator);
|
||||||
|
|
|
@ -2567,6 +2567,15 @@ void MainFrame::init_menubar_as_editor()
|
||||||
this, [this]() { return m_tabpanel->GetSelection() == tpPreview; },
|
this, [this]() { return m_tabpanel->GetSelection() == tpPreview; },
|
||||||
[this]() { return wxGetApp().show_gcode_window(); }, this);
|
[this]() { return wxGetApp().show_gcode_window(); }, this);
|
||||||
|
|
||||||
|
append_menu_check_item(
|
||||||
|
viewMenu, wxID_ANY, _L("Show 3D Navigator"), _L("Show 3D navigator in Prepare and Preview scene"),
|
||||||
|
[this](wxCommandEvent&) {
|
||||||
|
wxGetApp().toggle_show_3d_navigator();
|
||||||
|
m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT));
|
||||||
|
},
|
||||||
|
this, [this]() { return m_tabpanel->GetSelection() == TabPosition::tp3DEditor || m_tabpanel->GetSelection() == TabPosition::tpPreview; },
|
||||||
|
[this]() { return wxGetApp().show_3d_navigator(); }, this);
|
||||||
|
|
||||||
append_menu_item(
|
append_menu_item(
|
||||||
viewMenu, wxID_ANY, _L("Reset Window Layout"), _L("Reset to default window layout"),
|
viewMenu, wxID_ANY, _L("Reset Window Layout"), _L("Reset to default window layout"),
|
||||||
[this](wxCommandEvent&) { m_plater->reset_window_layout(); }, "", this,
|
[this](wxCommandEvent&) { m_plater->reset_window_layout(); }, "", this,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue