Implement texture frame mirror painting option

Closes #1156
Fix issue with stretched texture in UV editor while painting
This commit is contained in:
JannisX11 2022-08-18 13:41:12 +02:00
parent 38b76fd0ab
commit a6f8856b84
3 changed files with 51 additions and 27 deletions

View File

@ -496,7 +496,6 @@ const Timeline = {
Timeline.pause()
} else {
Timeline.setTime(0)
Timeline.start()
}
}
},

View File

@ -568,7 +568,6 @@ const Painter = {
ctx.globalCompositeOperation = 'source-over'
},
getMirrorPaintTargets(texture, x, y, uvTag) {
if (!uvTag || !Painter.current.element) return;
function getTargetWithOptions(symmetry_axes, local) {
let mirror_element = local ? Painter.current.element : Painter.getMirrorElement(Painter.current.element, symmetry_axes);
let even_brush_size = BarItems.slider_brush_size.get()%2 == 0 && Toolbox.selected.brush?.offset_even_radius && Condition(Toolbox.selected.brush?.floor_coordinates);
@ -681,7 +680,9 @@ const Painter = {
}
}
}
let targets = [];
if (uvTag & Painter.current.element) {
let mirror_vectors = [[
Painter.mirror_painting_options.axis.x?1:0,
Painter.mirror_painting_options.axis.y?1:0,
@ -710,7 +711,29 @@ const Painter = {
targets.push(getTargetWithOptions(mirror_vector, true));
}
})
}
// Texture animation
if (Painter.mirror_painting_options.texture_frames && Format.animated_textures && texture && texture.frameCount > 1) {
let spatial_targets = targets.slice();
for (let frame = 0; frame < texture.frameCount; frame++) {
if (frame == texture.currentFrame) continue;
targets.push({
element: Painter.current.element,
x,
y: y + (frame - texture.currentFrame) * texture.display_height,
face: Painter.current.face
});
spatial_targets.forEach(spatial => {
targets.push({
element: spatial.element,
x: spatial.x,
y: spatial.y + (frame - texture.currentFrame) * texture.display_height,
face: spatial.face
});
})
}
}
return targets.filter(target => !!target);
},
drawBrushLine(texture, end_x, end_y, event, new_face, uv) {

View File

@ -1908,6 +1908,8 @@ Interface.definePanels(function() {
if (this.texture && this.texture.display_canvas) {
Vue.nextTick(() => {
let wrapper = this.$refs.texture_canvas_wrapper;
this.texture.canvas.style.objectPosition = `0 ${-this.texture.currentFrame * this.inner_height}px`;
this.texture.canvas.style.objectFit = this.texture.frameCount > 1 ? 'cover' : 'fill';
wrapper.append(this.texture.canvas);
})
}