mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 19:13:49 +01:00
move generate thumb function
This commit is contained in:
parent
c31115aa0b
commit
65592d6f48
@ -1,4 +1,3 @@
|
||||
import 'blueimp-canvas-to-blob'; // canvas toBlob polyfill
|
||||
import { Matrix } from '@doodle3d/cal';
|
||||
import * as exportSTL from '@doodle3d/threejs-export-stl';
|
||||
import * as exportOBJ from '@doodle3d/threejs-export-obj';
|
||||
@ -11,8 +10,6 @@ import { shapeToPoints } from '../shape/shapeToPoints.js';
|
||||
import { SHAPE_TYPE_PROPERTIES } from '../constants/shapeTypeProperties.js';
|
||||
import { LINE_WIDTH } from '../constants/exportConstants.js';
|
||||
import { bufferToBase64 } from '../utils/binaryUtils.js';
|
||||
import { IMAGE_TYPE, IMAGE_QUALITY } from '../constants/saveConstants.js';
|
||||
import createScene from '../d3/createScene.js';
|
||||
|
||||
const THREE_BSP = ThreeBSP(THREE);
|
||||
|
||||
@ -174,34 +171,3 @@ export async function createFile(state, type, options) {
|
||||
throw new Error(`did not regonize type ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function generateThumb(state, width, height, responseType = 'blob') {
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
34
src/utils/generateThumb.js
Normal file
34
src/utils/generateThumb.js
Normal file
@ -0,0 +1,34 @@
|
||||
import 'blueimp-canvas-to-blob'; // canvas toBlob polyfill
|
||||
import createScene from '../d3/createScene.js';
|
||||
import { IMAGE_TYPE, IMAGE_QUALITY } from '../constants/saveConstants.js';
|
||||
|
||||
export function generateThumb(state, width, height, responseType = 'blob') {
|
||||
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