Fix issue with meshes and multiple texture templates
This commit is contained in:
parent
0e2175fbb9
commit
ebef3c45fc
@ -289,8 +289,13 @@ class Mesh extends OutlinerElement {
|
|||||||
this.sanitizeName();
|
this.sanitizeName();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
getUndoCopy() {
|
getUndoCopy(aspects = {}) {
|
||||||
var copy = new Mesh(this)
|
var copy = new Mesh(this)
|
||||||
|
if (aspects.uv_only) {
|
||||||
|
copy = {
|
||||||
|
faces: copy.faces,
|
||||||
|
}
|
||||||
|
}
|
||||||
copy.uuid = this.uuid;
|
copy.uuid = this.uuid;
|
||||||
delete copy.parent;
|
delete copy.parent;
|
||||||
for (let fkey in copy.faces) {
|
for (let fkey in copy.faces) {
|
||||||
@ -1922,13 +1927,10 @@ BARS.defineActions(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(start_face)
|
|
||||||
let start_vertices = start_face.getSortedVertices().filter((vkey, i) => selected_vertices.includes(vkey));
|
let start_vertices = start_face.getSortedVertices().filter((vkey, i) => selected_vertices.includes(vkey));
|
||||||
let start_offset = direction % start_vertices.length;
|
let start_offset = direction % start_vertices.length;
|
||||||
let start_edge = start_vertices.slice(start_offset, start_offset+2);
|
let start_edge = start_vertices.slice(start_offset, start_offset+2);
|
||||||
if (start_edge.length == 1) start_edge.splice(0, 0, start_vertices[0]);
|
if (start_edge.length == 1) start_edge.splice(0, 0, start_vertices[0]);
|
||||||
console.log({start_vertices, start_offset, direction, start_edge})
|
|
||||||
|
|
||||||
|
|
||||||
splitFace(start_face, start_edge, start_face.vertices.length == 4);
|
splitFace(start_face, start_edge, start_face.vertices.length == 4);
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ const TextureGenerator = {
|
|||||||
|
|
||||||
//Drawing
|
//Drawing
|
||||||
TextureGenerator.old_project_resolution = [Project.texture_width, Project.texture_height]
|
TextureGenerator.old_project_resolution = [Project.texture_width, Project.texture_height]
|
||||||
TextureGenerator.changeProjectResolution(new_resolution[0], new_resolution[1]);
|
let affected_elements = TextureGenerator.changeProjectResolution(new_resolution[0], new_resolution[1]);
|
||||||
|
|
||||||
templates.forEach(function(t) {
|
templates.forEach(function(t) {
|
||||||
if (options.rearrange_uv) {
|
if (options.rearrange_uv) {
|
||||||
@ -396,7 +396,7 @@ const TextureGenerator = {
|
|||||||
Undo.finishEdit('Create template', {
|
Undo.finishEdit('Create template', {
|
||||||
textures: [texture],
|
textures: [texture],
|
||||||
bitmap: true,
|
bitmap: true,
|
||||||
elements: cubes,
|
elements: cubes.slice().safePush( ...affected_elements),
|
||||||
selected_texture: true,
|
selected_texture: true,
|
||||||
uv_only: true,
|
uv_only: true,
|
||||||
uv_mode: true
|
uv_mode: true
|
||||||
@ -990,7 +990,7 @@ const TextureGenerator = {
|
|||||||
var dataUrl = canvas.toDataURL()
|
var dataUrl = canvas.toDataURL()
|
||||||
var texture = cb(dataUrl)
|
var texture = cb(dataUrl)
|
||||||
|
|
||||||
TextureGenerator.changeProjectResolution(new_resolution[0], new_resolution[1]);
|
let affected_elements = TextureGenerator.changeProjectResolution(new_resolution[0], new_resolution[1]);
|
||||||
|
|
||||||
if (texture) {
|
if (texture) {
|
||||||
element_list.forEach(function(element) {
|
element_list.forEach(function(element) {
|
||||||
@ -1012,7 +1012,7 @@ const TextureGenerator = {
|
|||||||
Undo.finishEdit('Create template', {
|
Undo.finishEdit('Create template', {
|
||||||
textures: [texture],
|
textures: [texture],
|
||||||
bitmap: true,
|
bitmap: true,
|
||||||
elements: element_list,
|
elements: [...element_list, ...affected_elements],
|
||||||
selected_texture: true,
|
selected_texture: true,
|
||||||
uv_only: true,
|
uv_only: true,
|
||||||
uv_mode: true
|
uv_mode: true
|
||||||
@ -1112,7 +1112,7 @@ const TextureGenerator = {
|
|||||||
var dataUrl = canvas.toDataURL()
|
var dataUrl = canvas.toDataURL()
|
||||||
var texture = cb(dataUrl)
|
var texture = cb(dataUrl)
|
||||||
|
|
||||||
TextureGenerator.changeProjectResolution(new_resolution[0], new_resolution[1]);
|
let affected_elements = TextureGenerator.changeProjectResolution(new_resolution[0], new_resolution[1]);
|
||||||
|
|
||||||
if (texture) {
|
if (texture) {
|
||||||
face_list.forEach(({face, fkey}, i) => {
|
face_list.forEach(({face, fkey}, i) => {
|
||||||
@ -1130,7 +1130,7 @@ const TextureGenerator = {
|
|||||||
Undo.finishEdit('Create template', {
|
Undo.finishEdit('Create template', {
|
||||||
textures: [texture],
|
textures: [texture],
|
||||||
bitmap: true,
|
bitmap: true,
|
||||||
elements: element_list,
|
elements: [...element_list, ...affected_elements],
|
||||||
selected_texture: true,
|
selected_texture: true,
|
||||||
uv_only: true,
|
uv_only: true,
|
||||||
uv_mode: true
|
uv_mode: true
|
||||||
@ -1142,21 +1142,35 @@ const TextureGenerator = {
|
|||||||
let factor_y = height / Project.texture_height;
|
let factor_y = height / Project.texture_height;
|
||||||
Project.texture_width = width;
|
Project.texture_width = width;
|
||||||
Project.texture_height = height;
|
Project.texture_height = height;
|
||||||
|
let changed_elements = [];
|
||||||
|
|
||||||
if (!Project.box_uv && !Format.single_texture) {
|
if (!Project.box_uv && !Format.single_texture && (factor_x !== 1 || factor_y !== 1)) {
|
||||||
Cube.all.forEach(cube => {
|
changed_elements = Outliner.elements.filter(el => el.faces && !el.selected);
|
||||||
if (cube.selected) return;
|
Undo.current_save.addElements(changed_elements, {uv_only: true});
|
||||||
for (var key in cube.faces) {
|
|
||||||
let face = cube.faces[key];
|
changed_elements.forEach(element => {
|
||||||
if (face.texture) {
|
if (element instanceof Cube) {
|
||||||
face.uv[0] *= factor_x
|
for (var key in element.faces) {
|
||||||
face.uv[1] *= factor_y;
|
let face = element.faces[key];
|
||||||
face.uv[2] *= factor_x;
|
if (face.texture) {
|
||||||
face.uv[3] *= factor_y;
|
face.uv[0] *= factor_x
|
||||||
|
face.uv[1] *= factor_y;
|
||||||
|
face.uv[2] *= factor_x;
|
||||||
|
face.uv[3] *= factor_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (element instanceof Mesh) {
|
||||||
|
for (var fkey in element.faces) {
|
||||||
|
let face = element.faces[fkey];
|
||||||
|
for (let vkey in face.uv) {
|
||||||
|
face.uv[vkey][0] *= factor_x;
|
||||||
|
face.uv[vkey][1] *= factor_y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Canvas.updateUV(cube)
|
element.preview_controller.updateUV(element);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return changed_elements;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -551,6 +551,12 @@ UndoSystem.save = class {
|
|||||||
this.textures[texture.uuid] = texture.getUndoCopy(this.aspects.bitmap)
|
this.textures[texture.uuid] = texture.getUndoCopy(this.aspects.bitmap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addElements(elements, aspects = {}) {
|
||||||
|
if (!this.elements) this.elements = {};
|
||||||
|
elements.forEach(el => {
|
||||||
|
this.elements[el.uuid] = el.getUndoCopy(aspects);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let Undo = null;
|
let Undo = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user