Brush over connected mesh faces #1384

This commit is contained in:
JannisX11 2022-08-04 00:11:19 +02:00
parent f8dc7b0ae5
commit a613371265
2 changed files with 41 additions and 0 deletions

View File

@ -130,6 +130,27 @@ class MeshFace extends Face {
}
return matrix;
}
getUVIsland() {
let keys = [this.getFaceKey()];
function crawl(face) {
for (let i = 0; i < face.vertices.length; i++) {
let adjacent = face.getAdjacentFace(i);
if (!adjacent) continue;
if (keys.includes(adjacent.key)) continue;
let epsilon = 0.2;
let uv_a1 = adjacent.face.uv[adjacent.edge[0]];
let uv_a2 = face.uv[adjacent.edge[0]];
if (!Math.epsilon(uv_a1[0], uv_a2[0], epsilon) || !Math.epsilon(uv_a1[1], uv_a2[1], epsilon)) continue;
let uv_b1 = adjacent.face.uv[adjacent.edge[1]];
let uv_b2 = face.uv[adjacent.edge[1]];
if (!Math.epsilon(uv_b1[0], uv_b2[0], epsilon) || !Math.epsilon(uv_b1[1], uv_b2[1], epsilon)) continue;
keys.push(adjacent.key);
crawl(adjacent.face);
}
}
crawl(this);
return keys;
}
getAngleTo(other_face) {
let a = new THREE.Vector3().fromArray(this.getNormal());
let b = new THREE.Vector3().fromArray(other_face.getNormal());

View File

@ -287,10 +287,24 @@ const Painter = {
}
} else {
let min_x = Project.texture_width, min_y = Project.texture_height, max_x = 0, max_y = 0;
for (let vkey in uvTag) {
min_x = Math.min(min_x, uvTag[vkey][0]); max_x = Math.max(max_x, uvTag[vkey][0]);
min_y = Math.min(min_y, uvTag[vkey][1]); max_y = Math.max(max_y, uvTag[vkey][1]);
}
let current_face = Mesh.selected[0] && Mesh.selected[0].faces[Painter.current.face];
if (current_face) {
let island = current_face.getUVIsland();
island.forEach(fkey => {
let face = Mesh.selected[0].faces[fkey];
for (let vkey in face.uv) {
min_x = Math.min(min_x, face.uv[vkey][0]); max_x = Math.max(max_x, face.uv[vkey][0]);
min_y = Math.min(min_y, face.uv[vkey][1]); max_y = Math.max(max_y, face.uv[vkey][1]);
}
})
}
rect = Painter.editing_area = [
Math.floor(min_x * uvFactorX),
Math.floor(min_y * uvFactorY) + anim_offset,
@ -351,6 +365,12 @@ const Painter = {
let face = Painter.current.element.faces[Painter.current.face];
if (face && face.vertices.length > 2 && !Painter.current.face_matrices[Painter.current.face]) {
Painter.current.face_matrices[Painter.current.face] = face.getOccupationMatrix(true, [0, 0]);
let island = face.getUVIsland();
for (let fkey of island) {
let face = Painter.current.element.faces[fkey];
console.log(Painter.current.element, fkey, face, island)
face.getOccupationMatrix(true, [0, 0], Painter.current.face_matrices[Painter.current.face]);
}
}
}
if (event.touches && event.touches[0] && event.touches[0].touchType == 'stylus' && event.touches[0].force) {