diff --git a/src/utils/exportUtils.js b/src/utils/exportUtils.js index 9d0f25d..3d2220e 100644 --- a/src/utils/exportUtils.js +++ b/src/utils/exportUtils.js @@ -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; - } - }); -} diff --git a/src/utils/generateThumb.js b/src/utils/generateThumb.js new file mode 100644 index 0000000..6dc50ba --- /dev/null +++ b/src/utils/generateThumb.js @@ -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; + } + }); +}