import { v4 as uuidv4 } from 'uuid' import { useStore } from '../useStore' import { faXmark } from '@fortawesome/free-solid-svg-icons' import { ActionButton } from './ActionButton' import Modal from 'react-modal' import React from 'react' import { useFormik } from 'formik' import { Models } from '@kittycad/lib' type OutputFormat = Models['OutputFormat_type'] export const ExportButton = () => { const { engineCommandManager } = useStore((s) => ({ engineCommandManager: s.engineCommandManager, })) const [modalIsOpen, setIsOpen] = React.useState(false) const defaultType = 'gltf' const [type, setType] = React.useState(defaultType) const customModalStyles = { content: { top: '50%', left: '50%', right: 'auto', bottom: 'auto', marginRight: '-50%', transform: 'translate(-50%, -50%)', }, } function openModal() { setIsOpen(true) } function closeModal() { setIsOpen(false) } // Default to gltf and embedded. const initialValues: OutputFormat = { type: defaultType, storage: 'embedded', } const formik = useFormik({ initialValues, onSubmit: (values: OutputFormat) => { // Set the default coords. if ( values.type === 'obj' || values.type === 'ply' || values.type === 'step' || values.type === 'stl' ) { // Set the default coords. // In the future we can make this configurable. // But for now, its probably best to keep it consistent with the // UI. values.coords = { forward: { axis: 'y', direction: 'negative', }, up: { axis: 'z', direction: 'positive', }, } } engineCommandManager?.sendSceneCommand({ type: 'modeling_cmd_req', cmd: { type: 'export', // By default let's leave this blank to export the whole scene. // In the future we might want to let the user choose which entities // in the scene to export. In that case, you'd pass the IDs thru here. entity_ids: [], format: values, }, cmd_id: uuidv4(), file_id: uuidv4(), }) closeModal() }, }) return ( <> Export Export your design Type { setType(e.target.value) formik.handleChange(e) }} > gltf obj ply step stl {(type === 'gltf' || type === 'ply' || type === 'stl') && ( <> {' '} Storage {type === 'gltf' && ( <> embedded binary standard > )} {type === 'ply' && ( <> ascii binary > )} {type === 'stl' && ( <> ascii binary_little_endian binary_big_endian > )} > )} Submit Close > ) }
Type
{ setType(e.target.value) formik.handleChange(e) }} > gltf obj ply step stl
{' '} Storage
{type === 'gltf' && ( <> embedded binary standard > )} {type === 'ply' && ( <> ascii binary > )} {type === 'stl' && ( <> ascii binary_little_endian binary_big_endian > )}