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

Added SERIES export option #119

Open
wants to merge 3 commits into
base: 1.21
Choose a base branch
from
Open
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
Expand Up @@ -75,10 +75,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 @@ -257,6 +257,9 @@ protected void build(FlowLayout rootComponent) {
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 All @@ -271,7 +274,7 @@ protected void build(FlowLayout rootComponent) {
builder.row.child(Components.button(Translate.gui("format." + animationFormat.extension), button -> {
animationFormat = animationFormat.next();
button.setMessage(Translate.gui("format." + animationFormat.extension));
}).horizontalSizing(Sizing.fixed(35)));
}).horizontalSizing(Sizing.fixed(40)));
}

IsometricUI.dynamicLabel(rightColumn, () -> {
Expand Down Expand Up @@ -407,8 +410,10 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
overwriteLatest.set(overwriteValue);
if (throwable != null) return;

this.exportAnimationButton.setMessage(Translate.gui("converting"));
this.client.execute(() -> this.notify(Translate.gui("converting_image_sequence")));
if (animationFormat != FFmpegDispatcher.Format.SERIES) {
this.exportAnimationButton.setMessage(Translate.gui("converting"));
this.client.execute(() -> this.notify(Translate.gui("converting_image_sequence")));
}

FFmpegDispatcher.assemble(
this.renderable.exportPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public Path resolveOffset() {
public File resolveFile(String extension) {
return ImageIO.next(exportRoot().resolve(this.effectiveOffset()).resolve(this.filename + "." + extension)).toFile();
}
public Path resolveDir() {
return ImageIO.next(exportRoot().resolve(this.effectiveOffset()).resolve(this.filename));
}

public ExportPathSpec relocate(String newOffset) {
return new ExportPathSpec(newOffset, this.filename, this.ignoreSaveIntoRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.glisco.isometricrenders.IsometricRenders;
import com.glisco.isometricrenders.property.GlobalProperties;
import net.minecraft.util.Util;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
Expand All @@ -13,6 +14,8 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import static com.glisco.isometricrenders.property.GlobalProperties.animationFormat;

public class FFmpegDispatcher {

private static Boolean ffmpegDetected = null;
Expand Down Expand Up @@ -59,6 +62,25 @@ public static CompletableFuture<Boolean> detectFFmpeg() {
public static CompletableFuture<File> assemble(ExportPathSpec target, Path sourcePath, Format format) {
target.resolveOffset().toFile().mkdirs();

if (animationFormat == FFmpegDispatcher.Format.SERIES) {
try {
Path export = target.resolveDir();
if (Files.exists(export))
FileUtils.deleteDirectory(export.toFile());
Files.createDirectory(export);
var files = Files.list(sourcePath)
.filter(path -> path.getFileName().toString().matches("seq_\\d+\\.png"))
.toList();
for (var file : files)
Files.move(file, export.resolve(file.getFileName().toString().substring(4)));
return CompletableFuture.completedFuture(export.toFile());
}
catch (IOException e) {
IsometricRenders.LOGGER.error("Could not launch ffmpeg", e);
return CompletableFuture.failedFuture(e);
}
}

final var defaultArgs = new ArrayList<>(List.of(new String[]{
"ffmpeg",
"-y",
Expand Down Expand Up @@ -105,7 +127,8 @@ public static CompletableFuture<File> assemble(ExportPathSpec target, Path sourc
public enum Format {
APNG("apng", new String[]{"-plays", "0"}),
GIF("gif", new String[]{"-plays", "0", "-pix_fmt", "yuv420p"}),
MP4("mp4", new String[]{"-preset", "slow", "-crf", "20", "-pix_fmt", "yuv420p"});
MP4("mp4", new String[]{"-preset", "slow", "-crf", "20", "-pix_fmt", "yuv420p"}),
SERIES("series", new String[]{});

public final String extension;
public final String[] arguments;
Expand All @@ -117,9 +140,10 @@ public enum Format {

public Format next() {
return switch (this) {
case MP4 -> APNG;
case APNG -> GIF;
case GIF -> MP4;
case MP4 -> SERIES;
case SERIES -> APNG;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"gui.isometric-renders.format.mp4": "MP4",
"gui.isometric-renders.format.apng": "APNG",
"gui.isometric-renders.format.gif": "GIF",
"gui.isometric-renders.format.series": "SERIES",
"gui.isometric-renders.detecting_ffmpeg": "Detecting FFmpeg...",
"gui.isometric-renders.no_ffmpeg_1": "FFmpeg was not detected",
"gui.isometric-renders.no_ffmpeg_2": "Please download it from",
Expand Down