From 40090c51e67f9faa11cfd982b8020185439e2be5 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 28 Nov 2021 12:21:58 +0100 Subject: [PATCH] Backgrounds are now saved per tab Improve missing texture + ground graphic Fix mesh template angles --- assets/missing.png | Bin 195 -> 130 bytes js/interface/settings.js | 2 +- js/io/formats/bbmodel.js | 13 +++++-------- js/io/project.js | 13 +++++++++++++ js/preview/preview.js | 21 ++------------------- js/texturing/texture_generator.js | 2 +- js/texturing/uv.js | 6 ++++-- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/assets/missing.png b/assets/missing.png index bda426393c4810601a0bf2830dc8e2ff658c1db8..1847a9eed4254294e0afdf3ae34840be7a87d4e7 100644 GIT binary patch delta 112 zcmX@i*u*$NGLwmcfnmbL3^O3*>FMGaV$pka(neke1p%h3J6M1ByB+6?h=}Uwbepxl zkNaf!ZB@RLcK#e5S(Sg!urV+^V6ZT&VZYY7owxJV-xpcG-|Cl6npBj)Pzopr0Kq0H>;M1& delta 178 zcmZo-Jj^&jvYw5BfkFQB|3o0gmgMd3!tfsi7wla=87RV8;1OBOz`!jG!i)^F=12eq z*-JcqUD+S9bMac3$*g&D2q+Zb>Eak-aXNWV!NWuKY+MZ7%*@Qq9UUBzv+nPyJbd7Y zgQCJMhRn=NHX#1QyWj?^^9hESMpJ`01?^*|%<>&NFPQx2+o_&dwvYSXo=WF!j0`Wl Wg?&DJ@{a);&fw|l=d#Wzp$PyR_d4eQ diff --git a/js/interface/settings.js b/js/interface/settings.js index 93fe38a8..bea3b90f 100644 --- a/js/interface/settings.js +++ b/js/interface/settings.js @@ -179,7 +179,7 @@ const Settings = { currentwindow.webContents.setZoomFactor(factor) resizeWindow() }}); - new Setting('hide_tab_bar', {category: 'interface', value: !isApp, onChange() { + new Setting('hide_tab_bar', {category: 'interface', value: Blockbench.isMobile, onChange() { updateTabBarVisibility(); }}); new Setting('origin_size', {category: 'interface', value: 10, type: 'number'}); diff --git a/js/io/formats/bbmodel.js b/js/io/formats/bbmodel.js index 3ed4667f..15cd04ed 100644 --- a/js/io/formats/bbmodel.js +++ b/js/io/formats/bbmodel.js @@ -168,10 +168,9 @@ var codec = new Codec('project', { // Backgrounds const backgrounds = {}; - for (var key in canvas_scenes) { - let scene = canvas_scenes[key]; - if (scene.image && scene.save_in_project !== false) { - scene.save_in_project = true; + for (var key in Project.backgrounds) { + let scene = Project.backgrounds[key]; + if (scene.image) { backgrounds[key] = scene.getSaveCopy(); } } @@ -304,12 +303,10 @@ var codec = new Codec('project', { } if (model.backgrounds) { for (var key in model.backgrounds) { - if (canvas_scenes.hasOwnProperty(key)) { + if (Project.backgrounds.hasOwnProperty(key)) { let store = model.backgrounds[key] - let real = canvas_scenes[key] - - real.save_in_project = true; + let real = Project.backgrounds[key] if (store.image !== undefined) {real.image = store.image} if (store.size !== undefined) {real.size = store.size} diff --git a/js/io/project.js b/js/io/project.js index 1e4e5c5e..7508d562 100644 --- a/js/io/project.js +++ b/js/io/project.js @@ -28,6 +28,16 @@ class ModelProject { this.previews = {}; this.EditSession = null; + this.backgrounds = { + normal: new PreviewBackground({name: 'menu.preview.perspective.normal', lock: null}), + ortho_top: new PreviewBackground({name: 'direction.top', lock: true}), + ortho_bottom: new PreviewBackground({name: 'direction.bottom', lock: true}), + ortho_south: new PreviewBackground({name: 'direction.south', lock: true}), + ortho_north: new PreviewBackground({name: 'direction.north', lock: true}), + ortho_east: new PreviewBackground({name: 'direction.east', lock: true}), + ortho_west: new PreviewBackground({name: 'direction.west', lock: true}), + } + // Data this.elements = []; this.groups = []; @@ -191,6 +201,9 @@ class ModelProject { Blockbench.dispatchEvent('select_project', {project: this}); + Preview.all.forEach(p => { + if (p.canvas.isConnected) p.loadBackground() + }) if (Preview.selected) Preview.selected.occupyTransformer(); setProjectTitle(this.name); setStartScreen(!Project); diff --git a/js/preview/preview.js b/js/preview/preview.js index c7161832..bbc1439b 100644 --- a/js/preview/preview.js +++ b/js/preview/preview.js @@ -1242,9 +1242,9 @@ class Preview { this.background = canvas_scenes.normal } } else if (this.angle !== null) { - this.background = canvas_scenes['ortho_'+this.angle] + this.background = Project && Project.backgrounds['ortho_'+this.angle] } else { - this.background = canvas_scenes.normal + this.background = Project && Project.backgrounds.normal } return this.background } @@ -1465,9 +1465,6 @@ class Preview { {id: 'background', icon: 'wallpaper', name: 'menu.preview.background', children(preview) { var has_background = !!preview.background.image function applyBackground(image) { - if (!preview.background.image) { - preview.background.save_in_project = null; - } preview.background.image = image; preview.loadBackground(); Settings.saveLocalStorages(); @@ -2128,7 +2125,6 @@ class PreviewBackground { this.x = data.x||0 this.y = data.y||0 this.lock = data.lock||false - this.save_in_project = false; this.defaults = Object.assign({}, this); this.defaults.image = this.image; this.imgtag = new Image(); @@ -2192,16 +2188,7 @@ function initCanvas() { canvas_scenes = { - normal: new PreviewBackground({name: 'menu.preview.perspective.normal', lock: null}), - ortho_top: new PreviewBackground({name: 'direction.top', lock: true}), - ortho_bottom: new PreviewBackground({name: 'direction.bottom', lock: true}), - ortho_south: new PreviewBackground({name: 'direction.south', lock: true}), - ortho_north: new PreviewBackground({name: 'direction.north', lock: true}), - ortho_east: new PreviewBackground({name: 'direction.east', lock: true}), - ortho_west: new PreviewBackground({name: 'direction.west', lock: true}), - monitor: new PreviewBackground({name: 'display.reference.monitor' }), - inventory_nine: new PreviewBackground({name: 'display.reference.inventory_nine', image: './assets/inventory_nine.png', x: 0, y: -525, size: 1051, lock: true}), inventory_full: new PreviewBackground({name: 'display.reference.inventory_full', image: './assets/inventory_full.png', x: 0, y: -1740, size: 2781, lock: true}), hud: new PreviewBackground({name: 'display.reference.hud', image: './assets/hud.png', x: -224, y: -447.5, size: 3391, lock: true}), @@ -2219,9 +2206,6 @@ function initCanvas() { let store = stored_canvas_scenes[key] let real = canvas_scenes[key] - if (store.save_in_project) continue; - if (store.save_in_project == null) {real.save_in_project = false} - if (store.image !== undefined) {real.image = store.image} if (store.size !== undefined) {real.size = store.size} if (store.x !== undefined) {real.x = store.x} @@ -2231,7 +2215,6 @@ function initCanvas() { } } } - active_scene = canvas_scenes.normal MediaPreview = new Preview({id: 'media', offscreen: true}) diff --git a/js/texturing/texture_generator.js b/js/texturing/texture_generator.js index 2bc1ab48..5381e5b7 100644 --- a/js/texturing/texture_generator.js +++ b/js/texturing/texture_generator.js @@ -654,7 +654,7 @@ const TextureGenerator = { vec2.fromArray(mesh.vertices[face_group.faces[0].vertices[0]]) ) let rot = cameraTargetToRotation([0, 0, 0], normal_vec.toArray()); - let e = new THREE.Euler(Math.degToRad(rot[1] - 90), Math.degToRad(rot[0]), 0); + let e = new THREE.Euler(Math.degToRad(-rot[1] - 90), Math.degToRad(rot[0]), 0); let vertex_uvs = {}; face_group.faces.forEach(face => { face.vertices.forEach(vkey => { diff --git a/js/texturing/uv.js b/js/texturing/uv.js index 99e8d53a..aebddedc 100644 --- a/js/texturing/uv.js +++ b/js/texturing/uv.js @@ -756,10 +756,12 @@ const UVEditor = { normal_vec, vec2.fromArray(obj.vertices[face.vertices[0]]) ) + let rot = cameraTargetToRotation([0, 0, 0], normal_vec.toArray()); + let e = new THREE.Euler(Math.degToRad(-rot[1] - 90), Math.degToRad(rot[0]), 0); + console.log({rot, e, normal_vec}) face.vertices.forEach(vkey => { let coplanar_pos = plane.projectPoint(vec3.fromArray(obj.vertices[vkey]), vec4.set(0, 0, 0)); - let q = quat.setFromUnitVectors(normal_vec, THREE.NormalY); - coplanar_pos.applyQuaternion(q); + coplanar_pos.applyEuler(e); vertex_uvs[vkey] = [ Math.roundTo(coplanar_pos.x, 4), Math.roundTo(coplanar_pos.z, 4),