From 028aac8137a343750fc90263b9d2522c5c088917 Mon Sep 17 00:00:00 2001 From: "2817212736@qq.com" <2817212736@qq.com> Date: Fri, 30 May 2025 10:44:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/MaterialAdjuster.vue | 43 +++++++++++++++++------------ src/components/MaterialView.vue | 10 +++---- src/lib/libOutputConfig.ts | 8 +++--- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index b21e113..827efa7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "material-editor", "private": true, - "version": "1.0.8", + "version": "1.0.9", "type": "module", "scripts": { "dev": "vite", diff --git a/src/components/MaterialAdjuster.vue b/src/components/MaterialAdjuster.vue index 5d67846..7c5b652 100644 --- a/src/components/MaterialAdjuster.vue +++ b/src/components/MaterialAdjuster.vue @@ -29,8 +29,8 @@

纹理选择(DEBUG)

- -
@@ -127,11 +127,11 @@ export interface MaterialRequest { const scene = useScene(); const props = defineProps<{ - textureSrc?: string; + readonly textureSrcList?: string[]; }>(); const emits = defineEmits<{ (e: 'cancel'): void; - (e: 'submit', data: MaterialRequest): void; + (e: 'submit', data: MaterialRequest[]): void; }>(); const Material = computed(() => scene.Material); @@ -139,7 +139,8 @@ const CurrGeometry = computed(() => scene.CurrGeometry); const Geometries = computed(() => scene.Geometries); const debugMode = ref(false); -const _textureSrc = ref(props.textureSrc); +const _textureSrc = ref(props.textureSrcList); +const debugTextureSrc = ref(""); const textureAdjustment = ref({ wrapS: 0, wrapT: 0, @@ -158,17 +159,17 @@ const uploading = ref(false); // }); const materialInfo = reactive({ dirId: DirectoryId.MaterialDir, // 正常来说是2 - materialName: '材质1', + materialName: '材质', inputText:'', }); onMounted(() => { - scene.ChangeTextureFromUrlAsync(_textureSrc.value); + scene.ChangeTextureFromUrlAsync(_textureSrc.value[0]); }) -watch(() => props.textureSrc, async (val) => { +watch(() => props.textureSrcList, async (val) => { _textureSrc.value = val; - await scene.ChangeTextureFromUrlAsync(_textureSrc.value); + await scene.ChangeTextureFromUrlAsync(_textureSrc.value[0]); }); watch(textureAdjustment, async (val) => { @@ -234,14 +235,22 @@ async function HandleUpload() { } uploading.value = true; - const data = { - name: materialInfo.materialName, - logo: await scene.GenerateMaterialLogoAsync(), - // jsonString -> Deflate -> BinaryString -> Base64 - file: ToDeflatedBase64(await scene.SerializeMaterialAsync()) - }; - emits('submit', data); - return data; + const result = []; + // 遍历纹理链接列表,更改纹理后将材质序列化,然后还原场景 + let idx = 0; + for (const src of props.textureSrcList) { + await scene.ChangeTextureFromUrlAsync(src); + const mat = { + name: materialInfo.materialName + ++idx, + logo: await scene.GenerateMaterialLogoAsync(), + // jsonString -> Deflate -> BinaryString -> Base64 + file: ToDeflatedBase64(await scene.SerializeMaterialAsync()) + }; + result.push(mat); + } + await scene.ChangeTextureFromUrlAsync(_textureSrc.value[0]); + emits('submit', result); + return result; } finally { uploading.value = false; } diff --git a/src/components/MaterialView.vue b/src/components/MaterialView.vue index 68356cf..94242a0 100644 --- a/src/components/MaterialView.vue +++ b/src/components/MaterialView.vue @@ -1,11 +1,11 @@ diff --git a/src/lib/libOutputConfig.ts b/src/lib/libOutputConfig.ts index 4f67877..5784552 100644 --- a/src/lib/libOutputConfig.ts +++ b/src/lib/libOutputConfig.ts @@ -3,7 +3,7 @@ import type { MaterialRequest } from "../components/MaterialAdjuster.vue" let _libOutputConfig = { host:'https://tapi.cfcad.cn:7779', - textureSrc: "", + textureSrc: [], file: undefined, submitCallback: undefined, cancelCallback: undefined, @@ -23,8 +23,8 @@ export type LibOutputConfig = { * 材质文件域名 */ host: string, - /** 材质贴图链接 */ - textureSrc: string, + /** 材质贴图链接列表,场景会只会载入第一个链接作为纹理预览,但是导出提交时会为所有链接创建材质 */ + textureSrc: Array, /** 材质预设数据,base64编码 */ file?: string, /** 环境贴图链接(立方体贴图,按照顺序输入[右左上下前后]) */ @@ -32,7 +32,7 @@ export type LibOutputConfig = { /** 灰度环境贴图链接,输入格式与环境贴图一致 */ grayEnvTextureSrc: string[], /** 提交材质时的回调 */ - submitCallback?: (data: MaterialRequest) => void, + submitCallback?: (data: Array) => void, /** * 取消材质编辑时的回调 * @deprecated 不需要使用