Added single frame render.

This commit is contained in:
Quicksticks-oss committed 2024-03-29 22:18:54 -04:00
1 parent 2df5466fb2
commit 8e56db67ee
2 files changed
+55 -11

No files matched your search

@@ -99,6 +99,10 @@ export const ControlsTopButtons = () => {
const handleButtonLoad = () => {};
const handleButtonSingleFrame = () => {
editorEngine?.generateFrame();
};
return (
<div className="flex flex-col gap-2 pl-3 pt-3">
<div className="flex gap-2">
@@ -165,7 +169,7 @@ export const ControlsTopButtons = () => {
</div>
<div className="flex gap-2">
<Button onClick={handleButtonLoad}>Test Button</Button>
<Button onClick={handleButtonSingleFrame}>Render Single Frame</Button>
<Button onClick={handleButtonTakeFrame}>Take Frame</Button>
<Button onClick={handleButtonRender}>Render</Button>
{/* <Button onClick={handleButtonLoad}>Load</Button>
+50 -10
View File
@@ -821,7 +821,7 @@ class Editor {
new_video)
}
async stopPlayback() {
async stopPlayback(compile_audio: boolean = true) {
this.renderMode();
let ffmpeg = createFFmpeg({ log: true });
await ffmpeg.load();
@@ -855,12 +855,14 @@ class Editor {
let itteration = 0;
for (const clip of this.timeline.timeline_items) {
if (clip.type == "lipsync" || clip.type == "audio") {
await this.convertAudioClip(itteration, ffmpeg, clip);
itteration += 1;
}
};
if (compile_audio) {
for (const clip of this.timeline.timeline_items) {
if (clip.type == "lipsync" || clip.type == "audio") {
await this.convertAudioClip(itteration, ffmpeg, clip);
itteration += 1;
}
};
}
let output = await ffmpeg.FS("readFile", itteration + "tmp.mp4");
// Create a Blob from the output file for downloading
@@ -882,6 +884,44 @@ class Editor {
}
async generateFrame() {
if (this.renderer) {
this.activeScene.renderMode(true);
if (this.activeScene.hot_items) {
this.activeScene.hot_items.forEach(element => {
element.visible = false;
});
}
if (this.render_camera && this.cam_obj) {
this.render_camera.position.copy(this.cam_obj.position);
this.render_camera.rotation.copy(this.cam_obj.rotation);
}
this.renderer.setSize(this.render_width, this.render_height);
this.renderer.render(this.activeScene.scene, this.render_camera);
let imgData = this.renderer.domElement.toDataURL();
this.activeScene.renderMode(false);
this.onWindowResize();
let ffmpeg = createFFmpeg({ log: false });
await ffmpeg.load();
await ffmpeg.FS(
"writeFile",
`render.png`,
await fetchFile(imgData),
);
await ffmpeg.run('-i', `render.png`, 'render.mp4');
let output = await ffmpeg.FS("readFile", 'render.mp4');
const blob = new Blob([output.buffer], { type: "video/mp4" });
let data = await this.api_manager.uploadMedia(blob, "render.wav");
return new Promise((resolve, reject) => {
resolve(data);
});
}
}
generateVideo() {
console.log("Generating video...");
if (this.rendering) { return; }
@@ -952,11 +992,11 @@ class Editor {
}
updateSelectedUI() {
if(this.selected == undefined) { return; }
if (this.selected == undefined) { return; }
let pos = this.selected.position;
let rot = this.selected.rotation;
let scale = this.selected.scale;
this.dispatchAppUiState({
type: APPUI_ACTION_TYPES.SHOW_CONTROLPANELS_SCENEOBJECT,
payload: {
@@ -970,7 +1010,7 @@ class Editor {
}
});
}
// Automaticly resize scene.
onWindowResize() {