diff --git a/zzio/scn/Trigger.cs b/zzio/scn/Trigger.cs index 56defcc4..33c659c2 100644 --- a/zzio/scn/Trigger.cs +++ b/zzio/scn/Trigger.cs @@ -27,7 +27,7 @@ public class Trigger : ISceneSection public string s = ""; public Vector3 // TODO: Move Collider out pos, - size; // only if type == Box + end; // only if type == Box public float radius; // only if type == Sphere public void Read(Stream stream) @@ -44,12 +44,12 @@ public void Read(Stream stream) ii4 = reader.ReadUInt32(); s = reader.ReadZString(); pos = reader.ReadVector3(); - size = new Vector3(); + end = new Vector3(); radius = 0.0f; switch (colliderType) { case TriggerColliderType.Box: - size = reader.ReadVector3(); + end = reader.ReadVector3(); break; case TriggerColliderType.Sphere: radius = reader.ReadSingle(); @@ -76,7 +76,7 @@ public void Write(Stream stream) switch (colliderType) { case TriggerColliderType.Box: - writer.Write(size); + writer.Write(end); break; case TriggerColliderType.Sphere: writer.Write(radius); diff --git a/zzre/game/systems/TriggerActivation.cs b/zzre/game/systems/TriggerActivation.cs index aa929ed7..db5a57d0 100644 --- a/zzre/game/systems/TriggerActivation.cs +++ b/zzre/game/systems/TriggerActivation.cs @@ -101,7 +101,7 @@ private bool ShouldBeActive(Location location, Trigger trigger) case TriggerColliderType.Point: return false; case TriggerColliderType.Box: - var box = new Box(Vector3.Zero, trigger.size); + var box = Box.FromMinMax(trigger.pos, trigger.end); if (!box.Intersects(location, playerPos)) return false; break; diff --git a/zzre/tools/sceneeditor/SceneEditor.ISelectable.cs b/zzre/tools/sceneeditor/SceneEditor.ISelectable.cs index 28480e56..80880c52 100644 --- a/zzre/tools/sceneeditor/SceneEditor.ISelectable.cs +++ b/zzre/tools/sceneeditor/SceneEditor.ISelectable.cs @@ -56,10 +56,8 @@ private class SelectionComponent : BaseDisposable private readonly SceneEditor editor; private readonly ITagContainer diContainer; private readonly Camera camera; - private readonly DebugLineRenderer boxBoundsRenderer; - private readonly DebugLineRenderer sphereBoundsRenderer; + private readonly DebugLineRenderer boundsRenderer; - private IRenderable? activeBoundsRenderer = null; private ISelectable[] lastPotentials = Array.Empty(); private int lastPotentialI; @@ -72,25 +70,21 @@ public SelectionComponent(ITagContainer diContainer) var fbArea = diContainer.GetTag(); var mouseEventArea = diContainer.GetTag(); - boxBoundsRenderer = new DebugLineRenderer(diContainer); - boxBoundsRenderer.Material.LinkTransformsTo(camera); - boxBoundsRenderer.Material.World.Value = Matrix4x4.Identity; - sphereBoundsRenderer = new DebugLineRenderer(diContainer); - sphereBoundsRenderer.Material.LinkTransformsTo(camera); - sphereBoundsRenderer.Material.World.Value = Matrix4x4.Identity; + boundsRenderer = new DebugLineRenderer(diContainer); + boundsRenderer.Material.LinkTransformsTo(camera); + boundsRenderer.Material.World.Value = Matrix4x4.Identity; editor.Window.OnContent += HandleGizmos; editor.OnLoadScene += () => editor.Selected = null; editor.OnNewSelection += HandleNewSelection; - fbArea.OnRender += HandleRender; + fbArea.OnRender += boundsRenderer.Render; mouseEventArea.OnButtonUp += HandleClick; } protected override void DisposeManaged() { base.DisposeManaged(); - boxBoundsRenderer.Dispose(); - sphereBoundsRenderer.Dispose(); + boundsRenderer.Dispose(); } private void HandleGizmos() @@ -114,25 +108,16 @@ private void HandleGizmos() private void HandleNewSelection(ISelectable? newSelected) { var bounds = newSelected?.RenderedBounds; - if (bounds is OrientedBox boxBounds) - { - boxBoundsRenderer.Clear(); - boxBoundsRenderer.AddBox(boxBounds, IColor.Red); - activeBoundsRenderer = boxBoundsRenderer; - } + boundsRenderer.Clear(); + if (bounds is OrientedBox orientedBoxBounds) + boundsRenderer.AddBox(orientedBoxBounds, IColor.Red); + else if (bounds is Box boxBounds) + boundsRenderer.AddBox(boxBounds, IColor.Red); else if (bounds is Sphere sphereBounds) - { - sphereBoundsRenderer.Clear(); - sphereBoundsRenderer.AddDiamondSphere(sphereBounds, IColor.Red); - activeBoundsRenderer = sphereBoundsRenderer; - } - else - activeBoundsRenderer = null; + boundsRenderer.AddDiamondSphere(sphereBounds, IColor.Red); editor.fbArea.IsDirty = true; } - private void HandleRender(CommandList cl) => activeBoundsRenderer?.Render(cl); - private void HandleClick(MouseButton button, Vector2 pos) { if (button != MouseButton.Left || ImGuizmo.IsOver() || ImGuizmo.IsUsing()) diff --git a/zzre/tools/sceneeditor/SceneEditor.Trigger.cs b/zzre/tools/sceneeditor/SceneEditor.Trigger.cs index 0100f3de..0cad9c66 100644 --- a/zzre/tools/sceneeditor/SceneEditor.Trigger.cs +++ b/zzre/tools/sceneeditor/SceneEditor.Trigger.cs @@ -36,14 +36,14 @@ private class Trigger : BaseDisposable, ISelectable public IRaycastable? RenderedBounds => SceneTrigger.colliderType switch { - TriggerColliderType.Box => new Box(Vector3.Zero, SceneTrigger.size).TransformToWorld(Location), + TriggerColliderType.Box => Box.FromMinMax(Location.GlobalPosition, Location.GlobalPosition + SceneTrigger.end - SceneTrigger.pos), TriggerColliderType.Sphere => new Sphere(Location.GlobalPosition, SceneTrigger.radius), TriggerColliderType.Point => null, _ => throw new NotImplementedException("Unknown TriggerColliderType") }; public float ViewSize => SceneTrigger.colliderType switch { - TriggerColliderType.Box => SceneTrigger.size.MaxComponent(), + TriggerColliderType.Box => (SceneTrigger.end - SceneTrigger.pos).MaxComponent(), TriggerColliderType.Sphere => SceneTrigger.radius * 2f, TriggerColliderType.Point => PointTriggerSize * 2f, _ => throw new NotImplementedException("Unknown TriggerColliderType") @@ -75,7 +75,8 @@ public void Content() break; case TriggerColliderType.Box: - InputFloat3("Size", ref SceneTrigger.size); + var size = SceneTrigger.end - SceneTrigger.pos; + InputFloat3("Size", ref size); break; } }