mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
2D Polygon Collider editor with Gizmos
+ Added Handles class
This commit is contained in:
@@ -77,6 +77,37 @@ namespace GlitchyEditor.EditWindows
|
||||
ShowAddComponentButton(entity);
|
||||
}
|
||||
|
||||
public void DrawSceneGUI(Entity entity)
|
||||
{
|
||||
DrawComponenSceneGUI<PolygonCollider2DComponent>(entity, => ShowPolygonColliderSceneGUI);
|
||||
}
|
||||
|
||||
static void ShowPolygonColliderSceneGUI(Entity entity, PolygonCollider2DComponent* collider)
|
||||
{
|
||||
for (int i < collider.VertexCount)
|
||||
{
|
||||
Matrix localToWorld = entity.Transform.WorldTransform * Matrix.Translation(collider.Offset.X, collider.Offset.Y, 0);
|
||||
Matrix transform = Matrix.Translation(float3(collider.Vertices[i], 0)) * localToWorld;
|
||||
|
||||
if (Handles.ShowGizmo(ref transform, .TRANSLATE_X | .TRANSLATE_Y, true, id: (int32)i))
|
||||
{
|
||||
transform = localToWorld.Invert() * transform;
|
||||
|
||||
collider.Vertices[i] = transform.Translation.XY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawComponenSceneGUI<TComponent>(Entity entity, function void(Entity, TComponent*) showSceneGUI) where TComponent: struct, new
|
||||
{
|
||||
if (!entity.HasComponent<TComponent>())
|
||||
return;
|
||||
|
||||
TComponent* component = entity.GetComponent<TComponent>();
|
||||
|
||||
showSceneGUI(entity, component);
|
||||
}
|
||||
|
||||
private static void ShowComponentContextMenu<TComponent>(Entity entity, TComponent* component) where TComponent: struct, new
|
||||
{
|
||||
if (ImGui.Selectable("Remove Component"))
|
||||
|
||||
@@ -321,6 +321,8 @@ namespace GlitchyEditor.EditWindows
|
||||
var view = _editor.CurrentCamera.View;
|
||||
var projection = _editor.CurrentCamera.Projection;
|
||||
|
||||
Handles.SetViewProjection(view, projection);
|
||||
|
||||
if(_editor.EntityHierarchyWindow.SelectedEntities.Count == 0)
|
||||
return false;
|
||||
|
||||
@@ -337,11 +339,15 @@ namespace GlitchyEditor.EditWindows
|
||||
parentView = parentTransformCmp.WorldTransform.Invert();
|
||||
}
|
||||
|
||||
_editor.ComponentEditWindow.DrawSceneGUI(entity);
|
||||
|
||||
float3 snap = (float3)_snap;
|
||||
if (_gizmoType.HasFlag(.ROTATE))
|
||||
snap = (float3)_angleSnap;
|
||||
|
||||
if (ImGuizmo.Manipulate((.)&view, (.)&projection, _gizmoType, _gizmoMode, (.)&worldTransform, null, _doSnap ? (.)&snap : null))
|
||||
|
||||
Handles.SetSnap(_doSnap ? (float3?)snap : null);
|
||||
|
||||
if (Handles.ShowGizmo(ref worldTransform, _gizmoType, _gizmoMode case .WORLD, id: 1337))
|
||||
{
|
||||
// TODO: Fix when parent is scaled
|
||||
// Seems to work fine for parent rotation and translation but scaled parent ruins everything
|
||||
@@ -349,7 +355,7 @@ namespace GlitchyEditor.EditWindows
|
||||
transformCmp.LocalTransform = parentView * worldTransform;
|
||||
}
|
||||
|
||||
return ImGuizmo.IsUsing();
|
||||
return Handles.UsedGizmo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user