Skip to content

Commit

Permalink
TimelineConverter から DmxPacket の依存をなくす
Browse files Browse the repository at this point in the history
  • Loading branch information
nasshu2916 committed Nov 11, 2024
1 parent fe6949a commit 8e33d4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
26 changes: 25 additions & 1 deletion Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ArtNet.Packets;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -81,7 +83,29 @@ private static void ConvertPacket(ConvertAnim convertAnim)
}

var timelineConverter = new TimelineConverter(artNetDmxClip);
var dmxPackets = timelineConverter.ToDmxPackets();
var universeDataList = timelineConverter.ToUniverseData();
var dmxPackets = new List<(int, DmxPacket)>();
byte sequence = 0;
foreach (var universeData in universeDataList)
{
var packet = new DmxPacket
{
Sequence = sequence++,
Universe = (ushort) universeData.Universe,
Dmx = universeData.Values
};
dmxPackets.Add(((int) (universeData.Time * 1000f), packet)); ;

if (sequence >= 255)
{
sequence = 0;
}
else
{
sequence++;
}
}

var storeData = RecordData.Serialize(dmxPackets);


Expand Down
24 changes: 6 additions & 18 deletions Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ArtNet.Packets;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -60,10 +59,9 @@ public void SaveDmxTimelineClips(string directory)
AssetDatabase.Refresh();
}

public List<(int time, DmxPacket packet)> ToDmxPackets()
public List<UniverseData> ToUniverseData()
{
return Timelines.SelectMany(x => x.ToDmxPackets()).OrderBy(x => x.time).Select(x => ((int) (x.time * 1000f), x
.packet)).ToList();
return Timelines.SelectMany(x => x.ToUniverseData()).OrderBy(x => x.Time).ToList();
}

private static void SaveAsset<T>(T asset, string directory, string fileName) where T : UnityEngine.Object
Expand Down Expand Up @@ -209,10 +207,9 @@ private static bool IsOmittedFrame(
return Math.Abs(prevDiff / prevDiffTime - nextDiff / nextDiffTime) <= tolerance;
}

public IEnumerable<(float time, DmxPacket packet)> ToDmxPackets()
public IEnumerable<UniverseData> ToUniverseData()
{
byte sequence = 0;
var packets = new List<(float time, DmxPacket packet)>();
var universeData = new List<UniverseData>();
var allFrameTimes = AllFrameTimes().OrderBy(x => x).ToList();

foreach (var time in allFrameTimes)
Expand All @@ -223,19 +220,10 @@ private static bool IsOmittedFrame(
dmx[i] = FrameValue(i, time);
}

var packet = new DmxPacket { Sequence = sequence, Universe = (ushort) Universe, Dmx = dmx };
packets.Add((time, packet));
if (sequence >= 255)
{
sequence = 0;
}
else
{
sequence++;
}
universeData.Add(new UniverseData(time, (uint) Universe, dmx));
}

return packets;
return universeData;
}
}

Expand Down

0 comments on commit 8e33d4c

Please sign in to comment.