Giter VIP home page Giter VIP logo

Comments (7)

jdumas avatar jdumas commented on July 16, 2024 2

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.

Batres3 avatar Batres3 commented on July 16, 2024 1

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.

CedricGuillemet avatar CedricGuillemet commented on July 16, 2024

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.

jdumas avatar jdumas commented on July 16, 2024

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.

vamidi avatar vamidi commented on July 16, 2024

@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.

vamidi avatar vamidi commented on July 16, 2024

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.

vamidi avatar vamidi commented on July 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.