Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ jobs:
with:
dotnet-version: 8.0.x
- name: Build local dependencies
run: bash zzio/get-dependencies.sh
run: |
cd zzio
bash ./get-dependencies.sh
cd ..
- name: Install remote dependencies
run: dotnet restore zzio/zzio.sln -r ${{ matrix.target }} -p:NoWarn=NU1605
- name: Build
Expand Down
4 changes: 4 additions & 0 deletions zzio/scn/FOModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public void Write(Stream stream)
writer.Write(useCachedModels);
writer.Write(wiggleAmpl);
}
public FOModel Clone()
{
return (FOModel)this.MemberwiseClone();
}
}
14 changes: 6 additions & 8 deletions zzio/scn/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public void Write(Stream stream)
writer.WriteZString("[Scenefile]");
writeSingle(writer, version, "[Version]");
writeSingle(writer, misc, "[Misc]");
if (backdropFile.Length > 0)
{
writer.WriteZString("[Backdrop]");
writer.WriteZString(backdropFile);
}
writeArray(writer, lights, "[Lights]");
writeArray(writer, foModels, "[FOModels_v4]");
writeArray(writer, models, "[Models_v3]");
Expand All @@ -136,15 +141,8 @@ public void Write(Stream stream)
writer.Write(sceneOrigin);
writeArray(writer, textureProperties, "[TextureProperties]");
writeSingle(writer, waypointSystem, "[WaypointSystem]");

if (backdropFile.Length > 0)
{
writer.WriteZString("[Backdrop]");
writer.WriteZString(backdropFile);
}
writeArray(writer, effects, "[Effects]");
writer.WriteZString("[EOS]");
}
}
}
}
}
4 changes: 4 additions & 0 deletions zzio/scn/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ public void Write(Stream stream)
break;
}
}
public Trigger Clone()
{
return (Trigger)this.MemberwiseClone();
}
}
10 changes: 8 additions & 2 deletions zzre.core/math/ZZIOExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Numerics;
using Veldrid;
using zzio;
Expand Down Expand Up @@ -28,6 +28,12 @@ public static Quaternion ToZZRotation(this Vector3 v)
return Quaternion.Conjugate(Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateLookAt(Vector3.Zero, v, up)));
}

public static Vector3 FromZZRotation(this Quaternion q)
{
Matrix4x4 rotationMatrix = Matrix4x4.CreateFromQuaternion(Quaternion.Conjugate(q));
return Vector3.Normalize(new Vector3(rotationMatrix.M13, rotationMatrix.M23, rotationMatrix.M33));
}

public static Vector3 ToZZRotationVector(this Quaternion rotation) =>
Vector3.Transform(-Vector3.UnitZ, rotation) * -1f;

Expand All @@ -45,7 +51,7 @@ public static Vector3 ToZZRotationVector(this Quaternion rotation) =>
};

// adapted from https://gist.github.com/ciembor/1494530 - "It's the do what you want license :)"

public static FColor RGBToHSL(this FColor c)
{
float max = Max(Max(c.r, c.g), c.b);
Expand Down
2 changes: 2 additions & 0 deletions zzre/imgui/TwoColumnEditorTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public void AddInfoSection(string name, Action content, bool defaultOpen = true,

public void ClearInfoSections() => infoSections.Clear();

public void ResetColumnWidth() => didSetColumnWidth = 0;

private void HandleContent()
{
ImGui.Columns(2, null, true);
Expand Down
74 changes: 73 additions & 1 deletion zzre/tools/sceneeditor/SceneEditor.FOModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using Veldrid;
Expand Down Expand Up @@ -34,6 +35,12 @@ private sealed class FOModel : BaseDisposable, ISelectable
public IRaycastable RenderedBounds => SelectableBounds;
public float ViewSize => mesh.BoundingBox.MaxSizeComponent;

public void SyncWithScene()
{
SceneFOModel.pos = Location.LocalPosition;
SceneFOModel.rot = Location.LocalRotation.FromZZRotation();
}

public FOModel(ITagContainer diContainer, zzio.scn.FOModel sceneModel)
{
this.diContainer = diContainer;
Expand Down Expand Up @@ -174,6 +181,12 @@ public FOModelComponent(ITagContainer diContainer)
editor.editor.AddInfoSection("FOModels", HandleInfoSection, false);
}

public void SyncWithScene()
{
foreach (var foModel in models)
foModel.SyncWithScene();
}

protected override void DisposeManaged()
{
base.DisposeManaged();
Expand All @@ -189,7 +202,19 @@ private void HandleLoadScene()
if (editor.scene == null)
return;

models = editor.scene.foModels.Select(m => new FOModel(diContainer, m)).ToArray();
var list = new List<FOModel>();
foreach (var m in editor.scene.foModels)
{
try
{
list.Add(new FOModel(diContainer, m));
}
catch (InvalidDataException)
{
Console.Error.WriteLine("Fail to load FOModel with ID {0}, ignoring file {1}", m.idx, m.filename);
}
}
models = [.. list];
}

private void HandleRender(CommandList cl)
Expand Down Expand Up @@ -221,7 +246,54 @@ private void HandleInfoSection()
TreePop();
}
}
private FOModel? FindCurrentFoModel()
{
foreach (var foModel in models)
{
if (foModel == editor.Selected)
return foModel;
}
return null;
}
private uint GetNextAvailableFoModelID()
{
uint result = 1;
foreach (var foModel in models)
{
result = Math.Max(result, foModel.SceneFOModel.idx);
}
return result + 1;
}
public void DeleteCurrentFoModel()
{
var currentFoModel = FindCurrentFoModel();
if (currentFoModel == null || editor.scene == null)
return;

SyncWithScene();


editor.scene.foModels = editor.scene.foModels.Where(
model => model.idx != currentFoModel.SceneFOModel.idx
).ToArray();

HandleLoadScene();
editor.Selected = null;
}
public void DuplicateCurrentFoModel()
{
var currentFoModel = FindCurrentFoModel();
if (currentFoModel == null || editor.scene == null)
return;

SyncWithScene();

var copy = currentFoModel.SceneFOModel.Clone();
copy.idx = GetNextAvailableFoModelID();
editor.scene.foModels = [.. editor.scene.foModels, copy];
HandleLoadScene();
editor.Selected = models.Last();
}
IEnumerator<ISelectable> IEnumerable<ISelectable>.GetEnumerator() => ((IEnumerable<ISelectable>)models).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => models.Cast<ISelectable>().GetEnumerator();
}
Expand Down
8 changes: 6 additions & 2 deletions zzre/tools/sceneeditor/SceneEditor.ISelectable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ImGuizmoNET;
using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -24,6 +25,7 @@ public interface ISelectable
private readonly List<IEnumerable<ISelectable>> selectableContainers = [];
private IEnumerable<ISelectable> Selectables => selectableContainers.SelectMany(c => c);

