psydack / uimgui

UImGui (Unity ImGui) is an UPM package for the immediate mode GUI library using ImGui.NET. This project is based on RG.ImGui project.
MIT License
349 stars 55 forks source link

[QUESTION] How does ImGuizmo work with Unity? #36

Closed Jake-NSW closed 1 year ago

Jake-NSW commented 2 years ago

I've tried rendering a simple box gizmo. And what ever I try doesn't seem to work. Doesn't help that there is barely any documentation anywhere (.NET and C++ Side)

I Would of thought this is all I had to do.

ImGuizmo.SetOrthographic( false );
var io = ImGui.GetIO();
ImGuizmo.SetRect( 0, 0, io.DisplaySize.x, io.DisplaySize.y );

var camera = Engine.Camera;
var matrix = entity.transform.localToWorldMatrix[0];
var view = camera.worldToCameraMatrix[0];
var projection = camera.projectionMatrix[0];

ImGuizmo.Manipulate( ref view, ref projection, OPERATION.TRANSLATE, MODE.WORLD, ref matrix );

But nothing shows in the viewport.

psydack commented 2 years ago

Hello there.

What’s the unity version and render pipeline?

Thank you for using and reporting.

Em qui., 31 de mar. de 2022 às 01:51, Jake K @.***> escreveu:

I've tried rendering a simple box gizmo. And what ever I try doesn't seem to work. Doesn't help that there is barely any documentation anywhere (.NET and C++ Side)

I Would of thought this is all I had to do.

ImGuizmo.SetOrthographic( false );var io = ImGui.GetIO();ImGuizmo.SetRect( 0, 0, io.DisplaySize.x, io.DisplaySize.y ); var camera = Engine.Camera;var matrix = entity.transform.localToWorldMatrix[0];var view = camera.worldToCameraMatrix[0];var projection = camera.projectionMatrix[0]; ImGuizmo.Manipulate( ref view, ref projection, OPERATION.TRANSLATE, MODE.WORLD, ref matrix );

But nothing shows in the viewport.

— Reply to this email directly, view it on GitHub https://github.com/psydack/uimgui/issues/36, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHK3M5VC5KP544FIY4E5Y3VCUVN5ANCNFSM5SED32YA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Jake-NSW commented 2 years ago

Hey, I'm using the default render pipeline, and I'm using Unity 2021.2.6f1

psydack commented 2 years ago

Sorry to answer late, but I couldn't test yet because I'm still working on mac port. Did you make any progress?

Zguy commented 2 years ago

I don't know if OP ever solved their problem, but for anyone else stumbling upon this thread looking for an answer, here's what's going wrong.

The problem is that when you do this var matrix = entity.transform.localToWorldMatrix[0]; you are storing the first element and just throwing away the rest of the matrix. That means that once you get to the Manipulate line there's no more matrix but just the one float value, so it's going to read garbage memory around the float value.

What you need to do is something like this

var matrix = entity.transform.localToWorldMatrix;
var view = camera.worldToCameraMatrix;
var projection = camera.projectionMatrix;

ImGuizmo.Manipulate( ref view.m00, ref projection.m00, OPERATION.TRANSLATE, MODE.WORLD, ref matrix.m00 );

Hope it helps somebody.

psydack commented 1 year ago

Hey @Zguy .

It's been while since I was active in this project.

Would be great if you can add an example on README.md. I would be very glad to accept you PR.

Thanks.