Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved rotation during export #118

Draft
wants to merge 3 commits into
base: 1.21
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.glisco.isometricrenders.mixin;

import com.glisco.isometricrenders.property.GlobalProperties;
import com.glisco.isometricrenders.screen.RenderScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderTickCounter;
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.ModifyVariable;

@Mixin(RenderTickCounter.Dynamic.class)
public class RenderTickCounterMixin {

@Shadow private long prevTimeMillis;

@ModifyVariable(method = "beginRenderTick(JZ)I", index = 1, argsOnly = true, at = @At("HEAD"))
public long test(long value) {
return MinecraftClient.getInstance().currentScreen instanceof RenderScreen rs && rs.remainingAnimationFrames > 0
? this.prevTimeMillis + (1000L / GlobalProperties.exportFramerate) : value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.glisco.isometricrenders.render.Renderable;
import com.glisco.isometricrenders.screen.IsometricUI;
import com.glisco.isometricrenders.screen.RenderScreen;
import com.glisco.isometricrenders.util.ClientRenderCallback;
import com.glisco.isometricrenders.util.Translate;
import io.wispforest.owo.ui.component.ButtonComponent;
Expand Down Expand Up @@ -75,10 +76,15 @@ public void applyToViewMatrix(Matrix4fStack modelViewStack) {
this.updateAndApplyRotationOffset(modelViewStack);
}

public float rotationOffset() {
public float getRotationOffset() {
return this.rotationOffset;
}

public void setRotationOffset(int offset) {
this.rotationOffset = offset;
this.rotationOffsetUpdated = true;
}

protected void updateAndApplyRotationOffset(Matrix4fStack modelViewStack) {
if (rotationSpeed.get() != 0) {
if (!this.rotationOffsetUpdated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void withParticleCamera(Consumer<Camera> action) {
Camera camera = MinecraftClient.getInstance().getEntityRenderDispatcher().camera;
float previousYaw = camera.getYaw(), previousPitch = camera.getPitch();

((CameraInvoker) camera).isometric$setRotation(this.properties().rotation.get() + 180 + this.properties().rotationOffset(), this.properties().slant.get());
((CameraInvoker) camera).isometric$setRotation(this.properties().rotation.get() + 180 + this.properties().getRotationOffset(), this.properties().slant.get());
action.accept(camera);

((CameraInvoker) camera).isometric$setRotation(previousYaw, previousPitch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class RenderScreen extends BaseOwoScreen<FlowLayout> {
private final FlowLayout rightColumn = Containers.verticalFlow(Sizing.fill(100), Sizing.content());

private final List<Framebuffer> renderedFrames = new ArrayList<>();
private int remainingAnimationFrames;
public int remainingAnimationFrames;

public RenderScreen(Renderable<?> renderable) {
this.renderable = renderable;
Expand Down Expand Up @@ -251,12 +251,17 @@ protected void build(FlowLayout rootComponent) {
framerateField.setTextPredicate(s -> s.matches("\\d*"));
framerateField.setChangedListener(s -> {
if (s.isBlank()) return;
exportFramerate = Integer.parseInt(s);
int rate = Integer.parseInt(s);
if (rate != 0)
exportFramerate = rate;
});

try (var builder = IsometricUI.row(rightColumn)) {
this.exportAnimationButton = Components.button(Translate.gui("export_animation"), button -> {
if (this.memoryGuard.canFit(this.estimateMemoryUsage(exportFrames)) || Screen.hasShiftDown()) {
if (this.renderable.properties() instanceof DefaultPropertyBundle dpb) {
dpb.setRotationOffset(0);
}
this.remainingAnimationFrames = exportFrames;

this.client.getWindow().setFramerateLimit(Integer.parseInt(framerateField.getText()));
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/isometric-renders.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"compatibilityLevel": "JAVA_16",
"plugin": "com.glisco.isometricrenders.mixin.IsometricMixinPlugin",
"client": [
"DrawContextMixin",
"HandledScreenMixin",
"LivingEntityRendererMixin",
"MinecraftClientMixin",
"ParticleManagerMixin",
"DrawContextMixin",
"RenderTickCounterMixin",
"SliderWidgetInvoker",
"TextureManagerMixin",
"WorldRendererMixin",
Expand Down