Add advanced screenshot function

This commit is contained in:
JannisX11 2023-10-28 01:36:35 +02:00
parent 5c7aa7c546
commit 70ed4887f4
5 changed files with 115 additions and 4 deletions

View File

@ -444,6 +444,7 @@ const MenuBar = {
new MenuSeparator('media'),
'screenshot_model',
'screenshot_app',
'advanced_screenshot',
'record_model_gif',
'timelapse',
])

View File

@ -1410,6 +1410,24 @@ class Preview {
console.warn('Preview.updateBackground() is no longer supported')
}
//Misc
copyView(preview) {
this.setProjectionMode(preview.isOrtho);
// Update camera
this.controls.unlinked = preview.controls.unlinked;
this.controls.target.copy(preview.controls.target);
this.camera.position.copy(preview.camera.position);
this.camera.quaternion.copy(preview.camera.quaternion);
if (this.isOrtho) {
this.camera.zoom = preview.camera.zoom;
this.camera.top = preview.camera.top;
this.camera.bottom = preview.camera.bottom;
this.camera.right = preview.camera.right;
this.camera.left = preview.camera.left;
this.camOrtho.updateProjectionMatrix();
} else {
this.setFOV(preview.camPers.fov);
}
}
screenshot(options, cb) {
return Screencam.screenshotPreview(this, options, cb);
}

View File

@ -48,9 +48,29 @@ const Screencam = {
})
}
}),
screenshotPreview(preview, options, cb) {
if (!options) options = 0;
advanced_screenshot_dialog: new Dialog({
id: 'advanced_screenshot',
title: 'action.advanced_screenshot',
form: {
/*angle_preset: {type: 'select', label: 'dialog.advanced_screenshot.angle_preset', value: 'view', options: {
view: 'View',
}},*/
resolution: {type: 'vector', label: 'dialog.advanced_screenshot.resolution', dimensions: 2, value: [1920, 1080]},
//zoom_to_fit: {type: 'checkbox', label: 'dialog.advanced_screenshot.zoom_to_fit', value: false},
zoom: {type: 'number', label: 'dialog.advanced_screenshot.zoom', value: 40, condition: form => !form.zoom_to_fit},
anti_aliasing: {type: 'select', label: 'dialog.advanced_screenshot.anti_aliasing', value: 'ssaa', options: {
off: 'dialog.advanced_screenshot.anti_aliasing.off',
msaa: 'dialog.advanced_screenshot.anti_aliasing.msaa',
ssaa: 'dialog.advanced_screenshot.anti_aliasing.ssaa',
}},
show_gizmos: {type: 'checkbox', label: 'dialog.advanced_screenshot.show_gizmos'},
shading: {type: 'checkbox', label: 'dialog.advanced_screenshot.shading', value: settings.shading.value},
},
onConfirm(result) {
Screencam.advancedScreenshot(Preview.selected, result, Screencam.returnScreenshot);
}
}),
screenshotPreview(preview, options = 0, cb) {
Canvas.withoutGizmos(function() {
preview.render()
@ -104,6 +124,57 @@ const Screencam = {
}
})
},
async advancedScreenshot(preview = Preview.selected, options = 0, cb) {
let current_shading = settings.shading.value;
let render = async () => {
if (typeof options.shading == 'boolean' && options.shading != current_shading) {
settings.shading.set(options.shading);
}
let render_viewport = options.anti_aliasing == 'msaa' ? MediaPreview : Screencam.NoAAPreview;
let sample_factor = options.anti_aliasing == 'ssaa' ? 4 : 1;
render_viewport.resize(options.resolution[0] * sample_factor, options.resolution[1] * sample_factor);
render_viewport.copyView(preview);
if (!render_viewport.isOrtho) {
render_viewport.camera.setFocalLength(options.zoom);
}
render_viewport.render();
if (options.anti_aliasing == 'ssaa') {
let img_frame = new CanvasFrame(options.resolution[0] * sample_factor, options.resolution[1] * sample_factor);
let frame = new CanvasFrame(options.resolution[0], options.resolution[1]);
let img = new Image()
img.src = render_viewport.canvas.toDataURL();
await new Promise((resolve, reject) => {
img.onload = function() {
resolve()
}
img.onerror = reject;
})
img_frame.ctx.filter = `blur(1px)`;
img_frame.ctx.drawImage(img, 0, 0, options.resolution[0] * sample_factor, options.resolution[1] * sample_factor, 0, 0, options.resolution[0] * sample_factor, options.resolution[1] * sample_factor);
frame.ctx.drawImage(img_frame.canvas, 0, 0, options.resolution[0] * sample_factor, options.resolution[1] * sample_factor, 0, 0, options.resolution[0], options.resolution[1]);
Screencam.returnScreenshot(frame.canvas.toDataURL(), cb);
} else {
Screencam.returnScreenshot(render_viewport.canvas.toDataURL(), cb);
}
if (settings.shading.value != current_shading) {
settings.shading.set(current_shading);
}
};
if (options.show_gizmos) {
render();
} else {
Canvas.withoutGizmos(render);
}
},
fullScreen(options = 0, cb) {
setTimeout(async function() {
let screenshot = await currentwindow.capturePage();
@ -674,6 +745,14 @@ BARS.defineActions(function() {
}
}
})
new Action('advanced_screenshot', {
icon: 'add_a_photo',
category: 'view',
condition: () => !!Project && !Format.image_editor,
click() {
Screencam.advanced_screenshot_dialog.show();
}
})
new Action('record_model_gif', {
icon: 'local_movies',
category: 'view',

File diff suppressed because one or more lines are too long

View File

@ -606,6 +606,17 @@
"dialog.create_gif.turn.desc": "Rotate the model while recording. Use negative values to turn the model clockwise. A value of 60 corresponds to one rotation every second.",
"dialog.create_gif.play": "Start Animation",
"dialog.advanced_screenshot.angle_preset": "Angle Preset",
"dialog.advanced_screenshot.resolution": "Resolution",
"dialog.advanced_screenshot.zoom_to_fit": "Zoom To Fit",
"dialog.advanced_screenshot.zoom": "Zoom / Focal Length",
"dialog.advanced_screenshot.anti_aliasing": "Anti-aliasing",
"dialog.advanced_screenshot.anti_aliasing.off": "Off",
"dialog.advanced_screenshot.anti_aliasing.msaa": "Multisampling",
"dialog.advanced_screenshot.anti_aliasing.ssaa": "Supersampling",
"dialog.advanced_screenshot.show_gizmos": "Show Edit Gizmos",
"dialog.advanced_screenshot.shading": "Shading",
"dialog.timelapse.interval": "Interval (Seconds)",
"dialog.timelapse.source": "Source",
"dialog.timelapse.source.interface": "Interface",
@ -1503,6 +1514,8 @@
"action.preview_scene.desc": "Change the model preview scene",
"action.screenshot_model": "Screenshot Model",
"action.screenshot_model.desc": "Take a cropped screenshot of the model from the current angle",
"action.advanced_screenshot": "Advanced Screenshot...",
"action.advanced_screenshot.desc": "Take a screenshot of the model with advanced options",
"action.record_model_gif": "Record GIF...",
"action.record_model_gif.desc": "Record an animated GIF of the model from the current angle",
"action.cancel_gif": "Cancel GIF",