From 8eebeab692f482348f96325986fcb9fa359a67e0 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:48:21 +0900 Subject: [PATCH] Update poster.ts --- .../src/utility/room/objects/poster.ts | 76 ++++++++++++------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/packages/frontend/src/utility/room/objects/poster.ts b/packages/frontend/src/utility/room/objects/poster.ts index eec38c3dcf..7682d0299c 100644 --- a/packages/frontend/src/utility/room/objects/poster.ts +++ b/packages/frontend/src/utility/room/objects/poster.ts @@ -90,37 +90,61 @@ export const poster = defineObject({ let newDy = dy; if (options.fit === 'cover') { - 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); + const ratio = targetAspect / srcAspect; + + let uRange: number; + let vRange: number; + + if (ratio < 1) { + uRange = ratio; // < 1 + vRange = 1; } 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); + uRange = 1; + vRange = 1 / ratio; // < 1 } + + const uMin = (1 - uRange) / 2; + const uMax = uMin + uRange; + const vMin = (1 - vRange) / 2; + const vMax = vMin + vRange; + + newAx = uMin; + newBx = uMax; + newCx = uMin; + newDx = uMax; + + newAy = 1 - vMax; + newBy = 1 - vMax; + newCy = 1 - vMin; + newDy = 1 - vMin; } else if (options.fit === 'contain') { - 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); + const ratio = targetAspect / srcAspect; + + let uRange: number; + let vRange: number; + + if (ratio > 1) { + uRange = ratio; // > 1 + vRange = 1; } 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); + uRange = 1; + vRange = 1 / ratio; // > 1 } + + const uMin = (1 - uRange) / 2; + const uMax = uMin + uRange; + const vMin = (1 - vRange) / 2; + const vMax = vMin + vRange; + + newAx = uMin; + newBx = uMax; + newCx = uMin; + newDx = uMax; + + newAy = 1 - vMax; + newBy = 1 - vMax; + newCy = 1 - vMin; + newDy = 1 - vMin; } uvs[4] = newAx;