Fixed soft brush snapping to texels

This commit is contained in:
Nestorboy 2024-11-03 22:46:44 +01:00
parent acd924c2cc
commit cae5c5c7be
3 changed files with 13 additions and 8 deletions

View File

@ -52,10 +52,12 @@ class CubeFace extends Face {
case 'down': return [7, 2, 3, 6];
}
}
texelToLocalMatrix(uv, truncate_offset = [0, 0], truncate_factor = [1, 1]) {
texelToLocalMatrix(uv, truncate_offset = [0, 0], truncate_factor = [1, 1], truncate) {
uv = [...uv];
uv[0] = Math.round(uv[0] + truncate_offset) - truncate_offset;
uv[1] = Math.round(uv[1] + truncate_offset) - truncate_offset;
if (truncate) {
uv[0] = Math.round(uv[0] + truncate_offset) - truncate_offset;
uv[1] = Math.round(uv[1] + truncate_offset) - truncate_offset;
}
uv[0] *= truncate_factor[0];
uv[1] *= truncate_factor[1];

View File

@ -288,7 +288,7 @@ class MeshFace extends Face {
if (this.mesh.faces[fkey] == this) return fkey;
}
}
texelToLocalMatrix(uv, truncate_offset = [0, 0], truncate_factor = [1, 1], vertices = this.getSortedVertices()) {
texelToLocalMatrix(uv, truncate_offset = [0, 0], truncate_factor = [1, 1], truncate, vertices = this.getSortedVertices()) {
let vert_a = vertices[0];
let vert_b = vertices[1];
let vert_c = vertices[2];
@ -314,8 +314,10 @@ class MeshFace extends Face {
let vertexc = this.mesh.vertices[vert_c];
uv = [...uv];
uv[0] = Math.round(uv[0] + truncate_offset) - truncate_offset;
uv[1] = Math.round(uv[1] + truncate_offset) - truncate_offset;
if (truncate) {
uv[0] = Math.round(uv[0] + truncate_offset) - truncate_offset;
uv[1] = Math.round(uv[1] + truncate_offset) - truncate_offset;
}
uv[0] *= truncate_factor[0];
uv[1] *= truncate_factor[1];

View File

@ -1085,7 +1085,8 @@ class Preview {
let offset = 0;
let x = intersect.uv.x * texture.width;
let y = (1-intersect.uv.y) * texture.height;
if (Condition(Toolbox.selected.brush.floor_coordinates)) {
let floor_coordinates = Condition(Toolbox.selected.brush.floor_coordinates);
if (floor_coordinates) {
offset = BarItems.slider_brush_size.get()%2 == 0 && Toolbox.selected.brush?.offset_even_radius ? 0 : 0.5;
}
if (texture.currentFrame) {
@ -1093,7 +1094,7 @@ class Preview {
}
// Position
let brush_matrix = face.texelToLocalMatrix([x, y], offset, [uv_factor_x, uv_factor_y]);
let brush_matrix = face.texelToLocalMatrix([x, y], offset, [uv_factor_x, uv_factor_y], floor_coordinates);
let brush_coord = new THREE.Vector3().setFromMatrixPosition(brush_matrix);
intersect.object.localToWorld(brush_coord);
if (!Format.centered_grid) {