Backgrounds are now saved per tab

Improve missing texture + ground graphic
Fix mesh template angles
This commit is contained in:
JannisX11 2021-11-28 12:21:58 +01:00
parent 67dcd3a071
commit 40090c51e6
7 changed files with 26 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 130 B

View File

@ -179,7 +179,7 @@ const Settings = {
currentwindow.webContents.setZoomFactor(factor) currentwindow.webContents.setZoomFactor(factor)
resizeWindow() resizeWindow()
}}); }});
new Setting('hide_tab_bar', {category: 'interface', value: !isApp, onChange() { new Setting('hide_tab_bar', {category: 'interface', value: Blockbench.isMobile, onChange() {
updateTabBarVisibility(); updateTabBarVisibility();
}}); }});
new Setting('origin_size', {category: 'interface', value: 10, type: 'number'}); new Setting('origin_size', {category: 'interface', value: 10, type: 'number'});

View File

@ -168,10 +168,9 @@ var codec = new Codec('project', {
// Backgrounds // Backgrounds
const backgrounds = {}; const backgrounds = {};
for (var key in canvas_scenes) { for (var key in Project.backgrounds) {
let scene = canvas_scenes[key]; let scene = Project.backgrounds[key];
if (scene.image && scene.save_in_project !== false) { if (scene.image) {
scene.save_in_project = true;
backgrounds[key] = scene.getSaveCopy(); backgrounds[key] = scene.getSaveCopy();
} }
} }
@ -304,12 +303,10 @@ var codec = new Codec('project', {
} }
if (model.backgrounds) { if (model.backgrounds) {
for (var key in model.backgrounds) { for (var key in model.backgrounds) {
if (canvas_scenes.hasOwnProperty(key)) { if (Project.backgrounds.hasOwnProperty(key)) {
let store = model.backgrounds[key] let store = model.backgrounds[key]
let real = canvas_scenes[key] let real = Project.backgrounds[key]
real.save_in_project = true;
if (store.image !== undefined) {real.image = store.image} if (store.image !== undefined) {real.image = store.image}
if (store.size !== undefined) {real.size = store.size} if (store.size !== undefined) {real.size = store.size}

View File

@ -28,6 +28,16 @@ class ModelProject {
this.previews = {}; this.previews = {};
this.EditSession = null; 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 // Data
this.elements = []; this.elements = [];
this.groups = []; this.groups = [];
@ -191,6 +201,9 @@ class ModelProject {
Blockbench.dispatchEvent('select_project', {project: this}); Blockbench.dispatchEvent('select_project', {project: this});
Preview.all.forEach(p => {
if (p.canvas.isConnected) p.loadBackground()
})
if (Preview.selected) Preview.selected.occupyTransformer(); if (Preview.selected) Preview.selected.occupyTransformer();
setProjectTitle(this.name); setProjectTitle(this.name);
setStartScreen(!Project); setStartScreen(!Project);

View File

@ -1242,9 +1242,9 @@ class Preview {
this.background = canvas_scenes.normal this.background = canvas_scenes.normal
} }
} else if (this.angle !== null) { } else if (this.angle !== null) {
this.background = canvas_scenes['ortho_'+this.angle] this.background = Project && Project.backgrounds['ortho_'+this.angle]
} else { } else {
this.background = canvas_scenes.normal this.background = Project && Project.backgrounds.normal
} }
return this.background return this.background
} }
@ -1465,9 +1465,6 @@ class Preview {
{id: 'background', icon: 'wallpaper', name: 'menu.preview.background', children(preview) { {id: 'background', icon: 'wallpaper', name: 'menu.preview.background', children(preview) {
var has_background = !!preview.background.image var has_background = !!preview.background.image
function applyBackground(image) { function applyBackground(image) {
if (!preview.background.image) {
preview.background.save_in_project = null;
}
preview.background.image = image; preview.background.image = image;
preview.loadBackground(); preview.loadBackground();
Settings.saveLocalStorages(); Settings.saveLocalStorages();
@ -2128,7 +2125,6 @@ class PreviewBackground {
this.x = data.x||0 this.x = data.x||0
this.y = data.y||0 this.y = data.y||0
this.lock = data.lock||false this.lock = data.lock||false
this.save_in_project = false;
this.defaults = Object.assign({}, this); this.defaults = Object.assign({}, this);
this.defaults.image = this.image; this.defaults.image = this.image;
this.imgtag = new Image(); this.imgtag = new Image();
@ -2192,16 +2188,7 @@ function initCanvas() {
canvas_scenes = { 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' }), 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_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}), 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}), 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 store = stored_canvas_scenes[key]
let real = 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.image !== undefined) {real.image = store.image}
if (store.size !== undefined) {real.size = store.size} if (store.size !== undefined) {real.size = store.size}
if (store.x !== undefined) {real.x = store.x} 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}) MediaPreview = new Preview({id: 'media', offscreen: true})

View File

@ -654,7 +654,7 @@ const TextureGenerator = {
vec2.fromArray(mesh.vertices[face_group.faces[0].vertices[0]]) vec2.fromArray(mesh.vertices[face_group.faces[0].vertices[0]])
) )
let rot = cameraTargetToRotation([0, 0, 0], normal_vec.toArray()); 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 = {}; let vertex_uvs = {};
face_group.faces.forEach(face => { face_group.faces.forEach(face => {
face.vertices.forEach(vkey => { face.vertices.forEach(vkey => {

View File

@ -756,10 +756,12 @@ const UVEditor = {
normal_vec, normal_vec,
vec2.fromArray(obj.vertices[face.vertices[0]]) 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 => { face.vertices.forEach(vkey => {
let coplanar_pos = plane.projectPoint(vec3.fromArray(obj.vertices[vkey]), vec4.set(0, 0, 0)); 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.applyEuler(e);
coplanar_pos.applyQuaternion(q);
vertex_uvs[vkey] = [ vertex_uvs[vkey] = [
Math.roundTo(coplanar_pos.x, 4), Math.roundTo(coplanar_pos.x, 4),
Math.roundTo(coplanar_pos.z, 4), Math.roundTo(coplanar_pos.z, 4),