Skip to content

Commit 5063fe3

Browse files
committed
Fixed cropping when texture frame is flipped
1 parent f3a4467 commit 5063fe3

2 files changed

Lines changed: 13 additions & 50 deletions

File tree

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ var TextureTintPipeline = new Class({
688688
// y += 259;
689689
}
690690

691-
692691
var xw = x + frameWidth;
693692
var yh = y + frameHeight;
694693

src/textures/Frame.js

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -478,55 +478,32 @@ var Frame = new Class({
478478

479479
x = Clamp(x, 0, cw);
480480
y = Clamp(y, 0, ch);
481-
width = Clamp(width, 0, cw);
482-
height = Clamp(height, 0, ch);
483481

484-
// Reserved for flipX/Y
485-
var cropWidth = width;
486-
var cropHeight = height;
482+
width = Clamp(width, 0, cw - x);
483+
height = Clamp(height, 0, ch - y);
487484

488-
if (x + width > cw)
489-
{
490-
width = (cw - x);
491-
}
492-
493-
if (y + height > ch)
494-
{
495-
height = (ch - y);
496-
}
497-
498-
var tw = this.source.width;
499-
var th = this.source.height;
500-
501-
var ox = cx;
502-
var oy = cy;
485+
var ox = cx + x;
486+
var oy = cy + y;
503487

504488
if (flipX)
505489
{
506-
ox = (tw - width) - (x * 2);
507-
// ox -= cropWidth;
490+
ox = cx + (cw - x - width);
508491
}
509492

510493
if (flipY)
511494
{
512-
oy = (th - height) - (y * 2);
513-
// oy -= cropHeight;
495+
oy = cy + (ch - y - height);
514496
}
515497

516-
this.setUVs(crop, ox + x, oy + y, width, height);
517-
518-
// console.log(crop.u0, crop.v0, crop.u1, crop.v1);
519-
498+
var tw = this.source.width;
499+
var th = this.source.height;
520500

521-
// crop.u0 = (x + ox) / tw;
522-
// crop.v0 = (y + oy) / th;
523-
// crop.u1 = (x + ox + width) / tw;
524-
// crop.v1 = (y + oy + height) / th;
501+
// Map the given coordinates into UV space, clamping to the 0-1 range.
525502

526-
// crop.u0 = (cx + x + ox) / tw;
527-
// crop.v0 = (cy + y + oy) / th;
528-
// crop.u1 = (cx + x + ox + width) / tw;
529-
// crop.v1 = (cy + y + oy + height) / th;
503+
crop.u0 = Math.max(0, ox / tw);
504+
crop.v0 = Math.max(0, oy / th);
505+
crop.u1 = Math.min(1, (ox + width) / tw);
506+
crop.v1 = Math.min(1, (oy + height) / th);
530507

531508
crop.width = width;
532509
crop.height = height;
@@ -543,19 +520,6 @@ var Frame = new Class({
543520
return crop;
544521
},
545522

546-
setUVs: function (dest, x, y, width, height)
547-
{
548-
var tw = this.source.width;
549-
var th = this.source.height;
550-
551-
// Map the given coordinates into UV space, clamping to the 0-1 range.
552-
553-
dest.u0 = Math.max(0, x / tw);
554-
dest.v0 = Math.max(0, y / th);
555-
dest.u1 = Math.min(1, (x + width) / tw);
556-
dest.v1 = Math.min(1, (y + height) / th);
557-
},
558-
559523
/**
560524
* Takes a crop data object and recalculates the UVs based on the dimensions inside the crop object.
561525
* Called automatically by `setFrame`.

0 commit comments

Comments
 (0)