1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-25 13:13:56 +02:00

Update poster.ts

This commit is contained in:
syuilo
2026-03-03 16:33:57 +09:00
parent 98f74b0c7a
commit 3874f7abe9

View File

@@ -55,18 +55,19 @@ export const poster = defineObject({
const uvs = pictureMesh.getVerticesData(BABYLON.VertexBuffer.UVKind); const uvs = pictureMesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
/** /**
* a(x,y)---b(x,y) * 0 1
* | | * 0 c(x,y)---a(x,y)
* c(x,y)---d(x,y) * | |
* 1 d(x,y)---b(x,y)
*/ */
const ax = uvs[6]; const ax = uvs[4];
const ay = uvs[7]; const ay = uvs[5];
const bx = uvs[2]; const bx = uvs[6];
const by = uvs[3]; const by = uvs[7];
const cx = uvs[4]; const cx = uvs[0];
const cy = uvs[5]; const cy = uvs[1];
const dx = uvs[0]; const dx = uvs[2];
const dy = uvs[1]; const dy = uvs[3];
const applyFit = () => { const applyFit = () => {
const tex = pictureMaterial.albedoTexture; const tex = pictureMaterial.albedoTexture;
@@ -79,29 +80,57 @@ export const poster = defineObject({
const targetHeight = options.height; const targetHeight = options.height;
const targetAspect = targetWidth / targetHeight; const targetAspect = targetWidth / targetHeight;
const newAx = ax; let newAx = ax;
const newAy = ay; let newAy = ay;
const newBx = bx; let newBx = bx;
const newBy = by; let newBy = by;
const newCx = cx; let newCx = cx;
const newCy = cy; let newCy = cy;
const newDx = dx; let newDx = dx;
const newDy = dy; let newDy = dy;
if (options.fit === 'cover') { if (options.fit === 'cover') {
// TODO if (targetAspect > srcAspect) {
const fitHeight = targetWidth / srcAspect;
const crop = (fitHeight - targetHeight) / fitHeight / 2;
newAy = ay + crop * (by - ay);
newBy = by - crop * (by - ay);
newCy = cy + crop * (dy - cy);
newDy = dy - crop * (dy - cy);
} else {
const fitWidth = targetHeight * srcAspect;
const crop = (fitWidth - targetWidth) / fitWidth / 2;
newAx = ax + crop * (bx - ax);
newBx = bx - crop * (bx - ax);
newCx = cx + crop * (dx - cx);
newDx = dx - crop * (dx - cx);
}
} else if (options.fit === 'contain') { } else if (options.fit === 'contain') {
// TODO if (targetAspect > srcAspect) {
const fitWidth = targetHeight * srcAspect;
const crop = (fitWidth - targetWidth) / fitWidth / 2;
newAx = ax + crop * (bx - ax);
newBx = bx - crop * (bx - ax);
newCx = cx + crop * (dx - cx);
newDx = dx - crop * (dx - cx);
} else {
const fitHeight = targetWidth / srcAspect;
const crop = (fitHeight - targetHeight) / fitHeight / 2;
newAy = ay + crop * (by - ay);
newBy = by - crop * (by - ay);
newCy = cy + crop * (dy - cy);
newDy = dy - crop * (dy - cy);
}
} }
uvs[6] = newAx; uvs[4] = newAx;
uvs[7] = newAy; uvs[5] = newAy;
uvs[2] = newBx; uvs[6] = newBx;
uvs[3] = newBy; uvs[7] = newBy;
uvs[4] = newCx; uvs[0] = newCx;
uvs[5] = newCy; uvs[1] = newCy;
uvs[0] = newDx; uvs[2] = newDx;
uvs[1] = newDy; uvs[3] = newDy;
pictureMesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs); pictureMesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
}; };