add FOV feature
This commit is contained in:
@@ -12,6 +12,7 @@ import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
@@ -114,6 +115,7 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
|
||||
if (wasAsyncMode) {
|
||||
replayHandler.getReplaySender().setAsyncMode(true);
|
||||
}
|
||||
FovProperty.currentOverride = null;
|
||||
unregister();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.replaymod.pathing.properties;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.replaystudio.pathing.property.AbstractProperty;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyPart;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyParts;
|
||||
import de.johni0702.minecraft.gui.utils.NonNull;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class FovProperty extends AbstractProperty<Triple<Float, Float, Float>> {
|
||||
public static final float DEFAULT_FOV = 70.0f;
|
||||
|
||||
public static volatile Float currentOverride = null;
|
||||
|
||||
public static final FovProperty FOV = new FovProperty("fov", DEFAULT_FOV);
|
||||
|
||||
public final PropertyPart<Triple<Float, Float, Float>> VALUE =
|
||||
new PropertyParts.ForFloatTriple(this, true, PropertyParts.TripleElement.LEFT);
|
||||
|
||||
private FovProperty(String id, float defaultValue) {
|
||||
super(id, "replaymod.gui.editkeyframe." + id, null, Triple.of(defaultValue, 0f, 0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Triple<Float, Float, Float>>> getParts() {
|
||||
return Collections.singletonList(VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Triple<Float, Float, Float> value, @NonNull Object replayHandler) {
|
||||
currentOverride = value.getLeft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Triple<Float, Float, Float> value) throws IOException {
|
||||
writer.value(value.getLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Float, Float, Float> fromJson(JsonReader reader) throws IOException {
|
||||
return Triple.of((float) reader.nextDouble(), 0f, 0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.replaymod.render.mixin;
|
||||
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public abstract class Mixin_DynamicFov {
|
||||
private static final String METHOD = "getBasicProjectionMatrix";
|
||||
//#if MC>=11903
|
||||
//#if MC>=12005
|
||||
//$$ private static final String TARGET = "Lorg/joml/Matrix4f;perspective(FFFF)Lorg/joml/Matrix4f;";
|
||||
//#else
|
||||
//$$ private static final String TARGET = "Lorg/joml/Matrix4f;setPerspective(FFFF)Lorg/joml/Matrix4f;";
|
||||
//#endif
|
||||
//$$ private static final boolean TARGET_REMAP = false;
|
||||
//#else
|
||||
private static final String TARGET = "Lnet/minecraft/util/math/Matrix4f;viewboxMatrix(DFFF)Lnet/minecraft/util/math/Matrix4f;";
|
||||
private static final boolean TARGET_REMAP = true;
|
||||
//#endif
|
||||
|
||||
@ModifyArg(method = METHOD, at = @At(value = "INVOKE", target = TARGET, remap = TARGET_REMAP), index = 0)
|
||||
//#if MC>=11903
|
||||
//$$ private float replayModRender_dynamicFov(float fovY) {
|
||||
//$$ Float override = FovProperty.currentOverride;
|
||||
//$$ if (override == null) return fovY;
|
||||
//$$ return (float) Math.toRadians(Math.max(1f, Math.min(179f, override)));
|
||||
//$$ }
|
||||
//#else
|
||||
private double replayModRender_dynamicFov(double fovY) {
|
||||
Float override = FovProperty.currentOverride;
|
||||
if (override == null) return fovY;
|
||||
return Math.max(1.0, Math.min(179.0, override));
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.replaymod.pathing.properties.CameraProperties;
|
||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||
import com.replaymod.pathing.properties.TimestampProperty;
|
||||
import com.replaymod.pathing.properties.LensProperties;
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||
import com.replaymod.replaystudio.pathing.change.AddKeyframe;
|
||||
import com.replaymod.replaystudio.pathing.change.Change;
|
||||
@@ -175,6 +176,7 @@ public class SPTimeline implements PathingRegistry {
|
||||
builder.setValue(CameraProperties.ROTATION, Triple.of(yaw, pitch, roll));
|
||||
builder.setValue(LensProperties.FOCAL_DISTANCE, Triple.of(LensProperties.DEFAULT_FOCAL_DISTANCE, 0f, 0f));
|
||||
builder.setValue(LensProperties.APERTURE_RADIUS, Triple.of(LensProperties.DEFAULT_APERTURE_RADIUS, 0f, 0f));
|
||||
builder.setValue(FovProperty.FOV, Triple.of(FovProperty.DEFAULT_FOV, 0f, 0f));
|
||||
if (spectated != -1) {
|
||||
builder.setValue(SpectatorProperty.PROPERTY, spectated);
|
||||
}
|
||||
@@ -322,6 +324,16 @@ public class SPTimeline implements PathingRegistry {
|
||||
return change;
|
||||
}
|
||||
|
||||
public Change updateFov(long time, float fov) {
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exist");
|
||||
Change change = UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(FovProperty.FOV, Triple.of(fov, 0f, 0f))
|
||||
.done();
|
||||
change.apply(timeline);
|
||||
return change;
|
||||
}
|
||||
|
||||
public Change setInterpolatorToDefault(long time) {
|
||||
LOGGER.debug("Setting interpolator of position keyframe at {} to the default", time);
|
||||
|
||||
@@ -468,6 +480,7 @@ public class SPTimeline implements PathingRegistry {
|
||||
interpolator.registerProperty(SpectatorProperty.PROPERTY);
|
||||
interpolator.registerProperty(LensProperties.FOCAL_DISTANCE);
|
||||
interpolator.registerProperty(LensProperties.APERTURE_RADIUS);
|
||||
interpolator.registerProperty(FovProperty.FOV);
|
||||
}
|
||||
// Now that we have an interpolator, set it for the current segment
|
||||
updates.put(segment, interpolator);
|
||||
@@ -588,6 +601,7 @@ public class SPTimeline implements PathingRegistry {
|
||||
interpolator.registerProperty(CameraProperties.ROTATION);
|
||||
interpolator.registerProperty(LensProperties.FOCAL_DISTANCE);
|
||||
interpolator.registerProperty(LensProperties.APERTURE_RADIUS);
|
||||
interpolator.registerProperty(FovProperty.FOV);
|
||||
return interpolator;
|
||||
}
|
||||
|
||||
@@ -612,6 +626,7 @@ public class SPTimeline implements PathingRegistry {
|
||||
timeline.registerProperty(SpectatorProperty.PROPERTY);
|
||||
timeline.registerProperty(LensProperties.FOCAL_DISTANCE);
|
||||
timeline.registerProperty(LensProperties.APERTURE_RADIUS);
|
||||
timeline.registerProperty(FovProperty.FOV);
|
||||
timeline.registerProperty(ExplicitInterpolationProperty.PROPERTY);
|
||||
|
||||
return timeline;
|
||||
|
||||
@@ -152,14 +152,17 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
|
||||
inputs.setLayout(new VerticalLayout().setSpacing(10)).addElements(new VerticalLayout.Data(0.5, false), lensPanel.load(this.keyframe));
|
||||
|
||||
link(lensPanel.focalDistanceField, lensPanel.apertureRadiusField, timeMinField, timeSecField, timeMSecField);
|
||||
link(lensPanel.focalDistanceField, lensPanel.apertureRadiusField, lensPanel.fovField, timeMinField, timeSecField, timeMSecField);
|
||||
|
||||
popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Change save() {
|
||||
return guiPathing.getMod().getCurrentTimeline().updateLensProperties(time, lensPanel.getFocalDistance(), lensPanel.getApertureRadius());
|
||||
SPTimeline timeline = guiPathing.getMod().getCurrentTimeline();
|
||||
Change lensChange = timeline.updateLensProperties(time, lensPanel.getFocalDistance(), lensPanel.getApertureRadius());
|
||||
Change fovChange = timeline.updateFov(time, lensPanel.getFov());
|
||||
return CombinedChange.createFromApplied(lensChange, fovChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -254,7 +257,7 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
|
||||
lensPanel.load(this.keyframe);
|
||||
|
||||
link(xField, yField, zField, yawField, pitchField, rollField, timeMinField, lensPanel.focalDistanceField, lensPanel.apertureRadiusField, timeSecField, timeMSecField);
|
||||
link(xField, yField, zField, yawField, pitchField, rollField, lensPanel.focalDistanceField, lensPanel.apertureRadiusField, lensPanel.fovField, timeMinField, timeSecField, timeMSecField);
|
||||
|
||||
popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
|
||||
}
|
||||
@@ -268,16 +271,17 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
);
|
||||
Change lensChange = timeline.updateLensProperties(time,
|
||||
lensPanel.getFocalDistance(), lensPanel.getApertureRadius());
|
||||
Change fovChange = timeline.updateFov(time, lensPanel.getFov());
|
||||
if (interpolationPanel.getSettingsPanel() == null) {
|
||||
// The last keyframe doesn't have interpolator settings because there is no segment following it
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange);
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange, fovChange);
|
||||
}
|
||||
Interpolator interpolator = interpolationPanel.getSettingsPanel().createInterpolator();
|
||||
if (interpolationPanel.getInterpolatorType() == InterpolatorType.DEFAULT) {
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange,
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange, fovChange,
|
||||
timeline.setInterpolatorToDefault(time), timeline.setDefaultInterpolator(interpolator));
|
||||
} else {
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange,
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange, fovChange,
|
||||
timeline.setInterpolator(time, interpolator));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.replaymod.simplepathing.gui;
|
||||
|
||||
import com.replaymod.pathing.properties.LensProperties;
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
@@ -13,12 +14,15 @@ public class GuiLensKeyframePanel extends AbstractGuiContainer<GuiLensKeyframePa
|
||||
new GuiNumberField().setValidateOnFocusChange(true).setSize(60, 20).setPrecision(3).setMinValue(0);
|
||||
public final GuiNumberField apertureRadiusField =
|
||||
new GuiNumberField().setValidateOnFocusChange(true).setSize(60, 20).setPrecision(4).setMinValue(0);
|
||||
public final GuiNumberField fovField =
|
||||
new GuiNumberField().setValidateOnFocusChange(true).setSize(60, 20).setPrecision(1).setMinValue(1).setMaxValue(179);
|
||||
|
||||
public GuiLensKeyframePanel() {
|
||||
setLayout(new GridLayout().setCellsEqualSize(false).setColumns(2).setSpacingX(3).setSpacingY(5));
|
||||
addElements(new GridLayout.Data(1, 0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.focalDistance"), focalDistanceField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.apertureRadius"), apertureRadiusField);
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.apertureRadius"), apertureRadiusField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.fov"), fovField);
|
||||
}
|
||||
|
||||
public GuiLensKeyframePanel load(Keyframe keyframe) {
|
||||
@@ -26,11 +30,14 @@ public class GuiLensKeyframePanel extends AbstractGuiContainer<GuiLensKeyframePa
|
||||
.map(Triple::getLeft).orElse(LensProperties.DEFAULT_FOCAL_DISTANCE));
|
||||
apertureRadiusField.setValue(keyframe.getValue(LensProperties.APERTURE_RADIUS)
|
||||
.map(Triple::getLeft).orElse(LensProperties.DEFAULT_APERTURE_RADIUS));
|
||||
fovField.setValue(keyframe.getValue(FovProperty.FOV)
|
||||
.map(Triple::getLeft).orElse(FovProperty.DEFAULT_FOV));
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFocalDistance() { return focalDistanceField.getFloat(); }
|
||||
public float getApertureRadius() { return apertureRadiusField.getFloat(); }
|
||||
public float getFov() { return fovField.getFloat(); }
|
||||
|
||||
@Override
|
||||
protected GuiLensKeyframePanel getThis() { return this; }
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"Mixin_Stereoscopic_HandRenderPass",
|
||||
"Mixin_SuppressFramebufferResizeDuringRender",
|
||||
"Mixin_UseGuiFramebufferDuringGuiRendering",
|
||||
"Mixin_DynamicFov",
|
||||
//#if MC>=11600
|
||||
"Mixin_AddIrisOdsShaderUniforms",
|
||||
"Mixin_LoadIrisOdsShaderPack",
|
||||
|
||||
Reference in New Issue
Block a user