Fix #1000 Auto UV causes cube UV to exceed limits

This commit is contained in:
JannisX11 2023-05-06 23:08:21 +02:00
parent b6097f968c
commit e65faa4ffa

View File

@ -777,7 +777,7 @@ const UVEditor = {
plane = new THREE.Plane();
this.getMappableElements().forEach(obj => {
var top2, left2;
let height, width;
let faces = face_keys || this.getFaces(obj, event);
if (obj instanceof Cube) {
faces.forEach(function(side) {
@ -787,21 +787,25 @@ const UVEditor = {
face.uv[0] = Math.min(face.uv[0], face.uv[2]);
face.uv[1] = Math.min(face.uv[1], face.uv[3]);
if (side == 'north' || side == 'south') {
left2 = limitNumber(obj.size('0'), 0, Project.texture_width)
top2 = limitNumber(obj.size('1'), 0, Project.texture_height)
width = obj.size(0);
height = obj.size(1);
} else if (side == 'east' || side == 'west') {
left2 = limitNumber(obj.size('2'), 0, Project.texture_width)
top2 = limitNumber(obj.size('1'), 0, Project.texture_height)
width = obj.size(2);
height = obj.size(1);
} else if (side == 'up' || side == 'down') {
left2 = limitNumber(obj.size('0'), 0, Project.texture_width)
top2 = limitNumber(obj.size('2'), 0, Project.texture_height)
width = obj.size(0);
height = obj.size(2);
}
if (face.rotation % 180) {
[left2, top2] = [top2, left2];
[width, height] = [height, width];
}
left2 *= UVEditor.getResolution(0, face) / Project.texture_width;
top2 *= UVEditor.getResolution(1, face) / Project.texture_height;
face.uv_size = [left2, top2];
width *= UVEditor.getResolution(0, face) / Project.texture_width;
height *= UVEditor.getResolution(1, face) / Project.texture_height;
width = Math.clamp(width, 0, Project.texture_width);
height = Math.clamp(height, 0, Project.texture_height);
face.uv[0] = Math.min(face.uv[0], Project.texture_width - width);
face.uv[1] = Math.min(face.uv[1], Project.texture_height - height);
face.uv_size = [width, height];
if (mirror_x) [face.uv[0], face.uv[2]] = [face.uv[2], face.uv[0]];
if (mirror_y) [face.uv[1], face.uv[3]] = [face.uv[3], face.uv[1]];
})