mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-03 14:38:50 +00:00
0.3.0
This commit is contained in:
1 parent
d2a217509f
commit
4d8f896cdf
90 files changed
+2318
-693
No files matched your search
@@ -35,6 +35,7 @@ repositories {
|
|||||||
includeGroup("maven.modrinth")
|
includeGroup("maven.modrinth")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
maven { url = "https://maven.bawnorton.com/releases" }
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
@@ -65,6 +66,7 @@ dependencies {
|
|||||||
|
|
||||||
modCompileOnly("maven.modrinth:sodium:RncWhTxD")
|
modCompileOnly("maven.modrinth:sodium:RncWhTxD")
|
||||||
modCompileOnly("maven.modrinth:iris:kuOV4Ece")
|
modCompileOnly("maven.modrinth:iris:kuOV4Ece")
|
||||||
|
modCompileOnly("maven.modrinth:bobby:2cuVyTav")
|
||||||
modImplementation("maven.modrinth:modmenu:xhN1IvHi")
|
modImplementation("maven.modrinth:modmenu:xhN1IvHi")
|
||||||
// modCompileOnly("maven.modrinth:axiom:D3uDJmiB")
|
// modCompileOnly("maven.modrinth:axiom:D3uDJmiB")
|
||||||
|
|
||||||
@@ -74,6 +76,8 @@ dependencies {
|
|||||||
// shadow(implementation("org.jcodec:jcodec-javase:0.2.5"))
|
// shadow(implementation("org.jcodec:jcodec-javase:0.2.5"))
|
||||||
// shadow(implementation("io.humble:humble-video-all:0.3.0"))
|
// shadow(implementation("io.humble:humble-video-all:0.3.0"))
|
||||||
|
|
||||||
|
include(implementation(annotationProcessor("com.bawnorton.mixinsquared:mixinsquared-fabric:0.2.0-beta.6")))
|
||||||
|
|
||||||
shadow(implementation("org.bytedeco:javacv-platform:1.5.10") {
|
shadow(implementation("org.bytedeco:javacv-platform:1.5.10") {
|
||||||
exclude group: "org.bytedeco", module: "artoolkitplus"
|
exclude group: "org.bytedeco", module: "artoolkitplus"
|
||||||
exclude group: "org.bytedeco", module: "artoolkitplus-platform"
|
exclude group: "org.bytedeco", module: "artoolkitplus-platform"
|
||||||
|
|||||||
+1
-1
@@ -14,4 +14,4 @@ maven_group=com.moulberry.flashback
|
|||||||
archives_base_name=flashback
|
archives_base_name=flashback
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.100.7+1.21
|
fabric_version=0.103.0+1.21.1
|
||||||
@@ -9,6 +9,14 @@ import com.moulberry.flashback.action.*;
|
|||||||
import com.moulberry.flashback.configuration.FlashbackConfig;
|
import com.moulberry.flashback.configuration.FlashbackConfig;
|
||||||
import com.moulberry.flashback.exporting.ExportJob;
|
import com.moulberry.flashback.exporting.ExportJob;
|
||||||
import com.moulberry.flashback.ext.MinecraftExt;
|
import com.moulberry.flashback.ext.MinecraftExt;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeRegistry;
|
||||||
|
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.SpeedKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.TimeOfDayKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
import com.moulberry.flashback.packet.FlashbackClearParticles;
|
import com.moulberry.flashback.packet.FlashbackClearParticles;
|
||||||
import com.moulberry.flashback.packet.FinishedServerTick;
|
import com.moulberry.flashback.packet.FinishedServerTick;
|
||||||
import com.moulberry.flashback.packet.FlashbackForceClientTick;
|
import com.moulberry.flashback.packet.FlashbackForceClientTick;
|
||||||
@@ -20,6 +28,7 @@ import com.moulberry.flashback.record.Recorder;
|
|||||||
import com.moulberry.flashback.record.ReplayExporter;
|
import com.moulberry.flashback.record.ReplayExporter;
|
||||||
import com.moulberry.flashback.screen.ConfigScreen;
|
import com.moulberry.flashback.screen.ConfigScreen;
|
||||||
import com.moulberry.flashback.screen.SaveReplayScreen;
|
import com.moulberry.flashback.screen.SaveReplayScreen;
|
||||||
|
import com.moulberry.flashback.visuals.ShaderManager;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
|
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
|
||||||
@@ -29,6 +38,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
|||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
|
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.FileUtil;
|
import net.minecraft.FileUtil;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
@@ -48,12 +58,12 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.*;
|
import net.minecraft.server.*;
|
||||||
|
import net.minecraft.server.packs.PackType;
|
||||||
import net.minecraft.server.packs.repository.PackRepository;
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
import net.minecraft.server.packs.repository.ServerPacksSource;
|
import net.minecraft.server.packs.repository.ServerPacksSource;
|
||||||
import net.minecraft.world.Difficulty;
|
import net.minecraft.world.Difficulty;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.flag.FeatureFlags;
|
import net.minecraft.world.flag.FeatureFlags;
|
||||||
import net.minecraft.world.level.*;
|
import net.minecraft.world.level.*;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
@@ -184,6 +194,16 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
|||||||
ActionRegistry.register(ActionMoveEntities.INSTANCE);
|
ActionRegistry.register(ActionMoveEntities.INSTANCE);
|
||||||
ActionRegistry.register(ActionLevelChunkCached.INSTANCE);
|
ActionRegistry.register(ActionLevelChunkCached.INSTANCE);
|
||||||
|
|
||||||
|
KeyframeRegistry.register(CameraKeyframeType.INSTANCE);
|
||||||
|
KeyframeRegistry.register(CameraOrbitKeyframeType.INSTANCE);
|
||||||
|
KeyframeRegistry.register(CameraShakeKeyframeType.INSTANCE);
|
||||||
|
KeyframeRegistry.register(FOVKeyframeType.INSTANCE);
|
||||||
|
KeyframeRegistry.register(SpeedKeyframeType.INSTANCE);
|
||||||
|
KeyframeRegistry.register(TimelapseKeyframeType.INSTANCE);
|
||||||
|
KeyframeRegistry.register(TimeOfDayKeyframeType.INSTANCE);
|
||||||
|
|
||||||
|
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(ShaderManager.INSTANCE);
|
||||||
|
|
||||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||||
var flashback = ClientCommandManager.literal("flashback");
|
var flashback = ClientCommandManager.literal("flashback");
|
||||||
flashback.then(ClientCommandManager.literal("start").executes(this::startRecordingReplay));
|
flashback.then(ClientCommandManager.literal("start").executes(this::startRecordingReplay));
|
||||||
@@ -376,7 +396,7 @@ public class Flashback implements ModInitializer, ClientModInitializer {
|
|||||||
|
|
||||||
if (Flashback.getConfig().showRecordingToasts) {
|
if (Flashback.getConfig().showRecordingToasts) {
|
||||||
SystemToast.add(Minecraft.getInstance().getToasts(), FlashbackSystemToasts.RECORDING_TOAST,
|
SystemToast.add(Minecraft.getInstance().getToasts(), FlashbackSystemToasts.RECORDING_TOAST,
|
||||||
Component.literal("Flashback"), Component.literal("Paused recording"));
|
Component.literal("Flashback"), Component.literal(pause ? "Paused recording" : "Unpaused recording"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.moulberry.flashback;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeRegistry;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
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 com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
|
||||||
@@ -10,10 +12,14 @@ 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.keyframe.impl.TimeOfDayKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
||||||
import com.moulberry.flashback.serialization.QuaternionTypeAdapater;
|
import com.moulberry.flashback.serialization.QuaterniondTypeAdapater;
|
||||||
|
import com.moulberry.flashback.serialization.QuaternionfTypeAdapater;
|
||||||
|
import com.moulberry.flashback.serialization.Vector3dTypeAdapater;
|
||||||
import com.moulberry.flashback.serialization.Vector3fTypeAdapater;
|
import com.moulberry.flashback.serialization.Vector3fTypeAdapater;
|
||||||
import com.moulberry.flashback.state.EditorStateHistoryAction;
|
import com.moulberry.flashback.state.EditorStateHistoryAction;
|
||||||
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
public class FlashbackGson {
|
public class FlashbackGson {
|
||||||
@@ -24,7 +30,10 @@ public class FlashbackGson {
|
|||||||
private static GsonBuilder build() {
|
private static GsonBuilder build() {
|
||||||
return new GsonBuilder()
|
return new GsonBuilder()
|
||||||
.registerTypeAdapter(Vector3f.class, new Vector3fTypeAdapater())
|
.registerTypeAdapter(Vector3f.class, new Vector3fTypeAdapater())
|
||||||
.registerTypeAdapter(Quaternionf.class, new QuaternionTypeAdapater())
|
.registerTypeAdapter(Quaternionf.class, new QuaternionfTypeAdapater())
|
||||||
|
.registerTypeAdapter(Vector3d.class, new Vector3dTypeAdapater())
|
||||||
|
.registerTypeAdapter(Quaterniond.class, new QuaterniondTypeAdapater())
|
||||||
|
.registerTypeHierarchyAdapter(KeyframeType.class, new KeyframeRegistry.TypeAdapter())
|
||||||
|
|
||||||
.registerTypeAdapter(CameraKeyframe.class, new CameraKeyframe.TypeAdapter())
|
.registerTypeAdapter(CameraKeyframe.class, new CameraKeyframe.TypeAdapter())
|
||||||
.registerTypeAdapter(CameraOrbitKeyframe.class, new CameraOrbitKeyframe.TypeAdapter())
|
.registerTypeAdapter(CameraOrbitKeyframe.class, new CameraOrbitKeyframe.TypeAdapter())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.moulberry.flashback;
|
package com.moulberry.flashback;
|
||||||
|
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
|
||||||
public class Interpolation {
|
public class Interpolation {
|
||||||
@@ -18,8 +19,8 @@ public class Interpolation {
|
|||||||
return from + Mth.wrapDegrees(to - from) * amount;
|
return from + Mth.wrapDegrees(to - from) * amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Quaternionf linear(Quaternionf from, Quaternionf to, float amount) {
|
public static Quaterniond linear(Quaterniond from, Quaterniond to, float amount) {
|
||||||
return from.slerp(to, amount, new Quaternionf());
|
return from.slerp(to, amount, new Quaterniond());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ public class Utils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Utils.ClosestElement findClosest(float position, float leftPosition, float rightPosition, float threshold) {
|
public static ClosestElement findClosest(float position, float leftPosition, float rightPosition, float threshold) {
|
||||||
boolean leftValid = Math.abs(leftPosition - position) <= threshold;
|
boolean leftValid = Math.abs(leftPosition - position) <= threshold;
|
||||||
boolean rightValid = Math.abs(rightPosition - position) <= threshold;
|
boolean rightValid = Math.abs(rightPosition - position) <= threshold;
|
||||||
|
|
||||||
@@ -93,30 +93,36 @@ public class Utils {
|
|||||||
private static final int HOUR_TO_TICKS = MINUTE_TO_TICKS * 60;
|
private static final int HOUR_TO_TICKS = MINUTE_TO_TICKS * 60;
|
||||||
|
|
||||||
public static int stringToTime(String string) {
|
public static int stringToTime(String string) {
|
||||||
int number = 0;
|
int numberStart = 0;
|
||||||
int modifier = 1;
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
for (char c : string.toCharArray()) {
|
char[] characters = string.toCharArray();
|
||||||
if (c >= '0' && c <= '9') {
|
for (int i = 0; i < characters.length; i++) {
|
||||||
if (modifier > 1) {
|
char c = characters[i];
|
||||||
total += number * modifier;
|
|
||||||
number = 0;
|
|
||||||
modifier = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
number *= 10;
|
if (c == 't' || c == 's' || c == 'm' || c == 'h') {
|
||||||
number += c - '0';
|
try {
|
||||||
} else if (c == 's') {
|
double value = Double.parseDouble(string.substring(numberStart, i));
|
||||||
modifier *= SECOND_TO_TICKS;
|
int multiplier = switch (c) {
|
||||||
} else if (c == 'm') {
|
case 't' -> 1;
|
||||||
modifier *= MINUTE_TO_TICKS;
|
case 's' -> SECOND_TO_TICKS;
|
||||||
} else if (c == 'h') {
|
case 'm' -> MINUTE_TO_TICKS;
|
||||||
modifier *= HOUR_TO_TICKS;
|
case 'h' -> HOUR_TO_TICKS;
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + c);
|
||||||
|
};
|
||||||
|
total += (int)(value * multiplier);
|
||||||
|
i += 1;
|
||||||
|
numberStart = i;
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
total += number * modifier;
|
if (numberStart < characters.length) {
|
||||||
|
try {
|
||||||
|
double value = Double.parseDouble(string.substring(numberStart));
|
||||||
|
total += (int)(value * SECOND_TO_TICKS);
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
@@ -140,9 +146,13 @@ public class Utils {
|
|||||||
builder.append(minutes).append('m');
|
builder.append(minutes).append('m');
|
||||||
timeToString(builder, ticks - minutes*MINUTE_TO_TICKS);
|
timeToString(builder, ticks - minutes*MINUTE_TO_TICKS);
|
||||||
} else if (ticks >= SECOND_TO_TICKS) {
|
} else if (ticks >= SECOND_TO_TICKS) {
|
||||||
|
if (ticks % SECOND_TO_TICKS == 0) {
|
||||||
int seconds = ticks / SECOND_TO_TICKS;
|
int seconds = ticks / SECOND_TO_TICKS;
|
||||||
builder.append(seconds).append('s');
|
builder.append(seconds).append('s');
|
||||||
timeToString(builder, ticks - seconds*SECOND_TO_TICKS);
|
} else {
|
||||||
|
double seconds = (double) ticks / SECOND_TO_TICKS;
|
||||||
|
builder.append(seconds).append('s');
|
||||||
|
}
|
||||||
} else if (ticks > 0) {
|
} else if (ticks > 0) {
|
||||||
builder.append(ticks).append('t');
|
builder.append(ticks).append('t');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public enum VideoCodec implements ComboOption {
|
|||||||
private final String text;
|
private final String text;
|
||||||
private final int codecId;
|
private final int codecId;
|
||||||
private String[] encoders;
|
private String[] encoders;
|
||||||
|
private boolean supportsTransparency = false;
|
||||||
|
|
||||||
VideoCodec(String text, int codecId) {
|
VideoCodec(String text, int codecId) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
@@ -43,6 +44,18 @@ public enum VideoCodec implements ComboOption {
|
|||||||
return this.codecId;
|
return this.codecId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean supportsTransparency() {
|
||||||
|
if (this == VP9) {
|
||||||
|
// VP9 supports transparency (yuva420p), but apparently most decoders for it do not. Let's not mark it as supporting transparency
|
||||||
|
// See also: https://trac.ffmpeg.org/ticket/8468
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.encoders == null) {
|
||||||
|
this.getEncoders();
|
||||||
|
}
|
||||||
|
return this.supportsTransparency;
|
||||||
|
}
|
||||||
|
|
||||||
public String[] getEncoders() {
|
public String[] getEncoders() {
|
||||||
if (this.encoders == null) {
|
if (this.encoders == null) {
|
||||||
List<String> encodersHardware = new ArrayList<>();
|
List<String> encodersHardware = new ArrayList<>();
|
||||||
@@ -70,6 +83,20 @@ public enum VideoCodec implements ComboOption {
|
|||||||
int capabilities = codec.capabilities();
|
int capabilities = codec.capabilities();
|
||||||
String name = codec.name().getString();
|
String name = codec.name().getString();
|
||||||
|
|
||||||
|
this.supportsTransparency = false;
|
||||||
|
for (int i = 0;; i++) {
|
||||||
|
int pixFmt = codec.pix_fmts().get(i);
|
||||||
|
if (pixFmt == -1) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (PixelFormatHelper.doesPixelFormatSupportTransparency(pixFmt)) {
|
||||||
|
System.out.println(name + " supports transparency because of " + PixelFormatHelper.pixelFormatToString(pixFmt));
|
||||||
|
this.supportsTransparency = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((capabilities & avcodec.AV_CODEC_CAP_HARDWARE) != 0) {
|
if ((capabilities & avcodec.AV_CODEC_CAP_HARDWARE) != 0) {
|
||||||
encodersHardware.add(name);
|
encodersHardware.add(name);
|
||||||
} else if ((capabilities & avcodec.AV_CODEC_CAP_HYBRID) != 0 || codecHasHwConfig(codec)) {
|
} else if ((capabilities & avcodec.AV_CODEC_CAP_HYBRID) != 0 || codecHasHwConfig(codec)) {
|
||||||
@@ -126,7 +153,7 @@ public enum VideoCodec implements ComboOption {
|
|||||||
AVRational time_base = av_inv_q(frameRate);
|
AVRational time_base = av_inv_q(frameRate);
|
||||||
codecContext.time_base(time_base);
|
codecContext.time_base(time_base);
|
||||||
|
|
||||||
int pixelFormat = PixelFormatHelper.getBestPixelFormat(codec.name().getString());
|
int pixelFormat = PixelFormatHelper.getBestPixelFormat(codec.name().getString(), false);
|
||||||
codecContext.pix_fmt(pixelFormat);
|
codecContext.pix_fmt(pixelFormat);
|
||||||
|
|
||||||
if ((codec.capabilities() & AV_CODEC_CAP_EXPERIMENTAL) != 0) {
|
if ((codec.capabilities() & AV_CODEC_CAP_EXPERIMENTAL) != 0) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public enum VideoContainer implements ComboOption {
|
|||||||
private final String text;
|
private final String text;
|
||||||
private final String extension;
|
private final String extension;
|
||||||
private VideoCodec[] supportedVideoCodecs = null;
|
private VideoCodec[] supportedVideoCodecs = null;
|
||||||
|
private VideoCodec[] supportedVideoCodecsWithTransparency = null;
|
||||||
private AudioCodec[] supportedAudioCodecs = null;
|
private AudioCodec[] supportedAudioCodecs = null;
|
||||||
|
|
||||||
VideoContainer(String text, String extension) {
|
VideoContainer(String text, String extension) {
|
||||||
@@ -33,8 +34,20 @@ public enum VideoContainer implements ComboOption {
|
|||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoCodec[] getSupportedVideoCodecs() {
|
public static VideoContainer[] findSupportedContainers(boolean transparency) {
|
||||||
if (this.supportedVideoCodecs == null) {
|
List<VideoContainer> containers = new ArrayList<>();
|
||||||
|
for (VideoContainer videoContainer : VideoContainer.values()) {
|
||||||
|
if (videoContainer.getSupportedVideoCodecs(transparency).length != 0) {
|
||||||
|
containers.add(videoContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return containers.toArray(new VideoContainer[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VideoCodec[] getSupportedVideoCodecs(boolean transparency) {
|
||||||
|
VideoCodec[] codecs = transparency ? this.supportedVideoCodecsWithTransparency : this.supportedVideoCodecs;
|
||||||
|
|
||||||
|
if (codecs == null) {
|
||||||
List<VideoCodec> supportedCodecs = new ArrayList<>();
|
List<VideoCodec> supportedCodecs = new ArrayList<>();
|
||||||
try (AVOutputFormat outputFormat = avformat.av_guess_format(this.extension, "test."+this.extension, null)) {
|
try (AVOutputFormat outputFormat = avformat.av_guess_format(this.extension, "test."+this.extension, null)) {
|
||||||
for (VideoCodec codec : VideoCodec.values()) {
|
for (VideoCodec codec : VideoCodec.values()) {
|
||||||
@@ -44,6 +57,9 @@ public enum VideoContainer implements ComboOption {
|
|||||||
if (codec.getEncoders().length == 0) {
|
if (codec.getEncoders().length == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (transparency && !codec.supportsTransparency()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int ret = avformat.avformat_query_codec(outputFormat, codec.codecId(), avcodec.FF_COMPLIANCE_NORMAL);
|
int ret = avformat.avformat_query_codec(outputFormat, codec.codecId(), avcodec.FF_COMPLIANCE_NORMAL);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
@@ -52,9 +68,14 @@ public enum VideoContainer implements ComboOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.supportedVideoCodecs = supportedCodecs.toArray(new VideoCodec[0]);
|
codecs = supportedCodecs.toArray(new VideoCodec[0]);
|
||||||
|
if (transparency) {
|
||||||
|
this.supportedVideoCodecsWithTransparency = codecs;
|
||||||
|
} else {
|
||||||
|
this.supportedVideoCodecs = codecs;
|
||||||
}
|
}
|
||||||
return this.supportedVideoCodecs;
|
}
|
||||||
|
return codecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AudioCodec[] getSupportedAudioCodecs() {
|
public AudioCodec[] getSupportedAudioCodecs() {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.common.reflect.Reflection;
|
|||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.FlashbackGson;
|
import com.moulberry.flashback.FlashbackGson;
|
||||||
import com.moulberry.flashback.SneakyThrow;
|
import com.moulberry.flashback.SneakyThrow;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.OptionInstance;
|
import net.minecraft.client.OptionInstance;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -19,7 +20,9 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class FlashbackConfig {
|
public class FlashbackConfig {
|
||||||
|
|
||||||
@@ -43,6 +46,8 @@ public class FlashbackConfig {
|
|||||||
@OptionDescription("flashback.option.hide_pause_menu_controls.description")
|
@OptionDescription("flashback.option.hide_pause_menu_controls.description")
|
||||||
public boolean hidePauseMenuControls = false;
|
public boolean hidePauseMenuControls = false;
|
||||||
|
|
||||||
|
public Set<String> openedWindows = new HashSet<>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public OptionInstance<?>[] createOptionInstances() {
|
public OptionInstance<?>[] createOptionInstances() {
|
||||||
List<OptionInstance<?>> options = new ArrayList<>();
|
List<OptionInstance<?>> options = new ArrayList<>();
|
||||||
@@ -110,6 +115,11 @@ public class FlashbackConfig {
|
|||||||
return new FlashbackConfig();
|
return new FlashbackConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveToDefaultFolder() {
|
||||||
|
Path configFolder = FabricLoader.getInstance().getConfigDir().resolve("flashback");
|
||||||
|
this.saveToFolder(configFolder);
|
||||||
|
}
|
||||||
|
|
||||||
public void saveToFolder(Path configFolder) {
|
public void saveToFolder(Path configFolder) {
|
||||||
Path primary = configFolder.resolve("flashback.json");
|
Path primary = configFolder.resolve("flashback.json");
|
||||||
Path backup = configFolder.resolve(".flashback.json.backup");
|
Path backup = configFolder.resolve(".flashback.json.backup");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public record SavedTrack(KeyframeType type, int track, boolean copiedFromDisabled,
|
public record SavedTrack(KeyframeType<?> type, int track, boolean copiedFromDisabled,
|
||||||
TreeMap<Integer, Keyframe> keyframes) {
|
TreeMap<Integer, Keyframe> keyframes) {
|
||||||
public int applyToEditorState(EditorState editorState, int cursorTicks, int totalTicks) {
|
public int applyToEditorState(EditorState editorState, int cursorTicks, int totalTicks) {
|
||||||
if (this.keyframes == null || this.keyframes.isEmpty()) {
|
if (this.keyframes == null || this.keyframes.isEmpty()) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.moulberry.flashback.state.EditorState;
|
|||||||
import com.moulberry.flashback.state.KeyframeTrack;
|
import com.moulberry.flashback.state.KeyframeTrack;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
|
|
||||||
public record SelectedKeyframes(KeyframeType type, int trackIndex, IntSet keyframeTicks) {
|
public record SelectedKeyframes(KeyframeType<?> type, int trackIndex, IntSet keyframeTicks) {
|
||||||
public boolean checkValid(EditorState state) {
|
public boolean checkValid(EditorState state) {
|
||||||
if (this.trackIndex < 0 || this.trackIndex >= state.keyframeTracks.size()) {
|
if (this.trackIndex < 0 || this.trackIndex >= state.keyframeTracks.size()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.mojang.blaze3d.platform.TextureUtil;
|
|||||||
import com.mojang.blaze3d.platform.Window;
|
import com.mojang.blaze3d.platform.Window;
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.editor.ui.windows.ExportQueueWindow;
|
import com.moulberry.flashback.editor.ui.windows.ExportQueueWindow;
|
||||||
|
import com.moulberry.flashback.editor.ui.windows.PlayerListWindow;
|
||||||
import com.moulberry.flashback.editor.ui.windows.SelectedEntityPopup;
|
import com.moulberry.flashback.editor.ui.windows.SelectedEntityPopup;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
@@ -59,6 +60,8 @@ public class ReplayUI {
|
|||||||
public static int frameY = 0;
|
public static int frameY = 0;
|
||||||
public static int frameWidth = 1;
|
public static int frameWidth = 1;
|
||||||
public static int frameHeight = 1;
|
public static int frameHeight = 1;
|
||||||
|
public static int viewportSizeX = 1;
|
||||||
|
public static int viewportSizeY = 1;
|
||||||
private static boolean activeLastFrame = false;
|
private static boolean activeLastFrame = false;
|
||||||
|
|
||||||
public static Matrix4f lastProjectionMatrix = null;
|
public static Matrix4f lastProjectionMatrix = null;
|
||||||
@@ -556,6 +559,8 @@ public class ReplayUI {
|
|||||||
}
|
}
|
||||||
frameWidth = (int) Math.max(1, maxX - minX);
|
frameWidth = (int) Math.max(1, maxX - minX);
|
||||||
frameHeight = (int) Math.max(1, maxY - minY);
|
frameHeight = (int) Math.max(1, maxY - minY);
|
||||||
|
viewportSizeX = (int) ImGui.getMainViewport().getSizeX();
|
||||||
|
viewportSizeY = (int) ImGui.getMainViewport().getSizeY();
|
||||||
|
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
Sizing sizing = editorState == null ? Sizing.KEEP_ASPECT_RATIO : editorState.replayVisuals.sizing;
|
Sizing sizing = editorState == null ? Sizing.KEEP_ASPECT_RATIO : editorState.replayVisuals.sizing;
|
||||||
@@ -693,6 +698,7 @@ public class ReplayUI {
|
|||||||
TimelineWindow.render();
|
TimelineWindow.render();
|
||||||
StartExportWindow.render();
|
StartExportWindow.render();
|
||||||
ExportQueueWindow.render();
|
ExportQueueWindow.render();
|
||||||
|
PlayerListWindow.render();
|
||||||
|
|
||||||
popupOpenLastFrame = ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup);
|
popupOpenLastFrame = ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.moulberry.flashback.editor.ui;
|
||||||
|
|
||||||
|
public enum WindowOpenState {
|
||||||
|
|
||||||
|
UNKNOWN,
|
||||||
|
OPEN,
|
||||||
|
CLOSED
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.moulberry.flashback.editor.ui.windows;
|
package com.moulberry.flashback.editor.ui.windows;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.exporting.ExportJobQueue;
|
import com.moulberry.flashback.exporting.ExportJobQueue;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -8,6 +9,12 @@ public class MainMenuBar {
|
|||||||
|
|
||||||
public static void render() {
|
public static void render() {
|
||||||
if (ImGui.beginMainMenuBar()) {
|
if (ImGui.beginMainMenuBar()) {
|
||||||
|
renderInner();
|
||||||
|
ImGui.endMainMenuBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void renderInner() {
|
||||||
if (ImGui.menuItem("Export")) {
|
if (ImGui.menuItem("Export")) {
|
||||||
StartExportWindow.open();
|
StartExportWindow.open();
|
||||||
}
|
}
|
||||||
@@ -23,7 +30,15 @@ public class MainMenuBar {
|
|||||||
Minecraft.getInstance().options.hideGui = true;
|
Minecraft.getInstance().options.hideGui = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.endMainMenuBar();
|
if (ImGui.menuItem("Player List")) {
|
||||||
|
var openedWindows = Flashback.getConfig().openedWindows;
|
||||||
|
boolean playerListIsOpen = openedWindows.contains("player_list");
|
||||||
|
if (playerListIsOpen) {
|
||||||
|
openedWindows.remove("player_list");
|
||||||
|
} else {
|
||||||
|
openedWindows.add("player_list");
|
||||||
|
}
|
||||||
|
Flashback.getConfig().saveToDefaultFolder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
package com.moulberry.flashback.editor.ui.windows;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
|
import com.moulberry.flashback.editor.ui.WindowOpenState;
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.ImGuiViewport;
|
||||||
|
import imgui.flag.ImGuiCond;
|
||||||
|
import imgui.flag.ImGuiWindowFlags;
|
||||||
|
import imgui.type.ImString;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
|
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class PlayerListWindow {
|
||||||
|
|
||||||
|
private static WindowOpenState wasOpen = WindowOpenState.UNKNOWN;
|
||||||
|
|
||||||
|
private static String lastSearch = null;
|
||||||
|
private static long lastUpdate = 0;
|
||||||
|
private static ImString search = ImGuiHelper.createResizableImString("");
|
||||||
|
private static List<PlayerInfo> searchedPlayers = new ArrayList<>();
|
||||||
|
|
||||||
|
private static void updatePlayerList() {
|
||||||
|
searchedPlayers.clear();
|
||||||
|
|
||||||
|
ClientPacketListener connection = Minecraft.getInstance().getConnection();
|
||||||
|
if (connection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientLevel level = Minecraft.getInstance().level;
|
||||||
|
Entity camera = Minecraft.getInstance().getCameraEntity();
|
||||||
|
|
||||||
|
record SearchEntry(double distanceSq, PlayerInfo info) {}
|
||||||
|
List<SearchEntry> searchEntries = new ArrayList<>();
|
||||||
|
List<SearchEntry> searchEntriesLowPriority = new ArrayList<>();
|
||||||
|
|
||||||
|
String searchLower = lastSearch.toLowerCase(Locale.ROOT);
|
||||||
|
boolean blankSearch = lastSearch.isBlank();
|
||||||
|
|
||||||
|
for (PlayerInfo playerInfo : connection.getOnlinePlayers()) {
|
||||||
|
GameProfile profile = playerInfo.getProfile();
|
||||||
|
|
||||||
|
if (profile.getId().version() == 4) {
|
||||||
|
|
||||||
|
double distanceSq = Double.MAX_VALUE;
|
||||||
|
|
||||||
|
if (level != null && camera != null) {
|
||||||
|
Player player = level.getPlayerByUUID(profile.getId());
|
||||||
|
if (player != null) {
|
||||||
|
distanceSq = player.distanceToSqr(camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchEntry searchEntry = new SearchEntry(distanceSq, playerInfo);
|
||||||
|
if (blankSearch) {
|
||||||
|
searchEntries.add(searchEntry);
|
||||||
|
} else {
|
||||||
|
String nameLower = profile.getName().toLowerCase(Locale.ROOT);
|
||||||
|
if (nameLower.startsWith(searchLower)) {
|
||||||
|
searchEntries.add(searchEntry);
|
||||||
|
} else if (nameLower.contains(searchLower)) {
|
||||||
|
searchEntriesLowPriority.add(searchEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
searchEntries.sort(Comparator.comparingDouble(SearchEntry::distanceSq));
|
||||||
|
searchEntriesLowPriority.sort(Comparator.comparingDouble(SearchEntry::distanceSq));
|
||||||
|
if (searchEntries.size() < 16) {
|
||||||
|
searchEntries.addAll(searchEntriesLowPriority);
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = Math.min(16, searchEntries.size());
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
searchedPlayers.add(searchEntries.get(i).info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void render() {
|
||||||
|
// todo: refactor this if we want to add a lot more windows
|
||||||
|
if (!Flashback.getConfig().openedWindows.contains("player_list")) {
|
||||||
|
wasOpen = WindowOpenState.CLOSED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (wasOpen == WindowOpenState.CLOSED) {
|
||||||
|
ImGuiViewport viewport = ImGui.getMainViewport();
|
||||||
|
ImGui.setNextWindowPos(viewport.getCenterX(), viewport.getCenterY(), ImGuiCond.Appearing, 0.5f, 0.5f);
|
||||||
|
}
|
||||||
|
wasOpen = WindowOpenState.OPEN;
|
||||||
|
|
||||||
|
ImGui.setNextWindowSizeConstraints(250, 50, 5000, 5000);
|
||||||
|
if (ImGui.begin("Player List###PlayerList", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoFocusOnAppearing)) {
|
||||||
|
ImGui.setNextItemWidth(ImGui.getContentRegionAvailX() - ImGuiHelper.calcTextWidth("Search") - 32);
|
||||||
|
if (ImGui.inputText("Search", search)) {
|
||||||
|
lastSearch = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
if (lastSearch == null || currentTime > lastUpdate + 3000 || currentTime < lastUpdate) {
|
||||||
|
lastSearch = ImGuiHelper.getString(search);
|
||||||
|
lastUpdate = currentTime;
|
||||||
|
updatePlayerList();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
|
||||||
|
for (int i = 0; i < searchedPlayers.size(); i++) {
|
||||||
|
ImGui.pushID(i);
|
||||||
|
PlayerInfo playerInfo = searchedPlayers.get(i);
|
||||||
|
GameProfile profile = playerInfo.getProfile();
|
||||||
|
|
||||||
|
ImGui.text(profile.getName());
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.smallButton("Teleport")) {
|
||||||
|
Minecraft.getInstance().getConnection().sendUnsignedCommand("teleport " + profile.getId());
|
||||||
|
lastUpdate = currentTime;
|
||||||
|
}
|
||||||
|
if (editorState != null) {
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (editorState.hideDuringExport.contains(profile.getId())) {
|
||||||
|
if (ImGui.smallButton("Show")) {
|
||||||
|
editorState.hideDuringExport.remove(profile.getId());
|
||||||
|
lastUpdate = currentTime;
|
||||||
|
}
|
||||||
|
} else if (ImGui.smallButton("Hide")) {
|
||||||
|
editorState.hideDuringExport.add(profile.getId());
|
||||||
|
lastUpdate = currentTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.popID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ public class SelectedEntityPopup {
|
|||||||
if (ImGui.button("Look At")) {
|
if (ImGui.button("Look At")) {
|
||||||
Minecraft.getInstance().cameraEntity.lookAt(EntityAnchorArgument.Anchor.EYES, entity.getEyePosition());
|
Minecraft.getInstance().cameraEntity.lookAt(EntityAnchorArgument.Anchor.EYES, entity.getEyePosition());
|
||||||
}
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
if (ImGui.button("Spectate")) {
|
if (ImGui.button("Spectate")) {
|
||||||
Minecraft.getInstance().player.connection.sendUnsignedCommand("spectate " + entity.getUUID());
|
Minecraft.getInstance().player.connection.sendUnsignedCommand("spectate " + entity.getUUID());
|
||||||
ImGui.closeCurrentPopup();
|
ImGui.closeCurrentPopup();
|
||||||
@@ -32,12 +33,19 @@ public class SelectedEntityPopup {
|
|||||||
editorState.audioSourceEntity = entity.getUUID();
|
editorState.audioSourceEntity = entity.getUUID();
|
||||||
editorState.markDirty();
|
editorState.markDirty();
|
||||||
}
|
}
|
||||||
|
boolean isHiddenDuringExport = editorState.hideDuringExport.contains(entity.getUUID());
|
||||||
|
if (ImGui.checkbox("Hide During Export", isHiddenDuringExport)) {
|
||||||
|
if (isHiddenDuringExport) {
|
||||||
|
editorState.hideDuringExport.remove(entity.getUUID());
|
||||||
|
} else {
|
||||||
|
editorState.hideDuringExport.add(entity.getUUID());
|
||||||
|
}
|
||||||
|
editorState.markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
// ImGui.sameLine();
|
// ImGui.sameLine();
|
||||||
// ImGui.button("Track Entity");
|
// ImGui.button("Track Entity");
|
||||||
//
|
//
|
||||||
// ImGui.checkbox("Hide During Export", false);
|
|
||||||
//
|
|
||||||
// ImGui.checkbox("Force Glowing", false);
|
// ImGui.checkbox("Force Glowing", false);
|
||||||
// ImGui.sameLine();
|
// ImGui.sameLine();
|
||||||
// ImGui.colorButton("Glow Colour", new float[4]);
|
// ImGui.colorButton("Glow Colour", new float[4]);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.moulberry.flashback.editor.ui.windows;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.Window;
|
import com.mojang.blaze3d.platform.Window;
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.combo_options.AspectRatio;
|
||||||
import com.moulberry.flashback.combo_options.AudioCodec;
|
import com.moulberry.flashback.combo_options.AudioCodec;
|
||||||
import com.moulberry.flashback.combo_options.VideoCodec;
|
import com.moulberry.flashback.combo_options.VideoCodec;
|
||||||
import com.moulberry.flashback.combo_options.VideoContainer;
|
import com.moulberry.flashback.combo_options.VideoContainer;
|
||||||
@@ -28,6 +29,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class StartExportWindow {
|
public class StartExportWindow {
|
||||||
@@ -36,19 +38,25 @@ public class StartExportWindow {
|
|||||||
private static boolean close = false;
|
private static boolean close = false;
|
||||||
|
|
||||||
private static final int[] lastFramebufferSize = new int[]{0, 0};
|
private static final int[] lastFramebufferSize = new int[]{0, 0};
|
||||||
|
private static AspectRatio lastCustomAspectRatio = null;
|
||||||
|
|
||||||
private static final int[] resolution = new int[]{1920, 1080};
|
private static final int[] resolution = new int[]{1920, 1080};
|
||||||
private static final int[] startEndTick = new int[]{0, 100};
|
private static final int[] startEndTick = new int[]{0, 100};
|
||||||
private static final ImFloat framerate = new ImFloat(60);
|
private static final ImFloat framerate = new ImFloat(60);
|
||||||
private static boolean resetRng = false;
|
private static boolean resetRng = false;
|
||||||
|
private static boolean ssaa = false;
|
||||||
|
|
||||||
private static VideoContainer container = VideoContainer.MP4;
|
private static VideoContainer[] supportedContainers = null;
|
||||||
private static VideoCodec videoCodec = VideoCodec.H264;
|
private static VideoContainer[] supportedContainersWithTransparency = null;
|
||||||
|
|
||||||
|
private static VideoContainer container = null;
|
||||||
|
private static VideoCodec videoCodec = null;
|
||||||
private static int[] selectedVideoEncoder = new int[]{0};
|
private static int[] selectedVideoEncoder = new int[]{0};
|
||||||
private static boolean useMaximumBitrate = false;
|
private static boolean useMaximumBitrate = false;
|
||||||
private static final ImString bitrate = ImGuiHelper.createResizableImString("20m");
|
private static final ImString bitrate = ImGuiHelper.createResizableImString("20m");
|
||||||
|
|
||||||
private static boolean recordAudio = false;
|
private static boolean recordAudio = false;
|
||||||
|
private static boolean transparentBackground = false;
|
||||||
private static AudioCodec audioCodec = AudioCodec.AAC;
|
private static AudioCodec audioCodec = AudioCodec.AAC;
|
||||||
|
|
||||||
private static Path defaultExportPath = null;
|
private static Path defaultExportPath = null;
|
||||||
@@ -59,6 +67,8 @@ public class StartExportWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void render() {
|
public static void render() {
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
|
||||||
if (open) {
|
if (open) {
|
||||||
ImGui.openPopup("###StartExport");
|
ImGui.openPopup("###StartExport");
|
||||||
Window window = Minecraft.getInstance().getWindow();
|
Window window = Minecraft.getInstance().getWindow();
|
||||||
@@ -72,6 +82,39 @@ public class StartExportWindow {
|
|||||||
lastFramebufferSize[1] = window.framebufferHeight;
|
lastFramebufferSize[1] = window.framebufferHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (editorState != null) {
|
||||||
|
AspectRatio aspectRatio = editorState.replayVisuals.changeAspectRatio;
|
||||||
|
if (aspectRatio != null && aspectRatio != lastCustomAspectRatio) {
|
||||||
|
switch (aspectRatio) {
|
||||||
|
case ASPECT_16_9 -> {
|
||||||
|
resolution[0] = 1920;
|
||||||
|
resolution[1] = 1080;
|
||||||
|
}
|
||||||
|
case ASPECT_9_16 -> {
|
||||||
|
resolution[0] = 1080;
|
||||||
|
resolution[1] = 1920;
|
||||||
|
}
|
||||||
|
case ASPECT_240_1 -> {
|
||||||
|
resolution[0] = 1920;
|
||||||
|
resolution[1] = 800;
|
||||||
|
}
|
||||||
|
case ASPECT_1_1 -> {
|
||||||
|
resolution[0] = 1920;
|
||||||
|
resolution[1] = 1920;
|
||||||
|
}
|
||||||
|
case ASPECT_4_3 -> {
|
||||||
|
resolution[0] = 1600;
|
||||||
|
resolution[1] = 1200;
|
||||||
|
}
|
||||||
|
case ASPECT_3_2 -> {
|
||||||
|
resolution[0] = 2160;
|
||||||
|
resolution[1] = 1440;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastCustomAspectRatio = aspectRatio;
|
||||||
|
}
|
||||||
|
|
||||||
open = false;
|
open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +135,6 @@ public class StartExportWindow {
|
|||||||
if (resolution[1] % 2 != 0) resolution[1] += 1;
|
if (resolution[1] % 2 != 0) resolution[1] += 1;
|
||||||
|
|
||||||
if (ImGui.inputInt2("Start/end tick", startEndTick)) {
|
if (ImGui.inputInt2("Start/end tick", startEndTick)) {
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
|
||||||
ReplayServer replayServer = Flashback.getReplayServer();
|
ReplayServer replayServer = Flashback.getReplayServer();
|
||||||
if (editorState != null && replayServer != null) {
|
if (editorState != null && replayServer != null) {
|
||||||
editorState.setExportTicks(startEndTick[0], startEndTick[1], replayServer.getTotalReplayTicks());
|
editorState.setExportTicks(startEndTick[0], startEndTick[1], replayServer.getTotalReplayTicks());
|
||||||
@@ -105,46 +147,16 @@ public class StartExportWindow {
|
|||||||
}
|
}
|
||||||
ImGuiHelper.tooltip("Attempts to remove randomness from the replay in order to produce more consistent outputs when recording the same scene multiple times");
|
ImGuiHelper.tooltip("Attempts to remove randomness from the replay in order to produce more consistent outputs when recording the same scene multiple times");
|
||||||
|
|
||||||
|
ImGui.sameLine();
|
||||||
|
|
||||||
|
if (ImGui.checkbox("SSAA", ssaa)) {
|
||||||
|
ssaa = !ssaa;
|
||||||
|
}
|
||||||
|
ImGuiHelper.tooltip("Supersampling Anti-Aliasing: Remove jagged edges by rendering the game at double resolution and downscaling");
|
||||||
|
|
||||||
ImGuiHelper.separatorWithText("Video Options");
|
ImGuiHelper.separatorWithText("Video Options");
|
||||||
|
|
||||||
VideoContainer newContainer = ImGuiHelper.enumCombo("Container", container);
|
renderVideoOptions(editorState);
|
||||||
if (newContainer != container) {
|
|
||||||
container = newContainer;
|
|
||||||
|
|
||||||
boolean supported = false;
|
|
||||||
for (VideoCodec supportedCodec : container.getSupportedVideoCodecs()) {
|
|
||||||
if (videoCodec == supportedCodec) {
|
|
||||||
supported = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!supported) {
|
|
||||||
videoCodec = container.getSupportedVideoCodecs()[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoCodec newCodec = ImGuiHelper.enumCombo("Codec", videoCodec, container.getSupportedVideoCodecs());
|
|
||||||
if (newCodec != videoCodec) {
|
|
||||||
videoCodec = newCodec;
|
|
||||||
selectedVideoEncoder[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] encoders = videoCodec.getEncoders();
|
|
||||||
if (encoders.length > 1) {
|
|
||||||
ImGuiHelper.combo("Encoder", selectedVideoEncoder, encoders);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.checkbox("Use Maximum Bitrate", useMaximumBitrate)) {
|
|
||||||
useMaximumBitrate = !useMaximumBitrate;
|
|
||||||
}
|
|
||||||
if (!useMaximumBitrate) {
|
|
||||||
ImGui.inputText("Bitrate", bitrate);
|
|
||||||
if (ImGui.isItemDeactivatedAfterEdit()) {
|
|
||||||
int numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate));
|
|
||||||
bitrate.set(bitrateToString(numBitrate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioCodec[] supportedAudioCodecs = container.getSupportedAudioCodecs();
|
AudioCodec[] supportedAudioCodecs = container.getSupportedAudioCodecs();
|
||||||
if (supportedAudioCodecs.length > 0) {
|
if (supportedAudioCodecs.length > 0) {
|
||||||
@@ -159,14 +171,13 @@ public class StartExportWindow {
|
|||||||
if (newAudioCodec != audioCodec) {
|
if (newAudioCodec != audioCodec) {
|
||||||
audioCodec = newAudioCodec;
|
audioCodec = newAudioCodec;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
|
||||||
if (editorState != null && editorState.audioSourceEntity != null) {
|
if (editorState != null && editorState.audioSourceEntity != null) {
|
||||||
ImGui.text("Audio Source: \nEntity(" + editorState.audioSourceEntity + ")");
|
ImGui.text("Audio Source: \nEntity(" + editorState.audioSourceEntity + ")");
|
||||||
} else {
|
} else {
|
||||||
ImGui.text("Audio Source: Camera");
|
ImGui.text("Audio Source: Camera");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
recordAudio = false;
|
recordAudio = false;
|
||||||
}
|
}
|
||||||
@@ -213,6 +224,69 @@ public class StartExportWindow {
|
|||||||
close = false;
|
close = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void renderVideoOptions(EditorState editorState) {
|
||||||
|
if (editorState != null && !editorState.replayVisuals.renderSky && ImGui.checkbox("Transparent Sky", transparentBackground)) {
|
||||||
|
transparentBackground = !transparentBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoContainer[] containers;
|
||||||
|
if (transparentBackground) {
|
||||||
|
if (supportedContainersWithTransparency == null) {
|
||||||
|
supportedContainersWithTransparency = VideoContainer.findSupportedContainers(true);
|
||||||
|
}
|
||||||
|
containers = supportedContainersWithTransparency;
|
||||||
|
} else {
|
||||||
|
if (supportedContainers == null) {
|
||||||
|
supportedContainers = VideoContainer.findSupportedContainers(false);
|
||||||
|
}
|
||||||
|
containers = supportedContainers;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (containers.length == 0) {
|
||||||
|
ImGui.text("No supported containers found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container == null || !Arrays.asList(containers).contains(container)) {
|
||||||
|
container = containers[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
container = ImGuiHelper.enumCombo("Container", container, containers);
|
||||||
|
|
||||||
|
VideoCodec[] codecs = container.getSupportedVideoCodecs(transparentBackground);
|
||||||
|
|
||||||
|
if (codecs.length == 0) {
|
||||||
|
ImGui.text("No supported codecs found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (videoCodec == null || !Arrays.asList(codecs).contains(videoCodec)) {
|
||||||
|
videoCodec = codecs[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoCodec newCodec = ImGuiHelper.enumCombo("Codec", videoCodec, codecs);
|
||||||
|
if (newCodec != videoCodec) {
|
||||||
|
videoCodec = newCodec;
|
||||||
|
selectedVideoEncoder[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] encoders = videoCodec.getEncoders();
|
||||||
|
if (encoders.length > 1) {
|
||||||
|
ImGuiHelper.combo("Encoder", selectedVideoEncoder, encoders);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.checkbox("Use Maximum Bitrate", useMaximumBitrate)) {
|
||||||
|
useMaximumBitrate = !useMaximumBitrate;
|
||||||
|
}
|
||||||
|
if (!useMaximumBitrate) {
|
||||||
|
ImGui.inputText("Bitrate", bitrate);
|
||||||
|
if (ImGui.isItemDeactivatedAfterEdit()) {
|
||||||
|
int numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate));
|
||||||
|
bitrate.set(bitrateToString(numBitrate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static CompletableFuture<ExportSettings> createExportSettings(@Nullable String name) {
|
private static CompletableFuture<ExportSettings> createExportSettings(@Nullable String name) {
|
||||||
int numBitrate;
|
int numBitrate;
|
||||||
if (useMaximumBitrate) {
|
if (useMaximumBitrate) {
|
||||||
@@ -266,12 +340,15 @@ public class StartExportWindow {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean transparent = transparentBackground && !editorState.replayVisuals.renderSky;
|
||||||
|
|
||||||
Path path = Path.of(pathStr);
|
Path path = Path.of(pathStr);
|
||||||
defaultExportPath = path.getParent();
|
defaultExportPath = path.getParent();
|
||||||
return new ExportSettings(name, editorState.copy(),
|
return new ExportSettings(name, editorState.copy(),
|
||||||
player.position(), player.getYRot(), player.getXRot(),
|
player.position(), player.getYRot(), player.getXRot(),
|
||||||
resolution[0], resolution[1], start, end,
|
resolution[0], resolution[1], start, end,
|
||||||
Math.max(1, framerate.get()), resetRng, container, videoCodec, encoder, numBitrate, recordAudio, path);
|
Math.max(1, framerate.get()), resetRng, container, videoCodec, encoder, numBitrate, transparent, ssaa,
|
||||||
|
recordAudio, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -7,21 +7,17 @@ import com.moulberry.flashback.Utils;
|
|||||||
import com.moulberry.flashback.editor.SavedTrack;
|
import com.moulberry.flashback.editor.SavedTrack;
|
||||||
import com.moulberry.flashback.editor.SelectedKeyframes;
|
import com.moulberry.flashback.editor.SelectedKeyframes;
|
||||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||||
import com.moulberry.flashback.ext.MinecraftExt;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeRegistry;
|
||||||
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
|
||||||
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
import com.moulberry.flashback.state.EditorStateHistoryAction;
|
import com.moulberry.flashback.state.EditorStateHistoryAction;
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
|
|
||||||
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
||||||
import com.moulberry.flashback.state.EditorStateHistoryEntry;
|
import com.moulberry.flashback.state.EditorStateHistoryEntry;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.keyframe.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
|
||||||
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
|
||||||
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
|
||||||
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
|
|
||||||
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
@@ -33,20 +29,17 @@ import imgui.flag.ImGuiMouseButton;
|
|||||||
import imgui.flag.ImGuiMouseCursor;
|
import imgui.flag.ImGuiMouseCursor;
|
||||||
import imgui.flag.ImGuiPopupFlags;
|
import imgui.flag.ImGuiPopupFlags;
|
||||||
import imgui.flag.ImGuiStyleVar;
|
import imgui.flag.ImGuiStyleVar;
|
||||||
|
import imgui.flag.ImGuiWindowFlags;
|
||||||
import imgui.type.ImFloat;
|
import imgui.type.ImFloat;
|
||||||
import imgui.type.ImInt;
|
import imgui.type.ImInt;
|
||||||
import imgui.type.ImString;
|
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
import org.joml.Vector3f;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class TimelineWindow {
|
public class TimelineWindow {
|
||||||
|
|
||||||
@@ -67,23 +60,7 @@ public class TimelineWindow {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private static Vector2f dragSelectOrigin = null;
|
private static Vector2f dragSelectOrigin = null;
|
||||||
|
|
||||||
private static final float[] fovKeyframeInput = new float[]{70.0f};
|
private static KeyframeType.KeyframeCreatePopup<?> createKeyframeWithPopup = null;
|
||||||
private static final float[] speedKeyframeInput = new float[]{1.0f};
|
|
||||||
private static final ImInt timeOfDayKeyframeInput = new ImInt(6000);
|
|
||||||
private static boolean cameraShakeSplitXYKeyframeInput = false;
|
|
||||||
private static final float[] cameraShakeFrequencyXKeyframeInput = new float[]{1.0f};
|
|
||||||
private static final float[] cameraShakeAmplitudeXKeyframeInput = new float[]{0.0f};
|
|
||||||
private static final float[] cameraShakeFrequencyYKeyframeInput = new float[]{1.0f};
|
|
||||||
private static final float[] cameraShakeAmplitudeYKeyframeInput = new float[]{0.0f};
|
|
||||||
private static final ImString timelapseKeyframeInput = ImGuiHelper.createResizableImString("0s");
|
|
||||||
static {
|
|
||||||
timelapseKeyframeInput.inputData.allowedChars = "0123456789tsmh";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final float[] cameraOrbitCenter = new float[]{0.0f, 0.0f, 0.0f};
|
|
||||||
private static final ImFloat cameraOrbitDistance = new ImFloat(8.0f);
|
|
||||||
private static final ImFloat cameraOrbitYaw = new ImFloat(0.0f);
|
|
||||||
private static final ImFloat cameraOrbitPitch = new ImFloat(0.0f);
|
|
||||||
|
|
||||||
private static float mouseX;
|
private static float mouseX;
|
||||||
private static float mouseY;
|
private static float mouseY;
|
||||||
@@ -136,11 +113,12 @@ public class TimelineWindow {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String timestamp = ticksToTimestamp(cursorTicks);
|
String timestamp = ticksToTimestamp(cursorTicks);
|
||||||
|
|
||||||
|
boolean hoveredBody = mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height;
|
||||||
|
|
||||||
ImGuiHelper.pushStyleVar(ImGuiStyleVar.WindowPadding, 0, 0);
|
ImGuiHelper.pushStyleVar(ImGuiStyleVar.WindowPadding, 0, 0);
|
||||||
boolean timelineVisible = ImGui.begin("Timeline (" + timestamp + "/" + cursorTicks + ")###Timeline");
|
boolean timelineVisible = ImGui.begin("Timeline (" + timestamp + "/" + cursorTicks + ")###Timeline", hoveredBody ? ImGuiWindowFlags.NoMove : ImGuiWindowFlags.None);
|
||||||
ImGuiHelper.popStyleVar();
|
ImGuiHelper.popStyleVar();
|
||||||
|
|
||||||
cursorTicks = replayServer.getReplayTick();
|
cursorTicks = replayServer.getReplayTick();
|
||||||
@@ -221,7 +199,7 @@ public class TimelineWindow {
|
|||||||
|
|
||||||
cursorTicks = currentReplayTick;
|
cursorTicks = currentReplayTick;
|
||||||
if (grabbedPlayback) {
|
if (grabbedPlayback) {
|
||||||
cursorTicks = timelineXToReplayTick(mouseX);
|
cursorTicks = timelineXToReplayTick(mouseX - x);
|
||||||
} else if (replayServer.jumpToTick >= 0) {
|
} else if (replayServer.jumpToTick >= 0) {
|
||||||
cursorTicks = replayServer.jumpToTick;
|
cursorTicks = replayServer.jumpToTick;
|
||||||
} else if (pendingStepBackwardsTicks > 0) {
|
} else if (pendingStepBackwardsTicks > 0) {
|
||||||
@@ -276,7 +254,7 @@ public class TimelineWindow {
|
|||||||
zoomBarExpanded = true;
|
zoomBarExpanded = true;
|
||||||
}
|
}
|
||||||
zoomBarHovered = mouseY >= y + height - zoomBarHeight && mouseY <= y + height &&
|
zoomBarHovered = mouseY >= y + height - zoomBarHeight && mouseY <= y + height &&
|
||||||
mouseX >= x + zoomBarMin && mouseX <= x + zoomBarMax;
|
mouseX >= zoomBarMin && mouseX <= zoomBarMax;
|
||||||
|
|
||||||
renderKeyframeElements(replayServer, editorState, x, y + middleY, cursorTicks, middleX);
|
renderKeyframeElements(replayServer, editorState, x, y + middleY, cursorTicks, middleX);
|
||||||
|
|
||||||
@@ -319,13 +297,13 @@ public class TimelineWindow {
|
|||||||
drawList.addRectFilled(x + middleX +1, y + height - zoomBarHeight, x + width, y + height, 0xFF404040, zoomBarHeight);
|
drawList.addRectFilled(x + middleX +1, y + height - zoomBarHeight, x + width, y + height, 0xFF404040, zoomBarHeight);
|
||||||
}
|
}
|
||||||
if (zoomBarHovered || grabbedZoomBar) {
|
if (zoomBarHovered || grabbedZoomBar) {
|
||||||
drawList.addRectFilled(x + zoomBarMin + zoomBarHeight /2f, y + height - zoomBarHeight, x + zoomBarMax - zoomBarHeight /2f, y + height, -1, zoomBarHeight);
|
drawList.addRectFilled(zoomBarMin + zoomBarHeight/2f, y + height - zoomBarHeight, zoomBarMax - zoomBarHeight/2f, y + height, -1, zoomBarHeight);
|
||||||
|
|
||||||
// Left/right resize
|
// Left/right resize
|
||||||
drawList.addCircleFilled(x + zoomBarMin + zoomBarHeight /2f, y + height - zoomBarHeight /2f, zoomBarHeight /2f, 0xffaaaa00);
|
drawList.addCircleFilled(zoomBarMin + zoomBarHeight/2f, y + height - zoomBarHeight/2f, zoomBarHeight/2f, 0xffaaaa00);
|
||||||
drawList.addCircleFilled(x + zoomBarMax - zoomBarHeight /2f, y + height - zoomBarHeight /2f, zoomBarHeight /2f, 0xffaaaa00);
|
drawList.addCircleFilled(zoomBarMax - zoomBarHeight/2f, y + height - zoomBarHeight/2f, zoomBarHeight/2f, 0xffaaaa00);
|
||||||
} else {
|
} else {
|
||||||
drawList.addRectFilled(x + zoomBarMin, y + height - zoomBarHeight, x + zoomBarMax, y + height, -1, zoomBarHeight);
|
drawList.addRectFilled(zoomBarMin, y + height - zoomBarHeight, zoomBarMax, y + height, -1, zoomBarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause/play button
|
// Pause/play button
|
||||||
@@ -450,13 +428,13 @@ public class TimelineWindow {
|
|||||||
if (grabbedExportBarResizeLeft) {
|
if (grabbedExportBarResizeLeft) {
|
||||||
ImGui.setMouseCursor(ImGuiMouseCursor.ResizeEW);
|
ImGui.setMouseCursor(ImGuiMouseCursor.ResizeEW);
|
||||||
|
|
||||||
int target = timelineXToReplayTick(mouseX);
|
int target = timelineXToReplayTick(mouseX - x);
|
||||||
editorState.setExportTicks(target, -1, totalTicks);
|
editorState.setExportTicks(target, -1, totalTicks);
|
||||||
}
|
}
|
||||||
if (grabbedExportBarResizeRight) {
|
if (grabbedExportBarResizeRight) {
|
||||||
ImGui.setMouseCursor(ImGuiMouseCursor.ResizeEW);
|
ImGui.setMouseCursor(ImGuiMouseCursor.ResizeEW);
|
||||||
|
|
||||||
int target = timelineXToReplayTick(mouseX);
|
int target = timelineXToReplayTick(mouseX - x);
|
||||||
editorState.setExportTicks(-1, target, totalTicks);
|
editorState.setExportTicks(-1, target, totalTicks);
|
||||||
}
|
}
|
||||||
if (zoomBarWidth > 1f && grabbedZoomBar) {
|
if (zoomBarWidth > 1f && grabbedZoomBar) {
|
||||||
@@ -484,7 +462,7 @@ public class TimelineWindow {
|
|||||||
editorState.markDirty();
|
editorState.markDirty();
|
||||||
}
|
}
|
||||||
if (grabbedPlayback) {
|
if (grabbedPlayback) {
|
||||||
int desiredTick = timelineXToReplayTick(mouseX);
|
int desiredTick = timelineXToReplayTick(mouseX - x);
|
||||||
|
|
||||||
if (desiredTick > currentReplayTick) {
|
if (desiredTick > currentReplayTick) {
|
||||||
replayServer.goToReplayTick(desiredTick);
|
replayServer.goToReplayTick(desiredTick);
|
||||||
@@ -687,6 +665,12 @@ public class TimelineWindow {
|
|||||||
// Pause button
|
// Pause button
|
||||||
if (hoveredPause) {
|
if (hoveredPause) {
|
||||||
replayServer.replayPaused = !replayServer.replayPaused;
|
replayServer.replayPaused = !replayServer.replayPaused;
|
||||||
|
if (!replayServer.replayPaused) {
|
||||||
|
Screen screen = Minecraft.getInstance().screen;
|
||||||
|
if (screen != null && screen.isPauseScreen()) {
|
||||||
|
Minecraft.getInstance().setScreen(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,9 +722,9 @@ public class TimelineWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (zoomBarHovered) {
|
if (zoomBarHovered) {
|
||||||
if (mouseX <= x + zoomBarMin + zoomBarHeight) {
|
if (mouseX <= zoomBarMin + zoomBarHeight) {
|
||||||
grabbedZoomBarResizeLeft = leftClicked;
|
grabbedZoomBarResizeLeft = leftClicked;
|
||||||
} else if (mouseX >= x + zoomBarMax - zoomBarHeight) {
|
} else if (mouseX >= zoomBarMax - zoomBarHeight) {
|
||||||
grabbedZoomBarResizeRight = leftClicked;
|
grabbedZoomBarResizeRight = leftClicked;
|
||||||
}
|
}
|
||||||
grabbedZoomBar = leftClicked;
|
grabbedZoomBar = leftClicked;
|
||||||
@@ -776,7 +760,7 @@ public class TimelineWindow {
|
|||||||
if (trackIndex >= 0 && trackIndex < editorState.keyframeTracks.size()) {
|
if (trackIndex >= 0 && trackIndex < editorState.keyframeTracks.size()) {
|
||||||
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(trackIndex);
|
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(trackIndex);
|
||||||
|
|
||||||
int tick = timelineXToReplayTick(mouseX);
|
int tick = timelineXToReplayTick(mouseX - x);
|
||||||
|
|
||||||
Map.Entry<Integer, Keyframe> floor = keyframeTrack.keyframesByTick.floorEntry(tick);
|
Map.Entry<Integer, Keyframe> floor = keyframeTrack.keyframesByTick.floorEntry(tick);
|
||||||
Map.Entry<Integer, Keyframe> ceil = keyframeTrack.keyframesByTick.ceilingEntry(tick);
|
Map.Entry<Integer, Keyframe> ceil = keyframeTrack.keyframesByTick.ceilingEntry(tick);
|
||||||
@@ -995,7 +979,7 @@ public class TimelineWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (grabbedPlayback) {
|
if (grabbedPlayback) {
|
||||||
int desiredTick = timelineXToReplayTick(mouseX);
|
int desiredTick = timelineXToReplayTick(mouseX - x);
|
||||||
replayServer.goToReplayTick(desiredTick);
|
replayServer.goToReplayTick(desiredTick);
|
||||||
replayServer.replayPaused = true;
|
replayServer.replayPaused = true;
|
||||||
grabbedPlayback = false;
|
grabbedPlayback = false;
|
||||||
@@ -1221,6 +1205,8 @@ public class TimelineWindow {
|
|||||||
|
|
||||||
Keyframe keyframe = entry.getValue();
|
Keyframe keyframe = entry.getValue();
|
||||||
|
|
||||||
|
float midY = y + 2 + (trackIndex+0.5f) * lineHeight;
|
||||||
|
|
||||||
if (selectedKeyframesForTrack != null && selectedKeyframesForTrack.keyframeTicks().contains(tick)) {
|
if (selectedKeyframesForTrack != null && selectedKeyframesForTrack.keyframeTicks().contains(tick)) {
|
||||||
int newTick = tick;
|
int newTick = tick;
|
||||||
|
|
||||||
@@ -1238,16 +1224,87 @@ public class TimelineWindow {
|
|||||||
int keyframeX = replayTickToTimelineX(newTick);
|
int keyframeX = replayTickToTimelineX(newTick);
|
||||||
|
|
||||||
float midX = x + keyframeX;
|
float midX = x + keyframeX;
|
||||||
float midY = y + 2 + (trackIndex+0.5f) * lineHeight;
|
|
||||||
|
|
||||||
drawKeyframe(foregroundDrawList, keyframe.interpolationType(), midX, midY, keyframeTrack.enabled ? 0xFF0000FF : 0x800000FF);
|
drawKeyframe(foregroundDrawList, keyframe.interpolationType(), midX, midY, keyframeTrack.enabled ? 0xFF0000FF : 0x800000FF);
|
||||||
} else {
|
} else {
|
||||||
int keyframeX = replayTickToTimelineX(tick);
|
int keyframeX = replayTickToTimelineX(tick);
|
||||||
|
|
||||||
float midX = x + keyframeX;
|
float midX = x + keyframeX;
|
||||||
float midY = y + 2 + (trackIndex+0.5f) * lineHeight;
|
|
||||||
|
|
||||||
drawKeyframe(drawList, keyframe.interpolationType(), midX, midY, keyframeTrack.enabled ? -1 : 0x80FFFFFF);
|
int colour = -1;
|
||||||
|
if (keyframeTrack.keyframeType == TimelapseKeyframeType.INSTANCE) {
|
||||||
|
if (keyframeTrack.keyframesByTick.size() == 1) {
|
||||||
|
colour = 0xFF155FFF;
|
||||||
|
|
||||||
|
if (Math.abs(mouseX - midX) < KEYFRAME_SIZE && Math.abs(mouseY - midY) < KEYFRAME_SIZE) {
|
||||||
|
ImGuiHelper.drawTooltip("Timelapse requires two keyframes");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var floorEntry = keyframeTrack.keyframesByTick.floorEntry(tick - 1);
|
||||||
|
if (floorEntry != null && floorEntry.getValue() instanceof TimelapseKeyframe timelapseKeyframe) {
|
||||||
|
if (timelapseKeyframe.ticks >= ((TimelapseKeyframe) keyframe).ticks) {
|
||||||
|
colour = 0xFF155FFF;
|
||||||
|
|
||||||
|
if (Math.abs(mouseX - midX) < KEYFRAME_SIZE && Math.abs(mouseY - midY) < KEYFRAME_SIZE) {
|
||||||
|
ImGuiHelper.drawTooltip("This keyframe's Time must be greater than the Time on the left.\nThe left keyframe must be set to the base time, e.g. 0s and the right keyframe must be set to the duration of the timelapse e.g. 10s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!keyframeTrack.enabled) {
|
||||||
|
colour &= 0xFFFFFF;
|
||||||
|
colour |= 0x80000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawKeyframe(drawList, keyframe.interpolationType(), midX, midY, colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((selectedKeyframesForTrack == null || grabMovementInfo == null) && keyframeTrack.keyframeType == TimelapseKeyframeType.INSTANCE) {
|
||||||
|
var floorEntry = keyframeTrack.keyframesByTick.floorEntry(tick - 1);
|
||||||
|
if (floorEntry != null) {
|
||||||
|
TimelapseKeyframe left = (TimelapseKeyframe) floorEntry.getValue();
|
||||||
|
TimelapseKeyframe right = (TimelapseKeyframe) keyframe;
|
||||||
|
|
||||||
|
int leftX = replayTickToTimelineX(floorEntry.getKey());
|
||||||
|
int rightX = replayTickToTimelineX(tick);
|
||||||
|
|
||||||
|
int tickDelta = right.ticks - left.ticks;
|
||||||
|
String message;
|
||||||
|
int textColour = -1;
|
||||||
|
if (tickDelta <= 0) {
|
||||||
|
message = "INVALID";
|
||||||
|
textColour = 0xFF155FFF;
|
||||||
|
} else {
|
||||||
|
message = Utils.timeToString(tickDelta);
|
||||||
|
}
|
||||||
|
|
||||||
|
float textY = midY - lineHeight*0.3f;
|
||||||
|
float midX = (leftX + rightX)/2f;
|
||||||
|
|
||||||
|
float textWidth = ImGuiHelper.calcTextWidth("Duration: " + message);
|
||||||
|
if (textWidth <= rightX - leftX) {
|
||||||
|
ImGui.getWindowDrawList().addText(x + midX - textWidth/2, textY,
|
||||||
|
textColour, "Duration: " + message);
|
||||||
|
} else {
|
||||||
|
textWidth = ImGuiHelper.calcTextWidth(message);
|
||||||
|
if (textWidth <= rightX - leftX) {
|
||||||
|
ImGui.getWindowDrawList().addText(x + midX - textWidth/2, textY,
|
||||||
|
textColour, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float startLine1 = x + leftX + KEYFRAME_SIZE;
|
||||||
|
float endLine1 = x + midX - textWidth/2f - 5;
|
||||||
|
float startLine2 = x + midX + textWidth/2f + 5;
|
||||||
|
float endLine2 = x + rightX - KEYFRAME_SIZE;
|
||||||
|
if (startLine1 < endLine1) {
|
||||||
|
ImGui.getWindowDrawList().addLine(startLine1, midY, endLine1, midY, 0x80FFFFFF);
|
||||||
|
}
|
||||||
|
if (startLine2 < endLine2) {
|
||||||
|
ImGui.getWindowDrawList().addLine(startLine2, midY, endLine2, midY, 0x80FFFFFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1309,187 +1366,55 @@ public class TimelineWindow {
|
|||||||
float buttonSize = ImGui.getTextLineHeight();
|
float buttonSize = ImGui.getTextLineHeight();
|
||||||
float spacingX = ImGui.getStyle().getItemSpacingX();
|
float spacingX = ImGui.getStyle().getItemSpacingX();
|
||||||
|
|
||||||
|
boolean hasOpenPopup = false;
|
||||||
|
|
||||||
for (int trackIndex = 0; trackIndex < editorState.keyframeTracks.size(); trackIndex++) {
|
for (int trackIndex = 0; trackIndex < editorState.keyframeTracks.size(); trackIndex++) {
|
||||||
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(trackIndex);
|
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(trackIndex);
|
||||||
KeyframeType keyframeType = keyframeTrack.keyframeType;
|
KeyframeType<?> keyframeType = keyframeTrack.keyframeType;
|
||||||
|
|
||||||
ImGui.pushID(trackIndex);
|
ImGui.pushID(trackIndex);
|
||||||
|
|
||||||
ImGui.setCursorPosX(8);
|
ImGui.setCursorPosX(8);
|
||||||
|
|
||||||
if (keyframeTrack.enabled) {
|
if (keyframeTrack.enabled) {
|
||||||
ImGui.text(keyframeType.name);
|
ImGui.text(keyframeType.name());
|
||||||
} else {
|
} else {
|
||||||
ImGui.textDisabled(keyframeType.name);
|
ImGui.textDisabled(keyframeType.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
|
|
||||||
float buttonX = middleX - (buttonSize + spacingX) * 3;
|
float buttonX = x + middleX - (buttonSize + spacingX) * 3;
|
||||||
float buttonY = ImGui.getCursorScreenPosY();
|
float buttonY = ImGui.getCursorScreenPosY();
|
||||||
ImGui.setCursorPosX(buttonX);
|
ImGui.setCursorPosX(buttonX - x);
|
||||||
if (ImGui.button("##Add", buttonSize, buttonSize)) {
|
if (ImGui.button("##Add", buttonSize, buttonSize)) {
|
||||||
LocalPlayer player = Minecraft.getInstance().player;
|
Keyframe keyframe = keyframeType.createDirect();
|
||||||
Keyframe keyframe = switch (keyframeType) {
|
|
||||||
case CAMERA -> new CameraKeyframe(player);
|
|
||||||
case CAMERA_ORBIT -> {
|
|
||||||
Vec3 eyePosition = player.getEyePosition();
|
|
||||||
cameraOrbitCenter[0] = (float) eyePosition.x;
|
|
||||||
cameraOrbitCenter[1] = (float) eyePosition.y;
|
|
||||||
cameraOrbitCenter[2] = (float) eyePosition.z;
|
|
||||||
ImGui.openPopup("##EnterCameraOrbit");
|
|
||||||
yield null;
|
|
||||||
}
|
|
||||||
case FOV -> {
|
|
||||||
fovKeyframeInput[0] = editorState.replayVisuals.overrideFov ? editorState.replayVisuals.overrideFovAmount : Minecraft.getInstance().options.fov().get();
|
|
||||||
ImGui.openPopup("##EnterFov");
|
|
||||||
yield null;
|
|
||||||
}
|
|
||||||
case SPEED -> {
|
|
||||||
speedKeyframeInput[0] = replayServer.getDesiredTickRate(false) / 20.0f;
|
|
||||||
ImGui.openPopup("##EnterSpeed");
|
|
||||||
yield null;
|
|
||||||
}
|
|
||||||
case TIMELAPSE -> {
|
|
||||||
ImGui.openPopup("##EnterTimelapse");
|
|
||||||
yield null;
|
|
||||||
}
|
|
||||||
case TIME_OF_DAY -> {
|
|
||||||
if (editorState.replayVisuals.overrideTimeOfDay >= 0) {
|
|
||||||
timeOfDayKeyframeInput.set((int) editorState.replayVisuals.overrideTimeOfDay);
|
|
||||||
} else {
|
|
||||||
timeOfDayKeyframeInput.set((int)(Minecraft.getInstance().level.getDayTime() % 24000));
|
|
||||||
}
|
|
||||||
ImGui.openPopup("##EnterTime");
|
|
||||||
yield null;
|
|
||||||
}
|
|
||||||
case CAMERA_SHAKE -> {
|
|
||||||
if (editorState.replayVisuals.overrideCameraShake) {
|
|
||||||
cameraShakeSplitXYKeyframeInput = editorState.replayVisuals.cameraShakeSplitParams;
|
|
||||||
cameraShakeFrequencyXKeyframeInput[0] = editorState.replayVisuals.cameraShakeXFrequency;
|
|
||||||
cameraShakeAmplitudeXKeyframeInput[0] = editorState.replayVisuals.cameraShakeXAmplitude;
|
|
||||||
cameraShakeFrequencyYKeyframeInput[0] = editorState.replayVisuals.cameraShakeYFrequency;
|
|
||||||
cameraShakeAmplitudeYKeyframeInput[0] = editorState.replayVisuals.cameraShakeYAmplitude;
|
|
||||||
ImGui.openPopup("##EnterCameraShake");
|
|
||||||
yield null;
|
|
||||||
} else {
|
|
||||||
cameraShakeSplitXYKeyframeInput = false;
|
|
||||||
cameraShakeFrequencyXKeyframeInput[0] = 1.0f;
|
|
||||||
cameraShakeAmplitudeXKeyframeInput[0] = 0.0f;
|
|
||||||
cameraShakeFrequencyYKeyframeInput[0] = 1.0f;
|
|
||||||
cameraShakeAmplitudeYKeyframeInput[0] = 0.0f;
|
|
||||||
ImGui.openPopup("##EnterCameraShake");
|
|
||||||
yield null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (keyframe != null) {
|
if (keyframe != null) {
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
|
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
|
||||||
|
} else {
|
||||||
|
if (keyframeType == TimelapseKeyframeType.INSTANCE && keyframeTrack.keyframesByTick.isEmpty()) {
|
||||||
|
editorState.setKeyframe(trackIndex, cursorTicks, new TimelapseKeyframe(0));
|
||||||
|
} else {
|
||||||
|
createKeyframeWithPopup = keyframeType.createPopup();
|
||||||
|
if (createKeyframeWithPopup != null) {
|
||||||
|
ImGui.openPopup("##CreateKeyframe");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawList.addRectFilled(buttonX + 2, buttonY + buttonSize/2 - 1, buttonX + buttonSize - 2, buttonY + buttonSize/2 + 1, -1);
|
drawList.addRectFilled(buttonX + 2, buttonY + buttonSize/2 - 1, buttonX + buttonSize - 2, buttonY + buttonSize/2 + 1, -1);
|
||||||
drawList.addRectFilled(buttonX + buttonSize/2 - 1, buttonY + 2, buttonX + buttonSize/2 + 1, buttonY + buttonSize - 2, -1);
|
drawList.addRectFilled(buttonX + buttonSize/2 - 1, buttonY + 2, buttonX + buttonSize/2 + 1, buttonY + buttonSize - 2, -1);
|
||||||
ImGuiHelper.tooltip("Add keyframe");
|
ImGuiHelper.tooltip("Add keyframe");
|
||||||
|
|
||||||
if (ImGui.beginPopup("##EnterSpeed")) {
|
if (ImGui.beginPopup("##CreateKeyframe")) {
|
||||||
ImGui.sliderFloat("Speed", speedKeyframeInput, 0.1f, 10f);
|
if (createKeyframeWithPopup != null) {
|
||||||
if (ImGui.button("Add")) {
|
hasOpenPopup = true;
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, new TickrateKeyframe(speedKeyframeInput[0] * 20.0f));
|
Keyframe keyframe = createKeyframeWithPopup.render();
|
||||||
ImGui.closeCurrentPopup();
|
if (keyframe != null) {
|
||||||
}
|
|
||||||
ImGui.sameLine();
|
|
||||||
if (ImGui.button("Cancel")) {
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.endPopup();
|
|
||||||
}
|
|
||||||
if (ImGui.beginPopup("##EnterTimelapse")) {
|
|
||||||
ImGui.inputText("Time", timelapseKeyframeInput);
|
|
||||||
if (ImGui.button("Add")) {
|
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, new TimelapseKeyframe(Utils.stringToTime(ImGuiHelper.getString(timelapseKeyframeInput))));
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.sameLine();
|
|
||||||
if (ImGui.button("Cancel")) {
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.endPopup();
|
|
||||||
}
|
|
||||||
if (ImGui.beginPopup("##EnterTime")) {
|
|
||||||
ImGui.inputInt("Time", timeOfDayKeyframeInput, 0);
|
|
||||||
if (ImGui.button("Add")) {
|
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, new TimeOfDayKeyframe(timeOfDayKeyframeInput.get()));
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.sameLine();
|
|
||||||
if (ImGui.button("Cancel")) {
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.endPopup();
|
|
||||||
}
|
|
||||||
if (ImGui.beginPopup("##EnterFov")) {
|
|
||||||
ImGui.sliderFloat("FOV", fovKeyframeInput, 1f, 110f);
|
|
||||||
if (ImGui.button("Add")) {
|
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, new FOVKeyframe(fovKeyframeInput[0]));
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.sameLine();
|
|
||||||
if (ImGui.button("Cancel")) {
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.endPopup();
|
|
||||||
}
|
|
||||||
if (ImGui.beginPopup("##EnterCameraOrbit")) {
|
|
||||||
ImGui.inputFloat3("Position", cameraOrbitCenter);
|
|
||||||
ImGui.inputFloat("Distance", cameraOrbitDistance);
|
|
||||||
ImGui.inputFloat("Yaw", cameraOrbitYaw);
|
|
||||||
ImGui.inputFloat("Pitch", cameraOrbitPitch);
|
|
||||||
|
|
||||||
if (ImGui.button("Add")) {
|
|
||||||
Vector3f center = new Vector3f(cameraOrbitCenter[0], cameraOrbitCenter[1], cameraOrbitCenter[2]);
|
|
||||||
Keyframe keyframe = new CameraOrbitKeyframe(center, cameraOrbitDistance.get(), cameraOrbitYaw.get(), cameraOrbitPitch.get());
|
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
|
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
|
||||||
ImGui.closeCurrentPopup();
|
ImGui.closeCurrentPopup();
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
|
||||||
if (ImGui.button("Cancel")) {
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.endPopup();
|
|
||||||
}
|
|
||||||
if (ImGui.beginPopup("##EnterCameraShake")) {
|
|
||||||
if (ImGui.checkbox("Split Y/X", cameraShakeSplitXYKeyframeInput)) {
|
|
||||||
cameraShakeSplitXYKeyframeInput = !cameraShakeSplitXYKeyframeInput;
|
|
||||||
if (!cameraShakeSplitXYKeyframeInput) {
|
|
||||||
cameraShakeFrequencyYKeyframeInput[0] = cameraShakeFrequencyXKeyframeInput[0];
|
|
||||||
cameraShakeAmplitudeYKeyframeInput[0] = cameraShakeAmplitudeXKeyframeInput[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cameraShakeSplitXYKeyframeInput) {
|
|
||||||
ImGui.sliderFloat("Frequency X", cameraShakeFrequencyXKeyframeInput, 0.1f, 10.0f, "%.1f");
|
|
||||||
ImGui.sliderFloat("Amplitude X", cameraShakeAmplitudeXKeyframeInput, 0.0f, 10.0f, "%.1f");
|
|
||||||
ImGui.sliderFloat("Frequency Y", cameraShakeFrequencyYKeyframeInput, 0.1f, 10.0f, "%.1f");
|
|
||||||
ImGui.sliderFloat("Amplitude Y", cameraShakeAmplitudeYKeyframeInput, 0.0f, 10.0f, "%.1f");
|
|
||||||
} else {
|
} else {
|
||||||
ImGui.sliderFloat("Frequency", cameraShakeFrequencyXKeyframeInput, 0.1f, 10.0f, "%.1f");
|
|
||||||
ImGui.sliderFloat("Amplitude", cameraShakeAmplitudeXKeyframeInput, 0.0f, 10.0f, "%.1f");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.button("Add")) {
|
|
||||||
Keyframe keyframe;
|
|
||||||
if (cameraShakeSplitXYKeyframeInput) {
|
|
||||||
keyframe = new CameraShakeKeyframe(cameraShakeFrequencyXKeyframeInput[0], cameraShakeAmplitudeXKeyframeInput[0],
|
|
||||||
cameraShakeFrequencyYKeyframeInput[0], cameraShakeAmplitudeYKeyframeInput[0]);
|
|
||||||
} else {
|
|
||||||
keyframe = new CameraShakeKeyframe(cameraShakeFrequencyXKeyframeInput[0], cameraShakeAmplitudeXKeyframeInput[0],
|
|
||||||
cameraShakeFrequencyXKeyframeInput[0], cameraShakeAmplitudeXKeyframeInput[0]);
|
|
||||||
}
|
|
||||||
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
|
|
||||||
ImGui.closeCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui.sameLine();
|
|
||||||
if (ImGui.button("Cancel")) {
|
|
||||||
ImGui.closeCurrentPopup();
|
ImGui.closeCurrentPopup();
|
||||||
}
|
}
|
||||||
ImGui.endPopup();
|
ImGui.endPopup();
|
||||||
@@ -1498,7 +1423,7 @@ public class TimelineWindow {
|
|||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
|
|
||||||
buttonX += buttonSize + spacingX;
|
buttonX += buttonSize + spacingX;
|
||||||
ImGui.setCursorPosX(buttonX);
|
ImGui.setCursorPosX(buttonX - x);
|
||||||
if (ImGui.button("##Clear", buttonSize, buttonSize)) {
|
if (ImGui.button("##Clear", buttonSize, buttonSize)) {
|
||||||
keyframeTrackToClear = trackIndex;
|
keyframeTrackToClear = trackIndex;
|
||||||
}
|
}
|
||||||
@@ -1508,7 +1433,7 @@ public class TimelineWindow {
|
|||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
|
|
||||||
buttonX += buttonSize + spacingX;
|
buttonX += buttonSize + spacingX;
|
||||||
ImGui.setCursorPosX(buttonX);
|
ImGui.setCursorPosX(buttonX - x);
|
||||||
if (ImGui.button("##ToggleEnabled", buttonSize, buttonSize)) {
|
if (ImGui.button("##ToggleEnabled", buttonSize, buttonSize)) {
|
||||||
keyframeTrack.enabled = !keyframeTrack.enabled;
|
keyframeTrack.enabled = !keyframeTrack.enabled;
|
||||||
}
|
}
|
||||||
@@ -1525,6 +1450,10 @@ public class TimelineWindow {
|
|||||||
ImGui.popID();
|
ImGui.popID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasOpenPopup) {
|
||||||
|
createKeyframeWithPopup = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (keyframeTrackToClear >= 0) {
|
if (keyframeTrackToClear >= 0) {
|
||||||
List<EditorStateHistoryAction> undo = new ArrayList<>();
|
List<EditorStateHistoryAction> undo = new ArrayList<>();
|
||||||
List<EditorStateHistoryAction> redo = new ArrayList<>();
|
List<EditorStateHistoryAction> redo = new ArrayList<>();
|
||||||
@@ -1547,16 +1476,16 @@ public class TimelineWindow {
|
|||||||
ImGui.openPopup("##AddKeyframeElement");
|
ImGui.openPopup("##AddKeyframeElement");
|
||||||
}
|
}
|
||||||
if (ImGui.beginPopup("##AddKeyframeElement")) {
|
if (ImGui.beginPopup("##AddKeyframeElement")) {
|
||||||
for (KeyframeType keyframeType : KeyframeType.KEYFRAME_TYPES) {
|
for (KeyframeType<?> type : KeyframeRegistry.getTypes()) {
|
||||||
if (ImGui.selectable(keyframeType.name)) {
|
if (ImGui.selectable(type.name())) {
|
||||||
List<EditorStateHistoryAction> undo = new ArrayList<>();
|
List<EditorStateHistoryAction> undo = new ArrayList<>();
|
||||||
List<EditorStateHistoryAction> redo = new ArrayList<>();
|
List<EditorStateHistoryAction> redo = new ArrayList<>();
|
||||||
|
|
||||||
int index = editorState.keyframeTracks.size();
|
int index = editorState.keyframeTracks.size();
|
||||||
undo.add(new EditorStateHistoryAction.RemoveTrack(keyframeType, index));
|
undo.add(new EditorStateHistoryAction.RemoveTrack(type, index));
|
||||||
redo.add(new EditorStateHistoryAction.AddTrack(keyframeType, index));
|
redo.add(new EditorStateHistoryAction.AddTrack(type, index));
|
||||||
|
|
||||||
editorState.push(new EditorStateHistoryEntry(undo, redo, "Create " + keyframeType + " track"));
|
editorState.push(new EditorStateHistoryEntry(undo, redo, "Create " + type.name() + " track"));
|
||||||
ImGui.closeCurrentPopup();
|
ImGui.closeCurrentPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,6 +229,13 @@ public class VisualsWindow {
|
|||||||
visuals.changeAspectRatio = ImGuiHelper.enumCombo("Aspect", visuals.changeAspectRatio);
|
visuals.changeAspectRatio = ImGuiHelper.enumCombo("Aspect", visuals.changeAspectRatio);
|
||||||
editorState.markDirty();
|
editorState.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!editorState.hideDuringExport.isEmpty()) {
|
||||||
|
if (ImGui.button("Unhide All Entities")) {
|
||||||
|
editorState.hideDuringExport.clear();
|
||||||
|
editorState.markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui.end();
|
ImGui.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.bytedeco.javacv.FFmpegLogCallback;
|
|||||||
import org.bytedeco.javacv.Frame;
|
import org.bytedeco.javacv.Frame;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -51,7 +52,7 @@ public class AsyncVideoEncoder implements AutoCloseable {
|
|||||||
|
|
||||||
private final AtomicReference<Throwable> threadedError = new AtomicReference<>(null);
|
private final AtomicReference<Throwable> threadedError = new AtomicReference<>(null);
|
||||||
|
|
||||||
private static final int SRC_PIXEL_FORMAT = avutil.AV_PIX_FMT_RGBA;
|
public static final int SRC_PIXEL_FORMAT = avutil.AV_PIX_FMT_RGBA;
|
||||||
|
|
||||||
private record ImageFrame(long pointer, int size, int width, int height, int channels, int imageDepth, int stride, int pixelFormat,
|
private record ImageFrame(long pointer, int size, int width, int height, int channels, int imageDepth, int stride, int pixelFormat,
|
||||||
@Nullable FloatBuffer audioBuffer) implements AutoCloseable {
|
@Nullable FloatBuffer audioBuffer) implements AutoCloseable {
|
||||||
@@ -89,11 +90,12 @@ public class AsyncVideoEncoder implements AutoCloseable {
|
|||||||
String extension = settings.container().extension();
|
String extension = settings.container().extension();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (FabricLoader.getInstance().isDevelopmentEnvironment() || true) {
|
|
||||||
FFmpegLogCallback.set();
|
FFmpegLogCallback.set();
|
||||||
}
|
|
||||||
|
|
||||||
int dstPixelFormat = PixelFormatHelper.getBestPixelFormat(settings.encoder());
|
boolean wantTransparency = settings.transparent();
|
||||||
|
|
||||||
|
int dstPixelFormat = PixelFormatHelper.getBestPixelFormat(settings.encoder(), wantTransparency);
|
||||||
|
Flashback.LOGGER.info("Encoding video with pixel format {}", PixelFormatHelper.pixelFormatToString(dstPixelFormat));
|
||||||
boolean needsRescale = SRC_PIXEL_FORMAT != dstPixelFormat;
|
boolean needsRescale = SRC_PIXEL_FORMAT != dstPixelFormat;
|
||||||
|
|
||||||
final FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(
|
final FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(
|
||||||
|
|||||||
@@ -14,14 +14,13 @@ import com.moulberry.flashback.compat.IrisApiWrapper;
|
|||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
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.types.SpeedKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
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 com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
import com.moulberry.flashback.state.KeyframeTrack;
|
|
||||||
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
|
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
|
||||||
import it.unimi.dsi.fastutil.doubles.DoubleList;
|
import it.unimi.dsi.fastutil.doubles.DoubleList;
|
||||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
|
||||||
import it.unimi.dsi.fastutil.floats.FloatList;
|
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.Screenshot;
|
import net.minecraft.client.Screenshot;
|
||||||
@@ -48,6 +47,7 @@ import java.util.EnumSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
import java.util.concurrent.locks.LockSupport;
|
||||||
@@ -94,11 +94,11 @@ public class ExportJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return this.settings.resolutionX();
|
return this.settings.resolutionX() * (this.settings.ssaa() ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return this.settings.resolutionY();
|
return this.settings.resolutionY() * (this.settings.ssaa() ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Random getParticleRandom() {
|
public Random getParticleRandom() {
|
||||||
@@ -248,11 +248,8 @@ public class ExportJob {
|
|||||||
this.settings.editorState().applyKeyframes(keyframeHandler, (float)(this.settings.startTick() + currentTickDouble));
|
this.settings.editorState().applyKeyframes(keyframeHandler, (float)(this.settings.startTick() + currentTickDouble));
|
||||||
|
|
||||||
|
|
||||||
SaveableFramebuffer saveable;
|
SaveableFramebuffer saveable = downloader.take();
|
||||||
RenderTarget renderTarget;
|
RenderTarget renderTarget = Minecraft.getInstance().mainRenderTarget;
|
||||||
|
|
||||||
saveable = downloader.take();
|
|
||||||
renderTarget = Minecraft.getInstance().mainRenderTarget;
|
|
||||||
|
|
||||||
renderTarget.bindWrite(true);
|
renderTarget.bindWrite(true);
|
||||||
RenderSystem.clear(16640, Minecraft.ON_OSX);
|
RenderSystem.clear(16640, Minecraft.ON_OSX);
|
||||||
@@ -294,7 +291,7 @@ public class ExportJob {
|
|||||||
submitDownloadedFrames(encoder, downloader, false);
|
submitDownloadedFrames(encoder, downloader, false);
|
||||||
|
|
||||||
saveable.audioBuffer = audioBuffer;
|
saveable.audioBuffer = audioBuffer;
|
||||||
downloader.startDownload(renderTarget, saveable);
|
downloader.startDownload(renderTarget, saveable, this.settings.ssaa());
|
||||||
|
|
||||||
if (cancel) {
|
if (cancel) {
|
||||||
ExportJobQueue.drainingQueue = false;
|
ExportJobQueue.drainingQueue = false;
|
||||||
@@ -594,8 +591,8 @@ public class ExportJob {
|
|||||||
private float tickrate = 20.0f;
|
private float tickrate = 20.0f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<KeyframeType> supportedKeyframes() {
|
public Set<KeyframeType<?>> supportedKeyframes() {
|
||||||
return EnumSet.of(KeyframeType.SPEED, KeyframeType.TIMELAPSE);
|
return Set.of(SpeedKeyframeType.INSTANCE, TimelapseKeyframeType.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public record ExportSettings(@Nullable String name, EditorState editorState,
|
|||||||
int resolutionX, int resolutionY, int startTick, int endTick, double framerate,
|
int resolutionX, int resolutionY, int startTick, int endTick, double framerate,
|
||||||
boolean resetRng,
|
boolean resetRng,
|
||||||
// Video
|
// Video
|
||||||
VideoContainer container, VideoCodec codec, String encoder, int bitrate,
|
VideoContainer container, VideoCodec codec, String encoder, int bitrate, boolean transparent, boolean ssaa,
|
||||||
// Audio
|
// Audio
|
||||||
boolean recordAudio,
|
boolean recordAudio,
|
||||||
// Output
|
// Output
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.moulberry.flashback.exporting;
|
package com.moulberry.flashback.exporting;
|
||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2BooleanMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import org.bytedeco.ffmpeg.avcodec.AVCodec;
|
import org.bytedeco.ffmpeg.avcodec.AVCodec;
|
||||||
@@ -15,26 +19,29 @@ import java.util.Map;
|
|||||||
public class PixelFormatHelper {
|
public class PixelFormatHelper {
|
||||||
|
|
||||||
private static final Map<String, Integer> bestPixelFormats = new HashMap<>();
|
private static final Map<String, Integer> bestPixelFormats = new HashMap<>();
|
||||||
|
private static final Map<String, Integer> bestPixelFormatsTransparent = new HashMap<>();
|
||||||
|
|
||||||
public static int getBestPixelFormat(String codecName) {
|
public static int getBestPixelFormat(String codecName, boolean transparent) {
|
||||||
if (bestPixelFormats.containsKey(codecName)) {
|
Map<String, Integer> best = transparent ? bestPixelFormatsTransparent : bestPixelFormats;
|
||||||
return bestPixelFormats.get(codecName);
|
|
||||||
|
if (best.containsKey(codecName)) {
|
||||||
|
return best.get(codecName);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bestPixelFormat = calculateBestPixelFormat(codecName);
|
int bestPixelFormat = calculateBestPixelFormat(codecName, transparent);
|
||||||
|
|
||||||
if (bestPixelFormat == avutil.AV_PIX_FMT_NONE) {
|
if (bestPixelFormat == avutil.AV_PIX_FMT_NONE) {
|
||||||
throw new RuntimeException("Unable to determine best alternate pixel format for " + codecName);
|
throw new RuntimeException("Unable to determine best alternate pixel format for " + codecName);
|
||||||
}
|
}
|
||||||
if (bestPixelFormat != avutil.AV_PIX_FMT_YUV420P) {
|
if (bestPixelFormat != avutil.AV_PIX_FMT_YUV420P) {
|
||||||
Flashback.LOGGER.info("Chose to use alternate pixel format {} for codec {}", pixelFormatToString(bestPixelFormat), codecName);
|
Flashback.LOGGER.info("Chose to use alternate pixel format {} for codec {} with transparent={}", pixelFormatToString(bestPixelFormat), codecName, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bestPixelFormats.put(codecName, bestPixelFormat);
|
best.put(codecName, bestPixelFormat);
|
||||||
return bestPixelFormat;
|
return bestPixelFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int calculateBestPixelFormat(String codecName) {
|
private static int calculateBestPixelFormat(String codecName, boolean transparent) {
|
||||||
try (AVCodec codec = avcodec.avcodec_find_encoder_by_name(codecName)) {
|
try (AVCodec codec = avcodec.avcodec_find_encoder_by_name(codecName)) {
|
||||||
IntList supportedFormats = new IntArrayList();
|
IntList supportedFormats = new IntArrayList();
|
||||||
|
|
||||||
@@ -51,7 +58,7 @@ public class PixelFormatHelper {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pixFmt == avutil.AV_PIX_FMT_YUV420P) {
|
if (!transparent && pixFmt == avutil.AV_PIX_FMT_YUV420P) {
|
||||||
return avutil.AV_PIX_FMT_YUV420P;
|
return avutil.AV_PIX_FMT_YUV420P;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,11 +68,54 @@ public class PixelFormatHelper {
|
|||||||
|
|
||||||
supportedFormats.add(avutil.AV_PIX_FMT_NONE);
|
supportedFormats.add(avutil.AV_PIX_FMT_NONE);
|
||||||
|
|
||||||
return avcodec.avcodec_find_best_pix_fmt_of_list(supportedFormats.toIntArray(), avutil.AV_PIX_FMT_BGRA, 0, new int[1]);
|
if (transparent) {
|
||||||
|
int format = avcodec.avcodec_find_best_pix_fmt_of_list(supportedFormats.toIntArray(), AsyncVideoEncoder.SRC_PIXEL_FORMAT, 1, new int[1]);
|
||||||
|
if (format != avutil.AV_PIX_FMT_NONE) {
|
||||||
|
return format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String pixelFormatToString(int pixelFormat) {
|
return avcodec.avcodec_find_best_pix_fmt_of_list(supportedFormats.toIntArray(), AsyncVideoEncoder.SRC_PIXEL_FORMAT, 0, new int[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pixel format supports transparency
|
||||||
|
private static final Int2BooleanMap pixelFormatSupportsTransparency = new Int2BooleanOpenHashMap();
|
||||||
|
|
||||||
|
public static boolean doesPixelFormatSupportTransparency(int pixelFormat) {
|
||||||
|
if (pixelFormatSupportsTransparency.containsKey(pixelFormat)) {
|
||||||
|
return pixelFormatSupportsTransparency.get(pixelFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean supports = calculateDoesPixelFormatSupportTransparency(pixelFormat);
|
||||||
|
pixelFormatSupportsTransparency.put(pixelFormat, supports);
|
||||||
|
return supports;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean calculateDoesPixelFormatSupportTransparency(int pixelFormat) {
|
||||||
|
try (var descriptor = avutil.av_pix_fmt_desc_get(pixelFormat)) {
|
||||||
|
if (descriptor == null || descriptor.isNull()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (descriptor.flags() & avutil.AV_PIX_FMT_FLAG_ALPHA) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pixel format names
|
||||||
|
private static final Int2ObjectMap<String> pixelFormatNames = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
public static String pixelFormatToString(int pixelFormat) {
|
||||||
|
if (pixelFormatNames.containsKey(pixelFormat)) {
|
||||||
|
return pixelFormatNames.get(pixelFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = pixelFormatToStringInner(pixelFormat);
|
||||||
|
pixelFormatNames.put(pixelFormat, name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String pixelFormatToStringInner(int pixelFormat) {
|
||||||
try (BytePointer name = avutil.av_get_pix_fmt_name(pixelFormat)) {
|
try (BytePointer name = avutil.av_get_pix_fmt_name(pixelFormat)) {
|
||||||
return name.getString();
|
return name.getString();
|
||||||
} catch (Throwable ignored) {}
|
} catch (Throwable ignored) {}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.moulberry.flashback.exporting;
|
|||||||
import com.mojang.blaze3d.pipeline.MainTarget;
|
import com.mojang.blaze3d.pipeline.MainTarget;
|
||||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||||
import com.mojang.blaze3d.platform.NativeImage;
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.lwjgl.opengl.GL30C;
|
import org.lwjgl.opengl.GL30C;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
@@ -20,7 +22,6 @@ public class SaveableFramebuffer implements AutoCloseable {
|
|||||||
this.pboId = -1;
|
this.pboId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void startDownload(RenderTarget framebuffer, int width, int height) {
|
public void startDownload(RenderTarget framebuffer, int width, int height) {
|
||||||
if (this.isDownloading) {
|
if (this.isDownloading) {
|
||||||
throw new IllegalStateException("Can't start downloading while already downloading");
|
throw new IllegalStateException("Can't start downloading while already downloading");
|
||||||
|
|||||||
@@ -4,17 +4,21 @@ import com.mojang.blaze3d.pipeline.RenderTarget;
|
|||||||
import com.mojang.blaze3d.pipeline.TextureTarget;
|
import com.mojang.blaze3d.pipeline.TextureTarget;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.platform.NativeImage;
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
|
import com.mojang.blaze3d.platform.TextureUtil;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
import com.mojang.blaze3d.vertex.BufferUploader;
|
import com.mojang.blaze3d.vertex.BufferUploader;
|
||||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
import com.moulberry.flashback.visuals.ShaderManager;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.ShaderInstance;
|
import net.minecraft.client.renderer.ShaderInstance;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL30C;
|
||||||
|
import org.lwjgl.opengl.GL32C;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,23 +33,16 @@ public class SaveableFramebufferQueue implements AutoCloseable {
|
|||||||
private final List<SaveableFramebuffer> available = new ArrayList<>();
|
private final List<SaveableFramebuffer> available = new ArrayList<>();
|
||||||
private final List<SaveableFramebuffer> waiting = new ArrayList<>();
|
private final List<SaveableFramebuffer> waiting = new ArrayList<>();
|
||||||
|
|
||||||
private final RenderTarget flipbuffer;
|
private final RenderTarget flipBuffer;
|
||||||
private final ShaderInstance flipShader;
|
|
||||||
|
|
||||||
public SaveableFramebufferQueue(int width, int height) {
|
public SaveableFramebufferQueue(int width, int height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.flipbuffer = new TextureTarget(width, height, false, false);
|
this.flipBuffer = new TextureTarget(width, height, false, false);
|
||||||
|
|
||||||
for (int i = 0; i < CAPACITY; i++) {
|
for (int i = 0; i < CAPACITY; i++) {
|
||||||
this.available.add(new SaveableFramebuffer());
|
this.available.add(new SaveableFramebuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
this.flipShader = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "blit_screen_flip", DefaultVertexFormat.BLIT_SCREEN);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaveableFramebuffer take() {
|
public SaveableFramebuffer take() {
|
||||||
@@ -55,7 +52,12 @@ public class SaveableFramebufferQueue implements AutoCloseable {
|
|||||||
return this.available.removeFirst();
|
return this.available.removeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void blitFlip(RenderTarget src) {
|
private void blitFlip(RenderTarget src, boolean supersampling) {
|
||||||
|
int oldFilterMode = src.filterMode;
|
||||||
|
if (supersampling) {
|
||||||
|
src.setFilterMode(GL11.GL_LINEAR);
|
||||||
|
}
|
||||||
|
|
||||||
GlStateManager._colorMask(true, true, true, true);
|
GlStateManager._colorMask(true, true, true, true);
|
||||||
GlStateManager._disableDepthTest();
|
GlStateManager._disableDepthTest();
|
||||||
GlStateManager._depthMask(false);
|
GlStateManager._depthMask(false);
|
||||||
@@ -63,27 +65,32 @@ public class SaveableFramebufferQueue implements AutoCloseable {
|
|||||||
GlStateManager._disableBlend();
|
GlStateManager._disableBlend();
|
||||||
RenderSystem.disableCull();
|
RenderSystem.disableCull();
|
||||||
|
|
||||||
this.flipbuffer.bindWrite(true);
|
this.flipBuffer.bindWrite(true);
|
||||||
this.flipShader.setSampler("DiffuseSampler", src.colorTextureId);
|
ShaderInstance flipShader = ShaderManager.blitScreenFlip;
|
||||||
this.flipShader.apply();
|
flipShader.setSampler("DiffuseSampler", src.colorTextureId);
|
||||||
|
flipShader.apply();
|
||||||
BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN);
|
BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN);
|
||||||
bufferBuilder.addVertex(0.0F, 1.0F, 0.0F);
|
bufferBuilder.addVertex(0.0F, 1.0F, 0.0F);
|
||||||
bufferBuilder.addVertex(1.0F, 1.0F, 0.0F);
|
bufferBuilder.addVertex(1.0F, 1.0F, 0.0F);
|
||||||
bufferBuilder.addVertex(1.0F, 0.0F, 0.0F);
|
bufferBuilder.addVertex(1.0F, 0.0F, 0.0F);
|
||||||
bufferBuilder.addVertex(0.0F, 0.0F, 0.0F);
|
bufferBuilder.addVertex(0.0F, 0.0F, 0.0F);
|
||||||
BufferUploader.draw(bufferBuilder.buildOrThrow());
|
BufferUploader.draw(bufferBuilder.buildOrThrow());
|
||||||
this.flipShader.clear();
|
flipShader.clear();
|
||||||
|
|
||||||
GlStateManager._depthMask(true);
|
GlStateManager._depthMask(true);
|
||||||
GlStateManager._colorMask(true, true, true, true);
|
GlStateManager._colorMask(true, true, true, true);
|
||||||
RenderSystem.enableCull();
|
RenderSystem.enableCull();
|
||||||
|
|
||||||
|
if (supersampling) {
|
||||||
|
src.setFilterMode(oldFilterMode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDownload(RenderTarget target, SaveableFramebuffer texture) {
|
public void startDownload(RenderTarget target, SaveableFramebuffer texture, boolean supersampling) {
|
||||||
// Do an inline flip
|
// Do an inline flip
|
||||||
this.blitFlip(target);
|
this.blitFlip(target, supersampling);
|
||||||
|
|
||||||
texture.startDownload(this.flipbuffer, this.width, this.height);
|
texture.startDownload(this.flipBuffer, this.width, this.height);
|
||||||
this.waiting.add(texture);
|
this.waiting.add(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +125,7 @@ public class SaveableFramebufferQueue implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
this.waiting.clear();
|
this.waiting.clear();
|
||||||
this.available.clear();
|
this.available.clear();
|
||||||
this.flipbuffer.destroyBuffers();
|
this.flipBuffer.destroyBuffers();
|
||||||
this.flipShader.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.moulberry.flashback.ext;
|
||||||
|
|
||||||
|
public interface ServerLevelExt {
|
||||||
|
|
||||||
|
void flashback$setSeedHash(long seedHash);
|
||||||
|
long flashback$getSeedHash();
|
||||||
|
|
||||||
|
boolean flashback$shouldSendChunk(long pos);
|
||||||
|
void flashback$markChunkAsSendable(long pos);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ public abstract class Keyframe {
|
|||||||
this.interpolationType = Objects.requireNonNullElse(interpolationType, InterpolationType.DEFAULT);
|
this.interpolationType = Objects.requireNonNullElse(interpolationType, InterpolationType.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract KeyframeType<?> keyframeType();
|
||||||
public abstract Keyframe copy();
|
public abstract Keyframe copy();
|
||||||
public abstract void apply(KeyframeHandler t);
|
public abstract void apply(KeyframeHandler t);
|
||||||
public abstract void applyInterpolated(KeyframeHandler t, Keyframe other, float amount);
|
public abstract void applyInterpolated(KeyframeHandler t, Keyframe other, float amount);
|
||||||
@@ -42,18 +43,6 @@ public abstract class Keyframe {
|
|||||||
String type;
|
String type;
|
||||||
if (jsonObject.has("type")) {
|
if (jsonObject.has("type")) {
|
||||||
type = jsonObject.get("type").getAsString();
|
type = jsonObject.get("type").getAsString();
|
||||||
} else if (jsonObject.has("position") && jsonObject.has("rotation")) {
|
|
||||||
type = "camera";
|
|
||||||
} else if (jsonObject.has("center") && jsonObject.has("distance")) {
|
|
||||||
type = "camera_orbit";
|
|
||||||
} else if (jsonObject.has("frequencyX") && jsonObject.has("amplitudeX")) {
|
|
||||||
type = "camera_shake";
|
|
||||||
} else if (jsonObject.has("fov")) {
|
|
||||||
type = "fov";
|
|
||||||
} else if (jsonObject.has("tickrate")) {
|
|
||||||
type = "tickrate";
|
|
||||||
} else if (jsonObject.has("time")) {
|
|
||||||
type = "time";
|
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unable to determine type of keyframe for: " + jsonObject);
|
throw new RuntimeException("Unable to determine type of keyframe for: " + jsonObject);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.moulberry.flashback.keyframe;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class KeyframeRegistry {
|
||||||
|
|
||||||
|
private static final List<KeyframeType<?>> types = new ArrayList<>();
|
||||||
|
private static final Map<String, KeyframeType<?>> typesById = new HashMap<>();
|
||||||
|
private static final Set<Class<?>> typesRegistered = new HashSet<>();
|
||||||
|
|
||||||
|
public static List<KeyframeType<?>> getTypes() {
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(KeyframeType<?> type) {
|
||||||
|
if (!typesRegistered.add(type.getClass())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
typesById.put(type.id(), type);
|
||||||
|
types.add(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TypeAdapter implements JsonSerializer<KeyframeType<?>>, JsonDeserializer<KeyframeType<?>> {
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
String id = json.getAsString();
|
||||||
|
return Objects.requireNonNull(typesById.get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(KeyframeType<?> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
return context.serialize(src.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,15 @@
|
|||||||
package com.moulberry.flashback.keyframe;
|
package com.moulberry.flashback.keyframe;
|
||||||
|
|
||||||
public enum KeyframeType {
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
import com.moulberry.flashback.state.KeyframeTrack;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
// todo: WIP DON'T COMMIT
|
||||||
|
public interface KeyframeType<T extends Keyframe> {
|
||||||
|
|
||||||
|
/*
|
||||||
CAMERA("Camera"),
|
CAMERA("Camera"),
|
||||||
CAMERA_ORBIT("Camera Orbit"),
|
CAMERA_ORBIT("Camera Orbit"),
|
||||||
FOV("FOV"),
|
FOV("FOV"),
|
||||||
@@ -9,13 +17,22 @@ public enum KeyframeType {
|
|||||||
TIMELAPSE("Timelapse"),
|
TIMELAPSE("Timelapse"),
|
||||||
TIME_OF_DAY("Time of day"),
|
TIME_OF_DAY("Time of day"),
|
||||||
CAMERA_SHAKE("Camera Shake");
|
CAMERA_SHAKE("Camera Shake");
|
||||||
|
*/
|
||||||
|
|
||||||
public static final KeyframeType[] KEYFRAME_TYPES = values();
|
String name();
|
||||||
|
String id();
|
||||||
|
@Nullable T createDirect();
|
||||||
|
@Nullable KeyframeCreatePopup<T> createPopup();
|
||||||
|
|
||||||
public final String name;
|
default boolean allowChangingInterpolationType() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default boolean allowChangingTimelineTick() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
KeyframeType(String name) {
|
interface KeyframeCreatePopup<T extends Keyframe> {
|
||||||
this.name = name;
|
@Nullable T render();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,21 @@
|
|||||||
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 net.minecraft.client.Minecraft;
|
import org.joml.Vector3d;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import org.joml.Quaternionf;
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface KeyframeHandler {
|
public interface KeyframeHandler {
|
||||||
|
|
||||||
EnumSet<KeyframeType> supportedKeyframes();
|
Set<KeyframeType<?>> supportedKeyframes();
|
||||||
|
|
||||||
default boolean alwaysApplyLastKeyframe() {
|
default boolean alwaysApplyLastKeyframe() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
default void applyCameraPosition(Vector3f position, float yaw, float pitch, float roll) {
|
default void applyCameraPosition(Vector3d position, double yaw, double pitch, double roll) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-7
@@ -1,14 +1,21 @@
|
|||||||
package com.moulberry.flashback.keyframe.handler;
|
package com.moulberry.flashback.keyframe.handler;
|
||||||
|
|
||||||
|
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.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 com.moulberry.flashback.keyframe.KeyframeType;
|
|
||||||
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.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MinecraftKeyframeHandler implements KeyframeHandler {
|
public class MinecraftKeyframeHandler implements KeyframeHandler {
|
||||||
|
|
||||||
@@ -19,24 +26,25 @@ public class MinecraftKeyframeHandler implements KeyframeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<KeyframeType> supportedKeyframes() {
|
public Set<KeyframeType<?>> supportedKeyframes() {
|
||||||
return EnumSet.of(KeyframeType.CAMERA, KeyframeType.CAMERA_ORBIT, KeyframeType.FOV, KeyframeType.TIME_OF_DAY, KeyframeType.CAMERA_SHAKE);
|
return Set.of(CameraKeyframeType.INSTANCE, CameraOrbitKeyframeType.INSTANCE, FOVKeyframeType.INSTANCE,
|
||||||
|
TimeOfDayKeyframeType.INSTANCE, CameraShakeKeyframeType.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyCameraPosition(Vector3f position, float yaw, float pitch, float roll) {
|
public void applyCameraPosition(Vector3d position, double yaw, double pitch, double roll) {
|
||||||
LocalPlayer player = this.minecraft.player;
|
LocalPlayer player = this.minecraft.player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.moveTo(position.x, position.y, position.z, yaw, pitch);
|
player.moveTo(position.x, position.y, position.z, (float) yaw, (float) pitch);
|
||||||
|
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
if (editorState != null) {
|
if (editorState != null) {
|
||||||
if (roll > -0.1 && roll < 0.1) {
|
if (roll > -0.01 && roll < 0.01) {
|
||||||
editorState.replayVisuals.overrideRoll = false;
|
editorState.replayVisuals.overrideRoll = false;
|
||||||
editorState.replayVisuals.overrideRollAmount = 0.0f;
|
editorState.replayVisuals.overrideRollAmount = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
editorState.replayVisuals.overrideRoll = true;
|
editorState.replayVisuals.overrideRoll = true;
|
||||||
editorState.replayVisuals.overrideRollAmount = roll;
|
editorState.replayVisuals.overrideRollAmount = (float) roll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -1,9 +1,12 @@
|
|||||||
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.types.SpeedKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ReplayServerKeyframeHandler implements KeyframeHandler {
|
public class ReplayServerKeyframeHandler implements KeyframeHandler {
|
||||||
|
|
||||||
@@ -19,8 +22,8 @@ public class ReplayServerKeyframeHandler implements KeyframeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<KeyframeType> supportedKeyframes() {
|
public Set<KeyframeType<?>> supportedKeyframes() {
|
||||||
return EnumSet.of(KeyframeType.SPEED, KeyframeType.TIMELAPSE);
|
return Set.of(SpeedKeyframeType.INSTANCE, TimelapseKeyframeType.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,105 +3,138 @@ package com.moulberry.flashback.keyframe.impl;
|
|||||||
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.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.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
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 com.moulberry.flashback.visuals.CameraPath;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImFloat;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaterniond;
|
||||||
|
import org.joml.Quaterniond;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CameraKeyframe extends Keyframe {
|
public class CameraKeyframe extends Keyframe {
|
||||||
|
|
||||||
public final Vector3f position;
|
private final Vector3d position;
|
||||||
public final Quaternionf quaternion;
|
private float yaw;
|
||||||
public final boolean hasRoll;
|
private float pitch;
|
||||||
|
private float roll;
|
||||||
|
|
||||||
private static Quaternionf getQuaternion(Entity entity) {
|
private static float getDefaultRoll() {
|
||||||
Quaternionf quaternionf = new Quaternionf();
|
|
||||||
float angleZ = 0.0f;
|
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
if (editorState != null && editorState.replayVisuals.overrideRoll) {
|
if (editorState != null && editorState.replayVisuals.overrideRoll) {
|
||||||
angleZ = (float) Math.toRadians(editorState.replayVisuals.overrideRollAmount);
|
return editorState.replayVisuals.overrideRollAmount;
|
||||||
}
|
|
||||||
quaternionf = quaternionf.rotationYXZ((float) -Math.toRadians(entity.getYRot()), (float) Math.toRadians(entity.getXRot()), -angleZ);
|
|
||||||
return quaternionf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CameraKeyframe(Entity entity) {
|
|
||||||
this(entity.position().toVector3f(), getQuaternion(entity), shouldHaveRoll());
|
|
||||||
}
|
|
||||||
|
|
||||||
public CameraKeyframe(Vector3f position, Quaternionf quaternion, boolean hasRoll) {
|
|
||||||
this(position, quaternion, hasRoll, InterpolationType.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CameraKeyframe(Vector3f position, Quaternionf quaternion, boolean hasRoll, InterpolationType interpolationType) {
|
|
||||||
this.position = position;
|
|
||||||
this.quaternion = quaternion;
|
|
||||||
this.hasRoll = hasRoll;
|
|
||||||
this.interpolationType(interpolationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Keyframe copy() {
|
|
||||||
return new CameraKeyframe(new Vector3f(this.position), new Quaternionf(this.quaternion), this.hasRoll, this.interpolationType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean shouldHaveRoll() {
|
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
|
||||||
return editorState != null && editorState.replayVisuals.overrideRoll && editorState.replayVisuals.overrideRollAmount != 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void apply(KeyframeHandler keyframeHandler, Vector3f position, Quaternionf quaternion, float rollScale) {
|
|
||||||
Vector3f euler = quaternion.getEulerAnglesYXZ(new Vector3f());
|
|
||||||
float yaw = (float) Mth.wrapDegrees(Math.toDegrees(euler.y));
|
|
||||||
float pitch = (float) Mth.wrapDegrees(Math.toDegrees(euler.x));
|
|
||||||
float roll = (float) Mth.wrapDegrees(Math.toDegrees(euler.z)) * rollScale;
|
|
||||||
|
|
||||||
// Handle singularity
|
|
||||||
double test = (double)quaternion.y * (double)quaternion.z - (double)quaternion.w * (double)quaternion.x;
|
|
||||||
final double MIN_TEST = 0.49999;
|
|
||||||
final double MAX_TEST = 0.499999;
|
|
||||||
if (test > MIN_TEST) {
|
|
||||||
float fixedYaw = (float) Mth.wrapDegrees(Math.toDegrees(2 * Math.atan2(quaternion.z, quaternion.w)));
|
|
||||||
if (test >= MAX_TEST) {
|
|
||||||
yaw = fixedYaw;
|
|
||||||
} else {
|
|
||||||
yaw = yaw + (float)(Mth.wrapDegrees(fixedYaw - yaw) * (test - MIN_TEST) / (MAX_TEST - MIN_TEST));
|
|
||||||
}
|
|
||||||
} else if (test < -MIN_TEST) {
|
|
||||||
float fixedYaw = (float) Mth.wrapDegrees(Math.toDegrees(-2 * Math.atan2(quaternion.z, quaternion.w)));
|
|
||||||
if (test <= -MAX_TEST) {
|
|
||||||
yaw = fixedYaw;
|
|
||||||
} else {
|
|
||||||
yaw = yaw + (float)(Mth.wrapDegrees(fixedYaw - yaw) * (test - -MIN_TEST) / (-MAX_TEST - -MIN_TEST));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply position
|
|
||||||
keyframeHandler.applyCameraPosition(position, -yaw, pitch, -roll);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static float calculateRollScale(CameraKeyframe left, CameraKeyframe right, float alpha) {
|
|
||||||
if (left.hasRoll && right.hasRoll) {
|
|
||||||
return 1.0f;
|
|
||||||
} else if (left.hasRoll) {
|
|
||||||
return 1.0f - alpha;
|
|
||||||
} else if (right.hasRoll) {
|
|
||||||
return alpha;
|
|
||||||
} else {
|
} else {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CameraKeyframe(Entity entity) {
|
||||||
|
this(new Vector3d(entity.getX(), entity.getY(), entity.getZ()), entity.getYRot(), entity.getXRot(), getDefaultRoll());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraKeyframe(Vector3d position, float yaw, float pitch, float roll) {
|
||||||
|
this(position, yaw, pitch, roll, InterpolationType.DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraKeyframe(Vector3d position, float yaw, float pitch, float roll, InterpolationType interpolationType) {
|
||||||
|
this.position = position;
|
||||||
|
this.yaw = yaw;
|
||||||
|
this.pitch = pitch;
|
||||||
|
this.roll = roll;
|
||||||
|
this.interpolationType(interpolationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Quaterniond getQuaternion() {
|
||||||
|
return new Quaterniond().rotationYXZ((float) -Math.toRadians(this.yaw), (float) Math.toRadians(this.pitch), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return CameraKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Keyframe copy() {
|
||||||
|
return new CameraKeyframe(new Vector3d(this.position), this.yaw, this.pitch, this.roll, this.interpolationType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderEditKeyframe(Consumer<Consumer<Keyframe>> update) {
|
||||||
|
float[] center = new float[]{(float) this.position.x, (float) this.position.y, (float) this.position.z};
|
||||||
|
if (ImGui.inputFloat3("Position", center)) {
|
||||||
|
if (center[0] != this.position.x) {
|
||||||
|
update.accept(keyframe -> ((CameraKeyframe)keyframe).position.x = center[0]);
|
||||||
|
}
|
||||||
|
if (center[1] != this.position.y) {
|
||||||
|
update.accept(keyframe -> ((CameraKeyframe)keyframe).position.y = center[1]);
|
||||||
|
}
|
||||||
|
if (center[2] != this.position.z) {
|
||||||
|
update.accept(keyframe -> ((CameraKeyframe)keyframe).position.z = center[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImFloat input = new ImFloat(this.yaw);
|
||||||
|
if (ImGui.inputFloat("Yaw", input)) {
|
||||||
|
if (input.get() != this.yaw) {
|
||||||
|
update.accept(keyframe -> ((CameraKeyframe)keyframe).yaw = input.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
input.set(this.pitch);
|
||||||
|
if (ImGui.inputFloat("Pitch", input)) {
|
||||||
|
if (input.get() != this.pitch) {
|
||||||
|
update.accept(keyframe -> ((CameraKeyframe)keyframe).pitch = input.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
input.set(this.roll);
|
||||||
|
if (ImGui.inputFloat("Roll", input)) {
|
||||||
|
if (input.get() != this.roll) {
|
||||||
|
update.accept(keyframe -> ((CameraKeyframe)keyframe).roll = input.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void apply(KeyframeHandler keyframeHandler, Vector3d position, Quaterniond quaternion, float roll) {
|
||||||
|
Vector3d euler = quaternion.getEulerAnglesYXZ(new Vector3d());
|
||||||
|
double yaw = Mth.wrapDegrees(Math.toDegrees(euler.y));
|
||||||
|
double pitch = Mth.wrapDegrees(Math.toDegrees(euler.x));
|
||||||
|
|
||||||
|
// Handle singularity
|
||||||
|
double test = quaternion.y * quaternion.z - quaternion.w * quaternion.x;
|
||||||
|
final double MIN_TEST = 0.49999;
|
||||||
|
final double MAX_TEST = 0.499999;
|
||||||
|
if (test > MIN_TEST) {
|
||||||
|
double fixedYaw = Mth.wrapDegrees(Math.toDegrees(2 * Math.atan2(quaternion.z, quaternion.w)));
|
||||||
|
if (test >= MAX_TEST) {
|
||||||
|
yaw = fixedYaw;
|
||||||
|
} else {
|
||||||
|
yaw = yaw + Mth.wrapDegrees(fixedYaw - yaw) * (test - MIN_TEST) / (MAX_TEST - MIN_TEST);
|
||||||
|
}
|
||||||
|
} else if (test < -MIN_TEST) {
|
||||||
|
double fixedYaw = Mth.wrapDegrees(Math.toDegrees(-2 * Math.atan2(quaternion.z, quaternion.w)));
|
||||||
|
if (test <= -MAX_TEST) {
|
||||||
|
yaw = fixedYaw;
|
||||||
|
} else {
|
||||||
|
yaw = yaw + Mth.wrapDegrees(fixedYaw - yaw) * (test - -MIN_TEST) / (-MAX_TEST - -MIN_TEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply position
|
||||||
|
keyframeHandler.applyCameraPosition(position, -yaw, pitch, roll);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(KeyframeHandler keyframeHandler) {
|
public void apply(KeyframeHandler keyframeHandler) {
|
||||||
apply(keyframeHandler, this.position, this.quaternion, this.hasRoll ? 1.0f : 0.0f);
|
apply(keyframeHandler, this.position, this.getQuaternion(), this.roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,10 +147,11 @@ public class CameraKeyframe extends Keyframe {
|
|||||||
double x = Interpolation.linear(this.position.x, other.position.x, amount);
|
double x = Interpolation.linear(this.position.x, other.position.x, amount);
|
||||||
double y = Interpolation.linear(this.position.y, other.position.y, amount);
|
double y = Interpolation.linear(this.position.y, other.position.y, amount);
|
||||||
double z = Interpolation.linear(this.position.z, other.position.z, amount);
|
double z = Interpolation.linear(this.position.z, other.position.z, amount);
|
||||||
Quaternionf quaternion = Interpolation.linear(this.quaternion, other.quaternion, amount);
|
float roll = Interpolation.linear(this.roll, other.roll, amount);
|
||||||
|
Quaterniond quaternion = Interpolation.linear(this.getQuaternion(), other.getQuaternion(), amount);
|
||||||
|
|
||||||
Vector3f position = new Vector3f((float) x, (float) y, (float) z);
|
Vector3d position = new Vector3d(x, y, z);
|
||||||
apply(keyframeHandler, position, quaternion, calculateRollScale(this, other, amount));
|
apply(keyframeHandler, position, quaternion, roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,59 +161,69 @@ public class CameraKeyframe extends Keyframe {
|
|||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
|
|
||||||
// Calculate position
|
// Calculate position
|
||||||
Vector3f position = CatmullRom.position(this.position,
|
Vector3d position = CatmullRom.position(this.position,
|
||||||
((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);
|
||||||
|
|
||||||
float x = position.x;
|
double x = position.x;
|
||||||
float y = position.y;
|
double y = position.y;
|
||||||
float z = position.z;
|
double z = position.z;
|
||||||
|
|
||||||
// Calculate rotation
|
// Calculate rotation
|
||||||
Quaternionf rotation = CatmullRom.rotation(this.quaternion,
|
Quaterniond rotation = CatmullRom.rotation(this.getQuaternion(),
|
||||||
((CameraKeyframe)p1).quaternion, ((CameraKeyframe)p2).quaternion,
|
((CameraKeyframe)p1).getQuaternion(), ((CameraKeyframe)p2).getQuaternion(),
|
||||||
((CameraKeyframe)p3).quaternion, time1, time2, time3, amount);
|
((CameraKeyframe)p3).getQuaternion(), time1, time2, time3, amount);
|
||||||
|
|
||||||
|
float roll = CatmullRom.value(this.roll,
|
||||||
|
((CameraKeyframe)p1).roll, ((CameraKeyframe)p2).roll,
|
||||||
|
((CameraKeyframe)p3).roll, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
if (lerpAmount >= 0) {
|
||||||
float linearX = Interpolation.linear(((CameraKeyframe)p1).position.x, ((CameraKeyframe)p2).position.x, lerpAmount);
|
double linearX = Interpolation.linear(((CameraKeyframe)p1).position.x, ((CameraKeyframe)p2).position.x, lerpAmount);
|
||||||
float linearY = Interpolation.linear(((CameraKeyframe)p1).position.y, ((CameraKeyframe)p2).position.y, lerpAmount);
|
double linearY = Interpolation.linear(((CameraKeyframe)p1).position.y, ((CameraKeyframe)p2).position.y, lerpAmount);
|
||||||
float linearZ = Interpolation.linear(((CameraKeyframe)p1).position.z, ((CameraKeyframe)p2).position.z, lerpAmount);
|
double linearZ = Interpolation.linear(((CameraKeyframe)p1).position.z, ((CameraKeyframe)p2).position.z, lerpAmount);
|
||||||
|
float linearRoll = Interpolation.linear(((CameraKeyframe)p1).roll, ((CameraKeyframe)p2).roll, lerpAmount);
|
||||||
|
|
||||||
Quaternionf linearQuaternion = Interpolation.linear(((CameraKeyframe)p1).quaternion, ((CameraKeyframe)p2).quaternion, lerpAmount);
|
Quaterniond linearQuaternion = Interpolation.linear(((CameraKeyframe)p1).getQuaternion(),
|
||||||
|
((CameraKeyframe)p2).getQuaternion(), lerpAmount);
|
||||||
|
|
||||||
if (lerpFromRight) {
|
if (lerpFromRight) {
|
||||||
x = Interpolation.linear(x, linearX, amount);
|
x = Interpolation.linear(x, linearX, amount);
|
||||||
y = Interpolation.linear(y, linearY, amount);
|
y = Interpolation.linear(y, linearY, amount);
|
||||||
z = Interpolation.linear(z, linearZ, amount);
|
z = Interpolation.linear(z, linearZ, amount);
|
||||||
|
roll = Interpolation.linear(roll, linearRoll, amount);
|
||||||
rotation = Interpolation.linear(rotation, linearQuaternion, amount);
|
rotation = Interpolation.linear(rotation, linearQuaternion, amount);
|
||||||
} else {
|
} else {
|
||||||
x = Interpolation.linear(linearX, x, amount);
|
x = Interpolation.linear(linearX, x, amount);
|
||||||
y = Interpolation.linear(linearY, y, amount);
|
y = Interpolation.linear(linearY, y, amount);
|
||||||
z = Interpolation.linear(linearZ, z, amount);
|
z = Interpolation.linear(linearZ, z, amount);
|
||||||
|
roll = Interpolation.linear(linearRoll, roll, amount);
|
||||||
rotation = Interpolation.linear(linearQuaternion, rotation, amount);
|
rotation = Interpolation.linear(linearQuaternion, rotation, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(keyframeHandler, new Vector3f(x, y, z), rotation, calculateRollScale((CameraKeyframe) p1, (CameraKeyframe) p2, amount));
|
apply(keyframeHandler, new Vector3d(x, y, z), rotation, roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<CameraKeyframe>, JsonDeserializer<CameraKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<CameraKeyframe>, JsonDeserializer<CameraKeyframe> {
|
||||||
@Override
|
@Override
|
||||||
public CameraKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public CameraKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
Vector3f position = context.deserialize(jsonObject.get("position"), Vector3f.class);
|
Vector3d position = context.deserialize(jsonObject.get("position"), Vector3d.class);
|
||||||
Quaternionf rotation = context.deserialize(jsonObject.get("rotation"), Quaternionf.class);
|
float yaw = jsonObject.has("yaw") ? jsonObject.get("yaw").getAsFloat() : 0.0f;
|
||||||
boolean hasRoll = jsonObject.has("has_roll") && jsonObject.get("has_roll").getAsBoolean();
|
float pitch = jsonObject.has("pitch") ? jsonObject.get("pitch").getAsFloat() : 0.0f;
|
||||||
|
float roll = jsonObject.has("roll") ? jsonObject.get("roll").getAsFloat() : 0.0f;
|
||||||
InterpolationType interpolationType = context.deserialize(jsonObject.get("interpolation_type"), InterpolationType.class);
|
InterpolationType interpolationType = context.deserialize(jsonObject.get("interpolation_type"), InterpolationType.class);
|
||||||
return new CameraKeyframe(position, rotation, hasRoll, interpolationType);
|
return new CameraKeyframe(position, yaw, pitch, roll, interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(CameraKeyframe src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(CameraKeyframe src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.add("position", context.serialize(src.position));
|
jsonObject.add("position", context.serialize(src.position));
|
||||||
jsonObject.add("rotation", context.serialize(src.quaternion));
|
jsonObject.add("yaw", context.serialize(src.yaw));
|
||||||
jsonObject.add("has_roll", context.serialize(src.hasRoll));
|
jsonObject.add("pitch", context.serialize(src.pitch));
|
||||||
|
jsonObject.add("roll", context.serialize(src.roll));
|
||||||
jsonObject.addProperty("type", "camera");
|
jsonObject.addProperty("type", "camera");
|
||||||
jsonObject.add("interpolation_type", context.serialize(src.interpolationType()));
|
jsonObject.add("interpolation_type", context.serialize(src.interpolationType()));
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import com.google.gson.JsonSerializationContext;
|
|||||||
import com.google.gson.JsonSerializer;
|
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.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.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
@@ -22,23 +24,23 @@ import net.minecraft.util.Mth;
|
|||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CameraOrbitKeyframe extends Keyframe {
|
public class CameraOrbitKeyframe extends Keyframe {
|
||||||
|
|
||||||
public final Vector3f center;
|
public final Vector3d center;
|
||||||
public float distance;
|
public float distance;
|
||||||
public float yaw;
|
public float yaw;
|
||||||
public float pitch;
|
public float pitch;
|
||||||
|
|
||||||
public CameraOrbitKeyframe(Vector3f center, float distance, float yaw, float pitch) {
|
public CameraOrbitKeyframe(Vector3d center, float distance, float yaw, float pitch) {
|
||||||
this(center, distance, yaw, pitch, InterpolationType.DEFAULT);
|
this(center, distance, yaw, pitch, InterpolationType.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CameraOrbitKeyframe(Vector3f center, float distance, float yaw, float pitch, InterpolationType interpolationType) {
|
public CameraOrbitKeyframe(Vector3d center, float distance, float yaw, float pitch, InterpolationType interpolationType) {
|
||||||
this.center = center;
|
this.center = center;
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
@@ -46,14 +48,19 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
this.interpolationType(interpolationType);
|
this.interpolationType(interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return CameraOrbitKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keyframe copy() {
|
public Keyframe copy() {
|
||||||
return new CameraOrbitKeyframe(new Vector3f(this.center), this.distance, this.yaw, this.pitch, this.interpolationType());
|
return new CameraOrbitKeyframe(new Vector3d(this.center), this.distance, this.yaw, this.pitch, this.interpolationType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderEditKeyframe(Consumer<Consumer<Keyframe>> update) {
|
public void renderEditKeyframe(Consumer<Consumer<Keyframe>> update) {
|
||||||
float[] center = new float[]{this.center.x, this.center.y, this.center.z};
|
float[] center = new float[]{(float) this.center.x, (float) this.center.y, (float) this.center.z};
|
||||||
if (ImGui.inputFloat3("Position", center)) {
|
if (ImGui.inputFloat3("Position", center)) {
|
||||||
if (center[0] != this.center.x) {
|
if (center[0] != this.center.x) {
|
||||||
update.accept(keyframe -> ((CameraOrbitKeyframe)keyframe).center.x = center[0]);
|
update.accept(keyframe -> ((CameraOrbitKeyframe)keyframe).center.x = center[0]);
|
||||||
@@ -85,7 +92,7 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void apply(KeyframeHandler keyframeHandler, Vector3f center, float distance, float yaw, float pitch) {
|
private void apply(KeyframeHandler keyframeHandler, 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);
|
||||||
@@ -93,8 +100,8 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
float cosPitch = Mth.cos(pitchRadians);
|
float cosPitch = Mth.cos(pitchRadians);
|
||||||
float sinPitch = Mth.sin(pitchRadians);
|
float sinPitch = Mth.sin(pitchRadians);
|
||||||
|
|
||||||
Vector3f look = new Vector3f(sinYaw * cosPitch, -sinPitch, cosYaw * cosPitch);
|
Vector3d look = new Vector3d(sinYaw * cosPitch, -sinPitch, cosYaw * cosPitch);
|
||||||
Vector3f cameraPosition = new Vector3f(center).sub(look.mul(distance));
|
Vector3d cameraPosition = new Vector3d(center).sub(look.mul(distance));
|
||||||
LocalPlayer player = Minecraft.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
cameraPosition.y -= player.getEyeHeight();
|
cameraPosition.y -= player.getEyeHeight();
|
||||||
@@ -121,7 +128,7 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
float yaw = Interpolation.linear(this.yaw, other.yaw, amount);
|
float yaw = Interpolation.linear(this.yaw, other.yaw, amount);
|
||||||
float pitch = Interpolation.linear(this.pitch, other.pitch, amount);
|
float pitch = Interpolation.linear(this.pitch, other.pitch, amount);
|
||||||
|
|
||||||
Vector3f center = new Vector3f((float) x, (float) y, (float) z);
|
Vector3d center = new Vector3d((float) x, (float) y, (float) z);
|
||||||
apply(keyframeHandler, center, distance, yaw, pitch);
|
apply(keyframeHandler, center, distance, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,13 +139,13 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
float time3 = t3 - t0;
|
float time3 = t3 - t0;
|
||||||
|
|
||||||
// Calculate position
|
// Calculate position
|
||||||
Vector3f 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);
|
||||||
|
|
||||||
float x = position.x;
|
double x = position.x;
|
||||||
float y = position.y;
|
double y = position.y;
|
||||||
float z = position.z;
|
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);
|
||||||
float yaw = CatmullRom.value(this.yaw, ((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw,
|
float yaw = CatmullRom.value(this.yaw, ((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw,
|
||||||
@@ -147,9 +154,9 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
((CameraOrbitKeyframe)p3).pitch, time1, time2, time3, amount);
|
((CameraOrbitKeyframe)p3).pitch, time1, time2, time3, amount);
|
||||||
|
|
||||||
if (lerpAmount >= 0) {
|
if (lerpAmount >= 0) {
|
||||||
float linearX = Interpolation.linear(((CameraOrbitKeyframe)p1).center.x, ((CameraOrbitKeyframe)p2).center.x, lerpAmount);
|
double linearX = Interpolation.linear(((CameraOrbitKeyframe)p1).center.x, ((CameraOrbitKeyframe)p2).center.x, lerpAmount);
|
||||||
float linearY = Interpolation.linear(((CameraOrbitKeyframe)p1).center.y, ((CameraOrbitKeyframe)p2).center.y, lerpAmount);
|
double linearY = Interpolation.linear(((CameraOrbitKeyframe)p1).center.y, ((CameraOrbitKeyframe)p2).center.y, lerpAmount);
|
||||||
float linearZ = Interpolation.linear(((CameraOrbitKeyframe)p1).center.z, ((CameraOrbitKeyframe)p2).center.z, 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 linearDistance = Interpolation.linear(((CameraOrbitKeyframe)p1).distance, ((CameraOrbitKeyframe)p2).distance, amount);
|
||||||
float linearYaw = Interpolation.linear(((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw, amount);
|
float linearYaw = Interpolation.linear(((CameraOrbitKeyframe)p1).yaw, ((CameraOrbitKeyframe)p2).yaw, amount);
|
||||||
float linearPitch = Interpolation.linear(((CameraOrbitKeyframe)p1).pitch, ((CameraOrbitKeyframe)p2).pitch, amount);
|
float linearPitch = Interpolation.linear(((CameraOrbitKeyframe)p1).pitch, ((CameraOrbitKeyframe)p2).pitch, amount);
|
||||||
@@ -171,14 +178,14 @@ public class CameraOrbitKeyframe extends Keyframe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(keyframeHandler, new Vector3f(x, y, z), distance, yaw, pitch);
|
apply(keyframeHandler, new Vector3d(x, y, z), distance, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeAdapter implements JsonSerializer<CameraOrbitKeyframe>, JsonDeserializer<CameraOrbitKeyframe> {
|
public static class TypeAdapter implements JsonSerializer<CameraOrbitKeyframe>, JsonDeserializer<CameraOrbitKeyframe> {
|
||||||
@Override
|
@Override
|
||||||
public CameraOrbitKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public CameraOrbitKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
Vector3f center = context.deserialize(jsonObject.get("center"), Vector3f.class);
|
Vector3d center = context.deserialize(jsonObject.get("center"), Vector3d.class);
|
||||||
float distance = jsonObject.get("distance").getAsFloat();
|
float distance = jsonObject.get("distance").getAsFloat();
|
||||||
float yaw = jsonObject.get("yaw").getAsFloat();
|
float yaw = jsonObject.get("yaw").getAsFloat();
|
||||||
float pitch = jsonObject.get("pitch").getAsFloat();
|
float pitch = jsonObject.get("pitch").getAsFloat();
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import com.google.gson.JsonSerializationContext;
|
|||||||
import com.google.gson.JsonSerializer;
|
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.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.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@@ -34,6 +36,11 @@ public class CameraShakeKeyframe extends Keyframe {
|
|||||||
this.interpolationType(interpolationType);
|
this.interpolationType(interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return CameraShakeKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keyframe copy() {
|
public Keyframe copy() {
|
||||||
return new CameraShakeKeyframe(this.frequencyX, this.amplitudeX, this.frequencyY, this.amplitudeY, this.interpolationType());
|
return new CameraShakeKeyframe(this.frequencyX, this.amplitudeX, this.frequencyY, this.amplitudeY, this.interpolationType());
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ 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.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.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
@@ -25,6 +27,11 @@ public class FOVKeyframe extends Keyframe {
|
|||||||
this.interpolationType(interpolationType);
|
this.interpolationType(interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return FOVKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keyframe copy() {
|
public Keyframe copy() {
|
||||||
return new FOVKeyframe(this.fov, this.interpolationType());
|
return new FOVKeyframe(this.fov, this.interpolationType());
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package com.moulberry.flashback.keyframe.impl;
|
|||||||
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.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.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
@@ -24,6 +26,11 @@ public class TickrateKeyframe extends Keyframe {
|
|||||||
this.interpolationType(interpolationType);
|
this.interpolationType(interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return SpeedKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keyframe copy() {
|
public Keyframe copy() {
|
||||||
return new TickrateKeyframe(this.tickrate, this.interpolationType());
|
return new TickrateKeyframe(this.tickrate, this.interpolationType());
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package com.moulberry.flashback.keyframe.impl;
|
|||||||
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.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.spline.CatmullRom;
|
import com.moulberry.flashback.spline.CatmullRom;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImInt;
|
import imgui.type.ImInt;
|
||||||
@@ -25,6 +27,11 @@ public class TimeOfDayKeyframe extends Keyframe {
|
|||||||
this.interpolationType(interpolationType);
|
this.interpolationType(interpolationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return TimeOfDayKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keyframe copy() {
|
public Keyframe copy() {
|
||||||
return new TimeOfDayKeyframe(this.time, this.interpolationType());
|
return new TimeOfDayKeyframe(this.time, this.interpolationType());
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import com.google.gson.JsonSerializer;
|
|||||||
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.Keyframe;
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
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 imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.type.ImString;
|
import imgui.type.ImString;
|
||||||
|
|
||||||
@@ -27,10 +29,15 @@ public class TimelapseKeyframe extends Keyframe {
|
|||||||
public TimelapseKeyframe(int ticks) {
|
public TimelapseKeyframe(int ticks) {
|
||||||
this.ticks = ticks;
|
this.ticks = ticks;
|
||||||
this.timelapseKeyframeInput = ImGuiHelper.createResizableImString(Utils.timeToString(this.ticks));
|
this.timelapseKeyframeInput = ImGuiHelper.createResizableImString(Utils.timeToString(this.ticks));
|
||||||
this.timelapseKeyframeInput.inputData.allowedChars = "0123456789tsmh";
|
this.timelapseKeyframeInput.inputData.allowedChars = "0123456789tsmh.";
|
||||||
this.interpolationType(InterpolationType.LINEAR);
|
this.interpolationType(InterpolationType.LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeType<?> keyframeType() {
|
||||||
|
return TimelapseKeyframeType.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keyframe copy() {
|
public Keyframe copy() {
|
||||||
return new TimelapseKeyframe(this.ticks);
|
return new TimelapseKeyframe(this.ticks);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.moulberry.flashback.keyframe.interpolation;
|
package com.moulberry.flashback.keyframe.interpolation;
|
||||||
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
|
||||||
|
|
||||||
public enum InterpolationType {
|
public enum InterpolationType {
|
||||||
|
|
||||||
SMOOTH(SidedInterpolationType.SMOOTH, SidedInterpolationType.SMOOTH),
|
SMOOTH(SidedInterpolationType.SMOOTH, SidedInterpolationType.SMOOTH),
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class CameraKeyframeType implements KeyframeType<CameraKeyframe> {
|
||||||
|
|
||||||
|
public static CameraKeyframeType INSTANCE = new CameraKeyframeType();
|
||||||
|
|
||||||
|
private CameraKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "Camera";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "CAMERA";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CameraKeyframe createDirect() {
|
||||||
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
|
if (player != null) {
|
||||||
|
return new CameraKeyframe(player);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<CameraKeyframe> createPopup() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.Keyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraKeyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImFloat;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
public class CameraOrbitKeyframeType implements KeyframeType<CameraOrbitKeyframe> {
|
||||||
|
|
||||||
|
public static CameraOrbitKeyframeType INSTANCE = new CameraOrbitKeyframeType();
|
||||||
|
|
||||||
|
private CameraOrbitKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "Camera Orbit";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "CAMERA_ORBIT";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CameraOrbitKeyframe createDirect() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<CameraOrbitKeyframe> createPopup() {
|
||||||
|
float[] cameraOrbitCenter = new float[]{0.0f, 0.0f, 0.0f};
|
||||||
|
ImFloat cameraOrbitDistance = new ImFloat(8.0f);
|
||||||
|
ImFloat cameraOrbitYaw = new ImFloat(0.0f);
|
||||||
|
ImFloat cameraOrbitPitch = new ImFloat(0.0f);
|
||||||
|
|
||||||
|
Entity entity = Minecraft.getInstance().cameraEntity;
|
||||||
|
if (entity != null) {
|
||||||
|
Vec3 eyePosition = entity.getEyePosition();
|
||||||
|
cameraOrbitCenter[0] = (float) eyePosition.x;
|
||||||
|
cameraOrbitCenter[1] = (float) eyePosition.y;
|
||||||
|
cameraOrbitCenter[2] = (float) eyePosition.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
return () -> {
|
||||||
|
ImGui.inputFloat3("Position", cameraOrbitCenter);
|
||||||
|
ImGui.inputFloat("Distance", cameraOrbitDistance);
|
||||||
|
ImGui.inputFloat("Yaw", cameraOrbitYaw);
|
||||||
|
ImGui.inputFloat("Pitch", cameraOrbitPitch);
|
||||||
|
|
||||||
|
if (ImGui.button("Add")) {
|
||||||
|
Vector3d center = new Vector3d(cameraOrbitCenter[0], cameraOrbitCenter[1], cameraOrbitCenter[2]);
|
||||||
|
return new CameraOrbitKeyframe(center, cameraOrbitDistance.get(), cameraOrbitYaw.get(), cameraOrbitPitch.get());
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Cancel")) {
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||||
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class CameraShakeKeyframeType implements KeyframeType<CameraShakeKeyframe> {
|
||||||
|
|
||||||
|
public static CameraShakeKeyframeType INSTANCE = new CameraShakeKeyframeType();
|
||||||
|
|
||||||
|
private CameraShakeKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "Camera Shake";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "CAMERA_SHAKE";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CameraShakeKeyframe createDirect() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<CameraShakeKeyframe> createPopup() {
|
||||||
|
boolean[] cameraShakeSplitXYKeyframeInput = new boolean[]{false};
|
||||||
|
float[] cameraShakeFrequencyXKeyframeInput = new float[]{1.0f};
|
||||||
|
float[] cameraShakeAmplitudeXKeyframeInput = new float[]{0.0f};
|
||||||
|
float[] cameraShakeFrequencyYKeyframeInput = new float[]{1.0f};
|
||||||
|
float[] cameraShakeAmplitudeYKeyframeInput = new float[]{0.0f};
|
||||||
|
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
if (editorState != null && editorState.replayVisuals.overrideCameraShake) {
|
||||||
|
cameraShakeSplitXYKeyframeInput[0] = editorState.replayVisuals.cameraShakeSplitParams;
|
||||||
|
cameraShakeFrequencyXKeyframeInput[0] = editorState.replayVisuals.cameraShakeXFrequency;
|
||||||
|
cameraShakeAmplitudeXKeyframeInput[0] = editorState.replayVisuals.cameraShakeXAmplitude;
|
||||||
|
cameraShakeFrequencyYKeyframeInput[0] = editorState.replayVisuals.cameraShakeYFrequency;
|
||||||
|
cameraShakeAmplitudeYKeyframeInput[0] = editorState.replayVisuals.cameraShakeYAmplitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
return () -> {
|
||||||
|
if (ImGui.checkbox("Split Y/X", cameraShakeSplitXYKeyframeInput[0])) {
|
||||||
|
cameraShakeSplitXYKeyframeInput[0] = !cameraShakeSplitXYKeyframeInput[0];
|
||||||
|
if (!cameraShakeSplitXYKeyframeInput[0]) {
|
||||||
|
cameraShakeFrequencyYKeyframeInput[0] = cameraShakeFrequencyXKeyframeInput[0];
|
||||||
|
cameraShakeAmplitudeYKeyframeInput[0] = cameraShakeAmplitudeXKeyframeInput[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cameraShakeSplitXYKeyframeInput[0]) {
|
||||||
|
ImGui.sliderFloat("Frequency X", cameraShakeFrequencyXKeyframeInput, 0.1f, 10.0f, "%.1f");
|
||||||
|
ImGui.sliderFloat("Amplitude X", cameraShakeAmplitudeXKeyframeInput, 0.0f, 10.0f, "%.1f");
|
||||||
|
ImGui.sliderFloat("Frequency Y", cameraShakeFrequencyYKeyframeInput, 0.1f, 10.0f, "%.1f");
|
||||||
|
ImGui.sliderFloat("Amplitude Y", cameraShakeAmplitudeYKeyframeInput, 0.0f, 10.0f, "%.1f");
|
||||||
|
} else {
|
||||||
|
ImGui.sliderFloat("Frequency", cameraShakeFrequencyXKeyframeInput, 0.1f, 10.0f, "%.1f");
|
||||||
|
ImGui.sliderFloat("Amplitude", cameraShakeAmplitudeXKeyframeInput, 0.0f, 10.0f, "%.1f");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.button("Add")) {
|
||||||
|
if (cameraShakeSplitXYKeyframeInput[0]) {
|
||||||
|
return new CameraShakeKeyframe(cameraShakeFrequencyXKeyframeInput[0], cameraShakeAmplitudeXKeyframeInput[0],
|
||||||
|
cameraShakeFrequencyYKeyframeInput[0], cameraShakeAmplitudeYKeyframeInput[0]);
|
||||||
|
} else {
|
||||||
|
return new CameraShakeKeyframe(cameraShakeFrequencyXKeyframeInput[0], cameraShakeAmplitudeXKeyframeInput[0],
|
||||||
|
cameraShakeFrequencyXKeyframeInput[0], cameraShakeAmplitudeXKeyframeInput[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Cancel")) {
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.CameraOrbitKeyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImFloat;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
public class FOVKeyframeType implements KeyframeType<FOVKeyframe> {
|
||||||
|
|
||||||
|
public static FOVKeyframeType INSTANCE = new FOVKeyframeType();
|
||||||
|
|
||||||
|
private FOVKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "FOV";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "FOV";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable FOVKeyframe createDirect() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<FOVKeyframe> createPopup() {
|
||||||
|
float[] fovKeyframeInput = new float[]{Minecraft.getInstance().options.fov().get()};
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
if (editorState != null && editorState.replayVisuals.overrideFov) {
|
||||||
|
fovKeyframeInput[0] = editorState.replayVisuals.overrideFovAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return () -> {
|
||||||
|
ImGui.sliderFloat("FOV", fovKeyframeInput, 1f, 110f);
|
||||||
|
if (ImGui.button("Add")) {
|
||||||
|
return new FOVKeyframe(fovKeyframeInput[0]);
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Cancel")) {
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||||
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class SpeedKeyframeType implements KeyframeType<TickrateKeyframe> {
|
||||||
|
|
||||||
|
public static SpeedKeyframeType INSTANCE = new SpeedKeyframeType();
|
||||||
|
|
||||||
|
private SpeedKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "Speed";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "SPEED";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable TickrateKeyframe createDirect() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<TickrateKeyframe> createPopup() {
|
||||||
|
float[] speedKeyframeInput = new float[]{1.0f};
|
||||||
|
ReplayServer replayServer = Flashback.getReplayServer();
|
||||||
|
if (replayServer != null) {
|
||||||
|
speedKeyframeInput[0] = replayServer.getDesiredTickRate(false) / 20.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return () -> {
|
||||||
|
ImGui.sliderFloat("Speed", speedKeyframeInput, 0.1f, 10f);
|
||||||
|
if (ImGui.button("Add")) {
|
||||||
|
return new TickrateKeyframe(speedKeyframeInput[0] * 20.0f);
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Cancel")) {
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.TickrateKeyframe;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
|
||||||
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImInt;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class TimeOfDayKeyframeType implements KeyframeType<TimeOfDayKeyframe> {
|
||||||
|
|
||||||
|
public static TimeOfDayKeyframeType INSTANCE = new TimeOfDayKeyframeType();
|
||||||
|
|
||||||
|
private TimeOfDayKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "Time of day";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "TIME_OF_DAY";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable TimeOfDayKeyframe createDirect() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<TimeOfDayKeyframe> createPopup() {
|
||||||
|
ImInt timeOfDayKeyframeInput = new ImInt();
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
if (editorState != null && editorState.replayVisuals.overrideTimeOfDay >= 0) {
|
||||||
|
timeOfDayKeyframeInput.set((int) editorState.replayVisuals.overrideTimeOfDay);
|
||||||
|
} else {
|
||||||
|
timeOfDayKeyframeInput.set((int)(Minecraft.getInstance().level.getDayTime() % 24000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return () -> {
|
||||||
|
ImGui.inputInt("Time", timeOfDayKeyframeInput, 0);
|
||||||
|
if (ImGui.button("Add")) {
|
||||||
|
return new TimeOfDayKeyframe(timeOfDayKeyframeInput.get());
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Cancel")) {
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.moulberry.flashback.keyframe.types;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Utils;
|
||||||
|
import com.moulberry.flashback.editor.ui.ImGuiHelper;
|
||||||
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe;
|
||||||
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImString;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class TimelapseKeyframeType implements KeyframeType<TimelapseKeyframe> {
|
||||||
|
|
||||||
|
public static TimelapseKeyframeType INSTANCE = new TimelapseKeyframeType();
|
||||||
|
|
||||||
|
private TimelapseKeyframeType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "Timelapse";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return "TIMELAPSE";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowChangingInterpolationType() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowChangingTimelineTick() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable TimelapseKeyframe createDirect() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyframeCreatePopup<TimelapseKeyframe> createPopup() {
|
||||||
|
ImString timelapseKeyframeInput = ImGuiHelper.createResizableImString("1s");
|
||||||
|
timelapseKeyframeInput.inputData.allowedChars = "0123456789tsmh.";
|
||||||
|
|
||||||
|
return () -> {
|
||||||
|
ImGui.inputText("Time", timelapseKeyframeInput);
|
||||||
|
if (ImGui.button("Add")) {
|
||||||
|
return new TimelapseKeyframe(Utils.stringToTime(ImGuiHelper.getString(timelapseKeyframeInput)));
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Cancel")) {
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,18 +3,27 @@ package com.moulberry.flashback.mixin;
|
|||||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
|
import com.mojang.blaze3d.vertex.BufferUploader;
|
||||||
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||||
|
import com.mojang.blaze3d.vertex.MeshData;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
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 com.moulberry.flashback.editor.ui.ReplayUI;
|
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||||
import com.moulberry.flashback.exporting.PerfectFrames;
|
import com.moulberry.flashback.exporting.PerfectFrames;
|
||||||
|
import com.moulberry.flashback.visuals.ShaderManager;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.CloudStatus;
|
import net.minecraft.client.CloudStatus;
|
||||||
import net.minecraft.client.DeltaTracker;
|
import net.minecraft.client.DeltaTracker;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.Options;
|
import net.minecraft.client.Options;
|
||||||
import net.minecraft.client.particle.ParticleEngine;
|
import net.minecraft.client.particle.ParticleEngine;
|
||||||
import net.minecraft.client.renderer.*;
|
import net.minecraft.client.renderer.*;
|
||||||
@@ -34,6 +43,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Mixin(value = LevelRenderer.class, priority = 1100)
|
@Mixin(value = LevelRenderer.class, priority = 1100)
|
||||||
public abstract class MixinLevelRenderer {
|
public abstract class MixinLevelRenderer {
|
||||||
|
|
||||||
@@ -64,17 +75,50 @@ public abstract class MixinLevelRenderer {
|
|||||||
@Inject(method = "renderSectionLayer", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "renderSectionLayer", at = @At("HEAD"), cancellable = true)
|
||||||
public void renderSectionLayer(RenderType renderType, double d, double e, double f, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
public void renderSectionLayer(RenderType renderType, double d, double e, double f, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
if (editorState != null && !editorState.replayVisuals.renderBlocks) {
|
if (editorState != null) {
|
||||||
|
if (!editorState.replayVisuals.renderBlocks) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSectionLayer(Lnet/minecraft/client/renderer/RenderType;DDDLorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V", ordinal = 2, shift = At.Shift.AFTER))
|
||||||
|
public void renderLevel_renderCutoutLayer(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
||||||
|
if (Flashback.isExporting() && Flashback.EXPORT_JOB.getSettings().transparent()) {
|
||||||
|
RenderTarget main = Minecraft.getInstance().mainRenderTarget;
|
||||||
|
|
||||||
|
RenderSystem.assertOnRenderThread();
|
||||||
|
GlStateManager._disableDepthTest();
|
||||||
|
GlStateManager._depthMask(false);
|
||||||
|
GlStateManager._viewport(0, 0, main.viewWidth, main.viewHeight);
|
||||||
|
GlStateManager._disableBlend();
|
||||||
|
ShaderInstance shaderInstance = Objects.requireNonNull(ShaderManager.blitScreenRoundAlpha, "Blit shader not loaded");
|
||||||
|
shaderInstance.setSampler("DiffuseSampler", main.colorTextureId);
|
||||||
|
shaderInstance.apply();
|
||||||
|
BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN);
|
||||||
|
bufferBuilder.addVertex(0.0f, 0.0f, 0.0f);
|
||||||
|
bufferBuilder.addVertex(1.0f, 0.0f, 0.0f);
|
||||||
|
bufferBuilder.addVertex(1.0f, 1.0f, 0.0f);
|
||||||
|
bufferBuilder.addVertex(0.0f, 1.0f, 0.0f);
|
||||||
|
BufferUploader.draw(bufferBuilder.buildOrThrow());
|
||||||
|
shaderInstance.clear();
|
||||||
|
GlStateManager._enableBlend();
|
||||||
|
GlStateManager._depthMask(true);
|
||||||
|
GlStateManager._enableDepthTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V", shift = At.Shift.AFTER))
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V", shift = At.Shift.AFTER))
|
||||||
public void renderLevel_levelFogColor(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
public void renderLevel_levelFogColor(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
if (editorState != null && !editorState.replayVisuals.renderSky) {
|
if (editorState != null && !editorState.replayVisuals.renderSky) {
|
||||||
|
if (Flashback.isExporting() && Flashback.EXPORT_JOB.getSettings().transparent()) {
|
||||||
|
RenderSystem.clearColor(0.0f, 0.0f, 0.0f, 0.0F);
|
||||||
|
} else {
|
||||||
RenderSystem.clearColor(0.0f, 1.0f, 0.0f, 0.0F);
|
RenderSystem.clearColor(0.0f, 1.0f, 0.0f, 0.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;render(Lnet/minecraft/world/level/block/entity/BlockEntity;FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V"))
|
@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;render(Lnet/minecraft/world/level/block/entity/BlockEntity;FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;)V"))
|
||||||
|
|||||||
@@ -6,18 +6,34 @@ import com.mojang.blaze3d.pipeline.RenderTarget;
|
|||||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL30;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(value = RenderTarget.class, priority = 1100)
|
@Mixin(value = RenderTarget.class, priority = 800)
|
||||||
public class MixinRenderTarget {
|
public abstract class MixinRenderTarget {
|
||||||
|
|
||||||
@WrapOperation(method = "_blitToScreen", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_viewport(IIII)V", remap = false))
|
@Shadow
|
||||||
public void blitToScreenViewport(int left, int bottom, int width, int height, Operation<Void> original) {
|
public int frameBufferId;
|
||||||
if ((Object)this == Minecraft.getInstance().getMainRenderTarget() && ReplayUI.shouldModifyViewport()) {
|
|
||||||
ReplayUI.setupMainViewport();
|
@Inject(method = "blitToScreen(IIZ)V", at = @At("HEAD"), cancellable = true)
|
||||||
} else {
|
public void blitToScreenSodium(int width, int height, boolean noBlend, CallbackInfo ci) {
|
||||||
original.call(left, bottom, width, height);
|
if ((Object)this == Minecraft.getInstance().getMainRenderTarget() && ReplayUI.isActive()) {
|
||||||
|
var window = Minecraft.getInstance().getWindow();
|
||||||
|
int frameBottom = (ReplayUI.viewportSizeY - (ReplayUI.frameY + ReplayUI.frameHeight)) * window.framebufferHeight / ReplayUI.viewportSizeY;
|
||||||
|
int frameLeft = ReplayUI.frameX * window.framebufferWidth / ReplayUI.viewportSizeX;
|
||||||
|
int frameWidth = Math.max(1, ReplayUI.frameWidth) * window.framebufferWidth / ReplayUI.viewportSizeX;
|
||||||
|
int frameHeight = Math.max(1, ReplayUI.frameHeight) * window.framebufferHeight / ReplayUI.viewportSizeY;
|
||||||
|
|
||||||
|
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, this.frameBufferId);
|
||||||
|
GL30.glBlitFramebuffer(0, 0, width, height, frameLeft, frameBottom, frameLeft+frameWidth, frameBottom+frameHeight,
|
||||||
|
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_LINEAR);
|
||||||
|
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, 0);
|
||||||
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.moulberry.flashback.mixin.compat;
|
||||||
|
|
||||||
|
import com.bawnorton.mixinsquared.TargetHandler;
|
||||||
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prevent Fabric from modifying the world gen
|
||||||
|
* The registry that our ReplayServer uses typically does not contain server-only registries
|
||||||
|
* like minecraft:worldgen/placed_feature and so trying to modify the world gen context using
|
||||||
|
* these server-only registries is bound to error
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Mixin(value = MinecraftServer.class, priority = 1500)
|
||||||
|
public class MixinFabricMinecraftServer {
|
||||||
|
@TargetHandler(
|
||||||
|
mixin = "net.fabricmc.fabric.mixin.biome.modification.MinecraftServerMixin",
|
||||||
|
name = "finalizeWorldGen"
|
||||||
|
)
|
||||||
|
@Inject(method = "@MixinSquared:Handler", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void preventWorldGenChanges(CallbackInfo ci) {
|
||||||
|
if ((Object) this instanceof ReplayServer) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.moulberry.flashback.mixin.compat.bobby;
|
||||||
|
|
||||||
|
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
|
||||||
|
import de.johni0702.minecraft.bobby.FakeChunkManager;
|
||||||
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
@IfModLoaded("bobby")
|
||||||
|
@Mixin(FakeChunkManager.class)
|
||||||
|
public interface FakeChunkManagerAccessor {
|
||||||
|
|
||||||
|
@Invoker(value = "getCurrentWorldOrServerName", remap = false)
|
||||||
|
static String getCurrentWorldOrServerName(ClientPacketListener clientPacketListener) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package com.moulberry.flashback.mixin.compat.bobby;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
import com.moulberry.flashback.record.FlashbackMeta;
|
||||||
|
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
|
||||||
|
import de.johni0702.minecraft.bobby.FakeChunkManager;
|
||||||
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@IfModLoaded("bobby")
|
||||||
|
@Mixin(FakeChunkManager.class)
|
||||||
|
public class MixinBobbyFakeChunkManager {
|
||||||
|
|
||||||
|
@Inject(method = "getCurrentWorldOrServerName", at = @At("HEAD"), cancellable = true)
|
||||||
|
private static void getCurrentWorldOrServerName(ClientPacketListener networkHandler, CallbackInfoReturnable<String> cir) {
|
||||||
|
ReplayServer replayServer = Flashback.getReplayServer();
|
||||||
|
if (replayServer != null) {
|
||||||
|
FlashbackMeta meta = replayServer.getMetadata();
|
||||||
|
if (meta != null && meta.bobbyWorldName != null) {
|
||||||
|
Flashback.LOGGER.info("Overriding Bobby World Name: {}", meta.bobbyWorldName);
|
||||||
|
cir.setReturnValue(meta.bobbyWorldName);
|
||||||
|
} else {
|
||||||
|
cir.setReturnValue("unknown_flashback");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "save", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void save(LevelChunk chunk, CallbackInfoReturnable<Supplier<LevelChunk>> cir) {
|
||||||
|
if (Flashback.isInReplay()) {
|
||||||
|
cir.setReturnValue(() -> chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.moulberry.flashback.mixin.playback;
|
|||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -12,6 +14,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Mixin(Entity.class)
|
@Mixin(Entity.class)
|
||||||
public abstract class MixinEntity {
|
public abstract class MixinEntity {
|
||||||
|
|
||||||
@@ -24,10 +28,18 @@ public abstract class MixinEntity {
|
|||||||
@Shadow
|
@Shadow
|
||||||
public abstract boolean isInvisibleTo(Player player);
|
public abstract boolean isInvisibleTo(Player player);
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract UUID getUUID();
|
||||||
|
|
||||||
@Inject(method = "isInvisibleTo", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "isInvisibleTo", at = @At("HEAD"), cancellable = true)
|
||||||
public void isInvisibleTo(Player player, CallbackInfoReturnable<Boolean> cir) {
|
public void isInvisibleTo(Player player, CallbackInfoReturnable<Boolean> cir) {
|
||||||
ReplayServer replayServer = Flashback.getReplayServer();
|
ReplayServer replayServer = Flashback.getReplayServer();
|
||||||
if (replayServer != null && player == Minecraft.getInstance().player) {
|
if (replayServer != null && player == Minecraft.getInstance().player) {
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
if (editorState != null && editorState.hideDuringExport.contains(this.getUUID())) {
|
||||||
|
cir.setReturnValue(true);
|
||||||
|
}
|
||||||
|
|
||||||
int localId = replayServer.getLocalPlayerId();
|
int localId = replayServer.getLocalPlayerId();
|
||||||
if (this.level.getEntity(localId) instanceof Player localPlayer) {
|
if (this.level.getEntity(localId) instanceof Player localPlayer) {
|
||||||
if ((Object)this == localPlayer) {
|
if ((Object)this == localPlayer) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.moulberry.flashback.mixin.playback;
|
|||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
@@ -10,7 +11,9 @@ import com.moulberry.flashback.editor.ui.ReplayUI;
|
|||||||
import com.moulberry.flashback.ext.ItemInHandRendererExt;
|
import com.moulberry.flashback.ext.ItemInHandRendererExt;
|
||||||
import com.moulberry.flashback.ext.MinecraftExt;
|
import com.moulberry.flashback.ext.MinecraftExt;
|
||||||
import com.moulberry.flashback.visuals.CameraRotation;
|
import com.moulberry.flashback.visuals.CameraRotation;
|
||||||
|
import com.moulberry.flashback.visuals.ShaderManager;
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.client.DeltaTracker;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.Options;
|
import net.minecraft.client.Options;
|
||||||
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
||||||
@@ -19,9 +22,12 @@ import net.minecraft.client.player.LocalPlayer;
|
|||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.PostChain;
|
||||||
|
import net.minecraft.client.renderer.ShaderInstance;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@@ -54,6 +60,39 @@ public abstract class MixinGameRenderer {
|
|||||||
@Shadow
|
@Shadow
|
||||||
public abstract float getDepthFar();
|
public abstract float getDepthFar();
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract void renderLevel(DeltaTracker deltaTracker);
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private @Nullable PostChain postEffect;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private boolean effectActive;
|
||||||
|
|
||||||
|
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void render(DeltaTracker deltaTracker, boolean bl, CallbackInfo ci) {
|
||||||
|
if (Flashback.isExporting()) {
|
||||||
|
int i = (int)(this.minecraft.mouseHandler.xpos() * (double)this.minecraft.getWindow().getGuiScaledWidth() / (double)this.minecraft.getWindow().getScreenWidth());
|
||||||
|
int j = (int)(this.minecraft.mouseHandler.ypos() * (double)this.minecraft.getWindow().getGuiScaledHeight() / (double)this.minecraft.getWindow().getScreenHeight());
|
||||||
|
RenderSystem.viewport(0, 0, this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight());
|
||||||
|
boolean bl2 = this.minecraft.isGameLoadFinished();
|
||||||
|
if (bl2 && bl && this.minecraft.level != null) {
|
||||||
|
this.minecraft.getProfiler().push("level");
|
||||||
|
this.renderLevel(deltaTracker);
|
||||||
|
this.minecraft.levelRenderer.doEntityOutline();
|
||||||
|
if (this.postEffect != null && this.effectActive) {
|
||||||
|
RenderSystem.disableBlend();
|
||||||
|
RenderSystem.disableDepthTest();
|
||||||
|
RenderSystem.resetTextureMatrix();
|
||||||
|
this.postEffect.process(deltaTracker.getGameTimeDeltaTicks());
|
||||||
|
}
|
||||||
|
this.minecraft.getMainRenderTarget().bindWrite(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@WrapOperation(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"))
|
@WrapOperation(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"))
|
||||||
public GameType getPlayerMode(MultiPlayerGameMode instance, Operation<GameType> original) {
|
public GameType getPlayerMode(MultiPlayerGameMode instance, Operation<GameType> original) {
|
||||||
if (Flashback.getSpectatingPlayer() != null) {
|
if (Flashback.getSpectatingPlayer() != null) {
|
||||||
@@ -87,24 +126,6 @@ public abstract class MixinGameRenderer {
|
|||||||
return CameraRotation.modifyViewQuaternion(original.call(instance));
|
return CameraRotation.modifyViewQuaternion(original.call(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Inject(method = "getProjectionMatrix", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;perspective(FFFF)Lorg/joml/Matrix4f;", shift = At.Shift.BEFORE))
|
|
||||||
// @Inject(method = "getProjectionMatrix", at = @At(value = "RETURN"))
|
|
||||||
// public void getProjectionMatrix(double d, CallbackInfoReturnable<Matrix4f> cir) {
|
|
||||||
// if (ReplayVisuals.overrideZoom) {
|
|
||||||
// cir.getReturnValue().scaleLocal(ReplayVisuals.overrideZoomAmount, ReplayVisuals.overrideZoomAmount, 1.0f);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Inject(method = "getProjectionMatrix", at = @At(value = "RETURN"), cancellable = true)
|
|
||||||
// public void getProjectionMatrix(double d, CallbackInfoReturnable<Matrix4f> cir) {
|
|
||||||
// if (ReplayVisuals.overrideZoom) {
|
|
||||||
// Window window = Minecraft.getInstance().getWindow();
|
|
||||||
// Matrix4f matrix4f = new Matrix4f().setOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 0.05f, this.getDepthFar());
|
|
||||||
// cir.setReturnValue(matrix4f);
|
|
||||||
//// cir.setReturnValue(new Matrix4f().ortho());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Inject(method = "tryTakeScreenshotIfNeeded", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "tryTakeScreenshotIfNeeded", at = @At("HEAD"), cancellable = true)
|
||||||
public void tryTakeScreenshotIfNeeded(CallbackInfo ci) {
|
public void tryTakeScreenshotIfNeeded(CallbackInfo ci) {
|
||||||
if (Flashback.isInReplay()) {
|
if (Flashback.isInReplay()) {
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ public abstract class MixinLevelChunk extends ChunkAccess implements LevelChunkE
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.cachedChunkId = -1;
|
||||||
|
|
||||||
// Update heightmaps
|
// Update heightmaps
|
||||||
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).update(localX, y, localZ, blockState);
|
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING).update(localX, y, localZ, blockState);
|
||||||
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES).update(localX, y, localZ, blockState);
|
this.heightmaps.get(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES).update(localX, y, localZ, blockState);
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.moulberry.flashback.mixin.playback;
|
package com.moulberry.flashback.mixin.playback;
|
||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||||
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.network.PlayerChunkSender;
|
import net.minecraft.server.network.PlayerChunkSender;
|
||||||
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -32,4 +35,14 @@ public class MixinPlayerChunkSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "markChunkPendingToSend", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void markChunkPendingToSend(LevelChunk levelChunk, CallbackInfo ci) {
|
||||||
|
ReplayServer replayServer = Flashback.getReplayServer();
|
||||||
|
if (replayServer != null) {
|
||||||
|
if (!((ServerLevelExt)levelChunk.getLevel()).flashback$shouldSendChunk(levelChunk.getPos().toLong())) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.moulberry.flashback.mixin.replay_server;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
|
||||||
|
@Mixin(ServerLevel.class)
|
||||||
|
public abstract class MixinServerLevel implements ServerLevelExt {
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private long seedHash = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flashback$setSeedHash(long seedHash) {
|
||||||
|
this.seedHash = seedHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long flashback$getSeedHash() {
|
||||||
|
return this.seedHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private final LongSet validChunks = new LongOpenHashSet();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean flashback$shouldSendChunk(long pos) {
|
||||||
|
return this.validChunks.contains(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flashback$markChunkAsSendable(long pos) {
|
||||||
|
this.validChunks.add(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+11
-1
@@ -25,9 +25,19 @@ public abstract class MixinEntityRenderDispatcher {
|
|||||||
private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, float g, float h, float i) {
|
private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, float g, float h, float i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void renderBefore(Entity entity, double d, double e, double f, float g, float h, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) {
|
||||||
|
if (Flashback.isExporting()) {
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
if (editorState != null && editorState.hideDuringExport.contains(entity.getUUID())) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add a yellow outline to selected entity
|
// Add a yellow outline to selected entity
|
||||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = At.Shift.BEFORE))
|
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = At.Shift.BEFORE))
|
||||||
public void render(Entity entity, double d, double e, double f, float g, float h, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) {
|
public void renderAfter(Entity entity, double d, double e, double f, float g, float h, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) {
|
||||||
if (Flashback.isInReplay()) {
|
if (Flashback.isInReplay()) {
|
||||||
if (ReplayUI.isEntitySelected(entity.getUUID())) {
|
if (ReplayUI.isEntitySelected(entity.getUUID())) {
|
||||||
renderHitbox(poseStack, multiBufferSource.getBuffer(RenderType.lines()), entity, h, 1.0f, 1.0f, 0.0f);
|
renderHitbox(poseStack, multiBufferSource.getBuffer(RenderType.lines()), entity, h, 1.0f, 1.0f, 0.0f);
|
||||||
|
|||||||
@@ -52,8 +52,13 @@ public class MixinGui {
|
|||||||
|
|
||||||
@Inject(method = "canRenderCrosshairForSpectator", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "canRenderCrosshairForSpectator", at = @At("HEAD"), cancellable = true)
|
||||||
public void canRenderCrosshairForSpectator(HitResult hitResult, CallbackInfoReturnable<Boolean> cir) {
|
public void canRenderCrosshairForSpectator(HitResult hitResult, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (Flashback.isExporting()) {
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (ReplayUI.isActive() && ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME) {
|
if (ReplayUI.isActive() && ReplayUI.imguiGlfw.getMouseHandledBy() == CustomImGuiImplGlfw.MouseHandledBy.GAME) {
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (Flashback.getSpectatingPlayer() != null) {
|
if (Flashback.getSpectatingPlayer() != null) {
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.moulberry.flashback.mixin.visuals;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.state.EditorState;
|
||||||
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
|
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(LivingEntityRenderer.class)
|
||||||
|
public class MixinLivingEntityRenderer {
|
||||||
|
|
||||||
|
@Inject(method = "isBodyVisible", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void isBodyVisible(LivingEntity livingEntity, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
if (editorState != null && editorState.hideDuringExport.contains(livingEntity.getUUID())) {
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.moulberry.flashback.playback;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||||
|
import net.minecraft.network.chat.ChatType;
|
||||||
|
import net.minecraft.network.chat.OutgoingChatMessage;
|
||||||
|
import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo;
|
||||||
|
import net.minecraft.network.protocol.status.ServerStatus;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ClientInformation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.stats.Stat;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class FakePlayer extends ServerPlayer {
|
||||||
|
|
||||||
|
public FakePlayer(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation clientInformation) {
|
||||||
|
super(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendChatMessage(OutgoingChatMessage outgoingChatMessage, boolean bl, ChatType.Bound bound) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendServerStatus(ServerStatus serverStatus) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int awardRecipes(Collection<RecipeHolder<?>> collection) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void awardStat(Stat<?> stat, int i) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,11 +5,14 @@ import com.moulberry.flashback.Flashback;
|
|||||||
import com.moulberry.flashback.PacketHelper;
|
import com.moulberry.flashback.PacketHelper;
|
||||||
import com.moulberry.flashback.exception.UnsupportedPacketException;
|
import com.moulberry.flashback.exception.UnsupportedPacketException;
|
||||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||||
|
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||||
import com.moulberry.flashback.ext.ThreadedLevelLightEngineExt;
|
import com.moulberry.flashback.ext.ThreadedLevelLightEngineExt;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||||
|
import net.minecraft.client.player.KeyboardInput;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
@@ -66,6 +69,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
|||||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
import net.minecraft.world.level.dimension.LevelStem;
|
import net.minecraft.world.level.dimension.LevelStem;
|
||||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
|
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||||||
import net.minecraft.world.level.storage.DerivedLevelData;
|
import net.minecraft.world.level.storage.DerivedLevelData;
|
||||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||||
import net.minecraft.world.level.storage.ServerLevelData;
|
import net.minecraft.world.level.storage.ServerLevelData;
|
||||||
@@ -112,7 +116,6 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
private void setBlockState(ServerLevel level, BlockPos blockPos, BlockState blockState) {
|
private void setBlockState(ServerLevel level, BlockPos blockPos, BlockState blockState) {
|
||||||
LevelChunk levelChunk = level.getChunkAt(blockPos);
|
LevelChunk levelChunk = level.getChunkAt(blockPos);
|
||||||
((LevelChunkExt)levelChunk).flashback$setBlockStateWithoutUpdates(blockPos, blockState);
|
((LevelChunkExt)levelChunk).flashback$setBlockStateWithoutUpdates(blockPos, blockState);
|
||||||
level.getChunkSource().blockChanged(blockPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flushPendingEntities() {
|
public void flushPendingEntities() {
|
||||||
@@ -184,12 +187,12 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnPlayer(ClientboundAddEntityPacket addEntityPacket, GameProfile gameProfile, GameType gameType) {
|
private ServerPlayer spawnPlayer(ClientboundAddEntityPacket addEntityPacket, GameProfile gameProfile, GameType gameType) {
|
||||||
this.flushPendingEntities();
|
this.flushPendingEntities();
|
||||||
gameProfile.getProperties().removeAll("IsReplayViewer");
|
gameProfile.getProperties().removeAll("IsReplayViewer");
|
||||||
|
|
||||||
CommonListenerCookie commonListenerCookie = CommonListenerCookie.createInitial(gameProfile, false);
|
CommonListenerCookie commonListenerCookie = CommonListenerCookie.createInitial(gameProfile, false);
|
||||||
ServerPlayer serverPlayer = new ServerPlayer(this.replayServer, this.level(), commonListenerCookie.gameProfile(), commonListenerCookie.clientInformation()){
|
ServerPlayer serverPlayer = new FakePlayer(this.replayServer, this.level(), commonListenerCookie.gameProfile(), commonListenerCookie.clientInformation()){
|
||||||
@Override
|
@Override
|
||||||
public boolean isSpectator() {
|
public boolean isSpectator() {
|
||||||
return false;
|
return false;
|
||||||
@@ -220,6 +223,8 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
serverPlayer.recreateFromPacket(addEntityPacket);
|
serverPlayer.recreateFromPacket(addEntityPacket);
|
||||||
this.replayServer.getPlayerList().placeNewPlayer(connection, serverPlayer, commonListenerCookie);
|
this.replayServer.getPlayerList().placeNewPlayer(connection, serverPlayer, commonListenerCookie);
|
||||||
serverPlayer.setGameMode(gameType);
|
serverPlayer.setGameMode(gameType);
|
||||||
|
|
||||||
|
return serverPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -326,6 +331,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
public void handleBlockUpdate(ClientboundBlockUpdatePacket clientboundBlockUpdatePacket) {
|
public void handleBlockUpdate(ClientboundBlockUpdatePacket clientboundBlockUpdatePacket) {
|
||||||
this.setBlockState(this.level(), clientboundBlockUpdatePacket.getPos(),
|
this.setBlockState(this.level(), clientboundBlockUpdatePacket.getPos(),
|
||||||
clientboundBlockUpdatePacket.getBlockState());
|
clientboundBlockUpdatePacket.getBlockState());
|
||||||
|
forward(clientboundBlockUpdatePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -354,11 +360,24 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
clientboundSectionBlocksUpdatePacket.runUpdates((blockPos, blockState) -> {
|
clientboundSectionBlocksUpdatePacket.runUpdates((blockPos, blockState) -> {
|
||||||
this.setBlockState(level, blockPos, blockState);
|
this.setBlockState(level, blockPos, blockState);
|
||||||
});
|
});
|
||||||
|
forward(clientboundSectionBlocksUpdatePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMapItemData(ClientboundMapItemDataPacket clientboundMapItemDataPacket) {
|
public void handleMapItemData(ClientboundMapItemDataPacket clientboundMapItemDataPacket) {
|
||||||
forward(clientboundMapItemDataPacket);
|
forward(clientboundMapItemDataPacket);
|
||||||
|
|
||||||
|
ServerLevel level = this.level();
|
||||||
|
if (level == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapItemSavedData mapItemSavedData = level.getMapData(clientboundMapItemDataPacket.mapId());
|
||||||
|
if (mapItemSavedData == null) {
|
||||||
|
mapItemSavedData = MapItemSavedData.createForClient(clientboundMapItemDataPacket.scale(), clientboundMapItemDataPacket.locked(), level.dimension());
|
||||||
|
level.setMapData(clientboundMapItemDataPacket.mapId(), mapItemSavedData);
|
||||||
|
}
|
||||||
|
clientboundMapItemDataPacket.applyToMap(mapItemSavedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -482,6 +501,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
this.applyLightData(levelLightEngine, x, z, lightData);
|
this.applyLightData(levelLightEngine, x, z, lightData);
|
||||||
|
|
||||||
ChunkPos chunkPos = chunk.getPos();
|
ChunkPos chunkPos = chunk.getPos();
|
||||||
|
((ServerLevelExt)this.level()).flashback$markChunkAsSendable(chunkPos.toLong());
|
||||||
for (ServerPlayer serverPlayer : this.replayServer.getReplayViewers()) {
|
for (ServerPlayer serverPlayer : this.replayServer.getReplayViewers()) {
|
||||||
if (serverPlayer.getChunkTrackingView().contains(chunkPos)) {
|
if (serverPlayer.getChunkTrackingView().contains(chunkPos)) {
|
||||||
serverPlayer.connection.chunkSender.markChunkPendingToSend(chunk);
|
serverPlayer.connection.chunkSender.markChunkPendingToSend(chunk);
|
||||||
@@ -657,6 +677,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerLevel newLevel = this.replayServer.getLevel(dimension);
|
ServerLevel newLevel = this.replayServer.getLevel(dimension);
|
||||||
|
((ServerLevelExt) newLevel).flashback$setSeedHash(commonPlayerSpawnInfo.seed());
|
||||||
|
|
||||||
if (newLevel == oldLevel) {
|
if (newLevel == oldLevel) {
|
||||||
// Change to new dimension
|
// Change to new dimension
|
||||||
@@ -832,6 +853,30 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.ensureWorldCreated(clientboundRespawnPacket.commonPlayerSpawnInfo(), localPlayer, false);
|
this.ensureWorldCreated(clientboundRespawnPacket.commonPlayerSpawnInfo(), localPlayer, false);
|
||||||
|
|
||||||
|
if (localPlayer instanceof ServerPlayer oldServerPlayer) {
|
||||||
|
ClientboundAddEntityPacket addEntityPacket = new ClientboundAddEntityPacket(oldServerPlayer.getId(), oldServerPlayer.getUUID(),
|
||||||
|
oldServerPlayer.getX(), oldServerPlayer.getY(), oldServerPlayer.getZ(), oldServerPlayer.getXRot(), oldServerPlayer.getYRot(), EntityType.PLAYER,
|
||||||
|
0, Vec3.ZERO, oldServerPlayer.getYHeadRot());
|
||||||
|
|
||||||
|
ServerPlayer newServerPlayer = this.spawnPlayer(addEntityPacket, oldServerPlayer.getGameProfile(), oldServerPlayer.gameMode.getGameModeForPlayer());
|
||||||
|
|
||||||
|
if (clientboundRespawnPacket.shouldKeep((byte)2)) {
|
||||||
|
newServerPlayer.setShiftKeyDown(oldServerPlayer.isShiftKeyDown());
|
||||||
|
newServerPlayer.setSprinting(oldServerPlayer.isSprinting());
|
||||||
|
|
||||||
|
var oldEntityData = oldServerPlayer.getEntityData().getNonDefaultValues();
|
||||||
|
if (oldEntityData != null) {
|
||||||
|
newServerPlayer.getEntityData().assignValues(oldEntityData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientboundRespawnPacket.shouldKeep((byte)1)) {
|
||||||
|
newServerPlayer.getAttributes().assignAllValues(oldServerPlayer.getAttributes());
|
||||||
|
} else {
|
||||||
|
newServerPlayer.getAttributes().assignBaseValues(oldServerPlayer.getAttributes());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -861,10 +906,12 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: SynchedEntityData#assignValues isn't used because it doesn't mark the value as dirty
|
||||||
|
|
||||||
SynchedEntityData entityData = entity.getEntityData();
|
SynchedEntityData entityData = entity.getEntityData();
|
||||||
for (SynchedEntityData.DataValue<?> dataValue : clientboundSetEntityDataPacket.packedItems()) {
|
for (SynchedEntityData.DataValue<?> dataValue : clientboundSetEntityDataPacket.packedItems()) {
|
||||||
SynchedEntityData.DataItem<?> dataItem = entityData.itemsById[dataValue.id()];
|
SynchedEntityData.DataItem<?> dataItem = entityData.itemsById[dataValue.id()];
|
||||||
entityData.set((EntityDataAccessor) dataItem.getAccessor(), dataValue.value());
|
entityData.set((EntityDataAccessor) dataItem.getAccessor(), dataValue.value(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package com.moulberry.flashback.playback;
|
package com.moulberry.flashback.playback;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||||
|
import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ClientInformation;
|
import net.minecraft.server.level.ClientInformation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.stats.Stat;
|
import net.minecraft.stats.Stat;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||||
|
import net.minecraft.world.level.biome.BiomeManager;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -19,6 +23,14 @@ public class ReplayPlayer extends ServerPlayer {
|
|||||||
super(minecraftServer, serverLevel, gameProfile, clientInformation);
|
super(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonPlayerSpawnInfo createCommonSpawnInfo(ServerLevel serverLevel) {
|
||||||
|
return new CommonPlayerSpawnInfo(serverLevel.dimensionTypeRegistration(), serverLevel.dimension(),
|
||||||
|
((ServerLevelExt)serverLevel).flashback$getSeedHash(), this.gameMode.getGameModeForPlayer(),
|
||||||
|
this.gameMode.getPreviousGameModeForPlayer(),
|
||||||
|
serverLevel.isDebug(), serverLevel.isFlat(), this.getLastDeathLocation(), this.getPortalCooldown());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int awardRecipes(Collection<RecipeHolder<?>> collection) {
|
public int awardRecipes(Collection<RecipeHolder<?>> collection) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -28,5 +40,21 @@ public class ReplayPlayer extends ServerPlayer {
|
|||||||
public void awardStat(Stat<?> stat, int i) {
|
public void awardStat(Stat<?> stat, int i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void indicateDamage(double d, double e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleDamageEvent(DamageSource damageSource) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hurt(DamageSource damageSource, float f) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInvulnerableTo(DamageSource damageSource) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,10 @@ import com.moulberry.flashback.record.FlashbackMeta;
|
|||||||
import com.moulberry.flashback.record.Recorder;
|
import com.moulberry.flashback.record.Recorder;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.handler.codec.DecoderException;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -45,10 +47,12 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
import net.minecraft.server.level.TicketType;
|
import net.minecraft.server.level.TicketType;
|
||||||
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
|
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
|
||||||
import net.minecraft.server.network.ConfigurationTask;
|
import net.minecraft.server.network.ConfigurationTask;
|
||||||
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
import net.minecraft.server.packs.repository.PackRepository;
|
import net.minecraft.server.packs.repository.PackRepository;
|
||||||
import net.minecraft.server.players.PlayerList;
|
import net.minecraft.server.players.PlayerList;
|
||||||
import net.minecraft.world.BossEvent;
|
import net.minecraft.world.BossEvent;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.flag.FeatureFlagSet;
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
@@ -72,14 +76,12 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
|
|
||||||
public class ReplayServer extends IntegratedServer {
|
public class ReplayServer extends IntegratedServer {
|
||||||
|
|
||||||
@@ -109,6 +111,8 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
private boolean processedSnapshot = false;
|
private boolean processedSnapshot = false;
|
||||||
private volatile boolean fastForwarding = false;
|
private volatile boolean fastForwarding = false;
|
||||||
|
|
||||||
|
private int printFailedDecodePacketCount = 8;
|
||||||
|
|
||||||
private final UUID playbackUUID;
|
private final UUID playbackUUID;
|
||||||
private final FlashbackMeta metadata;
|
private final FlashbackMeta metadata;
|
||||||
private final TreeMap<Integer, PlayableChunk> playableChunksByStart = new TreeMap<>();
|
private final TreeMap<Integer, PlayableChunk> playableChunksByStart = new TreeMap<>();
|
||||||
@@ -124,6 +128,7 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
|
|
||||||
private Component shutdownReason = null;
|
private Component shutdownReason = null;
|
||||||
private FileSystem playbackFileSystem = null;
|
private FileSystem playbackFileSystem = null;
|
||||||
|
private boolean initializedWithSnapshot = false;
|
||||||
|
|
||||||
public ReplayServer(Thread thread, Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Services services,
|
public ReplayServer(Thread thread, Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Services services,
|
||||||
ChunkProgressListenerFactory chunkProgressListenerFactory, UUID playbackUUID, Path path) {
|
ChunkProgressListenerFactory chunkProgressListenerFactory, UUID playbackUUID, Path path) {
|
||||||
@@ -254,6 +259,22 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
public void broadcastSystemMessage(Component component, Function<ServerPlayer, Component> function, boolean bl) {
|
public void broadcastSystemMessage(Component component, Function<ServerPlayer, Component> function, boolean bl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendPlayerPermissionLevel(ServerPlayer serverPlayer) {
|
||||||
|
if (serverPlayer instanceof FakePlayer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.sendPlayerPermissionLevel(serverPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendAllPlayerInfo(ServerPlayer serverPlayer) {
|
||||||
|
if (serverPlayer instanceof FakePlayer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.sendAllPlayerInfo(serverPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void broadcast(@Nullable Player player, double x, double y, double z, double distance, ResourceKey<Level> resourceKey, Packet<?> packet) {
|
public void broadcast(@Nullable Player player, double x, double y, double z, double distance, ResourceKey<Level> resourceKey, Packet<?> packet) {
|
||||||
UUID audioSourceEntity = null;
|
UUID audioSourceEntity = null;
|
||||||
@@ -286,6 +307,10 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendLevelInfo(ServerPlayer serverPlayer, ServerLevel serverLevel) {
|
public void sendLevelInfo(ServerPlayer serverPlayer, ServerLevel serverLevel) {
|
||||||
|
if (serverPlayer instanceof FakePlayer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
super.sendLevelInfo(serverPlayer, serverLevel);
|
super.sendLevelInfo(serverPlayer, serverLevel);
|
||||||
|
|
||||||
// Send all resource packs
|
// Send all resource packs
|
||||||
@@ -323,10 +348,6 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
this.loadLevel();
|
this.loadLevel();
|
||||||
this.overworld().noSave = true;
|
this.overworld().noSave = true;
|
||||||
|
|
||||||
// Play initial snapshot
|
|
||||||
ReplayReader replayReader = this.playableChunksByStart.get(0).getOrLoadReplayReader(this.registryAccess());
|
|
||||||
replayReader.handleSnapshot(this);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,7 +521,20 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
public void handleGamePacket(RegistryFriendlyByteBuf friendlyByteBuf) {
|
public void handleGamePacket(RegistryFriendlyByteBuf friendlyByteBuf) {
|
||||||
this.configurationPacketHandler.flushPendingConfiguration();
|
this.configurationPacketHandler.flushPendingConfiguration();
|
||||||
|
|
||||||
Packet<? super ClientGamePacketListener> packet = this.gamePacketCodec.decode(friendlyByteBuf);
|
Packet<? super ClientGamePacketListener> packet;
|
||||||
|
try {
|
||||||
|
packet = this.gamePacketCodec.decode(friendlyByteBuf);
|
||||||
|
} catch (DecoderException decoderException) {
|
||||||
|
// Failed to decode packet, lets try ignoring it
|
||||||
|
if (printFailedDecodePacketCount > 0) {
|
||||||
|
Flashback.LOGGER.error("Failed to decode packet from replay stream", decoderException);
|
||||||
|
printFailedDecodePacketCount -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gamePacketHandler.flushPendingEntities();
|
||||||
|
friendlyByteBuf.readerIndex(friendlyByteBuf.writerIndex());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!AllowPendingEntityPacketSet.allowPendingEntity(packet)) {
|
if (!AllowPendingEntityPacketSet.allowPendingEntity(packet)) {
|
||||||
this.gamePacketHandler.flushPendingEntities();
|
this.gamePacketHandler.flushPendingEntities();
|
||||||
}
|
}
|
||||||
@@ -623,6 +657,14 @@ public class ReplayServer extends IntegratedServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickServer(BooleanSupplier booleanSupplier) {
|
public void tickServer(BooleanSupplier booleanSupplier) {
|
||||||
|
if (!this.initializedWithSnapshot) {
|
||||||
|
this.initializedWithSnapshot = true;
|
||||||
|
|
||||||
|
// Play initial snapshot
|
||||||
|
ReplayReader replayReader = this.playableChunksByStart.get(0).getOrLoadReplayReader(this.registryAccess());
|
||||||
|
replayReader.handleSnapshot(this);
|
||||||
|
}
|
||||||
|
|
||||||
this.lastReplayTick = this.currentTick;
|
this.lastReplayTick = this.currentTick;
|
||||||
this.lastTickTimeNanos = this.nextTickTimeNanos - this.tickRateManager().nanosecondsPerTick();
|
this.lastTickTimeNanos = this.nextTickTimeNanos - this.tickRateManager().nanosecondsPerTick();
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public class FlashbackMeta {
|
|||||||
public UUID replayIdentifier = UUID.randomUUID();
|
public UUID replayIdentifier = UUID.randomUUID();
|
||||||
public String name = "Unnamed";
|
public String name = "Unnamed";
|
||||||
public String versionString = null;
|
public String versionString = null;
|
||||||
|
public String bobbyWorldName = null;
|
||||||
public int dataVersion = 0;
|
public int dataVersion = 0;
|
||||||
public int protocolVersion = 0;
|
public int protocolVersion = 0;
|
||||||
|
|
||||||
@@ -33,6 +34,9 @@ public class FlashbackMeta {
|
|||||||
if (this.protocolVersion != 0) {
|
if (this.protocolVersion != 0) {
|
||||||
meta.addProperty("protocol_version", this.protocolVersion);
|
meta.addProperty("protocol_version", this.protocolVersion);
|
||||||
}
|
}
|
||||||
|
if (this.bobbyWorldName != null) {
|
||||||
|
meta.addProperty("bobby_world_name", this.bobbyWorldName);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.totalTicks > 0) {
|
if (this.totalTicks > 0) {
|
||||||
meta.addProperty("total_ticks", this.totalTicks);
|
meta.addProperty("total_ticks", this.totalTicks);
|
||||||
@@ -72,6 +76,9 @@ public class FlashbackMeta {
|
|||||||
if (meta.has("protocol_version")) {
|
if (meta.has("protocol_version")) {
|
||||||
flashbackMeta.protocolVersion = meta.get("protocol_version").getAsInt();
|
flashbackMeta.protocolVersion = meta.get("protocol_version").getAsInt();
|
||||||
}
|
}
|
||||||
|
if (meta.has("bobby_world_name")) {
|
||||||
|
flashbackMeta.bobbyWorldName = meta.get("bobby_world_name").getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
// Total ticks
|
// Total ticks
|
||||||
if (meta.has("total_ticks")) {
|
if (meta.has("total_ticks")) {
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import com.moulberry.flashback.PacketHelper;
|
|||||||
import com.moulberry.flashback.action.*;
|
import com.moulberry.flashback.action.*;
|
||||||
import com.moulberry.flashback.io.AsyncReplaySaver;
|
import com.moulberry.flashback.io.AsyncReplaySaver;
|
||||||
import com.moulberry.flashback.io.ReplayWriter;
|
import com.moulberry.flashback.io.ReplayWriter;
|
||||||
|
import com.moulberry.flashback.mixin.compat.bobby.FakeChunkManagerAccessor;
|
||||||
|
import de.johni0702.minecraft.bobby.FakeChunkManager;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.Screenshot;
|
import net.minecraft.client.Screenshot;
|
||||||
@@ -31,6 +34,8 @@ import net.minecraft.nbt.Tag;
|
|||||||
import net.minecraft.network.ConnectionProtocol;
|
import net.minecraft.network.ConnectionProtocol;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.PlayerChatMessage;
|
||||||
|
import net.minecraft.network.chat.SignedMessageBody;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket;
|
import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket;
|
||||||
@@ -61,6 +66,9 @@ import net.minecraft.world.level.GameType;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.border.WorldBorder;
|
import net.minecraft.world.level.border.WorldBorder;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
import net.minecraft.world.level.saveddata.maps.MapDecoration;
|
||||||
|
import net.minecraft.world.level.saveddata.maps.MapId;
|
||||||
|
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||||||
import net.minecraft.world.scores.*;
|
import net.minecraft.world.scores.*;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -122,6 +130,13 @@ public class Recorder {
|
|||||||
this.metadata.dataVersion = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
this.metadata.dataVersion = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
||||||
this.metadata.protocolVersion = SharedConstants.getProtocolVersion();
|
this.metadata.protocolVersion = SharedConstants.getProtocolVersion();
|
||||||
this.metadata.versionString = SharedConstants.VERSION_STRING;
|
this.metadata.versionString = SharedConstants.VERSION_STRING;
|
||||||
|
|
||||||
|
if (FabricLoader.getInstance().isModLoaded("bobby")) {
|
||||||
|
try {
|
||||||
|
String bobbyWorldName = FakeChunkManagerAccessor.getCurrentWorldOrServerName(Minecraft.getInstance().getConnection());
|
||||||
|
this.metadata.bobbyWorldName = bobbyWorldName;
|
||||||
|
} catch (Throwable t) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRegistryAccess(RegistryAccess registryAccess) {
|
public void setRegistryAccess(RegistryAccess registryAccess) {
|
||||||
@@ -468,6 +483,17 @@ public class Recorder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert player chat packets into system chat packets
|
||||||
|
if (packet instanceof ClientboundPlayerChatPacket playerChatPacket) {
|
||||||
|
try {
|
||||||
|
Component content = playerChatPacket.unsignedContent() != null ? playerChatPacket.unsignedContent() : Component.literal(playerChatPacket.body().content());
|
||||||
|
Component decorated = playerChatPacket.chatType().decorate(content);
|
||||||
|
packet = new ClientboundSystemChatPacket(decorated, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (IgnoredPacketSet.isIgnored(packet)) {
|
if (IgnoredPacketSet.isIgnored(packet)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -547,7 +573,8 @@ public class Recorder {
|
|||||||
List<Packet<? super ClientGamePacketListener>> gamePackets = new ArrayList<>();
|
List<Packet<? super ClientGamePacketListener>> gamePackets = new ArrayList<>();
|
||||||
|
|
||||||
// Login packet
|
// Login packet
|
||||||
CommonPlayerSpawnInfo commonPlayerSpawnInfo = new CommonPlayerSpawnInfo(level.dimensionTypeRegistration(), level.dimension(), 0,
|
long hashedSeed = level.getBiomeManager().biomeZoomSeed;
|
||||||
|
CommonPlayerSpawnInfo commonPlayerSpawnInfo = new CommonPlayerSpawnInfo(level.dimensionTypeRegistration(), level.dimension(), hashedSeed,
|
||||||
gameMode.getPlayerMode(), gameMode.getPreviousPlayerMode(), level.isDebug(), level.getLevelData().isFlat, Optional.empty(), 0);
|
gameMode.getPlayerMode(), gameMode.getPreviousPlayerMode(), level.isDebug(), level.getLevelData().isFlat, Optional.empty(), 0);
|
||||||
var loginPacket = new ClientboundLoginPacket(localPlayer.getId(), level.getLevelData().isHardcore(), connection.levels(),
|
var loginPacket = new ClientboundLoginPacket(localPlayer.getId(), level.getLevelData().isHardcore(), connection.levels(),
|
||||||
1, Minecraft.getInstance().options.getEffectiveRenderDistance(), level.getServerSimulationDistance(),
|
1, Minecraft.getInstance().options.getEffectiveRenderDistance(), level.getServerSimulationDistance(),
|
||||||
@@ -740,6 +767,33 @@ public class Recorder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map data
|
||||||
|
for (Map.Entry<MapId, MapItemSavedData> entry : level.mapData.entrySet()) {
|
||||||
|
MapItemSavedData data = entry.getValue();
|
||||||
|
|
||||||
|
int offsetX = 0;
|
||||||
|
int offsetY = 0;
|
||||||
|
int sizeX = 128;
|
||||||
|
int sizeY = 128;
|
||||||
|
|
||||||
|
if (data.colors.length != sizeX * sizeY) {
|
||||||
|
Flashback.LOGGER.error("Unable to save snapshot of map data, expected colour array to be size {}, got {} instead", sizeX * sizeY, data.colors.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] colorsCopy = new byte[sizeX * sizeY];
|
||||||
|
System.arraycopy(data.colors, 0, colorsCopy, 0, sizeX * sizeY);
|
||||||
|
MapItemSavedData.MapPatch patch = new MapItemSavedData.MapPatch(offsetX, offsetY, sizeX, sizeY, colorsCopy);
|
||||||
|
|
||||||
|
ArrayList<MapDecoration> decorations = new ArrayList<>();
|
||||||
|
for (MapDecoration decoration : data.getDecorations()) {
|
||||||
|
decorations.add(decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
var packet = new ClientboundMapItemDataPacket(entry.getKey(), data.scale, data.locked, decorations, patch);
|
||||||
|
gamePackets.add(packet);
|
||||||
|
}
|
||||||
|
|
||||||
this.asyncReplaySaver.writeGamePackets(this.gamePacketCodec, gamePackets);
|
this.asyncReplaySaver.writeGamePackets(this.gamePacketCodec, gamePackets);
|
||||||
|
|
||||||
if (asActualSnapshot) {
|
if (asActualSnapshot) {
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ public class ConfigScreen extends OptionsSubScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removed() {
|
public void removed() {
|
||||||
Path configFolder = FabricLoader.getInstance().getConfigDir().resolve("flashback");
|
Flashback.getConfig().saveToDefaultFolder();
|
||||||
Flashback.getConfig().saveToFolder(configFolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
package com.moulberry.flashback.screen;
|
package com.moulberry.flashback.screen;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
@@ -11,6 +8,8 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
|
|
||||||
public class FlashbackButton extends Button {
|
public class FlashbackButton extends Button {
|
||||||
|
|
||||||
|
private static final ResourceLocation ICON_PIXELATED = ResourceLocation.parse("flashback:icon_pixelated.png");
|
||||||
|
|
||||||
public FlashbackButton(int x, int y, int width, int height, Component component, OnPress onPress) {
|
public FlashbackButton(int x, int y, int width, int height, Component component, OnPress onPress) {
|
||||||
super(x, y, width, height, component, onPress, DEFAULT_NARRATION);
|
super(x, y, width, height, component, onPress, DEFAULT_NARRATION);
|
||||||
}
|
}
|
||||||
@@ -19,30 +18,14 @@ public class FlashbackButton extends Button {
|
|||||||
protected void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
|
protected void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
|
||||||
super.renderWidget(guiGraphics, i, j, f);
|
super.renderWidget(guiGraphics, i, j, f);
|
||||||
|
|
||||||
final int size = 14;
|
final int size = 16;
|
||||||
int paddingX = (this.getWidth() - size) / 2;
|
int paddingX = (this.getWidth() - size) / 2;
|
||||||
int paddingY = (this.getHeight() - size) / 2;
|
int paddingY = (this.getHeight() - size) / 2;
|
||||||
|
|
||||||
int x = this.getX() + paddingX;
|
int x = this.getX() + paddingX;
|
||||||
int y = this.getY() + paddingY;
|
int y = this.getY() + paddingY;
|
||||||
|
|
||||||
double guiScale = Minecraft.getInstance().getWindow().getGuiScale();
|
guiGraphics.blit(ICON_PIXELATED, x, y, 0f, 0f, size, size, size, size);
|
||||||
int realSize = (int)(size * guiScale);
|
|
||||||
|
|
||||||
ResourceLocation icon;
|
|
||||||
if (realSize == 14) {
|
|
||||||
icon = ResourceLocation.parse("flashback:icon_14x.png");
|
|
||||||
} else if (realSize == 28) {
|
|
||||||
icon = ResourceLocation.parse("flashback:icon_28x.png");
|
|
||||||
} else if (realSize == 42) {
|
|
||||||
icon = ResourceLocation.parse("flashback:icon_42x.png");
|
|
||||||
} else if (realSize == 56) {
|
|
||||||
icon = ResourceLocation.parse("flashback:icon_56x.png");
|
|
||||||
} else {
|
|
||||||
icon = ResourceLocation.parse("flashback:icon.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
guiGraphics.blit(icon, x, y, 0f, 0f, size, size, size, size);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.moulberry.flashback.screen;
|
package com.moulberry.flashback.screen;
|
||||||
|
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
@@ -37,6 +39,11 @@ public class SelectReplayScreen extends Screen {
|
|||||||
.bounds(this.width / 2 + 4, this.height - 28, 72, 20).build());
|
.bounds(this.width / 2 + 4, this.height - 28, 72, 20).build());
|
||||||
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, button -> this.minecraft.setScreen(this.lastScreen))
|
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, button -> this.minecraft.setScreen(this.lastScreen))
|
||||||
.bounds(this.width / 2 + 82, this.height - 28, 72, 20).build());
|
.bounds(this.width / 2 + 82, this.height - 28, 72, 20).build());
|
||||||
|
|
||||||
|
if (this.width/2 > 154 + 128) {
|
||||||
|
this.addRenderableWidget(Button.builder(Component.literal("Flashback Settings"), btn -> Minecraft.getInstance().setScreen(new ConfigScreen(this)))
|
||||||
|
.bounds(this.width - 120 - 8, this.height - 28, 120, 20).build());
|
||||||
|
}
|
||||||
this.updateButtonStatus(null);
|
this.updateButtonStatus(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.moulberry.flashback.serialization;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
import org.joml.Quaterniond;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public class QuaterniondTypeAdapater implements JsonSerializer<Quaterniond>, JsonDeserializer<Quaterniond> {
|
||||||
|
@Override
|
||||||
|
public Quaterniond deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
JsonArray jsonArray = json.getAsJsonArray();
|
||||||
|
if (jsonArray.size() != 4) {
|
||||||
|
throw new IllegalStateException("Error deserializing Quaterniond, expected array to have length 4, was length " + jsonArray.size() + " instead");
|
||||||
|
}
|
||||||
|
double x = jsonArray.get(0).getAsDouble();
|
||||||
|
double y = jsonArray.get(1).getAsDouble();
|
||||||
|
double z = jsonArray.get(2).getAsDouble();
|
||||||
|
double w = jsonArray.get(3).getAsDouble();
|
||||||
|
return new Quaterniond(x, y, z, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(Quaterniond src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
jsonArray.add(src.x);
|
||||||
|
jsonArray.add(src.y);
|
||||||
|
jsonArray.add(src.z);
|
||||||
|
jsonArray.add(src.w);
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-2
@@ -1,12 +1,11 @@
|
|||||||
package com.moulberry.flashback.serialization;
|
package com.moulberry.flashback.serialization;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
public class QuaternionTypeAdapater implements JsonSerializer<Quaternionf>, JsonDeserializer<Quaternionf> {
|
public class QuaternionfTypeAdapater implements JsonSerializer<Quaternionf>, JsonDeserializer<Quaternionf> {
|
||||||
@Override
|
@Override
|
||||||
public Quaternionf deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public Quaternionf deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonArray jsonArray = json.getAsJsonArray();
|
JsonArray jsonArray = json.getAsJsonArray();
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.moulberry.flashback.serialization;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public class Vector3dTypeAdapater implements JsonSerializer<Vector3d>, JsonDeserializer<Vector3d> {
|
||||||
|
@Override
|
||||||
|
public Vector3d deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
JsonArray jsonArray = json.getAsJsonArray();
|
||||||
|
if (jsonArray.size() != 3) {
|
||||||
|
throw new IllegalStateException("Error deserializing Vector3f, expected array to have length 3, was length " + jsonArray.size() + " instead");
|
||||||
|
}
|
||||||
|
double x = jsonArray.get(0).getAsDouble();
|
||||||
|
double y = jsonArray.get(1).getAsDouble();
|
||||||
|
double z = jsonArray.get(2).getAsDouble();
|
||||||
|
|
||||||
|
return new Vector3d(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(Vector3d src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
jsonArray.add(src.x);
|
||||||
|
jsonArray.add(src.y);
|
||||||
|
jsonArray.add(src.z);
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,192 +1,193 @@
|
|||||||
package com.moulberry.flashback.spline;
|
package com.moulberry.flashback.spline;
|
||||||
|
|
||||||
import com.moulberry.flashback.Interpolation;
|
import com.moulberry.flashback.Interpolation;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaterniond;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
public class CatmullRom {
|
public class CatmullRom {
|
||||||
|
|
||||||
private static float positionCentripetalTj(Vector3f p1, Vector3f p2) {
|
private static double positionCentripetalTj(Vector3d p1, Vector3d p2) {
|
||||||
float dx = p2.x - p1.x;
|
double dx = p2.x - p1.x;
|
||||||
float dy = p2.y - p1.y;
|
double dy = p2.y - p1.y;
|
||||||
float dz = p2.z - p1.z;
|
double dz = p2.z - p1.z;
|
||||||
return (float) Math.pow(dx*dx + dy*dy + dz*dz, 0.25f);
|
return Math.pow(dx*dx + dy*dy + dz*dz, 0.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3f position(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float time1, float time2, float time3, float amount) {
|
public static Vector3d position(Vector3d p0, Vector3d p1, Vector3d p2, Vector3d p3, float time1, float time2, float time3, float amount) {
|
||||||
float tj1 = positionCentripetalTj(p0, p1);
|
double tj1 = positionCentripetalTj(p0, p1);
|
||||||
float tj2 = positionCentripetalTj(p1, p2);
|
double tj2 = positionCentripetalTj(p1, p2);
|
||||||
float tj3 = positionCentripetalTj(p2, p3);
|
double tj3 = positionCentripetalTj(p2, p3);
|
||||||
float averageTj = (tj1 + tj2 + tj3) / 3f;
|
double averageTj = (tj1 + tj2 + tj3) / 3f;
|
||||||
|
|
||||||
if (averageTj == 0.0) {
|
if (averageTj == 0.0) {
|
||||||
return new Vector3f(p1);
|
return new Vector3d(p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float averageTime = time3 / 3f;
|
double averageTime = time3 / 3f;
|
||||||
float relation = averageTime / averageTj;
|
double relation = averageTime / averageTj;
|
||||||
|
|
||||||
float deltaTime1 = 0.0f;
|
double deltaTime1 = 0.0f;
|
||||||
if (time1 > 0.0f) {
|
if (time1 > 0.0f) {
|
||||||
float factor1 = (tj1 * relation) / time1;
|
double factor1 = (tj1 * relation) / time1;
|
||||||
factor1 = Math.max(0.4f, Math.min(2.5f, factor1));
|
factor1 = Math.max(0.4f, Math.min(2.5f, factor1));
|
||||||
deltaTime1 = (tj1 * relation) / factor1;
|
deltaTime1 = (tj1 * relation) / factor1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float deltaTime2 = 0.0f;
|
double deltaTime2 = 0.0f;
|
||||||
if (time2 - time1 > 0.0f) {
|
if (time2 - time1 > 0.0f) {
|
||||||
float factor2 = (tj2 * relation) / (time2 - time1);
|
double factor2 = (tj2 * relation) / (time2 - time1);
|
||||||
factor2 = Math.max(0.4f, Math.min(2.5f, factor2));
|
factor2 = Math.max(0.4f, Math.min(2.5f, factor2));
|
||||||
deltaTime2 = (tj2 * relation) / factor2;
|
deltaTime2 = (tj2 * relation) / factor2;
|
||||||
}
|
}
|
||||||
|
|
||||||
float deltaTime3 = 0.0f;
|
double deltaTime3 = 0.0f;
|
||||||
if (time3 - time2 > 0.0f) {
|
if (time3 - time2 > 0.0f) {
|
||||||
float factor3 = (tj3 * relation) / (time3 - time2);
|
double factor3 = (tj3 * relation) / (time3 - time2);
|
||||||
factor3 = Math.max(0.4f, Math.min(2.5f, factor3));
|
factor3 = Math.max(0.4f, Math.min(2.5f, factor3));
|
||||||
deltaTime3 = (tj3 * relation) / factor3;
|
deltaTime3 = (tj3 * relation) / factor3;
|
||||||
}
|
}
|
||||||
|
|
||||||
float t0 = 0;
|
double t0 = 0;
|
||||||
float t1 = t0 + deltaTime1;
|
double t1 = t0 + deltaTime1;
|
||||||
float t2 = t1 + deltaTime2;
|
double t2 = t1 + deltaTime2;
|
||||||
float t3 = t2 + deltaTime3;
|
double t3 = t2 + deltaTime3;
|
||||||
|
|
||||||
float t = t1 + (t2 - t1) * amount;
|
double t = t1 + (t2 - t1) * amount;
|
||||||
|
|
||||||
Vector3f a1;
|
Vector3d a1;
|
||||||
if (t0 == t1) {
|
if (t0 == t1) {
|
||||||
a1 = p0.lerp(p1, 0.5f, new Vector3f());
|
a1 = p0.lerp(p1, 0.5f, new Vector3d());
|
||||||
} else {
|
} else {
|
||||||
a1 = p0.lerp(p1, (t - t0)/(t1 - t0), new Vector3f());
|
a1 = p0.lerp(p1, (t - t0)/(t1 - t0), new Vector3d());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f a2;
|
Vector3d a2;
|
||||||
if (t1 == t2) {
|
if (t1 == t2) {
|
||||||
a2 = p1.lerp(p2, 0.5f, new Vector3f());
|
a2 = p1.lerp(p2, 0.5f, new Vector3d());
|
||||||
} else {
|
} else {
|
||||||
a2 = p1.lerp(p2, (t - t1)/(t2 - t1), new Vector3f());
|
a2 = p1.lerp(p2, (t - t1)/(t2 - t1), new Vector3d());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f a3;
|
Vector3d a3;
|
||||||
if (t2 == t3) {
|
if (t2 == t3) {
|
||||||
a3 = p2.lerp(p3, 0.5f, new Vector3f());
|
a3 = p2.lerp(p3, 0.5f, new Vector3d());
|
||||||
} else {
|
} else {
|
||||||
a3 = p2.lerp(p3, (t - t2)/(t3 - t2), new Vector3f());
|
a3 = p2.lerp(p3, (t - t2)/(t3 - t2), new Vector3d());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f b1;
|
Vector3d b1;
|
||||||
if (t0 == t2) {
|
if (t0 == t2) {
|
||||||
b1 = a1.lerp(a2, 0.5f, new Vector3f());
|
b1 = a1.lerp(a2, 0.5f, new Vector3d());
|
||||||
} else {
|
} else {
|
||||||
b1 = a1.lerp(a2, (t - t0)/(t2 - t0), new Vector3f());
|
b1 = a1.lerp(a2, (t - t0)/(t2 - t0), new Vector3d());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f b2;
|
Vector3d b2;
|
||||||
if (t1 == t3) {
|
if (t1 == t3) {
|
||||||
b2 = a2.lerp(a3, 0.5f, new Vector3f());
|
b2 = a2.lerp(a3, 0.5f, new Vector3d());
|
||||||
} else {
|
} else {
|
||||||
b2 = a2.lerp(a3, (t - t1)/(t3 - t1), new Vector3f());
|
b2 = a2.lerp(a3, (t - t1)/(t3 - t1), new Vector3d());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t1 == t2) {
|
if (t1 == t2) {
|
||||||
return b1.lerp(b2, 0.5f, new Vector3f());
|
return b1.lerp(b2, 0.5f, new Vector3d());
|
||||||
} else {
|
} else {
|
||||||
return b1.lerp(b2, (t - t1)/(t2 - t1), new Vector3f());
|
return b1.lerp(b2, (t - t1)/(t2 - t1), new Vector3d());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float rotationCentripetalTj(Quaternionf p1, Quaternionf p2) {
|
private static double rotationCentripetalTj(Quaterniond p1, Quaterniond p2) {
|
||||||
Quaternionf delta = p1.invert(new Quaternionf()).mul(p2);
|
Quaterniond delta = p1.invert(new Quaterniond()).mul(p2);
|
||||||
|
|
||||||
float lengthSq = delta.x*delta.x + delta.y*delta.y + delta.z*delta.z;
|
double lengthSq = delta.x*delta.x + delta.y*delta.y + delta.z*delta.z;
|
||||||
float length = (float) Math.sqrt(lengthSq);
|
double length = Math.sqrt(lengthSq);
|
||||||
|
|
||||||
float angleBetween = (float) Math.abs(2 * Math.atan2(length, delta.w));
|
double angleBetween = Math.abs(2 * Math.atan2(length, delta.w));
|
||||||
angleBetween = (float) Math.max(0, Math.min(Math.PI, angleBetween));
|
angleBetween = Math.max(0, Math.min(Math.PI, angleBetween));
|
||||||
return (float) Math.pow(angleBetween, 0.5f);
|
return Math.pow(angleBetween, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Quaternionf rotation(Quaternionf p0, Quaternionf p1, Quaternionf p2, Quaternionf p3, float time1, float time2, float time3, float amount) {
|
public static Quaterniond rotation(Quaterniond p0, Quaterniond p1, Quaterniond p2, Quaterniond p3, float time1, float time2, float time3, float amount) {
|
||||||
float tj1 = rotationCentripetalTj(p0, p1);
|
double tj1 = rotationCentripetalTj(p0, p1);
|
||||||
float tj2 = rotationCentripetalTj(p1, p2);
|
double tj2 = rotationCentripetalTj(p1, p2);
|
||||||
float tj3 = rotationCentripetalTj(p2, p3);
|
double tj3 = rotationCentripetalTj(p2, p3);
|
||||||
float averageTj = (tj1 + tj2 + tj3) / 3f;
|
double averageTj = (tj1 + tj2 + tj3) / 3f;
|
||||||
|
|
||||||
if (averageTj == 0.0) {
|
if (averageTj == 0.0) {
|
||||||
return new Quaternionf(p1);
|
return new Quaterniond(p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float averageTime = time3 / 3f;
|
double averageTime = time3 / 3f;
|
||||||
float relation = averageTime / averageTj;
|
double relation = averageTime / averageTj;
|
||||||
|
|
||||||
float deltaTime1 = 0.0f;
|
double deltaTime1 = 0.0f;
|
||||||
if (time1 > 0.0f) {
|
if (time1 > 0.0f) {
|
||||||
float factor1 = (tj1 * relation) / time1;
|
double factor1 = (tj1 * relation) / time1;
|
||||||
factor1 = Math.max(0.4f, Math.min(2.5f, factor1));
|
factor1 = Math.max(0.4f, Math.min(2.5f, factor1));
|
||||||
deltaTime1 = (tj1 * relation) / factor1;
|
deltaTime1 = (tj1 * relation) / factor1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float deltaTime2 = 0.0f;
|
double deltaTime2 = 0.0f;
|
||||||
if (time2 - time1 > 0.0f) {
|
if (time2 - time1 > 0.0f) {
|
||||||
float factor2 = (tj2 * relation) / (time2 - time1);
|
double factor2 = (tj2 * relation) / (time2 - time1);
|
||||||
factor2 = Math.max(0.4f, Math.min(2.5f, factor2));
|
factor2 = Math.max(0.4f, Math.min(2.5f, factor2));
|
||||||
deltaTime2 = (tj2 * relation) / factor2;
|
deltaTime2 = (tj2 * relation) / factor2;
|
||||||
}
|
}
|
||||||
|
|
||||||
float deltaTime3 = 0.0f;
|
double deltaTime3 = 0.0f;
|
||||||
if (time3 - time2 > 0.0f) {
|
if (time3 - time2 > 0.0f) {
|
||||||
float factor3 = (tj3 * relation) / (time3 - time2);
|
double factor3 = (tj3 * relation) / (time3 - time2);
|
||||||
factor3 = Math.max(0.4f, Math.min(2.5f, factor3));
|
factor3 = Math.max(0.4f, Math.min(2.5f, factor3));
|
||||||
deltaTime3 = (tj3 * relation) / factor3;
|
deltaTime3 = (tj3 * relation) / factor3;
|
||||||
}
|
}
|
||||||
|
|
||||||
float t0 = 0;
|
double t0 = 0;
|
||||||
float t1 = t0 + deltaTime1;
|
double t1 = t0 + deltaTime1;
|
||||||
float t2 = t1 + deltaTime2;
|
double t2 = t1 + deltaTime2;
|
||||||
float t3 = t2 + deltaTime3;
|
double t3 = t2 + deltaTime3;
|
||||||
|
|
||||||
float t = t1 + (t2 - t1) * amount;
|
double t = t1 + (t2 - t1) * amount;
|
||||||
|
|
||||||
Quaternionf a1;
|
Quaterniond a1;
|
||||||
if (t0 == t1) {
|
if (t0 == t1) {
|
||||||
a1 = p0.nlerp(p1, 0.5f, new Quaternionf()).normalize();
|
a1 = p0.nlerp(p1, 0.5f, new Quaterniond()).normalize();
|
||||||
} else {
|
} else {
|
||||||
a1 = p0.nlerp(p1, (t - t0)/(t1 - t0), new Quaternionf()).normalize();
|
a1 = p0.nlerp(p1, (t - t0)/(t1 - t0), new Quaterniond()).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternionf a2;
|
Quaterniond a2;
|
||||||
if (t1 == t2) {
|
if (t1 == t2) {
|
||||||
a2 = p1.nlerp(p2, 0.5f, new Quaternionf()).normalize();
|
a2 = p1.nlerp(p2, 0.5f, new Quaterniond()).normalize();
|
||||||
} else {
|
} else {
|
||||||
a2 = p1.nlerp(p2, (t - t1)/(t2 - t1), new Quaternionf()).normalize();
|
a2 = p1.nlerp(p2, (t - t1)/(t2 - t1), new Quaterniond()).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternionf a3;
|
Quaterniond a3;
|
||||||
if (t2 == t3) {
|
if (t2 == t3) {
|
||||||
a3 = p2.nlerp(p3, 0.5f, new Quaternionf()).normalize();
|
a3 = p2.nlerp(p3, 0.5f, new Quaterniond()).normalize();
|
||||||
} else {
|
} else {
|
||||||
a3 = p2.nlerp(p3, (t - t2)/(t3 - t2), new Quaternionf()).normalize();
|
a3 = p2.nlerp(p3, (t - t2)/(t3 - t2), new Quaterniond()).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternionf b1;
|
Quaterniond b1;
|
||||||
if (t0 == t2) {
|
if (t0 == t2) {
|
||||||
b1 = a1.nlerp(a2, 0.5f, new Quaternionf()).normalize();
|
b1 = a1.nlerp(a2, 0.5f, new Quaterniond()).normalize();
|
||||||
} else {
|
} else {
|
||||||
b1 = a1.nlerp(a2, (t - t0)/(t2 - t0), new Quaternionf()).normalize();
|
b1 = a1.nlerp(a2, (t - t0)/(t2 - t0), new Quaterniond()).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternionf b2;
|
Quaterniond b2;
|
||||||
if (t1 == t3) {
|
if (t1 == t3) {
|
||||||
b2 = a2.nlerp(a3, 0.5f, new Quaternionf()).normalize();
|
b2 = a2.nlerp(a3, 0.5f, new Quaterniond()).normalize();
|
||||||
} else {
|
} else {
|
||||||
b2 = a2.nlerp(a3, (t - t1)/(t3 - t1), new Quaternionf()).normalize();
|
b2 = a2.nlerp(a3, (t - t1)/(t3 - t1), new Quaterniond()).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t1 == t2) {
|
if (t1 == t2) {
|
||||||
return b1.nlerp(b2, 0.5f, new Quaternionf()).normalize();
|
return b1.nlerp(b2, 0.5f, new Quaterniond()).normalize();
|
||||||
} else {
|
} else {
|
||||||
return b1.nlerp(b2, (t - t1)/(t2 - t1), new Quaternionf()).normalize();
|
return b1.nlerp(b2, (t - t1)/(t2 - t1), new Quaterniond()).normalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.moulberry.flashback.FlashbackGson;
|
|||||||
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.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
||||||
import com.moulberry.flashback.visuals.ReplayVisuals;
|
import com.moulberry.flashback.visuals.ReplayVisuals;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ public class EditorState {
|
|||||||
public int exportEndTicks = -1;
|
public int exportEndTicks = -1;
|
||||||
|
|
||||||
public UUID audioSourceEntity = null;
|
public UUID audioSourceEntity = null;
|
||||||
|
public Set<UUID> hideDuringExport = new HashSet<>();
|
||||||
|
|
||||||
public void setKeyframe(int trackIndex, int tick, Keyframe keyframe) {
|
public void setKeyframe(int trackIndex, int tick, Keyframe keyframe) {
|
||||||
if (trackIndex >= this.keyframeTracks.size()) {
|
if (trackIndex >= this.keyframeTracks.size()) {
|
||||||
@@ -146,14 +149,14 @@ public class EditorState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void applyKeyframes(KeyframeHandler keyframeHandler, float tick) {
|
public void applyKeyframes(KeyframeHandler keyframeHandler, float tick) {
|
||||||
EnumSet<KeyframeType> applied = EnumSet.noneOf(KeyframeType.class);
|
Set<KeyframeType<?>> applied = new HashSet<>();
|
||||||
for (KeyframeTrack keyframeTrack : this.keyframeTracks) {
|
for (KeyframeTrack keyframeTrack : this.keyframeTracks) {
|
||||||
// Ignore lines that are disabled
|
// Ignore lines that are disabled
|
||||||
if (!keyframeTrack.enabled) {
|
if (!keyframeTrack.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyframeType baseType = keyframeTrack.keyframeType == KeyframeType.CAMERA_ORBIT ? KeyframeType.CAMERA : keyframeTrack.keyframeType;
|
KeyframeType<?> baseType = keyframeTrack.keyframeType == CameraOrbitKeyframeType.INSTANCE ? CameraKeyframeType.INSTANCE : keyframeTrack.keyframeType;
|
||||||
|
|
||||||
// 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(baseType)) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public interface EditorStateHistoryAction {
|
|||||||
|
|
||||||
void apply(EditorState editorState);
|
void apply(EditorState editorState);
|
||||||
|
|
||||||
record SetKeyframe(KeyframeType type, int trackIndex, int tick, Keyframe keyframe) implements EditorStateHistoryAction {
|
record SetKeyframe(KeyframeType<?> type, int trackIndex, int tick, Keyframe keyframe) implements EditorStateHistoryAction {
|
||||||
@Override
|
@Override
|
||||||
public void apply(EditorState editorState) {
|
public void apply(EditorState editorState) {
|
||||||
if (this.trackIndex < editorState.keyframeTracks.size()) {
|
if (this.trackIndex < editorState.keyframeTracks.size()) {
|
||||||
@@ -31,7 +31,7 @@ public interface EditorStateHistoryAction {
|
|||||||
@Override
|
@Override
|
||||||
public SetKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public SetKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
KeyframeType type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
KeyframeType<?> type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
||||||
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
||||||
int tick = jsonObject.get("tick").getAsInt();
|
int tick = jsonObject.get("tick").getAsInt();
|
||||||
Keyframe keyframe = context.deserialize(jsonObject.get("keyframe"), Keyframe.class);
|
Keyframe keyframe = context.deserialize(jsonObject.get("keyframe"), Keyframe.class);
|
||||||
@@ -51,7 +51,7 @@ public interface EditorStateHistoryAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
record RemoveKeyframe(KeyframeType type, int trackIndex, int tick) implements EditorStateHistoryAction {
|
record RemoveKeyframe(KeyframeType<?> type, int trackIndex, int tick) implements EditorStateHistoryAction {
|
||||||
@Override
|
@Override
|
||||||
public void apply(EditorState editorState) {
|
public void apply(EditorState editorState) {
|
||||||
if (this.trackIndex < editorState.keyframeTracks.size()) {
|
if (this.trackIndex < editorState.keyframeTracks.size()) {
|
||||||
@@ -66,7 +66,7 @@ public interface EditorStateHistoryAction {
|
|||||||
@Override
|
@Override
|
||||||
public RemoveKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public RemoveKeyframe deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
KeyframeType type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
KeyframeType<?> type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
||||||
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
||||||
int tick = jsonObject.get("tick").getAsInt();
|
int tick = jsonObject.get("tick").getAsInt();
|
||||||
return new RemoveKeyframe(type, trackIndex, tick);
|
return new RemoveKeyframe(type, trackIndex, tick);
|
||||||
@@ -84,7 +84,7 @@ public interface EditorStateHistoryAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
record AddTrack(KeyframeType type, int trackIndex) implements EditorStateHistoryAction {
|
record AddTrack(KeyframeType<?> type, int trackIndex) implements EditorStateHistoryAction {
|
||||||
@Override
|
@Override
|
||||||
public void apply(EditorState editorState) {
|
public void apply(EditorState editorState) {
|
||||||
if (this.trackIndex <= editorState.keyframeTracks.size()) {
|
if (this.trackIndex <= editorState.keyframeTracks.size()) {
|
||||||
@@ -96,7 +96,7 @@ public interface EditorStateHistoryAction {
|
|||||||
@Override
|
@Override
|
||||||
public AddTrack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public AddTrack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
KeyframeType type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
KeyframeType<?> type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
||||||
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
||||||
return new AddTrack(type, trackIndex);
|
return new AddTrack(type, trackIndex);
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ public interface EditorStateHistoryAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
record RemoveTrack(KeyframeType type, int trackIndex) implements EditorStateHistoryAction {
|
record RemoveTrack(KeyframeType<?> type, int trackIndex) implements EditorStateHistoryAction {
|
||||||
@Override
|
@Override
|
||||||
public void apply(EditorState editorState) {
|
public void apply(EditorState editorState) {
|
||||||
if (this.trackIndex < editorState.keyframeTracks.size()) {
|
if (this.trackIndex < editorState.keyframeTracks.size()) {
|
||||||
@@ -127,7 +127,7 @@ public interface EditorStateHistoryAction {
|
|||||||
@Override
|
@Override
|
||||||
public RemoveTrack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public RemoveTrack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
KeyframeType type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
KeyframeType<?> type = context.deserialize(jsonObject.get("keyframe_type"), KeyframeType.class);
|
||||||
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
int trackIndex = jsonObject.get("trackIndex").getAsInt();
|
||||||
return new RemoveTrack(type, trackIndex);
|
return new RemoveTrack(type, trackIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
package com.moulberry.flashback.state;
|
package com.moulberry.flashback.state;
|
||||||
|
|
||||||
import com.moulberry.flashback.Flashback;
|
|
||||||
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.handler.KeyframeHandler;
|
|
||||||
import com.moulberry.flashback.keyframe.KeyframeType;
|
import com.moulberry.flashback.keyframe.KeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
|
||||||
|
import com.moulberry.flashback.keyframe.handler.ReplayServerKeyframeHandler;
|
||||||
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 java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class KeyframeTrack {
|
public class KeyframeTrack {
|
||||||
|
|
||||||
public final KeyframeType keyframeType;
|
public final KeyframeType<?> keyframeType;
|
||||||
public TreeMap<Integer, Keyframe> keyframesByTick = new TreeMap<>();
|
public TreeMap<Integer, Keyframe> keyframesByTick = new TreeMap<>();
|
||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
|
|
||||||
public KeyframeTrack(KeyframeType keyframeType) {
|
public KeyframeTrack(KeyframeType<?> keyframeType) {
|
||||||
this.keyframeType = keyframeType;
|
this.keyframeType = keyframeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ public class KeyframeTrack {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.keyframeType == KeyframeType.TIMELAPSE) {
|
if (this.keyframeType == TimelapseKeyframeType.INSTANCE) {
|
||||||
return this.tryApplyKeyframesTimelapse(t, tick);
|
return this.tryApplyKeyframesTimelapse(t, tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ 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.handler.KeyframeHandler;
|
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
|
||||||
|
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.CameraOrbitKeyframeType;
|
||||||
|
import com.moulberry.flashback.keyframe.types.FOVKeyframeType;
|
||||||
import com.moulberry.flashback.playback.ReplayServer;
|
import com.moulberry.flashback.playback.ReplayServer;
|
||||||
import com.moulberry.flashback.state.EditorState;
|
import com.moulberry.flashback.state.EditorState;
|
||||||
import com.moulberry.flashback.state.EditorStateManager;
|
import com.moulberry.flashback.state.EditorStateManager;
|
||||||
@@ -24,21 +27,29 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class CameraPath {
|
public class CameraPath {
|
||||||
|
|
||||||
private static VertexBuffer cameraPathVertexBuffer = null;
|
private static VertexBuffer cameraPathVertexBuffer = null;
|
||||||
private static CameraPathArgs lastCameraPathArgs = null;
|
private static CameraPathArgs lastCameraPathArgs = null;
|
||||||
|
private static Vector3d basePosition = null;
|
||||||
private static int lastEditorStateModCount = 0;
|
private static int lastEditorStateModCount = 0;
|
||||||
private static int lastCursorTick = 0;
|
private static int lastCursorTick = 0;
|
||||||
|
|
||||||
public static void renderCameraPath(PoseStack poseStack, Camera camera, ReplayServer replayServer) {
|
public static void renderCameraPath(PoseStack poseStack, Camera camera, ReplayServer replayServer) {
|
||||||
RenderSystem.assertOnRenderThread();
|
RenderSystem.assertOnRenderThread();
|
||||||
|
|
||||||
|
if (Minecraft.getInstance().options.hideGui) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
EditorState state = replayServer.getEditorState();
|
EditorState state = replayServer.getEditorState();
|
||||||
int replayTick = TimelineWindow.getCursorTick();
|
int replayTick = TimelineWindow.getCursorTick();
|
||||||
|
|
||||||
@@ -49,7 +60,8 @@ public class CameraPath {
|
|||||||
lastCameraPathArgs = cameraPathArgs;
|
lastCameraPathArgs = cameraPathArgs;
|
||||||
|
|
||||||
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
|
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
|
||||||
buildCameraPath(state, cameraPathArgs, bufferBuilder);
|
Vector3d basePosition = new Vector3d(camera.getPosition().x, camera.getPosition().y, camera.getPosition().z);
|
||||||
|
buildCameraPath(state, basePosition.mul(-1, new Vector3d()), cameraPathArgs, bufferBuilder);
|
||||||
|
|
||||||
if (cameraPathVertexBuffer != null) {
|
if (cameraPathVertexBuffer != null) {
|
||||||
cameraPathVertexBuffer.close();
|
cameraPathVertexBuffer.close();
|
||||||
@@ -58,6 +70,7 @@ public class CameraPath {
|
|||||||
|
|
||||||
MeshData meshData = bufferBuilder.build();
|
MeshData meshData = bufferBuilder.build();
|
||||||
if (meshData != null) {
|
if (meshData != null) {
|
||||||
|
CameraPath.basePosition = basePosition;
|
||||||
cameraPathVertexBuffer = new VertexBuffer(VertexBuffer.Usage.STATIC);
|
cameraPathVertexBuffer = new VertexBuffer(VertexBuffer.Usage.STATIC);
|
||||||
cameraPathVertexBuffer.bind();
|
cameraPathVertexBuffer.bind();
|
||||||
cameraPathVertexBuffer.upload(meshData);
|
cameraPathVertexBuffer.upload(meshData);
|
||||||
@@ -83,8 +96,8 @@ public class CameraPath {
|
|||||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
||||||
|
|
||||||
poseStack.pushPose();
|
poseStack.pushPose();
|
||||||
poseStack.translate(-camera.getPosition().x,
|
poseStack.translate(basePosition.x-camera.getPosition().x,
|
||||||
-camera.getPosition().y + camera.eyeHeight, -camera.getPosition().z);
|
basePosition.y-camera.getPosition().y + camera.eyeHeight, basePosition.z-camera.getPosition().z);
|
||||||
|
|
||||||
cameraPathVertexBuffer.bind();
|
cameraPathVertexBuffer.bind();
|
||||||
cameraPathVertexBuffer.drawWithShader(poseStack.last().pose(), RenderSystem.getProjectionMatrix(), GameRenderer.getRendertypeLinesShader());
|
cameraPathVertexBuffer.drawWithShader(poseStack.last().pose(), RenderSystem.getProjectionMatrix(), GameRenderer.getRendertypeLinesShader());
|
||||||
@@ -99,7 +112,8 @@ public class CameraPath {
|
|||||||
state.applyKeyframes(fovHandler, replayTick);
|
state.applyKeyframes(fovHandler, replayTick);
|
||||||
if (handler.position != null) {
|
if (handler.position != null) {
|
||||||
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
|
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
|
||||||
renderCamera(bufferBuilder, handler.position, handler.angle, fovHandler.fov, getCameraColour(false, true), 1.0f);
|
renderCamera(bufferBuilder, handler.position.sub(basePosition, new Vector3d()), handler.angle, fovHandler.fov,
|
||||||
|
getCameraColour(false, true), 1.0f);
|
||||||
|
|
||||||
var oldModelViewMatrix = new Matrix4f(RenderSystem.getModelViewMatrix());
|
var oldModelViewMatrix = new Matrix4f(RenderSystem.getModelViewMatrix());
|
||||||
RenderSystem.getModelViewMatrix().set(poseStack.last().pose());
|
RenderSystem.getModelViewMatrix().set(poseStack.last().pose());
|
||||||
@@ -116,7 +130,7 @@ 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(EditorState state, int replayTick, EnumSet<KeyframeType> supportedKeyframes) {
|
private static CameraPathArgs createCameraPathArgs(EditorState state, int replayTick, Set<KeyframeType<?>> supportedKeyframes) {
|
||||||
int lastCameraTick = -1;
|
int lastCameraTick = -1;
|
||||||
int nextCameraTick = -1;
|
int nextCameraTick = -1;
|
||||||
|
|
||||||
@@ -160,7 +174,7 @@ public class CameraPath {
|
|||||||
return new CameraPathArgs(lastLastCameraTick, lastCameraTick, nextCameraTick, nextNextCameraTick);
|
return new CameraPathArgs(lastLastCameraTick, lastCameraTick, nextCameraTick, nextNextCameraTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCameraPath(EditorState state, CameraPathArgs args, BufferBuilder bufferBuilder) {
|
private static void buildCameraPath(EditorState state, Vector3d offset, CameraPathArgs args, BufferBuilder bufferBuilder) {
|
||||||
var handler = new CapturingKeyframeHandler();
|
var handler = new CapturingKeyframeHandler();
|
||||||
var fovHandler = new FovCapturingKeyframeHandler();
|
var fovHandler = new FovCapturingKeyframeHandler();
|
||||||
float defaultFov = Minecraft.getInstance().options.fov().get();
|
float defaultFov = Minecraft.getInstance().options.fov().get();
|
||||||
@@ -170,7 +184,7 @@ public class CameraPath {
|
|||||||
state.applyKeyframes(handler, args.lastCameraTick);
|
state.applyKeyframes(handler, args.lastCameraTick);
|
||||||
state.applyKeyframes(fovHandler, args.lastCameraTick);
|
state.applyKeyframes(fovHandler, args.lastCameraTick);
|
||||||
|
|
||||||
renderCamera(bufferBuilder, handler.position, handler.angle, fovHandler.fov,
|
renderCamera(bufferBuilder, handler.position.add(offset, new Vector3d()), handler.angle, fovHandler.fov,
|
||||||
getCameraColour(false, false), 1.0f);
|
getCameraColour(false, false), 1.0f);
|
||||||
|
|
||||||
if (args.lastLastCameraTick != -1) {
|
if (args.lastLastCameraTick != -1) {
|
||||||
@@ -178,9 +192,9 @@ public class CameraPath {
|
|||||||
state.applyKeyframes(handler, args.lastLastCameraTick);
|
state.applyKeyframes(handler, args.lastLastCameraTick);
|
||||||
state.applyKeyframes(fovHandler, args.lastLastCameraTick);
|
state.applyKeyframes(fovHandler, args.lastLastCameraTick);
|
||||||
|
|
||||||
renderCamera(bufferBuilder, handler.position, handler.angle, fovHandler.fov,
|
renderCamera(bufferBuilder, handler.position.add(offset, new Vector3d()), handler.angle, fovHandler.fov,
|
||||||
getCameraColour(false, false), 0.6f);
|
getCameraColour(false, false), 0.6f);
|
||||||
renderPath(bufferBuilder, args.lastLastCameraTick, args.lastCameraTick, state, handler, 0.6f);
|
renderPath(bufferBuilder, args.lastLastCameraTick, args.lastCameraTick, state, offset, handler, 0.6f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +203,7 @@ public class CameraPath {
|
|||||||
state.applyKeyframes(handler, args.nextCameraTick);
|
state.applyKeyframes(handler, args.nextCameraTick);
|
||||||
state.applyKeyframes(fovHandler, args.nextCameraTick);
|
state.applyKeyframes(fovHandler, args.nextCameraTick);
|
||||||
|
|
||||||
renderCamera(bufferBuilder, handler.position, handler.angle, fovHandler.fov,
|
renderCamera(bufferBuilder, handler.position.add(offset, new Vector3d()), handler.angle, fovHandler.fov,
|
||||||
getCameraColour(false, false), 1.0f);
|
getCameraColour(false, false), 1.0f);
|
||||||
|
|
||||||
if (args.nextNextCameraTick != -1) {
|
if (args.nextNextCameraTick != -1) {
|
||||||
@@ -197,14 +211,14 @@ public class CameraPath {
|
|||||||
state.applyKeyframes(handler, args.nextNextCameraTick);
|
state.applyKeyframes(handler, args.nextNextCameraTick);
|
||||||
state.applyKeyframes(fovHandler, args.nextNextCameraTick);
|
state.applyKeyframes(fovHandler, args.nextNextCameraTick);
|
||||||
|
|
||||||
renderCamera(bufferBuilder, handler.position, handler.angle, fovHandler.fov,
|
renderCamera(bufferBuilder, handler.position.add(offset, new Vector3d()), handler.angle, fovHandler.fov,
|
||||||
getCameraColour(false, false), 0.6f);
|
getCameraColour(false, false), 0.6f);
|
||||||
renderPath(bufferBuilder, args.nextCameraTick, args.nextNextCameraTick, state, handler, 0.6f);
|
renderPath(bufferBuilder, args.nextCameraTick, args.nextNextCameraTick, state, offset, handler, 0.6f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.lastCameraTick != -1 && args.nextCameraTick != -1) {
|
if (args.lastCameraTick != -1 && args.nextCameraTick != -1) {
|
||||||
renderPath(bufferBuilder, args.lastCameraTick, args.nextCameraTick, state, handler, 1.0f);
|
renderPath(bufferBuilder, args.lastCameraTick, args.nextCameraTick, state, offset, handler, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,32 +233,28 @@ public class CameraPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void renderPath(BufferBuilder bufferBuilder, int fromTick, int toTick,
|
private static void renderPath(BufferBuilder bufferBuilder, int fromTick, int toTick,
|
||||||
EditorState editorState, CapturingKeyframeHandler handler, float opacity) {
|
EditorState editorState, Vector3d offset, CapturingKeyframeHandler handler, float opacity) {
|
||||||
Vector3f lastPosition = null;
|
Vector3d lastPosition = null;
|
||||||
|
|
||||||
int step = (toTick - fromTick) / 2000 + 1;
|
int step = (toTick - fromTick) / 2000 + 1;
|
||||||
|
|
||||||
for (int tick = fromTick; tick <= toTick; tick += step) {
|
for (int tick = fromTick; tick <= toTick; tick += step) {
|
||||||
editorState.applyKeyframes(handler, tick);
|
editorState.applyKeyframes(handler, tick);
|
||||||
Vector3f rawPosition = new Vector3f(handler.position);
|
Vector3d position = handler.position.add(offset, new Vector3d());
|
||||||
|
|
||||||
double x = rawPosition.x;
|
|
||||||
double y = rawPosition.y;
|
|
||||||
double z = rawPosition.z;
|
|
||||||
|
|
||||||
Vector3f position = new Vector3f((float) x, (float) y, (float) z);
|
|
||||||
|
|
||||||
if (lastPosition != null) {
|
if (lastPosition != null) {
|
||||||
float dx = position.x - lastPosition.x;
|
double dx = position.x - lastPosition.x;
|
||||||
float dy = position.y - lastPosition.y;
|
double dy = position.y - lastPosition.y;
|
||||||
float dz = position.z - lastPosition.z;
|
double dz = position.z - lastPosition.z;
|
||||||
float distanceInv = 1f / (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
|
float distanceInv = 1f / (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||||
dx *= distanceInv;
|
dx *= distanceInv;
|
||||||
dy *= distanceInv;
|
dy *= distanceInv;
|
||||||
dz *= distanceInv;
|
dz *= distanceInv;
|
||||||
|
|
||||||
bufferBuilder.addVertex(lastPosition.x, lastPosition.y, lastPosition.z).setColor(1.0f, 1.0f, 0.1f, 0.0f).setNormal(dx, dy, dz);
|
bufferBuilder.addVertex((float) lastPosition.x, (float) lastPosition.y, (float) lastPosition.z).setColor(1.0f, 1.0f, 0.1f, 0.0f)
|
||||||
bufferBuilder.addVertex( position.x, position.y, position.z).setColor(1.0f, 1.0f, 0.1f, opacity).setNormal(dx, dy, dz);
|
.setNormal((float) dx, (float) dy, (float) dz);
|
||||||
|
bufferBuilder.addVertex((float) position.x, (float) position.y, (float) position.z).setColor(1.0f, 1.0f, 0.1f, opacity)
|
||||||
|
.setNormal((float) dx, (float) dy, (float) dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPosition = position;
|
lastPosition = position;
|
||||||
@@ -252,10 +262,10 @@ public class CameraPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final PoseStack cameraPoseStack = new PoseStack();
|
private static final PoseStack cameraPoseStack = new PoseStack();
|
||||||
private static void renderCamera(BufferBuilder bufferBuilder, Vector3f position, Quaternionf angle, float fov, int rgb, float opacity) {
|
private static void renderCamera(BufferBuilder bufferBuilder, Vector3d position, Quaterniond angle, float fov, int rgb, float opacity) {
|
||||||
cameraPoseStack.pushPose();
|
cameraPoseStack.pushPose();
|
||||||
cameraPoseStack.translate(position.x, position.y, position.z);
|
cameraPoseStack.translate(position.x, position.y, position.z);
|
||||||
cameraPoseStack.mulPose(angle);
|
cameraPoseStack.mulPose(new Quaternionf(angle));
|
||||||
|
|
||||||
PoseStack.Pose pose = cameraPoseStack.last();
|
PoseStack.Pose pose = cameraPoseStack.last();
|
||||||
|
|
||||||
@@ -294,14 +304,14 @@ public class CameraPath {
|
|||||||
cameraPoseStack.popPose();
|
cameraPoseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final EnumSet<KeyframeType> SUPPORTED_CAMERA_KEYFRAMES = EnumSet.of(KeyframeType.CAMERA, KeyframeType.CAMERA_ORBIT);
|
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 Vector3f position;
|
private Vector3d position;
|
||||||
private Quaternionf angle;
|
private Quaterniond angle;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<KeyframeType> supportedKeyframes() {
|
public Set<KeyframeType<?>> supportedKeyframes() {
|
||||||
return SUPPORTED_CAMERA_KEYFRAMES;
|
return SUPPORTED_CAMERA_KEYFRAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,9 +321,9 @@ public class CameraPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyCameraPosition(Vector3f position, float yaw, float pitch, float roll) {
|
public void applyCameraPosition(Vector3d position, double yaw, double pitch, double roll) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.angle = new Quaternionf().rotationYXZ((float) -Math.toRadians(yaw), (float) Math.toRadians(pitch), (float) -Math.toRadians(roll));
|
this.angle = new Quaterniond().rotationYXZ((float) -Math.toRadians(yaw), (float) Math.toRadians(pitch), (float) -Math.toRadians(roll));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,8 +331,8 @@ public class CameraPath {
|
|||||||
private float fov;
|
private float fov;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<KeyframeType> supportedKeyframes() {
|
public Set<KeyframeType<?>> supportedKeyframes() {
|
||||||
return EnumSet.of(KeyframeType.FOV);
|
return Set.of(FOVKeyframeType.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.moulberry.flashback.visuals;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||||
|
import com.moulberry.flashback.Flashback;
|
||||||
|
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||||
|
import net.fabricmc.fabric.impl.client.rendering.FabricShaderProgram;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.ShaderInstance;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ShaderManager implements SimpleSynchronousResourceReloadListener {
|
||||||
|
|
||||||
|
public static final ShaderManager INSTANCE = new ShaderManager();
|
||||||
|
|
||||||
|
public static ShaderInstance blitScreenRoundAlpha;
|
||||||
|
public static ShaderInstance blitScreenFlip;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getFabricId() {
|
||||||
|
return ResourceLocation.parse("flashback:shaders");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResourceManagerReload(ResourceManager resourceManager) {
|
||||||
|
Flashback.LOGGER.info("Reloading shaders...");
|
||||||
|
|
||||||
|
if (blitScreenRoundAlpha != null) {
|
||||||
|
blitScreenRoundAlpha.close();
|
||||||
|
blitScreenRoundAlpha = null;
|
||||||
|
}
|
||||||
|
if (blitScreenFlip != null) {
|
||||||
|
blitScreenFlip.close();
|
||||||
|
blitScreenFlip = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
blitScreenRoundAlpha = new FabricShaderProgram(Minecraft.getInstance().getResourceManager(),
|
||||||
|
ResourceLocation.parse("flashback:blit_screen_round_alpha"), DefaultVertexFormat.BLIT_SCREEN);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Flashback.LOGGER.error("Failed to load flashback:blit_screen_round_alpha shader", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
blitScreenFlip = new FabricShaderProgram(Minecraft.getInstance().getResourceManager(),
|
||||||
|
ResourceLocation.parse("flashback:blit_screen_flip"), DefaultVertexFormat.BLIT_SCREEN);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Flashback.LOGGER.error("Failed to load flashback:blit_screen_flip shader", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 271 B |
Binary file not shown.
|
Before Width: | Height: | Size: 576 B |
Binary file not shown.
|
Before Width: | Height: | Size: 882 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 211 B |
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"vertex": "blit_screen_flip",
|
"vertex": "flashback:blit_screen_flip",
|
||||||
"fragment": "blit_screen",
|
"fragment": "blit_screen",
|
||||||
"samplers": [
|
"samplers": [
|
||||||
{ "name": "DiffuseSampler" }
|
{ "name": "DiffuseSampler" }
|
||||||
File renamed without changes.
@@ -0,0 +1,13 @@
|
|||||||
|
#version 150
|
||||||
|
|
||||||
|
uniform sampler2D DiffuseSampler;
|
||||||
|
|
||||||
|
in vec2 texCoord;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 color = texture(DiffuseSampler, texCoord);
|
||||||
|
color.a = round(color.a);
|
||||||
|
fragColor = color;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"vertex": "flashback:blit_screen_round_alpha",
|
||||||
|
"fragment": "flashback:blit_screen_round_alpha",
|
||||||
|
"samplers": [
|
||||||
|
{ "name": "DiffuseSampler" }
|
||||||
|
],
|
||||||
|
"uniforms": [
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#version 150
|
||||||
|
|
||||||
|
in vec3 Position;
|
||||||
|
|
||||||
|
out vec2 texCoord;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec2 screenPos = Position.xy * 2.0 - 1.0;
|
||||||
|
gl_Position = vec4(screenPos.x, screenPos.y, 1.0, 1.0);
|
||||||
|
texCoord = Position.xy;
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ accessWidener v1 named
|
|||||||
accessible class net/minecraft/client/multiplayer/ClientChunkCache$Storage
|
accessible class net/minecraft/client/multiplayer/ClientChunkCache$Storage
|
||||||
accessible field net/minecraft/client/multiplayer/ClientChunkCache storage Lnet/minecraft/client/multiplayer/ClientChunkCache$Storage;
|
accessible field net/minecraft/client/multiplayer/ClientChunkCache storage Lnet/minecraft/client/multiplayer/ClientChunkCache$Storage;
|
||||||
accessible field net/minecraft/client/multiplayer/ClientChunkCache$Storage chunks Ljava/util/concurrent/atomic/AtomicReferenceArray;
|
accessible field net/minecraft/client/multiplayer/ClientChunkCache$Storage chunks Ljava/util/concurrent/atomic/AtomicReferenceArray;
|
||||||
|
accessible field net/minecraft/world/level/biome/BiomeManager biomeZoomSeed J
|
||||||
|
accessible field net/minecraft/client/multiplayer/ClientLevel mapData Ljava/util/Map;
|
||||||
|
|
||||||
accessible method net/minecraft/tags/TagNetworkSerialization serializeToNetwork (Lnet/minecraft/core/Registry;)Lnet/minecraft/tags/TagNetworkSerialization$NetworkPayload;
|
accessible method net/minecraft/tags/TagNetworkSerialization serializeToNetwork (Lnet/minecraft/core/Registry;)Lnet/minecraft/tags/TagNetworkSerialization$NetworkPayload;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
"visuals.MixinFogRenderer",
|
"visuals.MixinFogRenderer",
|
||||||
"visuals.MixinGui",
|
"visuals.MixinGui",
|
||||||
"visuals.MixinLevelRenderer",
|
"visuals.MixinLevelRenderer",
|
||||||
|
"visuals.MixinLivingEntityRenderer",
|
||||||
"visuals.MixinLoadingOverlay",
|
"visuals.MixinLoadingOverlay",
|
||||||
"visuals.MixinMouseHandler",
|
"visuals.MixinMouseHandler",
|
||||||
"visuals.MixinOptions"
|
"visuals.MixinOptions"
|
||||||
@@ -38,7 +39,10 @@
|
|||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinThreadedLevelLightEngine",
|
"MixinThreadedLevelLightEngine",
|
||||||
"compat.MixinAxiomEditorUI",
|
"compat.MixinAxiomEditorUI",
|
||||||
|
"compat.MixinFabricMinecraftServer",
|
||||||
"compat.MixinSodiumWorldRenderer",
|
"compat.MixinSodiumWorldRenderer",
|
||||||
|
"compat.bobby.FakeChunkManagerAccessor",
|
||||||
|
"compat.bobby.MixinBobbyFakeChunkManager",
|
||||||
"playback.MixinAttributeInstance",
|
"playback.MixinAttributeInstance",
|
||||||
"playback.MixinChunkHolder",
|
"playback.MixinChunkHolder",
|
||||||
"playback.MixinEntity",
|
"playback.MixinEntity",
|
||||||
@@ -57,6 +61,7 @@
|
|||||||
"replay_server.MixinServerConfigurationPacketListenerImpl",
|
"replay_server.MixinServerConfigurationPacketListenerImpl",
|
||||||
"replay_server.MixinServerEntity",
|
"replay_server.MixinServerEntity",
|
||||||
"replay_server.MixinServerGamePacketListenerImpl",
|
"replay_server.MixinServerGamePacketListenerImpl",
|
||||||
|
"replay_server.MixinServerLevel",
|
||||||
"replay_server.MixinServerLoginPacketListenerImpl",
|
"replay_server.MixinServerLoginPacketListenerImpl",
|
||||||
"replay_server.MixinTickRateManager"
|
"replay_server.MixinTickRateManager"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in new issue
Block a user