固定模型缩略图比例
This commit is contained in:
@@ -131,7 +131,8 @@
|
|||||||
|
|
||||||
.thumb {
|
.thumb {
|
||||||
position: relative;
|
position: relative;
|
||||||
min-height: 150px;
|
aspect-ratio: 4 / 3;
|
||||||
|
min-height: 0;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
/* background:
|
/* background:
|
||||||
@@ -179,6 +180,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.thumb img {
|
.thumb img {
|
||||||
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ const zeroBasePoint: PreviewResolvedBasePoint = {
|
|||||||
const RAD_TO_DEG = 180 / Math.PI;
|
const RAD_TO_DEG = 180 / Math.PI;
|
||||||
const DEG_TO_RAD = Math.PI / 180;
|
const DEG_TO_RAD = Math.PI / 180;
|
||||||
const BASE_POINT_DECIMAL_PLACES = 3;
|
const BASE_POINT_DECIMAL_PLACES = 3;
|
||||||
|
const THUMBNAIL_WIDTH = 512;
|
||||||
|
const THUMBNAIL_HEIGHT = 384;
|
||||||
|
|
||||||
const previewEnvironmentUrl = "/DayCityOutdoor.exr";
|
const previewEnvironmentUrl = "/DayCityOutdoor.exr";
|
||||||
const DEFAULT_PREVIEW_FRAME_INTERVAL_MS = 20;
|
const DEFAULT_PREVIEW_FRAME_INTERVAL_MS = 20;
|
||||||
@@ -599,15 +601,31 @@ async function screenshotModel(modelId: number, onThumbnailSaved?: () => Promise
|
|||||||
controls.update();
|
controls.update();
|
||||||
const oldBackground = scene.background;
|
const oldBackground = scene.background;
|
||||||
const oldClearAlpha = renderer.getClearAlpha();
|
const oldClearAlpha = renderer.getClearAlpha();
|
||||||
if (transparent) {
|
const oldPixelRatio = renderer.getPixelRatio();
|
||||||
scene.background = null;
|
const oldWidth = renderer.domElement.width / oldPixelRatio;
|
||||||
renderer.setClearColor(0x000000, 0);
|
const oldHeight = renderer.domElement.height / oldPixelRatio;
|
||||||
}
|
const oldAspect = camera.aspect;
|
||||||
renderer.render(scene, camera);
|
let thumbnail = "";
|
||||||
const thumbnail = renderer.domElement.toDataURL("image/png");
|
try {
|
||||||
if (transparent) {
|
if (transparent) {
|
||||||
scene.background = oldBackground;
|
scene.background = null;
|
||||||
renderer.setClearAlpha(oldClearAlpha);
|
renderer.setClearColor(0x000000, 0);
|
||||||
|
}
|
||||||
|
renderer.setPixelRatio(1);
|
||||||
|
renderer.setSize(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, false);
|
||||||
|
camera.aspect = THUMBNAIL_WIDTH / THUMBNAIL_HEIGHT;
|
||||||
|
camera.updateProjectionMatrix();
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
thumbnail = renderer.domElement.toDataURL("image/png");
|
||||||
|
} finally {
|
||||||
|
camera.aspect = oldAspect;
|
||||||
|
camera.updateProjectionMatrix();
|
||||||
|
renderer.setPixelRatio(oldPixelRatio);
|
||||||
|
renderer.setSize(oldWidth, oldHeight, false);
|
||||||
|
if (transparent) {
|
||||||
|
scene.background = oldBackground;
|
||||||
|
renderer.setClearAlpha(oldClearAlpha);
|
||||||
|
}
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
await api(`/api/models/${modelId}/thumbnail`, {
|
await api(`/api/models/${modelId}/thumbnail`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user