Skip to content

Commit

Permalink
Follow up on Split and Duplicate Key Frames
Browse files Browse the repository at this point in the history
Added new lines of code and parameter for ReplicateStrokes. Also renamed it to ReplicateStrokesToNewCanvas.

DuplicateStrokes from SketchMemoryScript is also copying strokes that were marked NotCreated. This occurs when joining strokes are "uncreated" to complete the join.
  • Loading branch information
JayMayo authored and andybak committed Jan 14, 2025
1 parent 66c1cd4 commit 1fe8075
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions Assets/Scripts/Animation/AnimationUI_Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,26 @@ public void ExtendKeyFrame(int trackNum)
return index;
}

private void ReplicateStrokes(List<Stroke> newStrokes, CanvasScript newCanvas)
private CanvasScript ReplicateStrokesToNewCanvas(List<Stroke> oldStrokes)
{
Dictionary<int, List<Stroke>> strokeGroups = new Dictionary<int, List<Stroke>>();
CanvasScript newCanvas = App.Scene.AddCanvas();
List<Stroke> newStrokes = oldStrokes
.Select(stroke => SketchMemoryScript.m_Instance.DuplicateStroke(
stroke, App.Scene.SelectionCanvas, null)).ToList();

for (int i = 0; i < oldStrokes.Count ; i++)
{
if (oldStrokes.Count == newStrokes.Count && oldStrokes[i].m_Type == Stroke.Type.NotCreated)
{
// using SketchMemory of oldStrokes to mark Uncreated strokes on newStrokes. Otherwise, Uncreated strokes will be re-made.
newStrokes[i].Uncreate();
} else {
Debug.LogWarning("Unexpected. Count of oldStrokes must match newStrokes.");
}
}

Dictionary<int, List<Stroke>> strokeGroups = new Dictionary<int, List<Stroke>>();

foreach (var stroke in newStrokes)
{
if (stroke.Group != SketchGroupTag.None)
Expand All @@ -982,40 +998,38 @@ private void ReplicateStrokes(List<Stroke> newStrokes, CanvasScript newCanvas)
case Stroke.Type.BatchedBrushStroke:
stroke.m_BatchSubset.m_ParentBatch.EnableSubset(stroke.m_BatchSubset);
break;
default:
Debug.LogError("Unexpected: redo NotCreated duplicate stroke");
break;
}
TiltMeterScript.m_Instance.AdjustMeter(stroke, up: true);
stroke.SetParentKeepWorldPosition(newCanvas);

if (stroke.m_Type != Stroke.Type.NotCreated)
{
TiltMeterScript.m_Instance.AdjustMeter(stroke, up: true);
stroke.SetParentKeepWorldPosition(newCanvas);
}
}

foreach (var sg in strokeGroups)
{
GroupManager.MoveStrokesToNewGroups(sg.Value,null);
}

return newCanvas;
}

public (int, int) SplitKeyFrame(int trackNum = -1, int frameNum = -1)
{
(int, int) index = (trackNum == -1 || frameNum == -1) ? GetCanvasLocation(App.Scene.ActiveCanvas) : (trackNum, frameNum);

CanvasScript newCanvas = App.Scene.AddCanvas();
CanvasScript oldCanvas = App.Scene.ActiveCanvas;

int frameLength = GetFrameLength(index.Item1, index.Item2);

int splittingIndex = FrameOn;
if (splittingIndex < index.Item2 || splittingIndex > index.Item2 + frameLength - 1) return (-1, -1);

List<Stroke> oldStrokes = SketchMemoryScript.m_Instance.GetMemoryList
.Where(x => x.Canvas == oldCanvas).ToList();

List<Stroke> newStrokes = oldStrokes.Select(stroke =>
SketchMemoryScript.m_Instance.DuplicateStroke(stroke, App.Scene.SelectionCanvas, null))
.ToList();
CanvasScript newCanvas = ReplicateStrokesToNewCanvas(oldStrokes);

ReplicateStrokes(newStrokes,newCanvas);
int frameLength = GetFrameLength(index.Item1, index.Item2);

int splittingIndex = FrameOn;
if (splittingIndex < index.Item2 || splittingIndex > index.Item2 + frameLength - 1) return (-1, -1);

for (int f = splittingIndex; f < index.Item2 + frameLength; f++)
{
Expand All @@ -1030,20 +1044,18 @@ private void ReplicateStrokes(List<Stroke> newStrokes, CanvasScript newCanvas)

public (int, int) DuplicateKeyFrame(int trackNum = -1, int frameNum = -1)
{

(int, int) index = (trackNum == -1 || frameNum == -1) ? GetCanvasLocation(App.Scene.ActiveCanvas) : (trackNum, frameNum);
CanvasScript newCanvas = App.Scene.AddCanvas();

CanvasScript oldCanvas = App.Scene.ActiveCanvas;

int frameLength = GetFrameLength(index.Item1, index.Item2);
(int, int) nextIndex = GetFollowingFrameIndex(index.Item1, index.Item2);
List<Stroke> oldStrokes = SketchMemoryScript.m_Instance.GetMemoryList
.Where(x => x.Canvas == oldCanvas).ToList();

List<Stroke> newStrokes = oldStrokes
.Select(stroke => SketchMemoryScript.m_Instance.DuplicateStroke(
stroke, App.Scene.SelectionCanvas, null)).ToList();
CanvasScript newCanvas = ReplicateStrokesToNewCanvas(oldStrokes);

ReplicateStrokes(newStrokes,newCanvas);
int frameLength = GetFrameLength(index.Item1, index.Item2);
(int, int) nextIndex = GetFollowingFrameIndex(index.Item1, index.Item2);

for (int f = 0; f < frameLength; f++)
{
Expand Down

0 comments on commit 1fe8075

Please sign in to comment.