mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-03 14:38:50 +00:00
Rework interpolation & add Hermite interpolation
This commit is contained in:
1 parent
2a8ac10ec2
commit
797287e490
38 files changed
+631
-342
No files matched your search
@@ -113,6 +113,8 @@ dependencies {
|
|||||||
shadow(api(rootProject.files('deps/imgui-java-natives-macos-1.86.11-10-g0dbf36c.jar')))
|
shadow(api(rootProject.files('deps/imgui-java-natives-macos-1.86.11-10-g0dbf36c.jar')))
|
||||||
shadow(api(rootProject.files('deps/imgui-java-natives-windows-1.86.11-10-g0dbf36c.jar')))
|
shadow(api(rootProject.files('deps/imgui-java-natives-windows-1.86.11-10-g0dbf36c.jar')))
|
||||||
|
|
||||||
|
shadow(implementation("org.apache.commons:commons-math3:3.6.1"))
|
||||||
|
|
||||||
// Native File Dialogs
|
// Native File Dialogs
|
||||||
String nfdVersion = "org.lwjgl:lwjgl-nfd:3.3.3";
|
String nfdVersion = "org.lwjgl:lwjgl-nfd:3.3.3";
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.moulberry.flashback;
|
package com.moulberry.flashback;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import org.apache.commons.math3.analysis.interpolation.HermiteInterpolator;
|
||||||
import org.joml.Math;
|
import org.joml.Math;
|
||||||
import org.joml.Quaterniond;
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Interpolation {
|
public class Interpolation {
|
||||||
|
|
||||||
public static double linear(double from, double to, double amount) {
|
public static double linear(double from, double to, double amount) {
|
||||||
|
|||||||
@@ -974,8 +974,8 @@ public class TimelineWindow {
|
|||||||
if (leftClicked) {
|
if (leftClicked) {
|
||||||
if (ImGui.isMouseDoubleClicked(ImGuiMouseButton.Left)) {
|
if (ImGui.isMouseDoubleClicked(ImGuiMouseButton.Left)) {
|
||||||
MinecraftKeyframeHandler minecraftKeyframeHandler = new MinecraftKeyframeHandler(Minecraft.getInstance());
|
MinecraftKeyframeHandler minecraftKeyframeHandler = new MinecraftKeyframeHandler(Minecraft.getInstance());
|
||||||
if (minecraftKeyframeHandler.supportedKeyframes().contains(closest.getValue().keyframeType())) {
|
if (closest.getValue().keyframeType().supportsHandler(minecraftKeyframeHandler)) {
|
||||||
closest.getValue().apply(minecraftKeyframeHandler);
|
closest.getValue().createChange().apply(minecraftKeyframeHandler);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
grabbedKeyframe = true;
|
grabbedKeyframe = true;
|
||||||
@@ -1141,7 +1141,7 @@ public class TimelineWindow {
|
|||||||
if (!multiple && editingKeyframe instanceof CameraKeyframe cameraKeyframe) {
|
if (!multiple && editingKeyframe instanceof CameraKeyframe cameraKeyframe) {
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("Apply")) {
|
if (ImGui.button("Apply")) {
|
||||||
cameraKeyframe.apply(new MinecraftKeyframeHandler(Minecraft.getInstance()));
|
cameraKeyframe.createChange().apply(new MinecraftKeyframeHandler(Minecraft.getInstance()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1566,6 +1566,10 @@ public class TimelineWindow {
|
|||||||
case HOLD -> {
|
case HOLD -> {
|
||||||
drawList.addRectFilled(x - keyframeSize, y - keyframeSize, x + keyframeSize, y + keyframeSize, colour);
|
drawList.addRectFilled(x - keyframeSize, y - keyframeSize, x + keyframeSize, y + keyframeSize, colour);
|
||||||
}
|
}
|
||||||
|
case HERMITE -> {
|
||||||
|
drawList.addTriangleFilled(x, y - keyframeSize, x + keyframeSize, y + keyframeSize,
|
||||||
|
x - keyframeSize, y + keyframeSize, colour);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.moulberry.flashback.keyframe;
|
|||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
||||||
@@ -14,6 +15,7 @@ import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
|||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -31,10 +33,9 @@ public abstract class Keyframe {
|
|||||||
|
|
||||||
public abstract KeyframeType<?> keyframeType();
|
public abstract KeyframeType<?> keyframeType();
|
||||||
public abstract Keyframe copy();
|
public abstract Keyframe copy();
|
||||||
public abstract void apply(KeyframeHandler t);
|
public abstract KeyframeChange createChange();
|
||||||
public abstract void applyInterpolated(KeyframeHandler t, Keyframe other, float amount);
|
public abstract KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount);
|
||||||
public abstract void applyInterpolatedSmooth(KeyframeHandler t, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount,
|
public abstract KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount);
|
||||||
float lerpAmount, boolean lerpFromRight);
|
|
||||||
|
|
||||||
public void renderEditKeyframe(Consumer<Consumer<Keyframe>> update) {}
|
public void renderEditKeyframe(Consumer<Consumer<Keyframe>> update) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.moulberry.flashback.keyframe;
|
package com.moulberry.flashback.keyframe;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface KeyframeType<T extends Keyframe> {
|
public interface KeyframeType<T extends Keyframe> {
|
||||||
@@ -12,6 +14,11 @@ public interface KeyframeType<T extends Keyframe> {
|
|||||||
@Nullable T createDirect();
|
@Nullable T createDirect();
|
||||||
@Nullable KeyframeCreatePopup<T> createPopup();
|
@Nullable KeyframeCreatePopup<T> createPopup();
|
||||||
|
|
||||||
|
Class<? extends KeyframeChange> keyframeChangeType();
|
||||||
|
default boolean supportsHandler(KeyframeHandler handler) {
|
||||||
|
return handler.supportsKeyframeChange(this.keyframeChangeType());
|
||||||
|
}
|
||||||
|
|
||||||
default boolean allowChangingInterpolationType() {
|
default boolean allowChangingInterpolationType() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
|
||||||
|
public interface KeyframeChange {
|
||||||
|
|
||||||
|
void apply(KeyframeHandler keyframeHandler);
|
||||||
|
KeyframeChange interpolate(KeyframeChange to, double amount);
|
||||||
|
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Interpolation;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
public record KeyframeChangeCameraPosition(Vector3d position, double yaw, double pitch, double roll) implements KeyframeChange {
|
||||||
|
@Override
|
||||||
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
|
keyframeHandler.applyCameraPosition(this.position, this.yaw, this.pitch, this.roll);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeChange interpolate(KeyframeChange to, double amount) {
|
||||||
|
KeyframeChangeCameraPosition other = (KeyframeChangeCameraPosition) to;
|
||||||
|
return new KeyframeChangeCameraPosition(
|
||||||
|
this.position.lerp(other.position, amount, new Vector3d()),
|
||||||
|
Interpolation.linear(this.yaw, other.yaw, amount),
|
||||||
|
Interpolation.linear(this.pitch, other.pitch, amount),
|
||||||
|
Interpolation.linear(this.roll, other.roll, amount)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Interpolation;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
|
||||||
|
public record KeyframeChangeCameraShake(float frequencyX, float amplitudeX, float frequencyY, float amplitudeY) implements KeyframeChange {
|
||||||
|
@Override
|
||||||
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
|
keyframeHandler.applyCameraShake(this.frequencyX, this.amplitudeX, this.frequencyY, this.amplitudeY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeChange interpolate(KeyframeChange to, double amount) {
|
||||||
|
KeyframeChangeCameraShake other = (KeyframeChangeCameraShake) to;
|
||||||
|
return new KeyframeChangeCameraShake(
|
||||||
|
(float) Interpolation.linear(this.frequencyX, other.frequencyX, amount),
|
||||||
|
(float) Interpolation.linear(this.amplitudeX, other.amplitudeX, amount),
|
||||||
|
(float) Interpolation.linear(this.frequencyY, other.frequencyY, amount),
|
||||||
|
(float) Interpolation.linear(this.amplitudeY, other.amplitudeY, amount)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Interpolation;
|
||||||
|
import com.moulberry.flashback.Utils;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
|
||||||
|
public record KeyframeChangeFov(float fov) implements KeyframeChange {
|
||||||
|
@Override
|
||||||
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
|
keyframeHandler.applyFov(this.fov);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeChange interpolate(KeyframeChange to, double amount) {
|
||||||
|
KeyframeChangeFov other = (KeyframeChangeFov) to;
|
||||||
|
float thisFocalLength = Utils.fovToFocalLength(this.fov);
|
||||||
|
float otherFocalLength = Utils.fovToFocalLength(other.fov);
|
||||||
|
float focalLength = (float) Interpolation.linear(thisFocalLength, otherFocalLength, amount);
|
||||||
|
|
||||||
|
return new KeyframeChangeFov(Utils.focalLengthToFov(focalLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
|
||||||
|
public record KeyframeChangeFreeze(boolean frozen, int frozenDelay) implements KeyframeChange {
|
||||||
|
@Override
|
||||||
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
|
keyframeHandler.applyFreeze(this.frozen, this.frozenDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeChange interpolate(KeyframeChange to, double amount) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Interpolation;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
|
||||||
|
public record KeyframeChangeTickrate(float tickrate) implements KeyframeChange {
|
||||||
|
@Override
|
||||||
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
|
keyframeHandler.applyTickrate(this.tickrate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeChange interpolate(KeyframeChange to, double amount) {
|
||||||
|
KeyframeChangeTickrate other = (KeyframeChangeTickrate) to;
|
||||||
|
return new KeyframeChangeTickrate(
|
||||||
|
(float) Interpolation.linear(this.tickrate, other.tickrate, amount)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.change;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Interpolation;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
|
||||||
|
public record KeyframeChangeTimeOfDay(int timeOfDay) implements KeyframeChange {
|
||||||
|
@Override
|
||||||
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
|
keyframeHandler.applyTimeOfDay(this.timeOfDay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeChange interpolate(KeyframeChange to, double amount) {
|
||||||
|
KeyframeChangeTimeOfDay other = (KeyframeChangeTimeOfDay) to;
|
||||||
|
return new KeyframeChangeTimeOfDay(
|
||||||
|
(int) Interpolation.linear(this.timeOfDay, other.timeOfDay, amount)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.moulberry.flashback.keyframe.handler;
|
package com.moulberry.flashback.keyframe.handler;
|
||||||
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
@@ -8,35 +9,28 @@ import java.util.EnumSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface KeyframeHandler {
|
public interface KeyframeHandler {
|
||||||
|
boolean supportsKeyframeChange(Class<? extends KeyframeChange> clazz);
|
||||||
Set<KeyframeType<?>> supportedKeyframes();
|
|
||||||
|
|
||||||
default boolean alwaysApplyLastKeyframe() {
|
default boolean alwaysApplyLastKeyframe() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyCameraPosition(Vector3d position, double yaw, double pitch, double roll) {
|
default void applyCameraPosition(Vector3d position, double yaw, double pitch, double roll) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyFov(float fov) {
|
default void applyFov(float fov) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyTickrate(float tickrate) {
|
default void applyTickrate(float tickrate) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyFreeze(boolean frozen, int frozenDelay) {
|
default void applyFreeze(boolean frozen, int frozenDelay) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyTimeOfDay(int timeOfDay) {
|
default void applyTimeOfDay(int timeOfDay) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyCameraShake(float frequencyX, float amplitudeX, float frequencyY, float amplitudeY) {
|
default void applyCameraShake(float frequencyX, float amplitudeX, float frequencyY, float amplitudeY) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+7
-25
@@ -1,37 +1,24 @@
|
|||||||
package com.moulberry.flashback.keyframe.handler;
|
package com.moulberry.flashback.keyframe.handler;
|
||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.keyframe.change.*;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.types.CameraShakeKeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.types.FOVKeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.types.FreezeKeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.types.TimeOfDayKeyframeType;
|
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MinecraftKeyframeHandler implements KeyframeHandler {
|
public record MinecraftKeyframeHandler(Minecraft minecraft) implements KeyframeHandler {
|
||||||
|
|
||||||
private final Minecraft minecraft;
|
private static final Set<Class<? extends KeyframeChange>> supportedChanges = Set.of(
|
||||||
|
KeyframeChangeCameraPosition.class, KeyframeChangeFov.class, KeyframeChangeTimeOfDay.class, KeyframeChangeCameraShake.class
|
||||||
public MinecraftKeyframeHandler(Minecraft minecraft) {
|
);
|
||||||
this.minecraft = minecraft;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<KeyframeType<?>> supportedKeyframes() {
|
public boolean supportsKeyframeChange(Class<? extends KeyframeChange> clazz) {
|
||||||
return Set.of(CameraKeyframeType.INSTANCE, CameraOrbitKeyframeType.INSTANCE, FOVKeyframeType.INSTANCE,
|
return supportedChanges.contains(clazz);
|
||||||
TimeOfDayKeyframeType.INSTANCE, CameraShakeKeyframeType.INSTANCE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,11 +50,6 @@ public class MinecraftKeyframeHandler implements KeyframeHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyTickrate(float tickrate) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyTimeOfDay(int timeOfDay) {
|
public void applyTimeOfDay(int timeOfDay) {
|
||||||
timeOfDay = timeOfDay % 24000;
|
timeOfDay = timeOfDay % 24000;
|
||||||
|
|||||||
+10
-9
@@ -1,6 +1,9 @@
|
|||||||
package com.moulberry.flashback.keyframe.handler;
|
package com.moulberry.flashback.keyframe.handler;
|
||||||
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFreeze;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
import com.moulberry.flashback.keyframe.types.FreezeKeyframeType;
|
import com.moulberry.flashback.keyframe.types.FreezeKeyframeType;
|
||||||
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
||||||
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
@@ -9,12 +12,15 @@ import com.moulberry.flashback.playback.ReplayServer;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ReplayServerKeyframeHandler implements KeyframeHandler {
|
public record ReplayServerKeyframeHandler(ReplayServer replayServer) implements KeyframeHandler {
|
||||||
|
|
||||||
private final ReplayServer replayServer;
|
private static final Set<Class<? extends KeyframeChange>> supportedChanges = Set.of(
|
||||||
|
KeyframeChangeTickrate.class, KeyframeChangeFreeze.class
|
||||||
|
);
|
||||||
|
|
||||||
public ReplayServerKeyframeHandler(ReplayServer replayServer) {
|
@Override
|
||||||
this.replayServer = replayServer;
|
public boolean supportsKeyframeChange(Class<? extends KeyframeChange> clazz) {
|
||||||
|
return supportedChanges.contains(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -22,11 +28,6 @@ public class ReplayServerKeyframeHandler implements KeyframeHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<KeyframeType<?>> supportedKeyframes() {
|
|
||||||
return Set.of(SpeedKeyframeType.INSTANCE, TimelapseKeyframeType.INSTANCE, FreezeKeyframeType.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyFov(float fov) {
|
public void applyFov(float fov) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.moulberry.flashback.keyframe.handler;
|
package com.moulberry.flashback.keyframe.handler;
|
||||||
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFreeze;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
import com.moulberry.flashback.keyframe.types.FreezeKeyframeType;
|
import com.moulberry.flashback.keyframe.types.FreezeKeyframeType;
|
||||||
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
||||||
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
@@ -8,13 +11,17 @@ import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TickrateKeyframeCapture implements KeyframeHandler {
|
public class TickrateKeyframeCapture implements KeyframeHandler {
|
||||||
|
private static final Set<Class<? extends KeyframeChange>> supportedChanges = Set.of(
|
||||||
|
KeyframeChangeTickrate.class, KeyframeChangeFreeze.class
|
||||||
|
);
|
||||||
|
|
||||||
public float tickrate = 20.0f;
|
public float tickrate = 20.0f;
|
||||||
public boolean frozen = false;
|
public boolean frozen = false;
|
||||||
public int frozenDelay = 0;
|
public int frozenDelay = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<KeyframeType<?>> supportedKeyframes() {
|
public boolean supportsKeyframeChange(Class<? extends KeyframeChange> clazz) {
|
||||||
return Set.of(SpeedKeyframeType.INSTANCE, TimelapseKeyframeType.INSTANCE, FreezeKeyframeType.INSTANCE);
|
return supportedChanges.contains(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.moulberry.flashback.Interpolation;
|
import com.moulberry.flashback.Interpolation;
|
||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
||||||
import com.moulberry.flashback.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import org.apache.commons.math3.analysis.interpolation.HermiteInterpolator;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CameraKeyframe extends Keyframe {
|
public class CameraKeyframe extends Keyframe {
|
||||||
@@ -107,31 +113,12 @@ public class CameraKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
keyframeHandler.applyCameraPosition(this.position, this.yaw, this.pitch, this.roll);
|
return new KeyframeChangeCameraPosition(this.position, this.yaw, this.pitch, this.roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe genericOther, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
if (!(genericOther instanceof CameraKeyframe other)) {
|
|
||||||
this.apply(keyframeHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double x = Interpolation.linear(this.position.x, other.position.x, amount);
|
|
||||||
double y = Interpolation.linear(this.position.y, other.position.y, amount);
|
|
||||||
double z = Interpolation.linear(this.position.z, other.position.z, amount);
|
|
||||||
Vector3d position = new Vector3d(x, y, z);
|
|
||||||
|
|
||||||
float yaw = Interpolation.linearAngle(this.yaw, other.yaw, amount);
|
|
||||||
float pitch = Interpolation.linearAngle(this.pitch, other.pitch, amount);
|
|
||||||
float roll = Interpolation.linearAngle(this.roll, other.roll, amount);
|
|
||||||
|
|
||||||
keyframeHandler.applyCameraPosition(position, yaw, pitch, roll);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
|
||||||
float time1 = t1 - t0;
|
float time1 = t1 - t0;
|
||||||
float time2 = t2 - t0;
|
float time2 = t2 - t0;
|
||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
@@ -141,10 +128,6 @@ public class CameraKeyframe extends Keyframe {
|
|||||||
((CameraKeyframe)p1).position, ((CameraKeyframe)p2).position,
|
((CameraKeyframe)p1).position, ((CameraKeyframe)p2).position,
|
||||||
((CameraKeyframe)p3).position, time1, time2, time3, amount);
|
((CameraKeyframe)p3).position, time1, time2, time3, amount);
|
||||||
|
|
||||||
double x = position.x;
|
|
||||||
double y = position.y;
|
|
||||||
double z = position.z;
|
|
||||||
|
|
||||||
// Calculate rotation
|
// Calculate rotation
|
||||||
float yaw = CatmullRom.degrees(this.yaw,
|
float yaw = CatmullRom.degrees(this.yaw,
|
||||||
((CameraKeyframe)p1).yaw, ((CameraKeyframe)p2).yaw,
|
((CameraKeyframe)p1).yaw, ((CameraKeyframe)p2).yaw,
|
||||||
@@ -156,35 +139,17 @@ public class CameraKeyframe extends Keyframe {
|
|||||||
((CameraKeyframe)p1).roll, ((CameraKeyframe)p2).roll,
|
((CameraKeyframe)p1).roll, ((CameraKeyframe)p2).roll,
|
||||||
((CameraKeyframe)p3).roll, time1, time2, time3, amount);
|
((CameraKeyframe)p3).roll, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
return new KeyframeChangeCameraPosition(position, yaw, pitch, roll);
|
||||||
double linearX = Interpolation.linear(((CameraKeyframe)p1).position.x, ((CameraKeyframe)p2).position.x, lerpAmount);
|
|
||||||
double linearY = Interpolation.linear(((CameraKeyframe)p1).position.y, ((CameraKeyframe)p2).position.y, lerpAmount);
|
|
||||||
double linearZ = Interpolation.linear(((CameraKeyframe)p1).position.z, ((CameraKeyframe)p2).position.z, lerpAmount);
|
|
||||||
float linearYaw = Interpolation.linearAngle(((CameraKeyframe)p1).yaw, ((CameraKeyframe)p2).yaw, lerpAmount);
|
|
||||||
float linearPitch = Interpolation.linearAngle(((CameraKeyframe)p1).pitch, ((CameraKeyframe)p2).pitch, lerpAmount);
|
|
||||||
float linearRoll = Interpolation.linearAngle(((CameraKeyframe)p1).roll, ((CameraKeyframe)p2).roll, lerpAmount);
|
|
||||||
|
|
||||||
if (lerpFromRight) {
|
|
||||||
x = Interpolation.linear(x, linearX, amount);
|
|
||||||
y = Interpolation.linear(y, linearY, amount);
|
|
||||||
z = Interpolation.linear(z, linearZ, amount);
|
|
||||||
yaw = Interpolation.linearAngle(yaw, linearYaw, amount);
|
|
||||||
pitch = Interpolation.linearAngle(pitch, linearPitch, amount);
|
|
||||||
roll = Interpolation.linearAngle(roll, linearRoll, amount);
|
|
||||||
} else {
|
|
||||||
x = Interpolation.linear(linearX, x, amount);
|
|
||||||
y = Interpolation.linear(linearY, y, amount);
|
|
||||||
z = Interpolation.linear(linearZ, z, amount);
|
|
||||||
yaw = Interpolation.linearAngle(linearYaw, yaw, amount);
|
|
||||||
pitch = Interpolation.linearAngle(linearPitch, pitch, amount);
|
|
||||||
roll = Interpolation.linearAngle(linearRoll, roll, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
position.x = x;
|
@Override
|
||||||
position.y = y;
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
position.z = z;
|
Vector3d position = Hermite.position(Maps.transformValues(keyframes, k -> ((CameraKeyframe)k).position), amount);
|
||||||
keyframeHandler.applyCameraPosition(position, yaw, pitch, roll);
|
double yaw = Hermite.degrees(Maps.transformValues(keyframes, k -> (double) ((CameraKeyframe)k).yaw), amount);
|
||||||
|
double pitch = Hermite.degrees(Maps.transformValues(keyframes, k -> (double) ((CameraKeyframe)k).pitch), amount);
|
||||||
|
double roll = Hermite.degrees(Maps.transformValues(keyframes, k -> (double) ((CameraKeyframe)k).roll), amount);
|
||||||
|
|
||||||
|
return new KeyframeChangeCameraPosition(position, yaw, pitch, roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<CameraKeyframe>, JsonDeserializer<CameraKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<CameraKeyframe>, JsonDeserializer<CameraKeyframe> {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -11,10 +12,13 @@ import com.moulberry.flashback.Interpolation;
|
|||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
||||||
import com.moulberry.flashback.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
@@ -28,6 +32,7 @@ import org.joml.Quaternionf;
|
|||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CameraOrbitKeyframe extends Keyframe {
|
public class CameraOrbitKeyframe extends Keyframe {
|
||||||
@@ -93,7 +98,7 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void apply(KeyframeHandler keyframeHandler, Vector3d center, float distance, float yaw, float pitch) {
|
private static KeyframeChangeCameraPosition createChangeFrom(Vector3d center, float distance, float yaw, float pitch) {
|
||||||
float pitchRadians = (float) Math.toRadians(pitch);
|
float pitchRadians = (float) Math.toRadians(pitch);
|
||||||
float yawRadians = (float) Math.toRadians(-yaw);
|
float yawRadians = (float) Math.toRadians(-yaw);
|
||||||
float cosYaw = Mth.cos(yawRadians);
|
float cosYaw = Mth.cos(yawRadians);
|
||||||
@@ -107,79 +112,46 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
if (player != null) {
|
if (player != null) {
|
||||||
cameraPosition.y -= player.getEyeHeight();
|
cameraPosition.y -= player.getEyeHeight();
|
||||||
}
|
}
|
||||||
keyframeHandler.applyCameraPosition(cameraPosition, yaw, pitch, 0.0f);
|
return new KeyframeChangeCameraPosition(cameraPosition, yaw, pitch, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
apply(keyframeHandler, this.center, this.distance, this.yaw, this.pitch);
|
return createChangeFrom(this.center, this.distance, this.yaw, this.pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe genericOther, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
if (!(genericOther instanceof CameraOrbitKeyframe other)) {
|
|
||||||
this.apply(keyframeHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double x = Interpolation.linear(this.center.x, other.center.x, amount);
|
|
||||||
double y = Interpolation.linear(this.center.y, other.center.y, amount);
|
|
||||||
double z = Interpolation.linear(this.center.z, other.center.z, amount);
|
|
||||||
float distance = Interpolation.linear(this.distance, other.distance, amount);
|
|
||||||
float yaw = Interpolation.linear(this.yaw, other.yaw, amount);
|
|
||||||
float pitch = Interpolation.linear(this.pitch, other.pitch, amount);
|
|
||||||
|
|
||||||
Vector3d center = new Vector3d((float) x, (float) y, (float) z);
|
|
||||||
apply(keyframeHandler, center, distance, yaw, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
|
||||||
float time1 = t1 - t0;
|
float time1 = t1 - t0;
|
||||||
float time2 = t2 - t0;
|
float time2 = t2 - t0;
|
||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
|
|
||||||
// Calculate position
|
|
||||||
Vector3d position = CatmullRom.position(this.center,
|
Vector3d position = CatmullRom.position(this.center,
|
||||||
((CameraOrbitKeyframe)p1).center, ((CameraOrbitKeyframe)p2).center,
|
((CameraOrbitKeyframe)p1).center, ((CameraOrbitKeyframe)p2).center,
|
||||||
((CameraOrbitKeyframe)p3).center, time1, time2, time3, amount);
|
((CameraOrbitKeyframe)p3).center, time1, time2, time3, amount);
|
||||||
|
|
||||||
double x = position.x;
|
|
||||||
double y = position.y;
|
|
||||||
double z = position.z;
|
|
||||||
float distance = CatmullRom.value(this.distance, ((CameraOrbitKeyframe)p1).distance, ((CameraOrbitKeyframe)p2).distance,
|
float distance = CatmullRom.value(this.distance, ((CameraOrbitKeyframe)p1).distance, ((CameraOrbitKeyframe)p2).distance,
|
||||||
((CameraOrbitKeyframe)p3).distance, time1, time2, time3, amount);
|
((CameraOrbitKeyframe)p3).distance, time1, time2, time3, amount);
|
||||||
|
|
||||||
|
// Note: we don't use CatmullRom#degrees because we want to allow multiple rotations in a single orbit
|
||||||
float yaw = CatmullRom.value(this.yaw, ((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw,
|
float yaw = CatmullRom.value(this.yaw, ((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw,
|
||||||
((CameraOrbitKeyframe)p3).yaw, time1, time2, time3, amount);
|
((CameraOrbitKeyframe)p3).yaw, time1, time2, time3, amount);
|
||||||
float pitch = CatmullRom.value(this.pitch, ((CameraOrbitKeyframe)p1).pitch, ((CameraOrbitKeyframe)p2).pitch,
|
float pitch = CatmullRom.value(this.pitch, ((CameraOrbitKeyframe)p1).pitch, ((CameraOrbitKeyframe)p2).pitch,
|
||||||
((CameraOrbitKeyframe)p3).pitch, time1, time2, time3, amount);
|
((CameraOrbitKeyframe)p3).pitch, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
return createChangeFrom(position, distance, yaw, pitch);
|
||||||
double linearX = Interpolation.linear(((CameraOrbitKeyframe)p1).center.x, ((CameraOrbitKeyframe)p2).center.x, lerpAmount);
|
|
||||||
double linearY = Interpolation.linear(((CameraOrbitKeyframe)p1).center.y, ((CameraOrbitKeyframe)p2).center.y, lerpAmount);
|
|
||||||
double linearZ = Interpolation.linear(((CameraOrbitKeyframe)p1).center.z, ((CameraOrbitKeyframe)p2).center.z, lerpAmount);
|
|
||||||
float linearDistance = Interpolation.linear(((CameraOrbitKeyframe)p1).distance, ((CameraOrbitKeyframe)p2).distance, amount);
|
|
||||||
float linearYaw = Interpolation.linear(((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw, amount);
|
|
||||||
float linearPitch = Interpolation.linear(((CameraOrbitKeyframe)p1).pitch, ((CameraOrbitKeyframe)p2).pitch, amount);
|
|
||||||
|
|
||||||
if (lerpFromRight) {
|
|
||||||
x = Interpolation.linear(x, linearX, amount);
|
|
||||||
y = Interpolation.linear(y, linearY, amount);
|
|
||||||
z = Interpolation.linear(z, linearZ, amount);
|
|
||||||
distance = Interpolation.linear(distance, linearDistance, amount);
|
|
||||||
yaw = Interpolation.linear(yaw, linearYaw, amount);
|
|
||||||
pitch = Interpolation.linear(pitch, linearPitch, amount);
|
|
||||||
} else {
|
|
||||||
x = Interpolation.linear(linearX, x, amount);
|
|
||||||
y = Interpolation.linear(linearY, y, amount);
|
|
||||||
z = Interpolation.linear(linearZ, z, amount);
|
|
||||||
distance = Interpolation.linear(linearDistance, distance, amount);
|
|
||||||
yaw = Interpolation.linear(linearYaw, yaw, amount);
|
|
||||||
pitch = Interpolation.linear(linearPitch, pitch, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(keyframeHandler, new Vector3d(x, y, z), distance, yaw, pitch);
|
@Override
|
||||||
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
|
Vector3d position = Hermite.position(Maps.transformValues(keyframes, k -> ((CameraOrbitKeyframe)k).center), amount);
|
||||||
|
double distance = Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraOrbitKeyframe)k).distance), amount);
|
||||||
|
|
||||||
|
// Note: we don't use Hermite#degrees because we want to allow multiple rotations in a single orbit
|
||||||
|
double yaw = Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraOrbitKeyframe)k).yaw), amount);
|
||||||
|
double pitch = Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraOrbitKeyframe)k).pitch), amount);
|
||||||
|
|
||||||
|
return createChangeFrom(position, (float) distance, (float) yaw, (float) pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<CameraOrbitKeyframe>, JsonDeserializer<CameraOrbitKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<CameraOrbitKeyframe>, JsonDeserializer<CameraOrbitKeyframe> {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -10,15 +11,20 @@ import com.google.gson.JsonSerializer;
|
|||||||
import com.moulberry.flashback.Interpolation;
|
import com.moulberry.flashback.Interpolation;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraShake;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFov;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.CameraShakeKeyframeType;
|
import com.moulberry.flashback.keyframe.types.CameraShakeKeyframeType;
|
||||||
import com.moulberry.flashback.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CameraShakeKeyframe extends Keyframe {
|
public class CameraShakeKeyframe extends Keyframe {
|
||||||
@@ -123,27 +129,12 @@ public class CameraShakeKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
keyframeHandler.applyCameraShake(this.frequencyX, this.amplitudeX, this.frequencyY, this.amplitudeY);
|
return new KeyframeChangeCameraShake(this.frequencyX, this.amplitudeX, this.frequencyY, this.amplitudeY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe otherGeneric, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
if (!(otherGeneric instanceof CameraShakeKeyframe other)) {
|
|
||||||
this.apply(keyframeHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float frequencyX = Interpolation.linear(this.frequencyX, other.frequencyX, amount);
|
|
||||||
float amplitudeX = Interpolation.linear(this.amplitudeX, other.amplitudeX, amount);
|
|
||||||
float frequencyY = Interpolation.linear(this.frequencyY, other.frequencyY, amount);
|
|
||||||
float amplitudeY = Interpolation.linear(this.amplitudeY, other.amplitudeY, amount);
|
|
||||||
|
|
||||||
keyframeHandler.applyCameraShake(frequencyX, amplitudeX, frequencyY, amplitudeY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
|
||||||
float time1 = t1 - t0;
|
float time1 = t1 - t0;
|
||||||
float time2 = t2 - t0;
|
float time2 = t2 - t0;
|
||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
@@ -157,26 +148,17 @@ public class CameraShakeKeyframe extends Keyframe {
|
|||||||
float amplitudeY = CatmullRom.value(this.amplitudeY, ((CameraShakeKeyframe)p1).amplitudeY,
|
float amplitudeY = CatmullRom.value(this.amplitudeY, ((CameraShakeKeyframe)p1).amplitudeY,
|
||||||
((CameraShakeKeyframe)p2).amplitudeY, ((CameraShakeKeyframe)p3).amplitudeY, time1, time2, time3, amount);
|
((CameraShakeKeyframe)p2).amplitudeY, ((CameraShakeKeyframe)p3).amplitudeY, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
return new KeyframeChangeCameraShake(frequencyX, amplitudeX, frequencyY, amplitudeY);
|
||||||
float linearFrequencyX = Interpolation.linear(((CameraShakeKeyframe)p1).frequencyX, ((CameraShakeKeyframe)p2).frequencyX, lerpAmount);
|
|
||||||
float linearAmplitudeX = Interpolation.linear(((CameraShakeKeyframe)p1).amplitudeX, ((CameraShakeKeyframe)p2).amplitudeX, lerpAmount);
|
|
||||||
float linearFrequencyY = Interpolation.linear(((CameraShakeKeyframe)p1).frequencyY, ((CameraShakeKeyframe)p2).frequencyY, lerpAmount);
|
|
||||||
float linearAmplitudeY = Interpolation.linear(((CameraShakeKeyframe)p1).amplitudeY, ((CameraShakeKeyframe)p2).amplitudeY, lerpAmount);
|
|
||||||
|
|
||||||
if (lerpFromRight) {
|
|
||||||
frequencyX = Interpolation.linear(frequencyX, linearFrequencyX, amount);
|
|
||||||
amplitudeX = Interpolation.linear(amplitudeX, linearAmplitudeX, amount);
|
|
||||||
frequencyY = Interpolation.linear(frequencyY, linearFrequencyY, amount);
|
|
||||||
amplitudeY = Interpolation.linear(amplitudeY, linearAmplitudeY, amount);
|
|
||||||
} else {
|
|
||||||
frequencyX = Interpolation.linear(linearFrequencyX, frequencyX, amount);
|
|
||||||
amplitudeX = Interpolation.linear(linearAmplitudeX, amplitudeX, amount);
|
|
||||||
frequencyY = Interpolation.linear(linearFrequencyY, frequencyY, amount);
|
|
||||||
amplitudeY = Interpolation.linear(linearAmplitudeY, amplitudeY, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keyframeHandler.applyCameraShake(frequencyX, amplitudeX, frequencyY, amplitudeY);
|
@Override
|
||||||
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
|
float frequencyX = (float) Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraShakeKeyframe)k).frequencyX), amount);
|
||||||
|
float amplitudeX = (float) Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraShakeKeyframe)k).amplitudeX), amount);
|
||||||
|
float frequencyY = (float) Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraShakeKeyframe)k).frequencyY), amount);
|
||||||
|
float amplitudeY = (float) Hermite.value(Maps.transformValues(keyframes, k -> (double) ((CameraShakeKeyframe)k).amplitudeY), amount);
|
||||||
|
|
||||||
|
return new KeyframeChangeCameraShake(frequencyX, amplitudeX, frequencyY, amplitudeY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<CameraShakeKeyframe>, JsonDeserializer<CameraShakeKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<CameraShakeKeyframe>, JsonDeserializer<CameraShakeKeyframe> {
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.moulberry.flashback.Interpolation;
|
import com.moulberry.flashback.Interpolation;
|
||||||
import com.moulberry.flashback.Utils;
|
import com.moulberry.flashback.Utils;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFov;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.FOVKeyframeType;
|
import com.moulberry.flashback.keyframe.types.FOVKeyframeType;
|
||||||
import com.moulberry.flashback.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class FOVKeyframe extends Keyframe {
|
public class FOVKeyframe extends Keyframe {
|
||||||
@@ -49,26 +54,12 @@ public class FOVKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
keyframeHandler.applyFov(this.fov);
|
return new KeyframeChangeFov(this.fov);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe otherGeneric, float amount) {
|
|
||||||
if (!(otherGeneric instanceof FOVKeyframe other)) {
|
|
||||||
this.apply(keyframeHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float thisFocalLength = Utils.fovToFocalLength(this.fov);
|
|
||||||
float otherFocalLength = Utils.fovToFocalLength(other.fov);
|
|
||||||
float focalLength = Interpolation.linear(thisFocalLength, otherFocalLength, amount);
|
|
||||||
keyframeHandler.applyFov(Utils.focalLengthToFov(focalLength));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
float time1 = t1 - t0;
|
float time1 = t1 - t0;
|
||||||
float time2 = t2 - t0;
|
float time2 = t2 - t0;
|
||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
@@ -80,17 +71,13 @@ public class FOVKeyframe extends Keyframe {
|
|||||||
|
|
||||||
float focalLength = CatmullRom.value(f0, f1, f2, f3, time1, time2, time3, amount);
|
float focalLength = CatmullRom.value(f0, f1, f2, f3, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
return new KeyframeChangeFov(Utils.focalLengthToFov(focalLength));
|
||||||
float linearFocalLength = Interpolation.linear(f1, f2, lerpAmount);
|
|
||||||
|
|
||||||
if (lerpFromRight) {
|
|
||||||
focalLength = Interpolation.linear(focalLength, linearFocalLength, amount);
|
|
||||||
} else {
|
|
||||||
focalLength = Interpolation.linear(linearFocalLength, focalLength, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keyframeHandler.applyFov(Utils.focalLengthToFov(focalLength));
|
@Override
|
||||||
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
|
float focalLength = (float) Hermite.value(Maps.transformValues(keyframes, k -> (double) Utils.fovToFocalLength(((FOVKeyframe)k).fov)), amount);
|
||||||
|
return new KeyframeChangeFov(Utils.focalLengthToFov(focalLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<FOVKeyframe>, JsonDeserializer<FOVKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<FOVKeyframe>, JsonDeserializer<FOVKeyframe> {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import com.moulberry.flashback.Interpolation;
|
|||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFreeze;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
||||||
@@ -18,6 +20,7 @@ import com.moulberry.flashback.spline.CatmullRom;
|
|||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class FreezeKeyframe extends Keyframe {
|
public class FreezeKeyframe extends Keyframe {
|
||||||
@@ -62,18 +65,18 @@ public class FreezeKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
keyframeHandler.applyFreeze(this.frozen, Math.max(0, Math.min(10, this.frozenDelay)));
|
return new KeyframeChangeFreeze(this.frozen, Math.max(0, Math.min(10, this.frozenDelay)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe otherGeneric, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
this.apply(keyframeHandler);
|
return this.createChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
p1.apply(keyframeHandler);
|
return this.createChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<FreezeKeyframe>, JsonDeserializer<FreezeKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<FreezeKeyframe>, JsonDeserializer<FreezeKeyframe> {
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.moulberry.flashback.Interpolation;
|
import com.moulberry.flashback.Interpolation;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
import com.moulberry.flashback.keyframe.types.SpeedKeyframeType;
|
||||||
import com.moulberry.flashback.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TickrateKeyframe extends Keyframe {
|
public class TickrateKeyframe extends Keyframe {
|
||||||
@@ -49,23 +54,12 @@ public class TickrateKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
keyframeHandler.applyTickrate(this.tickrate);
|
return new KeyframeChangeTickrate(this.tickrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe otherGeneric, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
if (!(otherGeneric instanceof TickrateKeyframe other)) {
|
|
||||||
this.apply(keyframeHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float tickrate = Interpolation.linear(this.tickrate, other.tickrate, amount);
|
|
||||||
keyframeHandler.applyTickrate(tickrate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
|
||||||
float time1 = t1 - t0;
|
float time1 = t1 - t0;
|
||||||
float time2 = t2 - t0;
|
float time2 = t2 - t0;
|
||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
@@ -74,17 +68,13 @@ public class TickrateKeyframe extends Keyframe {
|
|||||||
((TickrateKeyframe)p1).tickrate, ((TickrateKeyframe)p2).tickrate,
|
((TickrateKeyframe)p1).tickrate, ((TickrateKeyframe)p2).tickrate,
|
||||||
((TickrateKeyframe)p3).tickrate, time1, time2, time3, amount);
|
((TickrateKeyframe)p3).tickrate, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
return new KeyframeChangeTickrate(tickrate);
|
||||||
float linearTickrate = Interpolation.linear(((TickrateKeyframe)p1).tickrate, ((TickrateKeyframe)p2).tickrate, lerpAmount);
|
|
||||||
|
|
||||||
if (lerpFromRight) {
|
|
||||||
tickrate = Interpolation.linear(tickrate, linearTickrate, amount);
|
|
||||||
} else {
|
|
||||||
tickrate = Interpolation.linear(linearTickrate, tickrate, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keyframeHandler.applyTickrate(tickrate);
|
@Override
|
||||||
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
|
float tickrate = (float) Hermite.value(Maps.transformValues(keyframes, k -> (double) ((TickrateKeyframe)k).tickrate), amount);
|
||||||
|
return new KeyframeChangeTickrate(tickrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<TickrateKeyframe>, JsonDeserializer<TickrateKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<TickrateKeyframe>, JsonDeserializer<TickrateKeyframe> {
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.moulberry.flashback.Interpolation;
|
import com.moulberry.flashback.Interpolation;
|
||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTimeOfDay;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.TimeOfDayKeyframeType;
|
import com.moulberry.flashback.keyframe.types.TimeOfDayKeyframeType;
|
||||||
import com.moulberry.flashback.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImInt;
|
import imgui.type.ImInt;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TimeOfDayKeyframe extends Keyframe {
|
public class TimeOfDayKeyframe extends Keyframe {
|
||||||
@@ -50,45 +56,29 @@ public class TimeOfDayKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
keyframeHandler.applyTimeOfDay(this.time);
|
return new KeyframeChangeTimeOfDay(this.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe otherGeneric, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
if (!(otherGeneric instanceof TimeOfDayKeyframe other)) {
|
|
||||||
this.apply(keyframeHandler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int time = Math.round(Interpolation.linear(this.time, other.time, amount));
|
|
||||||
keyframeHandler.applyTimeOfDay(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
|
||||||
float time1 = t1 - t0;
|
float time1 = t1 - t0;
|
||||||
float time2 = t2 - t0;
|
float time2 = t2 - t0;
|
||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
|
|
||||||
float timeOfDay = CatmullRom.value(this.time,
|
int timeOfDay = (int) CatmullRom.value(this.time,
|
||||||
((TimeOfDayKeyframe)p1).time, ((TimeOfDayKeyframe)p2).time,
|
((TimeOfDayKeyframe)p1).time, ((TimeOfDayKeyframe)p2).time,
|
||||||
((TimeOfDayKeyframe)p3).time, time1, time2, time3, amount);
|
((TimeOfDayKeyframe)p3).time, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
return new KeyframeChangeTimeOfDay(timeOfDay);
|
||||||
float linearTimeOfDay = Interpolation.linear(((TimeOfDayKeyframe)p1).time, ((TimeOfDayKeyframe)p2).time, lerpAmount);
|
|
||||||
|
|
||||||
if (lerpFromRight) {
|
|
||||||
timeOfDay = Interpolation.linear(timeOfDay, linearTimeOfDay, amount);
|
|
||||||
} else {
|
|
||||||
timeOfDay = Interpolation.linear(linearTimeOfDay, timeOfDay, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keyframeHandler.applyTimeOfDay(Math.round(timeOfDay));
|
@Override
|
||||||
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
|
int timeOfDay = (int) Hermite.value(Maps.transformValues(keyframes, k -> (double) ((TimeOfDayKeyframe)k).time), amount);
|
||||||
|
return new KeyframeChangeTimeOfDay(timeOfDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<TimeOfDayKeyframe>, JsonDeserializer<TimeOfDayKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<TimeOfDayKeyframe>, JsonDeserializer<TimeOfDayKeyframe> {
|
||||||
@Override
|
@Override
|
||||||
public TimeOfDayKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public TimeOfDayKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.moulberry.flashback.keyframe.impl;
|
package com.moulberry.flashback.keyframe.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -11,13 +12,18 @@ import com.moulberry.flashback.Utils;
|
|||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
import com.moulberry.flashback.spline.Hermite;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImString;
|
import imgui.type.ImString;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TimelapseKeyframe extends Keyframe {
|
public class TimelapseKeyframe extends Keyframe {
|
||||||
@@ -61,17 +67,17 @@ public class TimelapseKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public KeyframeChange createChange() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolated(KeyframeHandler keyframeHandler, Keyframe otherGeneric, float amount) {
|
public KeyframeChange createSmoothInterpolatedChange(Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyInterpolatedSmooth(KeyframeHandler keyframeHandler, Keyframe p1, Keyframe p2, Keyframe p3, float t0, float t1, float t2, float t3, float amount, float lerpAmount, boolean lerpFromRight) {
|
public KeyframeChange createHermiteInterpolatedChange(Map<Integer, Keyframe> keyframes, float amount) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ public enum InterpolationType implements ComboOption {
|
|||||||
EASE_IN(SidedInterpolationType.EASE, SidedInterpolationType.LINEAR, "Ease In (Linear Out)"),
|
EASE_IN(SidedInterpolationType.EASE, SidedInterpolationType.LINEAR, "Ease In (Linear Out)"),
|
||||||
EASE_OUT(SidedInterpolationType.LINEAR, SidedInterpolationType.EASE, "Ease Out (Linear In)"),
|
EASE_OUT(SidedInterpolationType.LINEAR, SidedInterpolationType.EASE, "Ease Out (Linear In)"),
|
||||||
EASE_IN_OUT(SidedInterpolationType.EASE, SidedInterpolationType.EASE, "Ease In/Out"),
|
EASE_IN_OUT(SidedInterpolationType.EASE, SidedInterpolationType.EASE, "Ease In/Out"),
|
||||||
HOLD(SidedInterpolationType.HOLD, SidedInterpolationType.HOLD, "Hold");
|
HOLD(SidedInterpolationType.HOLD, SidedInterpolationType.HOLD, "Hold"),
|
||||||
|
HERMITE(SidedInterpolationType.HERMITE, SidedInterpolationType.HERMITE, "Smooth");
|
||||||
|
|
||||||
public static final InterpolationType[] INTERPOLATION_TYPES = values();
|
public static final InterpolationType[] INTERPOLATION_TYPES = values();
|
||||||
|
|
||||||
@@ -29,7 +30,8 @@ public enum InterpolationType implements ComboOption {
|
|||||||
"Ease In (Linear Out)",
|
"Ease In (Linear Out)",
|
||||||
"Ease Out (Linear In)",
|
"Ease Out (Linear In)",
|
||||||
"Ease In/Out",
|
"Ease In/Out",
|
||||||
"Hold"
|
"Hold",
|
||||||
|
"Hermite"
|
||||||
};
|
};
|
||||||
|
|
||||||
public final SidedInterpolationType leftSide;
|
public final SidedInterpolationType leftSide;
|
||||||
|
|||||||
+15
-3
@@ -5,11 +5,23 @@ public enum SidedInterpolationType {
|
|||||||
SMOOTH,
|
SMOOTH,
|
||||||
LINEAR,
|
LINEAR,
|
||||||
EASE,
|
EASE,
|
||||||
HOLD;
|
HOLD,
|
||||||
|
HERMITE;
|
||||||
|
|
||||||
|
private boolean isSpecial() {
|
||||||
|
return this == SidedInterpolationType.SMOOTH || this == SidedInterpolationType.HERMITE;
|
||||||
|
}
|
||||||
|
|
||||||
public static float interpolate(SidedInterpolationType left, SidedInterpolationType right, float amount) {
|
public static float interpolate(SidedInterpolationType left, SidedInterpolationType right, float amount) {
|
||||||
if (left == SidedInterpolationType.SMOOTH || right == SidedInterpolationType.SMOOTH) {
|
if (left.isSpecial()) {
|
||||||
throw new IllegalArgumentException("SMOOTH not allowed");
|
if (right.isSpecial()) {
|
||||||
|
left = SidedInterpolationType.LINEAR;
|
||||||
|
right = SidedInterpolationType.LINEAR;
|
||||||
|
} else {
|
||||||
|
left = right;
|
||||||
|
}
|
||||||
|
} else if (right.isSpecial()) {
|
||||||
|
right = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (left == SidedInterpolationType.HOLD) {
|
if (left == SidedInterpolationType.HOLD) {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.moulberry.flashback.keyframe.types;
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
@@ -14,6 +17,11 @@ public class CameraKeyframeType implements KeyframeType<CameraKeyframe> {
|
|||||||
private CameraKeyframeType() {
|
private CameraKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeCameraPosition.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ue04b";
|
return "\ue04b";
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package com.moulberry.flashback.keyframe.types;
|
|||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
@@ -22,6 +25,11 @@ public class CameraOrbitKeyframeType implements KeyframeType<CameraOrbitKeyframe
|
|||||||
private CameraOrbitKeyframeType() {
|
private CameraOrbitKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeCameraPosition.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ue577";
|
return "\ue577";
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package com.moulberry.flashback.keyframe.types;
|
|||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraShake;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
@@ -17,6 +21,10 @@ public class CameraShakeKeyframeType implements KeyframeType<CameraShakeKeyframe
|
|||||||
private CameraShakeKeyframeType() {
|
private CameraShakeKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeCameraShake.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.moulberry.flashback.keyframe.types;
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFov;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
@@ -20,6 +24,11 @@ public class FOVKeyframeType implements KeyframeType<FOVKeyframe> {
|
|||||||
private FOVKeyframeType() {
|
private FOVKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeFov.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ue3af";
|
return "\ue3af";
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package com.moulberry.flashback.keyframe.types;
|
|||||||
|
|
||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeFreeze;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.FreezeKeyframe;
|
import com.moulberry.flashback.keyframe.impl.FreezeKeyframe;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImBoolean;
|
import imgui.type.ImBoolean;
|
||||||
@@ -14,6 +18,11 @@ public class FreezeKeyframeType implements KeyframeType<FreezeKeyframe> {
|
|||||||
private FreezeKeyframeType() {
|
private FreezeKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeFreeze.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ueb3b";
|
return "\ueb3b";
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package com.moulberry.flashback.keyframe.types;
|
|||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
@@ -20,6 +24,11 @@ public class SpeedKeyframeType implements KeyframeType<TickrateKeyframe> {
|
|||||||
private SpeedKeyframeType() {
|
private SpeedKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeTickrate.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ue9e4";
|
return "\ue9e4";
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.moulberry.flashback.keyframe.types;
|
|||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTimeOfDay;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
@@ -20,6 +24,11 @@ public class TimeOfDayKeyframeType implements KeyframeType<TimeOfDayKeyframe> {
|
|||||||
private TimeOfDayKeyframeType() {
|
private TimeOfDayKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeTimeOfDay.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ue518";
|
return "\ue518";
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.moulberry.flashback.keyframe.types;
|
|||||||
import com.moulberry.flashback.Utils;
|
import com.moulberry.flashback.Utils;
|
||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeCameraPosition;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImString;
|
import imgui.type.ImString;
|
||||||
@@ -15,6 +19,11 @@ public class TimelapseKeyframeType implements KeyframeType<TimelapseKeyframe> {
|
|||||||
private TimelapseKeyframeType() {
|
private TimelapseKeyframeType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends KeyframeChange> keyframeChangeType() {
|
||||||
|
return KeyframeChangeTickrate.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String icon() {
|
public @Nullable String icon() {
|
||||||
return "\ue422";
|
return "\ue422";
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.moulberry.flashback.spline;
|
||||||
|
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import org.apache.commons.math3.analysis.interpolation.HermiteInterpolator;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Hermite {
|
||||||
|
|
||||||
|
public static Vector3d position(Map<Integer, Vector3d> map, float amount) {
|
||||||
|
HermiteInterpolator hermiteInterpolatorX = new HermiteInterpolator();
|
||||||
|
HermiteInterpolator hermiteInterpolatorY = new HermiteInterpolator();
|
||||||
|
HermiteInterpolator hermiteInterpolatorZ = new HermiteInterpolator();
|
||||||
|
|
||||||
|
double[] array = new double[1];
|
||||||
|
for (Map.Entry<Integer, Vector3d> entry : map.entrySet()) {
|
||||||
|
array[0] = entry.getValue().x;
|
||||||
|
hermiteInterpolatorX.addSamplePoint(entry.getKey(), array);
|
||||||
|
|
||||||
|
array[0] = entry.getValue().y;
|
||||||
|
hermiteInterpolatorY.addSamplePoint(entry.getKey(), array);
|
||||||
|
|
||||||
|
array[0] = entry.getValue().z;
|
||||||
|
hermiteInterpolatorZ.addSamplePoint(entry.getKey(), array);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Vector3d(
|
||||||
|
hermiteInterpolatorX.value(amount)[0],
|
||||||
|
hermiteInterpolatorY.value(amount)[0],
|
||||||
|
hermiteInterpolatorZ.value(amount)[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double value(Map<Integer, Double> map, float amount) {
|
||||||
|
HermiteInterpolator hermiteInterpolator = new HermiteInterpolator();
|
||||||
|
|
||||||
|
double[] array = new double[1];
|
||||||
|
for (Map.Entry<Integer, Double> entry : map.entrySet()) {
|
||||||
|
array[0] = entry.getValue();
|
||||||
|
hermiteInterpolator.addSamplePoint(entry.getKey(), array);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hermiteInterpolator.value(amount)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double degrees(Map<Integer, Double> map, float amount) {
|
||||||
|
HermiteInterpolator hermiteInterpolator = new HermiteInterpolator();
|
||||||
|
|
||||||
|
double lastAngle = 0.0;
|
||||||
|
|
||||||
|
double[] array = new double[1];
|
||||||
|
for (Map.Entry<Integer, Double> entry : map.entrySet()) {
|
||||||
|
double angle = lastAngle + Mth.wrapDegrees(entry.getValue() - lastAngle);
|
||||||
|
array[0] = angle;
|
||||||
|
|
||||||
|
hermiteInterpolator.addSamplePoint(entry.getKey(), array);
|
||||||
|
|
||||||
|
lastAngle = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Mth.wrapDegrees(hermiteInterpolator.value(amount)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.moulberry.flashback.FlashbackGson;
|
|||||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
||||||
@@ -125,23 +126,63 @@ public class EditorState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void applyKeyframes(KeyframeHandler keyframeHandler, float tick) {
|
public void applyKeyframes(KeyframeHandler keyframeHandler, float tick) {
|
||||||
Set<KeyframeType<?>> applied = new HashSet<>();
|
Set<Class<? extends KeyframeChange>> applied = new HashSet<>();
|
||||||
|
|
||||||
|
Map<Class<? extends KeyframeChange>, KeyframeTrack> maybeApplyLastTick = new HashMap<>();
|
||||||
|
|
||||||
for (KeyframeTrack keyframeTrack : this.currentScene().keyframeTracks) {
|
for (KeyframeTrack keyframeTrack : this.currentScene().keyframeTracks) {
|
||||||
// Ignore lines that are disabled
|
// Ignore lines that are disabled
|
||||||
if (!keyframeTrack.enabled) {
|
if (!keyframeTrack.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyframeType<?> baseType = keyframeTrack.keyframeType == CameraOrbitKeyframeType.INSTANCE ? CameraKeyframeType.INSTANCE : keyframeTrack.keyframeType;
|
Class<? extends KeyframeChange> keyframeChangeType = keyframeTrack.keyframeType.keyframeChangeType();
|
||||||
|
|
||||||
// Already applied a keyframe of this type earlier, skip
|
// Already applied a keyframe of this type earlier, skip
|
||||||
if (applied.contains(baseType)) {
|
if (applied.contains(keyframeChangeType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keyframeTrack.keyframeType.supportsHandler(keyframeHandler)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to apply keyframes, mark applied if successful
|
// Try to apply keyframes, mark applied if successful
|
||||||
if (keyframeTrack.tryApplyKeyframes(keyframeHandler, tick)) {
|
|
||||||
applied.add(baseType);
|
KeyframeChange change = keyframeTrack.createKeyframeChange(tick);
|
||||||
|
if (change == null) {
|
||||||
|
if (keyframeHandler.alwaysApplyLastKeyframe() && !keyframeTrack.keyframesByTick.isEmpty()) {
|
||||||
|
KeyframeTrack oldTrack = maybeApplyLastTick.get(keyframeChangeType);
|
||||||
|
if (oldTrack == null || keyframeTrack.keyframesByTick.lastKey() > oldTrack.keyframesByTick.lastKey()) {
|
||||||
|
maybeApplyLastTick.put(keyframeChangeType, keyframeTrack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (change.getClass() != keyframeChangeType) {
|
||||||
|
throw new IllegalStateException("Expected " + keyframeChangeType + ", got " + change.getClass() + ". Caused by: " + keyframeTrack.keyframeType.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
applied.add(keyframeChangeType);
|
||||||
|
maybeApplyLastTick.remove(keyframeChangeType);
|
||||||
|
change.apply(keyframeHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyframeHandler.alwaysApplyLastKeyframe() && !maybeApplyLastTick.isEmpty()) {
|
||||||
|
for (Map.Entry<Class<? extends KeyframeChange>, KeyframeTrack> entry : maybeApplyLastTick.entrySet()) {
|
||||||
|
KeyframeTrack keyframeTrack = entry.getValue();
|
||||||
|
KeyframeChange change = keyframeTrack.createKeyframeChange(keyframeTrack.keyframesByTick.lastKey());
|
||||||
|
|
||||||
|
if (change == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (change.getClass() != entry.getKey()) {
|
||||||
|
throw new IllegalStateException("Expected " + entry.getKey() + ", got " + change.getClass() + ". Caused by: " + keyframeTrack.keyframeType.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
change.apply(keyframeHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
package com.moulberry.flashback.state;
|
package com.moulberry.flashback.state;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Range;
|
||||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChange;
|
||||||
|
import com.moulberry.flashback.keyframe.change.KeyframeChangeTickrate;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.handler.ReplayServerKeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.ReplayServerKeyframeHandler;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.interpolation.SidedInterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.SidedInterpolationType;
|
||||||
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
import imgui.type.ImString;
|
import imgui.type.ImString;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
@@ -30,51 +38,43 @@ public class KeyframeTrack {
|
|||||||
this.keyframeType = keyframeType;
|
this.keyframeType = keyframeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tryApplyKeyframes(KeyframeHandler t, float tick) {
|
@Nullable
|
||||||
if (!t.supportedKeyframes().contains(this.keyframeType)) {
|
public KeyframeChange createKeyframeChange(float tick) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.keyframeType == TimelapseKeyframeType.INSTANCE) {
|
if (this.keyframeType == TimelapseKeyframeType.INSTANCE) {
|
||||||
return this.tryApplyKeyframesTimelapse(t, tick);
|
return this.tryApplyKeyframesTimelapse(tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if empty
|
// Skip if empty
|
||||||
TreeMap<Integer, Keyframe> keyframeTimes = this.keyframesByTick;
|
TreeMap<Integer, Keyframe> keyframeTimes = this.keyframesByTick;
|
||||||
if (keyframeTimes.isEmpty()) {
|
if (keyframeTimes.isEmpty()) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map.Entry<Integer, Keyframe> lowerEntry = keyframeTimes.floorEntry((int) tick);
|
Map.Entry<Integer, Keyframe> lowerEntry = keyframeTimes.floorEntry((int) tick);
|
||||||
if (lowerEntry == null) {
|
if (lowerEntry == null) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Keyframe lowerKeyframe = lowerEntry.getValue();
|
Keyframe lowerKeyframe = lowerEntry.getValue();
|
||||||
|
|
||||||
if (tick == lowerEntry.getKey()) {
|
if (tick == lowerEntry.getKey()) {
|
||||||
lowerKeyframe.apply(t);
|
return lowerKeyframe.createChange();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SidedInterpolationType leftInterpolation = lowerEntry.getValue().interpolationType().rightSide;
|
SidedInterpolationType leftInterpolation = lowerEntry.getValue().interpolationType().rightSide;
|
||||||
|
|
||||||
// Immediately apply hold
|
// Immediately apply hold
|
||||||
if (leftInterpolation == SidedInterpolationType.HOLD) {
|
if (leftInterpolation == SidedInterpolationType.HOLD) {
|
||||||
lowerKeyframe.apply(t);
|
return lowerKeyframe.createChange();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get next entry, skip if tick is not between two keyframes
|
// Get next entry, skip if tick is not between two keyframes
|
||||||
Map.Entry<Integer, Keyframe> ceilEntry = keyframeTimes.ceilingEntry(lowerEntry.getKey() + 1);
|
Map.Entry<Integer, Keyframe> ceilEntry = keyframeTimes.ceilingEntry(lowerEntry.getKey() + 1);
|
||||||
if (ceilEntry == null) {
|
if (ceilEntry == null) {
|
||||||
if ((int) tick == lowerEntry.getKey()) {
|
if ((int) tick == lowerEntry.getKey()) {
|
||||||
lowerKeyframe.apply(t);
|
return lowerKeyframe.createChange();
|
||||||
return true;
|
|
||||||
} else if (t.alwaysApplyLastKeyframe()) {
|
|
||||||
lowerKeyframe.apply(t);
|
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
SidedInterpolationType rightInterpolation = ceilEntry.getValue().interpolationType().leftSide;
|
SidedInterpolationType rightInterpolation = ceilEntry.getValue().interpolationType().leftSide;
|
||||||
@@ -84,10 +84,11 @@ public class KeyframeTrack {
|
|||||||
|
|
||||||
float amount = (tick - lowerEntry.getKey()) / (ceilEntry.getKey() - lowerEntry.getKey());
|
float amount = (tick - lowerEntry.getKey()) / (ceilEntry.getKey() - lowerEntry.getKey());
|
||||||
|
|
||||||
boolean isUsingSmooth = leftInterpolation == SidedInterpolationType.SMOOTH ||
|
KeyframeChange leftChange = null;
|
||||||
rightInterpolation == SidedInterpolationType.SMOOTH;
|
KeyframeChange rightChange = null;
|
||||||
|
|
||||||
if (isUsingSmooth) {
|
if (leftInterpolation == SidedInterpolationType.SMOOTH ||
|
||||||
|
rightInterpolation == SidedInterpolationType.SMOOTH) {
|
||||||
Map.Entry<Integer, Keyframe> beforeEntry = keyframeTimes.floorEntry(lowerEntry.getKey() - 1);
|
Map.Entry<Integer, Keyframe> beforeEntry = keyframeTimes.floorEntry(lowerEntry.getKey() - 1);
|
||||||
if (beforeEntry == null) {
|
if (beforeEntry == null) {
|
||||||
beforeEntry = lowerEntry;
|
beforeEntry = lowerEntry;
|
||||||
@@ -98,39 +99,109 @@ public class KeyframeTrack {
|
|||||||
afterAfterEntry = ceilEntry;
|
afterAfterEntry = ceilEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
float lerpAmount;
|
KeyframeChange smoothChange = beforeEntry.getValue().createSmoothInterpolatedChange(lowerEntry.getValue(), ceilEntry.getValue(), afterAfterEntry.getValue(),
|
||||||
boolean lerpFromRight;
|
beforeEntry.getKey(), lowerEntry.getKey(), ceilEntry.getKey(), afterAfterEntry.getKey(), amount);
|
||||||
if (leftInterpolation != SidedInterpolationType.SMOOTH) {
|
|
||||||
lerpAmount = SidedInterpolationType.interpolate(leftInterpolation, leftInterpolation, amount);
|
if (leftInterpolation == SidedInterpolationType.SMOOTH) {
|
||||||
lerpFromRight = false;
|
leftChange = smoothChange;
|
||||||
} else if (rightInterpolation != SidedInterpolationType.SMOOTH) {
|
}
|
||||||
lerpAmount = SidedInterpolationType.interpolate(rightInterpolation, rightInterpolation, amount);
|
if (rightInterpolation == SidedInterpolationType.SMOOTH) {
|
||||||
lerpFromRight = true;
|
rightChange = smoothChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (leftInterpolation == SidedInterpolationType.HERMITE ||
|
||||||
|
rightInterpolation == SidedInterpolationType.HERMITE) {
|
||||||
|
Integer minKey = lowerEntry.getKey();
|
||||||
|
|
||||||
|
while (minKey != null) {
|
||||||
|
Map.Entry<Integer, Keyframe> before = keyframeTimes.floorEntry(minKey - 1);
|
||||||
|
|
||||||
|
if (before == null) {
|
||||||
|
minKey = null;
|
||||||
|
break;
|
||||||
|
} else if (before.getValue().interpolationType() == InterpolationType.HOLD) {
|
||||||
|
// don't include the right-side of the hold keyframe, or anything before it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
minKey = before.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer maxKey = ceilEntry.getKey();
|
||||||
|
|
||||||
|
while (maxKey != null) {
|
||||||
|
Map.Entry<Integer, Keyframe> after = keyframeTimes.ceilingEntry(maxKey + 1);
|
||||||
|
|
||||||
|
if (after == null) {
|
||||||
|
maxKey = null;
|
||||||
|
break;
|
||||||
|
} else if (after.getValue().interpolationType() == InterpolationType.HOLD) {
|
||||||
|
// include the hold keyframe, but not anything after it
|
||||||
|
maxKey = after.getKey();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
maxKey = after.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Keyframe> subMap;
|
||||||
|
|
||||||
|
if (minKey != null) {
|
||||||
|
if (maxKey != null) {
|
||||||
|
subMap = Maps.subMap(this.keyframesByTick, Range.closed(minKey, maxKey));
|
||||||
} else {
|
} else {
|
||||||
lerpAmount = -1;
|
subMap = Maps.subMap(this.keyframesByTick, Range.atLeast(minKey));
|
||||||
lerpFromRight = false;
|
|
||||||
}
|
}
|
||||||
|
} else if (maxKey != null) {
|
||||||
beforeEntry.getValue().applyInterpolatedSmooth(t, lowerEntry.getValue(), ceilEntry.getValue(), afterAfterEntry.getValue(),
|
subMap = Maps.subMap(this.keyframesByTick, Range.atMost(maxKey));
|
||||||
beforeEntry.getKey(), lowerEntry.getKey(), ceilEntry.getKey(), afterAfterEntry.getKey(), amount, lerpAmount, lerpFromRight);
|
|
||||||
} else {
|
} else {
|
||||||
amount = SidedInterpolationType.interpolate(leftInterpolation, rightInterpolation, amount);
|
subMap = this.keyframesByTick;
|
||||||
|
}
|
||||||
|
|
||||||
if (amount == 0.0) {
|
KeyframeChange hermiteChange = lowerKeyframe.createHermiteInterpolatedChange(subMap, tick);
|
||||||
lowerKeyframe.apply(t);
|
if (leftInterpolation == SidedInterpolationType.HERMITE) {
|
||||||
|
leftChange = hermiteChange;
|
||||||
|
}
|
||||||
|
if (rightInterpolation == SidedInterpolationType.HERMITE) {
|
||||||
|
rightChange = hermiteChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// todo: hermite
|
||||||
|
if (leftChange == null || rightChange == null) {
|
||||||
|
double adjustedAmount = SidedInterpolationType.interpolate(leftInterpolation, rightInterpolation, amount);
|
||||||
|
|
||||||
|
KeyframeChange keyframeChange = lowerKeyframe.createChange();
|
||||||
|
|
||||||
|
if (adjustedAmount != 0.0) {
|
||||||
|
KeyframeChange keyframeChangeCeil = ceilEntry.getValue().createChange();
|
||||||
|
keyframeChange = keyframeChange.interpolate(keyframeChangeCeil, (float) adjustedAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftChange == null) {
|
||||||
|
leftChange = keyframeChange;
|
||||||
|
}
|
||||||
|
if (rightChange == null) {
|
||||||
|
rightChange = keyframeChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftChange == rightChange) {
|
||||||
|
return leftChange;
|
||||||
|
} else if (leftChange == null) {
|
||||||
|
return rightChange;
|
||||||
|
} else if (rightChange == null) {
|
||||||
|
return leftChange;
|
||||||
} else {
|
} else {
|
||||||
lowerKeyframe.applyInterpolated(t, ceilEntry.getValue(), amount);
|
return leftChange.interpolate(rightChange, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
@Nullable
|
||||||
}
|
private KeyframeChangeTickrate tryApplyKeyframesTimelapse(float tick) {
|
||||||
|
|
||||||
private boolean tryApplyKeyframesTimelapse(KeyframeHandler t, float tick) {
|
|
||||||
// Skip if empty
|
// Skip if empty
|
||||||
TreeMap<Integer, Keyframe> keyframeTimes = this.keyframesByTick;
|
TreeMap<Integer, Keyframe> keyframeTimes = this.keyframesByTick;
|
||||||
if (keyframeTimes.isEmpty()) {
|
if (keyframeTimes.isEmpty()) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map.Entry<Integer, Keyframe> lowerEntry = keyframeTimes.floorEntry((int) tick);
|
Map.Entry<Integer, Keyframe> lowerEntry = keyframeTimes.floorEntry((int) tick);
|
||||||
@@ -147,16 +218,14 @@ public class KeyframeTrack {
|
|||||||
|
|
||||||
if (ceilTicks <= lowerTicks) {
|
if (ceilTicks <= lowerTicks) {
|
||||||
ReplayUI.setInfoOverlayShort("Unable to timelapse. Right keyframe's time must be greater than left keyframe's time");
|
ReplayUI.setInfoOverlayShort("Unable to timelapse. Right keyframe's time must be greater than left keyframe's time");
|
||||||
t.applyTickrate(20);
|
return new KeyframeChangeTickrate(20.0f);
|
||||||
} else {
|
} else {
|
||||||
double tickrate = (double) (ceilEntry.getKey() - lowerEntry.getKey()) / (ceilTicks - lowerTicks) * 20;
|
double tickrate = (double) (ceilEntry.getKey() - lowerEntry.getKey()) / (ceilTicks - lowerTicks) * 20;
|
||||||
t.applyTickrate((float) tickrate);
|
return new KeyframeChangeTickrate((float) tickrate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ import com.moulberry.flashback.Utils;
|
|||||||
import com.moulberry.flashback.combo_options.Sizing;
|
import com.moulberry.flashback.combo_options.Sizing;
|
||||||
import com.moulberry.flashback.editor.ui.windows.TimelineWindow;
|
import com.moulberry.flashback.editor.ui.windows.TimelineWindow;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.change.*;
|
||||||
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
||||||
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
||||||
@@ -55,7 +56,7 @@ public class CameraPath {
|
|||||||
int replayTick = TimelineWindow.getCursorTick();
|
int replayTick = TimelineWindow.getCursorTick();
|
||||||
|
|
||||||
if (lastEditorStateModCount != state.modCount || lastCursorTick != replayTick) {
|
if (lastEditorStateModCount != state.modCount || lastCursorTick != replayTick) {
|
||||||
CameraPathArgs cameraPathArgs = createCameraPathArgs(state.currentScene(), replayTick, SUPPORTED_CAMERA_KEYFRAMES);
|
CameraPathArgs cameraPathArgs = createCameraPathArgs(state.currentScene(), replayTick);
|
||||||
|
|
||||||
if (lastEditorStateModCount != state.modCount || !cameraPathArgs.equals(lastCameraPathArgs)) {
|
if (lastEditorStateModCount != state.modCount || !cameraPathArgs.equals(lastCameraPathArgs)) {
|
||||||
lastCameraPathArgs = cameraPathArgs;
|
lastCameraPathArgs = cameraPathArgs;
|
||||||
@@ -131,13 +132,13 @@ public class CameraPath {
|
|||||||
|
|
||||||
private record CameraPathArgs(int lastLastCameraTick, int lastCameraTick, int nextCameraTick, int nextNextCameraTick) {}
|
private record CameraPathArgs(int lastLastCameraTick, int lastCameraTick, int nextCameraTick, int nextNextCameraTick) {}
|
||||||
|
|
||||||
private static CameraPathArgs createCameraPathArgs(EditorScene scene, int replayTick, Set<KeyframeType<?>> supportedKeyframes) {
|
private static CameraPathArgs createCameraPathArgs(EditorScene scene, int replayTick) {
|
||||||
int lastCameraTick = -1;
|
int lastCameraTick = -1;
|
||||||
int nextCameraTick = -1;
|
int nextCameraTick = -1;
|
||||||
|
|
||||||
for (int trackIndex = 0; trackIndex < scene.keyframeTracks.size(); trackIndex++) {
|
for (int trackIndex = 0; trackIndex < scene.keyframeTracks.size(); trackIndex++) {
|
||||||
KeyframeTrack keyframeTrack = scene.keyframeTracks.get(trackIndex);
|
KeyframeTrack keyframeTrack = scene.keyframeTracks.get(trackIndex);
|
||||||
if (keyframeTrack.enabled && supportedKeyframes.contains(keyframeTrack.keyframeType) && !keyframeTrack.keyframesByTick.isEmpty()) {
|
if (keyframeTrack.enabled && keyframeTrack.keyframeType.keyframeChangeType() == KeyframeChangeCameraPosition.class && !keyframeTrack.keyframesByTick.isEmpty()) {
|
||||||
var lastEntry = keyframeTrack.keyframesByTick.floorEntry(replayTick);
|
var lastEntry = keyframeTrack.keyframesByTick.floorEntry(replayTick);
|
||||||
var nextEntry = keyframeTrack.keyframesByTick.ceilingEntry(replayTick + 1);
|
var nextEntry = keyframeTrack.keyframesByTick.ceilingEntry(replayTick + 1);
|
||||||
|
|
||||||
@@ -159,7 +160,7 @@ public class CameraPath {
|
|||||||
|
|
||||||
for (int trackIndex = 0; trackIndex < scene.keyframeTracks.size(); trackIndex++) {
|
for (int trackIndex = 0; trackIndex < scene.keyframeTracks.size(); trackIndex++) {
|
||||||
KeyframeTrack keyframeTrack = scene.keyframeTracks.get(trackIndex);
|
KeyframeTrack keyframeTrack = scene.keyframeTracks.get(trackIndex);
|
||||||
if (keyframeTrack.enabled && supportedKeyframes.contains(keyframeTrack.keyframeType) && !keyframeTrack.keyframesByTick.isEmpty()) {
|
if (keyframeTrack.enabled &&keyframeTrack.keyframeType.keyframeChangeType() == KeyframeChangeCameraPosition.class && !keyframeTrack.keyframesByTick.isEmpty()) {
|
||||||
var lastLastEntry = lastCameraTick == -1 ? null : keyframeTrack.keyframesByTick.floorEntry(lastCameraTick - 1);
|
var lastLastEntry = lastCameraTick == -1 ? null : keyframeTrack.keyframesByTick.floorEntry(lastCameraTick - 1);
|
||||||
var nextNextEntry = nextCameraTick == -1 ? null : keyframeTrack.keyframesByTick.ceilingEntry(nextCameraTick + 1);
|
var nextNextEntry = nextCameraTick == -1 ? null : keyframeTrack.keyframesByTick.ceilingEntry(nextCameraTick + 1);
|
||||||
|
|
||||||
@@ -305,15 +306,13 @@ public class CameraPath {
|
|||||||
cameraPoseStack.popPose();
|
cameraPoseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<KeyframeType<?>> SUPPORTED_CAMERA_KEYFRAMES = Set.of(CameraKeyframeType.INSTANCE, CameraOrbitKeyframeType.INSTANCE);
|
|
||||||
|
|
||||||
private static class CapturingKeyframeHandler implements KeyframeHandler {
|
private static class CapturingKeyframeHandler implements KeyframeHandler {
|
||||||
private Vector3d position;
|
private Vector3d position;
|
||||||
private Quaterniond angle;
|
private Quaterniond angle;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<KeyframeType<?>> supportedKeyframes() {
|
public boolean supportsKeyframeChange(Class<? extends KeyframeChange> clazz) {
|
||||||
return SUPPORTED_CAMERA_KEYFRAMES;
|
return clazz == KeyframeChangeCameraPosition.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -332,8 +331,8 @@ public class CameraPath {
|
|||||||
private float fov;
|
private float fov;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<KeyframeType<?>> supportedKeyframes() {
|
public boolean supportsKeyframeChange(Class<? extends KeyframeChange> clazz) {
|
||||||
return Set.of(FOVKeyframeType.INSTANCE);
|
return clazz == KeyframeChangeFov.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user