mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 19:13:49 +01:00
move generate thumb
This commit is contained in:
parent
f5ba53e533
commit
655eaa0e65
@ -1,4 +1,2 @@
|
|||||||
export const THUMBNAIL_WIDTH = 240 * 2; // multiply times 2 because retina
|
|
||||||
export const THUMBNAIL_HEIGHT = 200 * 2;
|
|
||||||
export const IMAGE_TYPE = 'image/jpeg';
|
export const IMAGE_TYPE = 'image/jpeg';
|
||||||
export const IMAGE_QUALITY = 1; // 0 - 1
|
export const IMAGE_QUALITY = 1; // 0 - 1
|
||||||
|
@ -10,6 +10,8 @@ import { shapeToPoints } from '../shape/shapeToPoints.js';
|
|||||||
import { SHAPE_TYPE_PROPERTIES } from '../constants/shapeTypeProperties.js';
|
import { SHAPE_TYPE_PROPERTIES } from '../constants/shapeTypeProperties.js';
|
||||||
import { LINE_WIDTH } from '../constants/exportConstants.js';
|
import { LINE_WIDTH } from '../constants/exportConstants.js';
|
||||||
import { bufferToBase64 } from '../utils/binaryUtils.js';
|
import { bufferToBase64 } from '../utils/binaryUtils.js';
|
||||||
|
import { IMAGE_TYPE, IMAGE_QUALIT } from 'doodle3d-core/constants/saveConstants.js';
|
||||||
|
import createScene from '../d3/createScene.js';
|
||||||
|
|
||||||
const THREE_BSP = ThreeBSP(THREE);
|
const THREE_BSP = ThreeBSP(THREE);
|
||||||
|
|
||||||
@ -165,3 +167,34 @@ export async function createFile(state, type, options) {
|
|||||||
throw new Error(`did not regonize type ${type}`);
|
throw new Error(`did not regonize type ${type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function generateThumb(state, responseType = 'blob', width = THUMBNAIL_WIDTH, height = THUMBNAIL_HEIGHT) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const { render, renderer, setSize } = createScene(state);
|
||||||
|
|
||||||
|
setSize(width, height, 1.0);
|
||||||
|
render();
|
||||||
|
|
||||||
|
// possible to add encoder options for smaller file setSize
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob
|
||||||
|
switch (responseType) {
|
||||||
|
case 'base64':
|
||||||
|
const base64 = renderer.domElement.toDataURL(IMAGE_TYPE, IMAGE_QUALITY);
|
||||||
|
resolve(base64);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'objectURL':
|
||||||
|
renderer.domElement.toCanvas((blob) => {
|
||||||
|
const objectURL = URL.createObjectURL(blob);
|
||||||
|
resolve(objectURL);
|
||||||
|
}, IMAGE_TYPE, IMAGE_QUALITY);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
renderer.domElement.toBlob((blob) => {
|
||||||
|
resolve(blob);
|
||||||
|
}, IMAGE_TYPE, IMAGE_QUALITY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user