Add recent thumbnails for image projects

Open new image project when selecting Texture skin preset
DIsable brush outline while zooming in UV editor
Add attachables to description of bedrock enttiy format
This commit is contained in:
JannisX11 2022-10-09 19:39:58 +02:00
parent d935198fc2
commit 6debfd32db
4 changed files with 68 additions and 27 deletions

View File

@ -175,24 +175,29 @@ function updateRecentProjectData() {
updateRecentProjects()
}
async function updateRecentProjectThumbnail() {
if (Outliner.elements.length == 0) return;
let project = Project.getProjectMemory();
if (!project) return;
MediaPreview.resize(180, 100)
MediaPreview.loadAnglePreset(DefaultCameraPresets[0])
MediaPreview.setFOV(30);
let center = getSelectionCenter(true);
MediaPreview.controls.target.fromArray(center);
MediaPreview.controls.target.add(scene.position);
let box = Canvas.getModelSize();
let size = Math.max(box[0], box[1]*2)
MediaPreview.camera.position.multiplyScalar(size/50)
let thumbnail;
await new Promise((resolve, reject) => {
MediaPreview.screenshot({crop: false}, url => {
if (Format.id == 'image' && Texture.all.length) {
await new Promise((resolve, reject) => {
let tex = Texture.getDefault();
let frame = new CanvasFrame(180, 100);
frame.ctx.imageSmoothingEnabled = false;
let {width, height} = tex;
if (width > 180) {height /= width / 180; width = 180;}
if (height > 100) {width /= height / 100; height = 100;}
if (width < 180 && height < 100) {
let factor = Math.min(180 / width, 100 / height);
factor *= 0.92;
height *= factor; width *= factor;
}
frame.ctx.drawImage(tex.img, (180 - width)/2, (100 - height)/2, width, height)
let url = frame.canvas.toDataURL();
let hash = project.path.hashCode().toString().replace(/^-/, '0');
let path = PathModule.join(app.getPath('userData'), 'thumbnails', `${hash}.png`)
thumbnail = url;
@ -200,11 +205,36 @@ async function updateRecentProjectThumbnail() {
savetype: 'image',
content: url
}, resolve)
let store_path = project.path;
project.path = '';
project.path = store_path;
})
})
} else {
if (Outliner.elements.length == 0) return;
MediaPreview.resize(180, 100)
MediaPreview.loadAnglePreset(DefaultCameraPresets[0])
MediaPreview.setFOV(30);
let center = getSelectionCenter(true);
MediaPreview.controls.target.fromArray(center);
MediaPreview.controls.target.add(scene.position);
let box = Canvas.getModelSize();
let size = Math.max(box[0], box[1]*2)
MediaPreview.camera.position.multiplyScalar(size/50)
await new Promise((resolve, reject) => {
MediaPreview.screenshot({crop: false}, url => {
let hash = project.path.hashCode().toString().replace(/^-/, '0');
let path = PathModule.join(app.getPath('userData'), 'thumbnails', `${hash}.png`)
thumbnail = url;
Blockbench.writeFile(path, {
savetype: 'image',
content: url
}, resolve)
let store_path = project.path;
project.path = '';
project.path = store_path;
})
})
}
Blockbench.dispatchEvent('update_recent_project_thumbnail', {data: project, thumbnail});
StartScreen.vue.updateThumbnails([project.path]);

View File

@ -271,15 +271,24 @@ const skin_dialog = new Dialog({
},
draggable: true,
onConfirm(result) {
if (newProject(format)) {
let preset = skin_presets[result.model];
let model = JSON.parse(preset.model || (result.variant == 'java_edition' ? preset.model_java : preset.model_bedrock));
codec.parse(model, result.resolution/16, result.texture, result.pose, result.layer_template);
if (result.model == 'flat_texture') {
if (newProject(Formats.image)) {
if (result.texture) {
new Texture().fromPath(result.texture).add(false);
} else {
TextureGenerator.addBitmapDialog();
}
}
} else {
if (newProject(format)) {
let preset = skin_presets[result.model];
let model = JSON.parse(preset.model || (result.variant == 'java_edition' ? preset.model_java : preset.model_bedrock));
codec.parse(model, result.resolution/16, result.texture, result.pose, result.layer_template);
}
}
this.hide();
},
onCancel() {
this.hide();
Format = 0;
}
});

View File

@ -1969,8 +1969,10 @@ Interface.definePanels(function() {
if (this.zoom == 1 && Panels.uv.isInSidebar() && diagonal_offset/UVEditor.width < 0.12) {
this.centerView();
}
this.updateMouseCoords(event)
//if (Painter.selection.overlay) UVEditor.updatePastingOverlay()
if (this.mode == 'paint') {
this.mouse_coords.x = -1;
}
}
if (n > 0) {
Vue.nextTick(updateScroll);

View File

@ -118,7 +118,7 @@
"format.java_block.info.animation": "This format does not support animations in vanilla Minecraft. If you are creating a mod, you can use GeckoLib to animate models. If not, the only way to animate is to switch out the model using commands or animated textures.",
"format.bedrock": "Bedrock Entity",
"format.bedrock.desc": "Entity model for Minecraft Bedrock Edition",
"format.bedrock.desc": "Minecraft Bedrock Edition model for entities and item attachables",
"format.bedrock.info.textures": "Each model can only have one texture",
"format.bedrock_block": "Bedrock Block",