From 88a23577ac6271f12a871f511259e38c31d621a1 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 2 Apr 2023 21:44:09 +0200 Subject: [PATCH] Reference image web search and improvements Auto enable template generator padding on meshes --- css/window.css | 6 +- js/preview/reference_images.js | 92 +++++++++++++++++++++++++++++++ js/texturing/texture_generator.js | 2 +- 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/css/window.css b/css/window.css index f3fde86f..2d2433b9 100644 --- a/css/window.css +++ b/css/window.css @@ -992,12 +992,12 @@ margin: auto; height: auto; bottom: 0; - right: 0; - left: 0; + right: -150px; + left: -150px; background-color: var(--color-ui); max-width: fit-content; display: flex; - flex-wrap: wrap; + width: fit-content; } .toolbar[toolbar_id=reference_images] { diff --git a/js/preview/reference_images.js b/js/preview/reference_images.js index 277c778a..890082b9 100644 --- a/js/preview/reference_images.js +++ b/js/preview/reference_images.js @@ -887,6 +887,98 @@ BARS.defineActions(function() { return list; } }); + new Action('search_reference_image', { + icon: 'image_search', + category: 'view', + condition: isApp, + async click() { + if (!ReferenceImageMode.active) { + ReferenceImageMode.activate() + } + + let win = new electron.BrowserWindow({ + icon: 'icon.ico', + modal: true, + parent: currentwindow, + width: 1080, + height: 720, + menuBarVisible: false, + webPreferences: { + nodeIntegration: false, + contextIsolation: true + } + }) + if (process.platform !== 'darwin') { + win.setMenu(null); + } + let { getCursorScreenPoint, getDisplayNearestPoint } = electron.screen; + let currentScreen = getDisplayNearestPoint(getCursorScreenPoint()); + win.setBounds(currentScreen.workArea); + + win.loadURL('https://google.com/images'); + + win.webContents.setWindowOpenHandler(details => ({action: 'deny'})); + win.webContents.openDevTools() + + function addButton() { + win.webContents.insertCSS(` + #blockbench_load_reference { + position: fixed; + bottom: 20px; + left: 0; + right: 0; + margin: auto; + appearance: none; + border: none; + background-color: #3e90ff; + color: black; + width: 160px; + font-family: "segoe ui", roboto, sans-serif; + font-weight: normal; + height: 40px; + font-size: 18px; + cursor: pointer; + box-shadow: 2px 2px 20px rgba(0, 0, 0, 60%); + } + #blockbench_load_reference:hover { + color: #ffffff; + } + `) + win.webContents.executeJavaScript(` + let button = document.createElement('button'); + button.id = 'blockbench_load_reference'; + button.textContent = 'Load Image'; + button.onclick = event => { + let img; + document.querySelectorAll('c-wiz > div > div > div > div > div > a > img').forEach(node => { + if (node.checkVisibility()) img = node; + }); + if (img && img.src) { + location.assign(img.src); + } + }; + document.body.append(button); + `); + } + + win.webContents.on('did-stop-loading', () => { + try { + addButton(); + } catch (err) { + console.error(err) + } + }) + win.webContents.on('did-navigate', (event, url) => { + + if (url.match(/\.(png|gif|jpg|jpeg|tif|tiff)($|\?|\/)/i)) { + ReferenceImageMode.importReferences([{content: url, name: win.webContents.getTitle().substring(0, 24)}]); + win.close(); + } else if (!url.includes('google.com/')) { + win.close(); + } + }) + } + }); }) Interface.definePanels(function() { diff --git a/js/texturing/texture_generator.js b/js/texturing/texture_generator.js index 573561d6..181d8da3 100644 --- a/js/texturing/texture_generator.js +++ b/js/texturing/texture_generator.js @@ -54,7 +54,7 @@ const TextureGenerator = { combine_polys: {label: 'dialog.create_texture.combine_polys', description: 'dialog.create_texture.combine_polys.desc', type: 'checkbox', value: true, condition: (form) => (form.type == 'template' && form.rearrange_uv && Mesh.selected.length)}, max_edge_angle: {label: 'dialog.create_texture.max_edge_angle', description: 'dialog.create_texture.max_edge_angle.desc', type: 'number', value: 36, condition: (form) => (form.type == 'template' && form.rearrange_uv && Mesh.selected.length)}, max_island_angle: {label: 'dialog.create_texture.max_island_angle', description: 'dialog.create_texture.max_island_angle.desc', type: 'number', value: 45, condition: (form) => (form.type == 'template' && form.rearrange_uv && Mesh.selected.length)}, - padding: {label: 'dialog.create_texture.padding', description: 'dialog.create_texture.padding.desc', type: 'checkbox', value: false, condition: (form) => (form.type == 'template' && form.rearrange_uv)}, + padding: {label: 'dialog.create_texture.padding', description: 'dialog.create_texture.padding.desc', type: 'checkbox', value: Mesh.selected.length > 0, condition: (form) => (form.type == 'template' && form.rearrange_uv)}, }, onFormChange(form) {