修复材质导入问题

This commit is contained in:
2025-05-29 19:00:36 +08:00
parent 26f1c60a43
commit 99613dbc83
4 changed files with 40 additions and 38 deletions

View File

@@ -38,25 +38,25 @@
<label>金属度</label>
<CfFlex gap="1em">
<input v-model="Material.matalness" @change="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<input v-model="Material.matalness" @input="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<span>{{ Material.matalness }}</span>
</CfFlex>
<label>粗糙度</label>
<CfFlex gap="1em">
<input v-model="Material.roughness" @change="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<input v-model="Material.roughness" @input="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<span>{{ Material.roughness }}</span>
</CfFlex>
<label>法线强度</label>
<CfFlex gap="1em">
<input v-model="Material.bumpScale" @change="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<input v-model="Material.bumpScale" @input="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<span>{{ Material.bumpScale }}</span>
</CfFlex>
<label>高光</label>
<CfFlex gap="1em">
<input v-model="Material.specular" @change="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<input v-model="Material.specular" @input="UpdateMaterial" type="range" min="0" max="1" step="0.01" />
<span>{{ Material.specular }}</span>
</CfFlex>
</div>
@@ -64,9 +64,9 @@
<div class="adjust-section">
<h3>纹理调节</h3>
<label>启用纹理</label>
<input type="checkbox" v-model="enableTexture" />
<input type="checkbox" v-model="Material.useMap" @change="UpdateMaterial" />
<!-- <label>平铺U</label>
<label>平铺U</label>
<select v-model="textureAdjustment.wrapS">
<option value="0">镜像平铺</option>
<option value="1">平铺</option>
@@ -78,7 +78,7 @@
<option value="0">镜像平铺</option>
<option value="1">平铺</option>
<option value="2">展开</option>
</select> -->
</select>
<label>旋转</label>
<input v-model="textureAdjustment.rotation" type="number" step="0.01" min="0" max="359" />
@@ -108,9 +108,8 @@
</template>
<script setup lang='ts'>
import { ref, reactive, watch, onMounted } from "vue"
import { ref, reactive, watch, onMounted, computed } from "vue"
import { useScene, type TextureAdjustment } from "../stores/sceneStore";
import { storeToRefs } from "pinia";
import CfFlex from "./CfFlex.vue";
import { DirectoryId } from "../api/Request";
import { IsNullOrWhitespace } from "../helpers/helper.string";
@@ -135,9 +134,11 @@ const emits = defineEmits<{
(e: 'submit', data: MaterialRequest): void;
}>();
const debugMode = ref(true);
const { CurrGeometry, Geometries, Material } = storeToRefs(scene);
const enableTexture = ref(Material.value.useMap);
const Material = computed(() => scene.Material);
const CurrGeometry = computed(() => scene.CurrGeometry);
const Geometries = computed(() => scene.Geometries);
const debugMode = ref(false);
const _textureSrc = ref(props.textureSrc);
const textureAdjustment = ref<TextureAdjustment>({
wrapS: 0,
@@ -170,11 +171,6 @@ watch(() => props.textureSrc, async (val) => {
await scene.ChangeTextureFromUrlAsync(_textureSrc.value);
});
watch(enableTexture, async (val) => {
await EnableTexture(val);
});
watch(textureAdjustment, async (val) => {
UpdateTexture();
});
@@ -194,13 +190,18 @@ watch(() => scene.CurrTexture, (val) => {
})
async function UpdateMaterial() {
console.log(scene.CurrentShowObject)
// console.log((scene.CurrentShowObject.children[0] as Mesh).material.metalness);
// console.log(Material.value.Material.metalness);
// console.log(scene.Material == scene.GetEditor().Material)
// Material.value.matalness = model.metallic;
// Material.value.roughness = model.roughness;
// Material.value.bumpScale = model.normalScale;
// Material.value.specular = model.emissiveIntensity;
// Material.value.side = DoubleSide;
await scene.UpdateMaterialAsync();
scene.Update();
await scene.UpdateMaterialAsync();
}
function UpdateTexture() {
@@ -218,11 +219,6 @@ function UpdateTexture() {
scene.Update();
}
async function EnableTexture(enable: boolean) {
Material.value.useMap = enable;
await scene.UpdateMaterialAsync();
}
async function loadData() {
if(!materialInfo.inputText) return;
const json = JSON.parse(materialInfo.inputText);