move generate thumb function

This commit is contained in:
casperlamboo 2017-12-17 14:24:01 +01:00
parent c31115aa0b
commit 65592d6f48
2 changed files with 34 additions and 34 deletions

View File

@ -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;
}
});
}

View 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;
}
});
}