缩略图插件
This commit is contained in:
1 parent
065b6466f1
commit
96a0db09d8
9 files changed
+984
-59
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// 从画布像素里找实际有内容的包围盒(动态缩略图按整个动画的可见范围取景用)。
|
||||
// 与主插件 js/spine-visible-bounds.js 是同一份实现,只是出口兼容 <script> 加载。
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function findAlphaBounds(rgba, width, height, threshold = 4) {
|
||||
let left = width, top = height, right = 0, bottom = 0;
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
if (rgba[(y * width + x) * 4 + 3] <= threshold) continue;
|
||||
left = Math.min(left, x);
|
||||
top = Math.min(top, y);
|
||||
right = Math.max(right, x + 1);
|
||||
bottom = Math.max(bottom, y + 1);
|
||||
}
|
||||
}
|
||||
return right > left && bottom > top ? { left, top, right, bottom } : null;
|
||||
}
|
||||
|
||||
function toWorldBounds(pixels, width, height, scale, centerX, centerY) {
|
||||
if (!pixels || !isFinite(scale) || scale <= 0) return null;
|
||||
const left = centerX + (pixels.left - width / 2) / scale;
|
||||
const right = centerX + (pixels.right - width / 2) / scale;
|
||||
const top = centerY - (pixels.top - height / 2) / scale;
|
||||
const bottom = centerY - (pixels.bottom - height / 2) / scale;
|
||||
return { x: left, y: bottom, width: right - left, height: top - bottom };
|
||||
}
|
||||
|
||||
const api = { findAlphaBounds, toWorldBounds };
|
||||
if (typeof window !== 'undefined') window.SpineVisibleBounds = api;
|
||||
else if (typeof module !== 'undefined' && module.exports) module.exports = api;
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user