修复缩放
This commit is contained in:
1 parent
e2df519d2e
commit
e60506ef96
3 files changed
+20
-8
No files matched your search
@@ -491,11 +491,11 @@
|
||||
// baseFitScale 为自动适配用的基准缩放;panX/panY/zoom 为用户平移/缩放叠加。
|
||||
// fitScale = baseFitScale * zoom;fitCx/fitCy 是骨骼包围盒中心(世界坐标)。
|
||||
let fitScale = 1, fitCx = 0, fitCy = 0;
|
||||
function captureStableFitBounds() {
|
||||
const bounds = getBounds(skeleton);
|
||||
function captureStableFitBounds(bounds = getBounds(skeleton)) {
|
||||
stableFitBounds = bounds && bounds.width > 0 && bounds.height > 0
|
||||
? { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height }
|
||||
: null;
|
||||
return stableFitBounds !== null;
|
||||
}
|
||||
|
||||
function fitToCanvas() {
|
||||
@@ -504,7 +504,7 @@
|
||||
const bounds = stableFitBounds;
|
||||
const cw = canvas.clientWidth, ch = canvas.clientHeight;
|
||||
if (!bounds || bounds.width <= 0 || bounds.height <= 0) {
|
||||
baseFitScale = 1; baseFitCx = 0; baseFitCy = 0; fitScale = 1; fitCx = 0; fitCy = 0; return;
|
||||
baseFitScale = 1; baseFitCx = 0; baseFitCy = 0; fitScale = zoom; fitCx = 0; fitCy = 0; return;
|
||||
}
|
||||
const pad = 0.1;
|
||||
const sx = (cw * (1 - pad * 2)) / bounds.width;
|
||||
@@ -1440,7 +1440,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setAnimationByName(name, index) {
|
||||
async function setAnimationByName(name, index) {
|
||||
if (!state) return;
|
||||
const anim = findAnimByName(name);
|
||||
if (!anim) return;
|
||||
@@ -1452,6 +1452,11 @@
|
||||
state.update(0);
|
||||
state.apply(skeleton);
|
||||
updateWorld(skeleton);
|
||||
if (!stableFitBounds) {
|
||||
const geometryBounds = getBounds(skeleton);
|
||||
const bounds = await measureVisibleBounds(skeleton, geometryBounds, 1, () => {}) || geometryBounds;
|
||||
if (currentAnim === resolvedIndex && captureStableFitBounds(bounds)) fitToCanvas();
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user