import { v4 as uuidv4 } from 'uuid' import { useStore } from '../useStore' import { faFileExport, 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'] interface ExportButtonProps extends React.PropsWithChildren { className?: { button?: string // If we wanted more classname configuration of sub-elements, // put them here } } export const ExportButton = ({ children, className }: ExportButtonProps) => { const { engineCommandManager } = useStore((s) => ({ engineCommandManager: s.engineCommandManager, })) const [modalIsOpen, setIsOpen] = React.useState(false) const defaultType = 'gltf' const [type, setType] = React.useState(defaultType) function openModal() { setIsOpen(true) } function closeModal() { setIsOpen(false) } // Default to gltf and embedded. const initialValues: OutputFormat = { type: defaultType, storage: 'embedded', presentation: 'compact', } 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(), }) closeModal() }, }) const yo = formik.values return ( <> {children || 'Export'}

Export your design

{(type === 'gltf' || type === 'ply' || type === 'stl') && ( )}
Close Export
) }