From 13312f1ddfc50aad04478578f8de3d7e366678d4 Mon Sep 17 00:00:00 2001 From: "2817212736@qq.com" <2817212736@qq.com> Date: Fri, 13 Jun 2025 16:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BE=93=E5=85=A5=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E8=BE=93=E5=85=A5=E7=BA=B9=E7=90=86=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=97=B6=E9=9C=80=E6=8C=87=E5=AE=9A=E6=9D=90=E8=B4=A8?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/MaterialAdjuster.vue | 27 ++++++++++++++++----------- src/components/MaterialView.vue | 12 ++++++------ src/lib/libOutputConfig.ts | 9 +++++++-- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 7096a68..0649c58 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "material-editor", "private": true, - "version": "1.0.26", + "version": "1.0.27", "type": "module", "scripts": { "dev": "vite", diff --git a/src/components/MaterialAdjuster.vue b/src/components/MaterialAdjuster.vue index 13a6931..e2da467 100644 --- a/src/components/MaterialAdjuster.vue +++ b/src/components/MaterialAdjuster.vue @@ -135,7 +135,7 @@ const { Material, CurrGeometry, Geometries } = storeToRefs(scene); const props = defineProps<{ name?: string; - textureSrcList?: string[]; + textures?: {name: string, src: string}[]; /** 忽略纹理参数,提交时直接输出场景内的材质,用于某些在组件外对场景进行编辑的特殊情况(例如材质编辑模式) */ ignoreTexture?: boolean; }>(); @@ -144,8 +144,8 @@ const emits = defineEmits<{ (e: 'submit', data: MaterialRequest[]): void; }>(); -const debugMode = ref(false); -const textureSrc = computed(() => props.textureSrcList || []); +const debugMode = ref(true); +const Textures = computed(() => props.textures || []); const debugTextureSrc = ref(""); const textureAdjustment = ref({ wrapS: MirroredRepeatWrapping, @@ -202,9 +202,9 @@ const materialInfo = reactive({ inputText: '', }); -watch(textureSrc, async (val) => { +watch(Textures, async (val) => { if (val.length == 0) return; - await scene.ChangeTextureFromUrlAsync(val[0]); + await scene.ChangeTextureFromUrlAsync(val[0].src); }); watch(() => props.name, () => { @@ -261,7 +261,9 @@ async function HandleUpload() { uploading.value = true; const result = []; if (props.ignoreTexture) { - // 直接将材质序列化 + // 注意更改材质内部名称 + Material.value.Name = materialInfo.materialName; + // 将材质序列化 const mat = { name: materialInfo.materialName, logo: await scene.GenerateMaterialLogoAsync(), @@ -272,11 +274,13 @@ async function HandleUpload() { } else { // 遍历纹理链接列表,更改纹理后将材质序列化,然后还原场景 - let idx = 0; - for (const src of textureSrc.value) { - await scene.ChangeTextureFromUrlAsync(src); + for (const texture of Textures.value) { + // 注意更改材质内部名称 + Material.value.Name = texture.name; + // 更新纹理 + await scene.ChangeTextureFromUrlAsync(texture.src); const mat = { - name: textureSrc.value.length > 1 ? materialInfo.materialName + ++idx : materialInfo.materialName, + name: texture.name, logo: await scene.GenerateMaterialLogoAsync(), // jsonString -> Deflate -> BinaryString -> Base64 file: ToDeflatedBase64(await scene.SerializeMaterialAsync()) @@ -285,7 +289,8 @@ async function HandleUpload() { } } - await scene.ChangeTextureFromUrlAsync(textureSrc.value[0]); + // 还原场景纹理 + await scene.ChangeTextureFromUrlAsync(Textures.value[0].src); emits('submit', result); return result; } finally { diff --git a/src/components/MaterialView.vue b/src/components/MaterialView.vue index 735e436..64746dc 100644 --- a/src/components/MaterialView.vue +++ b/src/components/MaterialView.vue @@ -1,7 +1,7 @@ @@ -19,7 +19,7 @@ const eventbus = useEvent(); const container = useTemplateRef('container'); const adjusterRef = useTemplateRef('adjuster'); const config = GetConfig(); -const textureSrc = ref(Array.from(config.textureSrc)); +const textures = ref<{name: string, src: string}[]>(Array.from(config.textures)); const matName = ref(); const editMode = ref(false); @@ -45,7 +45,7 @@ function HandleUpload() { } function HandleChangeTexture() { - textureSrc.value = Array.from(config.textureSrc); + textures.value = Array.from(config.textures); } async function HandleUpdateConfig() { @@ -56,9 +56,9 @@ async function HandleUpdateConfig() { editMode.value = true; } else { editMode.value = false; } - if (config.textureSrc) { - textureSrc.value = Array.from(config.textureSrc); - await scene.ChangeTextureFromUrlAsync(textureSrc.value[0]); // 这一行是保证首次Mount组件时纹理能够立刻刷新 + if (config.textures) { + textures.value = Array.from(config.textures); + await scene.ChangeTextureFromUrlAsync(textures.value[0].src); // 这一行是保证首次Mount组件时纹理能够立刻刷新 } } diff --git a/src/lib/libOutputConfig.ts b/src/lib/libOutputConfig.ts index 652cf16..b6699e4 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: [], + textures: [], file: undefined, submitCallback: undefined, cancelCallback: undefined, @@ -24,7 +24,12 @@ export type LibOutputConfig = { */ host: string, /** 材质贴图链接列表,用与批量提交,场景会只会载入第一个链接作为纹理预览,但是导出提交时会为所有链接创建材质 */ - textureSrc: Array, + textures: Array<{ + /** 材质名 */ + name: string; + /** 纹理链接 */ + src: string; + }>, /** 更新模型,对材质进行编辑时赋值 */ updateModel?: { /** 材质名 */