private static OPERATION gizmoOperation = OPERATION.TRANSLATE;
private ISelectable? _selected;
private ISelectable? Selected
{
Expand Down Expand Up @@ -94,7 +96,9 @@ private void HandleGizmos()
var projection = camera.Projection;
var matrix = selected.Location.LocalToWorld;
ImGuizmo.SetDrawlist();
if (ImGuizmo.Manipulate(ref view.M11, ref projection.M11, OPERATION.TRANSLATE, MODE.LOCAL, ref matrix.M11))
if (!ImGuizmo.IsUsing())
gizmoOperation = ImGui.IsKeyDown(ImGuiKey.ModShift) ? OPERATION.ROTATE : OPERATION.TRANSLATE;
if (ImGuizmo.Manipulate(ref view.M11, ref projection.M11, gizmoOperation, MODE.LOCAL, ref matrix.M11))
{
selected.Location.LocalToWorld = matrix;
editor.TriggerSelectionManipulate();
Expand All @@ -117,7 +121,7 @@ private void HandleNewSelection(ISelectable? newSelected)

private void HandleClick(MouseButton button, Vector2 pos)
{
if (button != MouseButton.Left)// || ImGuizmo.IsOver() || ImGuizmo.IsUsing())
if (button != MouseButton.Left || ImGuizmo.IsUsing()) // || ImGuizmo.IsOver()
return;

var ray = camera.RayAt((pos * 2f - Vector2.One) * new Vector2(1f, -1f));
Expand Down
59 changes: 58 additions & 1 deletion zzre/tools/sceneeditor/SceneEditor.Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public void Content()
break;
}
}

public void SyncWithScene()
{
SceneTrigger.pos = Location.LocalPosition;
}
}

private sealed class TriggerComponent : BaseDisposable, IEnumerable<ISelectable>
Expand All @@ -90,7 +95,7 @@ private sealed class TriggerComponent : BaseDisposable, IEnumerable<ISelectable>

private Trigger[] triggers = [];
private bool wasSelected;
private float iconSize = 128f;
private float iconSize = 256f;

public TriggerComponent(ITagContainer diContainer)
{
Expand All @@ -112,6 +117,11 @@ public TriggerComponent(ITagContainer diContainer)
iconRenderer.Material.MainSampler.Sampler = iconFont.Sampler;
HandleResize();
}
public void SyncWithScene()
{
foreach (var trigger in triggers)
trigger.SyncWithScene();
}

protected override void DisposeManaged()
{
Expand All @@ -121,6 +131,53 @@ protected override void DisposeManaged()
trigger.Dispose();
}

public void DuplicateCurrentTrigger()
{
var currentTrigger = FindCurrentTrigger();
if (currentTrigger == null || editor.scene == null)
return;

SyncWithScene();

var copy = currentTrigger.SceneTrigger.Clone();
copy.idx = GetNextAvailableTriggerID();
editor.scene.triggers = [.. editor.scene.triggers, copy];
HandleLoadScene();
editor.Selected = triggers.Last();
}
public void DeleteCurrentTrigger()
{
var currentTrigger = FindCurrentTrigger();
if (currentTrigger == null || editor.scene == null)
return;

SyncWithScene();

editor.scene.triggers = editor.scene.triggers.Where(
trigger => trigger.idx != currentTrigger.SceneTrigger.idx
).ToArray();

HandleLoadScene();
editor.Selected = null;
}
private uint GetNextAvailableTriggerID()
{
uint result = 1;
foreach (var trigger in triggers)
{
result = Math.Max(result, trigger.SceneTrigger.idx);
}
return result + 1;
}
private Trigger? FindCurrentTrigger()
{
foreach (var trigger in triggers)
{
if (trigger == editor.Selected)
return trigger;
}
return null;
}
private void HandleLoadScene()
{
foreach (var oldTrigger in triggers)
Expand Down
Loading