diff --git a/src/components/modal/ImportSmapModal.vue b/src/components/modal/ImportSmapModal.vue new file mode 100644 index 0000000..7072209 --- /dev/null +++ b/src/components/modal/ImportSmapModal.vue @@ -0,0 +1,75 @@ + + + diff --git a/src/hooks/useMapConversion.ts b/src/hooks/useMapConversion.ts index a250197..96b426a 100644 --- a/src/hooks/useMapConversion.ts +++ b/src/hooks/useMapConversion.ts @@ -90,14 +90,15 @@ export function useMapConversion() { } }; - const convertSceneToIray = async (sceneJson: string, filename: string) => { + const convertSceneToIray = async (sceneJson: string, smapFile: File, filename: string) => { isConverting.value = true; try { const formData = new FormData(); const sceneBlob = new Blob([sceneJson], { type: 'application/json' }); formData.append('scene_file', sceneBlob, `${filename}.scene`); + formData.append('smap_file', smapFile); - const response = await mapConverterHttp.post(`${API_BASE_URL}/scene-to-iray`, formData, { + const response = await mapConverterHttp.post(`${API_BASE_URL}/smap-to-iray`, formData, { headers: { 'Content-Type': 'multipart/form-data' }, responseType: 'blob', }); diff --git a/src/pages/scene-editor.vue b/src/pages/scene-editor.vue index 11e8b62..2f0cbfc 100644 --- a/src/pages/scene-editor.vue +++ b/src/pages/scene-editor.vue @@ -8,6 +8,7 @@ import expandIcon from '../assets/icons/png/expand.png'; import foldIcon from '../assets/icons/png/fold.png'; import BatchEditToolbar from '../components/batch-edit-toolbar.vue'; import AutoCreateStorageModal from '../components/modal/auto-create-storage-modal.vue'; +import ImportSmapModal from '../components/modal/ImportSmapModal.vue'; import { useMapConversion } from '../hooks/useMapConversion'; import { EditorService } from '../services/editor.service'; import { useViewState } from '../services/useViewState'; @@ -160,39 +161,38 @@ const importScene = async () => { editor.value?.load(json, editable.value, undefined, true); }; -const importSmap = async () => { - const file = await selectFile('.smap'); - if (!file) return; - const sceneJson = await convertSmapToScene(file); +const importSmapModalVisible = ref(false); + +const handleImportSmapConfirm = async ({ + smapFile, + keepProperties, +}: { + smapFile: File; + keepProperties: boolean; +}) => { + let sceneJson: string | null = null; + if (keepProperties) { + // Update mode + const currentSceneJson = editor.value?.save(); + if (!currentSceneJson) { + message.error('无法获取当前场景数据,请确保场景不为空'); + return; + } + const sceneBlob = new Blob([currentSceneJson], { type: 'application/json' }); + const sceneFile = new File([sceneBlob], `${title.value || 'current'}.scene`, { + type: 'application/json', + }); + sceneJson = await convertSmapToScene(smapFile, sceneFile); + } else { + // Create mode + sceneJson = await convertSmapToScene(smapFile); + } + if (sceneJson) { editor.value?.load(sceneJson, editable.value, undefined, true); } }; -const handleUpdateSceneWithSmap = async () => { - // 1. Get current scene content from editor - const currentSceneJson = editor.value?.save(); - if (!currentSceneJson) { - message.error('无法获取当前场景数据,请确保场景不为空'); - return; - } - - // 2. Prompt user to select the .smap file - message.info('请选择用于更新当前场景的 SMAP 文件'); - const smapFile = await selectFile('.smap'); - if (!smapFile) return; - - // 3. Convert current scene json to a File object in memory - const sceneBlob = new Blob([currentSceneJson], { type: 'application/json' }); - const sceneFile = new File([sceneBlob], `${title.value || 'current'}.scene`, { type: 'application/json' }); - - // 4. Call the update function - const newSceneJson = await convertSmapToScene(smapFile, sceneFile); - if (newSceneJson) { - editor.value?.load(newSceneJson, editable.value, undefined, true); - } -}; - const importBinTask = async () => { try { const file = await selectFile('.xlsx,.xls'); @@ -240,8 +240,16 @@ const exportSmap = async () => { const exportAsIray = async () => { const json = editor.value?.save(); - if (!json) return; - await convertSceneToIray(json, title.value || 'unknown'); + if (!json) { + message.error('无法获取当前场景数据,请确保场景不为空'); + return; + } + + message.info('请选择一个 SMAP 文件用于 IRAY 导出'); + const smapFile = await selectFile('.smap'); + if (!smapFile) return; + + await convertSceneToIray(json, smapFile, title.value || 'unknown'); }; const show = ref(true); @@ -322,9 +330,8 @@ const handleAutoCreateStorageCancel = () => { {{ $t('导入') }} @@ -387,6 +394,8 @@ const handleAutoCreateStorageCancel = () => { + +