修复更改预览模型和纹理参数不生效的问题

This commit is contained in:
陈梓阳 2025-06-03 14:31:16 +08:00
parent 990dfa2944
commit 07565d42c4
3 changed files with 7 additions and 11 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "material-editor", "name": "material-editor",
"private": true, "private": true,
"version": "1.0.16", "version": "1.0.17",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@ -108,13 +108,13 @@
</template> </template>
<script setup lang='ts'> <script setup lang='ts'>
import { ref, reactive, watch, onMounted, computed } from "vue" import { ref, reactive, watch } from "vue"
import { useScene, type TextureAdjustment } from "../stores/sceneStore"; import { useScene, type TextureAdjustment } from "../stores/sceneStore";
import CfFlex from "./CfFlex.vue"; import CfFlex from "./CfFlex.vue";
import { DirectoryId } from "../api/Request"; import { DirectoryId } from "../api/Request";
import { IsNullOrWhitespace } from "../helpers/helper.string"; import { IsNullOrWhitespace } from "../helpers/helper.string";
import { FromDeflateBase64, ToDeflatedBase64 } from "../helpers/helper.material"; import { FromDeflateBase64, ToDeflatedBase64 } from "../helpers/helper.material";
import { AsyncDelay } from "../helpers/helper.async"; import { storeToRefs } from "pinia";
export interface MaterialRequest { export interface MaterialRequest {
/** 材质名 */ /** 材质名 */
@ -126,6 +126,7 @@ export interface MaterialRequest {
} }
const scene = useScene(); const scene = useScene();
const { Material, CurrGeometry, Geometries } = storeToRefs(scene);
const props = defineProps<{ const props = defineProps<{
name?: string; name?: string;
@ -138,10 +139,6 @@ const emits = defineEmits<{
(e: 'submit', data: MaterialRequest[]): void; (e: 'submit', data: MaterialRequest[]): void;
}>(); }>();
const Material = computed(() => scene.Material);
const CurrGeometry = computed(() => scene.CurrGeometry);
const Geometries = computed(() => scene.Geometries);
const debugMode = ref(true); const debugMode = ref(true);
const _textureSrc = ref(props.textureSrcList); const _textureSrc = ref(props.textureSrcList);
const debugTextureSrc = ref(""); const debugTextureSrc = ref("");
@ -174,7 +171,7 @@ watch(() => props.textureSrcList, async (val) => {
watch(textureAdjustment, async (val) => { watch(textureAdjustment, async (val) => {
UpdateTexture(); UpdateTexture();
}); }, { deep: true });
// //
watch(() => scene.CurrTexture, (val) => { watch(() => scene.CurrTexture, (val) => {
@ -205,7 +202,6 @@ async function UpdateMaterial() {
} }
function UpdateTexture() { function UpdateTexture() {
console.log('UpdateTexture')
const texture = scene.CurrTexture; const texture = scene.CurrTexture;
const val = textureAdjustment.value; const val = textureAdjustment.value;
texture.wrapS = val.wrapS; texture.wrapS = val.wrapS;
@ -227,6 +223,7 @@ async function loadData() {
} }
async function HandleUpload() { async function HandleUpload() {
console.log(scene.GetEditor().Viewer.Scene.children);
try { try {
if (IsNullOrWhitespace(materialInfo.materialName)) { if (IsNullOrWhitespace(materialInfo.materialName)) {
alert('材质名称不可为空'); alert('材质名称不可为空');
@ -244,7 +241,7 @@ async function HandleUpload() {
file: ToDeflatedBase64(await scene.SerializeMaterialAsync()) file: ToDeflatedBase64(await scene.SerializeMaterialAsync())
}; };
result.push(mat); result.push(mat);
} }
else { else {
// //
let idx = 0; let idx = 0;

View File

@ -75,7 +75,6 @@ const sceneSetup = () => {
} }
async function UpdateMaterialAsync() { async function UpdateMaterialAsync() {
console.log(Material.value.Update);
// TODO: Danger: 如果等待下面这一行,会导致更新卡住(未知问题) // TODO: Danger: 如果等待下面这一行,会导致更新卡住(未知问题)
Material.value.Update(); Material.value.Update();
// Material.value.Material.needsUpdate = true; // Material.value.Material.needsUpdate = true;