Comments (7)
In HandleAndDrawLocalBounds
I have made the following modifications to enforce edits on the XY plane, even when viewed at a grazing angle:
if ( i == 2 )
{
bestDot = dt;
bestAxis = i;
bestAxisWorldDirection = dirPlaneNormalWorld;
}
if( i == 2 && dt >= 0.1f )
{
axes[numAxes] = i;
axesWorldDirections[numAxes] = dirPlaneNormalWorld;
++numAxes;
}
// ....
for (unsigned int axisIndex = 0; axisIndex < numAxes; ++axisIndex)
{
if (axisIndex == 1) { break; }
And then my modified version of DrawCube
:
void DrawCube(const float *view, const float *projection, float *matrix)
{
matrix_t viewInverse;
viewInverse.Inverse(*(const matrix_t*)view);
const matrix_t& model = *(const matrix_t*)matrix;
matrix_t res = *(const matrix_t*)matrix * *(const matrix_t*)view * *(const matrix_t*)projection;
for (int iFace = 0; iFace < 6; iFace++)
{
const int normalIndex = (iFace % 3);
const int perpXIndex = (normalIndex + 1) % 3;
const int perpYIndex = (normalIndex + 2) % 3;
const float invert = (iFace > 2) ? -1.f : 1.f;
if (normalIndex != 2) { continue; }
const vec_t faceCoords[4] = {
/*directionUnary[normalIndex]*/ + directionUnary[perpXIndex] + directionUnary[perpYIndex],
/*directionUnary[normalIndex]*/ + directionUnary[perpXIndex] - directionUnary[perpYIndex],
/*directionUnary[normalIndex]*/ - directionUnary[perpXIndex] - directionUnary[perpYIndex],
/*directionUnary[normalIndex]*/ - directionUnary[perpXIndex] + directionUnary[perpYIndex],
};
// clipping
bool skipFace = false;
for (unsigned int iCoord = 0; iCoord < 4; iCoord++)
{
vec_t camSpacePosition;
camSpacePosition.TransformPoint(faceCoords[iCoord] * 0.5f * invert, gContext.mMVP);
// if (camSpacePosition.z < 0.001f)
// {
// skipFace = true;
// break;
// }
}
if (skipFace)
continue;
// 3D->2D
ImVec2 faceCoordsScreen[4];
for (unsigned int iCoord = 0; iCoord < 4; iCoord++)
faceCoordsScreen[iCoord] = worldToPos(faceCoords[iCoord] * 0.5f * invert, res);
// back face culling
vec_t cullPos, cullNormal;
cullPos.TransformPoint(faceCoords[0] * 0.5f * invert, model);
cullNormal.TransformVector(directionUnary[normalIndex] * invert, model);
float dt = Dot(Normalized(cullPos - viewInverse.v.position), Normalized(cullNormal));
if (dt>0.f)
continue;
// draw face with lighter color
gContext.mDrawList->AddConvexPolyFilled(faceCoordsScreen, 4, directionColor[normalIndex] | 0x808080);
}
}
My version of ImGuizmo is not in sync with upstream anymore, so I may be missing other small changes, but as I recall those where the changes I had to make.
from imguizmo.
I made a pull request implementing this as best I could, it seems to work fine if anyone wants to try it. It is on a branch of my fork of ImGuizmo.
from imguizmo.
Hi Jeremie,
Look for 'belowAxisLimit' boolean. It's true when the axis is nearly colinear with the camera view direction. If you enhance the checks with a mask (something like belowAxisLimit && ((1<<currentAxis)&AxisMask) you should be able to hide the axis you don't want.
AxisMask would be a combination of
AxisMaskX = 1, AxisMaskY = 2, AxisMaskZ = 4
And add a function ImGuizmo::SetAxisMask(int axisMask) to save the mask that in the context
from imguizmo.
Thanks! I've hardcoded those changes for now. I also had to fiddle around with the bestAxis
in HandleAndDrawLocalBounds()
to show the bounds in the plane I was interested in, even when it is viewed at a steep angle. I also modified the DrawCube()
function to draw a single face at a coordinate Z=0.
Things are a bit hardcoded for now, so I can't really do a PR, but I may do that later on.
from imguizmo.
@jdumas can you explain me how you did it? I want to try and make this (picture below) with Imguizmo where you can control a UI element within a X/Y plane
https://docs.unity3d.com/uploads/Main/UI_Anchored4.gif
from imguizmo.
Amazing! I will take a look at it! Thanks!
@jdumas, I tried it out and I think I am doing something wrong? How does it works actually? maybe I can try messing around with variables.
https://gyazo.com/8a8e9649f60de6ebeb4c31f3f3c17927
this needs to be replaced with your piece right?
if (dt >= bestDot) { bestDot = dt; bestAxis = i; bestAxisWorldDirection = dirPlaneNormalWorld; } if (dt >= 0.1f) { axes[numAxes] = i; axesWorldDirections[numAxes] = dirPlaneNormalWorld; ++numAxes; }
from imguizmo.
@jdumas based on the comment above is it still possible to provide an answer :D ? I notice if I rotate an object it starts to come, but do I need to rotate things beforehand?
from imguizmo.
Related Issues (20)
- ImGuizmo scaling issue when position is origin HOT 17
- How can modify the code to achieve this scaling gizmo HOT 4
- Example using ViewManipulate when game's view is represented with a Vector3 and a Quaternion? HOT 1
- Platform independent build system and example? HOT 3
- How to use ImGuizmo in UE5?
- Universal Operation Scale doesn't respect ImGuizmo::IsOver()
- ImGuizmo::IsOver() returns true when should not
- [question] How the mesh editing is implemented?
- Snap for universal transform
- Gizmo Flips Depending on View Angle HOT 1
- Support for Right-Handed Systems HOT 3
- Viewport changing when window is moved HOT 1
- adding the gizmo to a window that was just renamed leads to a crash with asan activated
- no guizmo rendered HOT 1
- Exposure of gContext.mbMouseOver
- Camera parented to Guizmo HOT 1
- Manipulate not working
- Updating operation during an active manipulation has unexpected behaviour.
- Gizmo not showing in custom window ( docking branch ) HOT 5
- Assertion fails for ImVector::operator[](int) HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imguizmo.