优化纹理参数绑定处理逻辑,添加默认纹理参数
This commit is contained in:
@@ -70,16 +70,16 @@
|
||||
|
||||
<label>平铺U</label>
|
||||
<select v-model="textureAdjustment.wrapS">
|
||||
<option value="0">镜像平铺</option>
|
||||
<option value="1">平铺</option>
|
||||
<option value="2">展开</option>
|
||||
<option :value="MirroredRepeatWrapping">镜像平铺</option>
|
||||
<option :value="RepeatWrapping">平铺</option>
|
||||
<option :value="ClampToEdgeWrapping">展开</option>
|
||||
</select>
|
||||
|
||||
<label>平铺V</label>
|
||||
<select v-model="textureAdjustment.wrapT">
|
||||
<option value="0">镜像平铺</option>
|
||||
<option value="1">平铺</option>
|
||||
<option value="2">展开</option>
|
||||
<option :value="MirroredRepeatWrapping">镜像平铺</option>
|
||||
<option :value="RepeatWrapping">平铺</option>
|
||||
<option :value="ClampToEdgeWrapping">展开</option>
|
||||
</select>
|
||||
|
||||
<label>旋转</label>
|
||||
@@ -119,6 +119,7 @@ import { FromDeflateBase64, ToDeflatedBase64 } from "../helpers/helper.material"
|
||||
import { storeToRefs } from "pinia";
|
||||
import { DownloadFile } from "../helpers/helper.web";
|
||||
import MathHelper from "../helpers/MathHelper";
|
||||
import { ClampToEdgeWrapping, MirroredRepeatWrapping, RepeatWrapping, Wrapping } from "three";
|
||||
|
||||
export interface MaterialRequest {
|
||||
/** 材质名 */
|
||||
@@ -144,11 +145,11 @@ const emits = defineEmits<{
|
||||
}>();
|
||||
|
||||
const debugMode = ref(false);
|
||||
const _textureSrc = ref(props.textureSrcList);
|
||||
const textureSrc = computed(() => props.textureSrcList || []);
|
||||
const debugTextureSrc = ref("");
|
||||
const textureAdjustment = ref<TextureAdjustment>({
|
||||
wrapS: 0,
|
||||
wrapT: 0,
|
||||
wrapS: MirroredRepeatWrapping,
|
||||
wrapT: MirroredRepeatWrapping,
|
||||
rotation: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
@@ -201,9 +202,9 @@ const materialInfo = reactive({
|
||||
inputText: '',
|
||||
});
|
||||
|
||||
watch(() => props.textureSrcList, async (val) => {
|
||||
_textureSrc.value = val;
|
||||
await scene.ChangeTextureFromUrlAsync(_textureSrc.value[0]);
|
||||
watch(textureSrc, async (val) => {
|
||||
if (val.length == 0) return;
|
||||
await scene.ChangeTextureFromUrlAsync(val[0]);
|
||||
});
|
||||
|
||||
watch(() => props.name, () => {
|
||||
@@ -211,19 +212,19 @@ watch(() => props.name, () => {
|
||||
});
|
||||
|
||||
watch(textureAdjustment, async (val) => {
|
||||
UpdateTexture();
|
||||
scene.UpdateTexture();
|
||||
}, { deep: true });
|
||||
|
||||
// 监听纹理更新
|
||||
watch(() => scene.CurrTexture, (val) => {
|
||||
textureAdjustment.value = {
|
||||
wrapS: val.wrapS,
|
||||
wrapT: val.wrapT,
|
||||
wrapS: val.WrapS,
|
||||
wrapT: val.WrapT,
|
||||
rotation: val.rotation,
|
||||
repeatX: val.repeat.x,
|
||||
repeatY: val.repeat.y,
|
||||
moveX: val.offset.x,
|
||||
moveY: val.offset.y
|
||||
repeatX: val.repeatX,
|
||||
repeatY: val.repeatY,
|
||||
moveX: val.moveX,
|
||||
moveY: val.moveY
|
||||
}
|
||||
})
|
||||
|
||||
@@ -242,20 +243,6 @@ async function UpdateMaterial() {
|
||||
await scene.UpdateMaterialAsync();
|
||||
}
|
||||
|
||||
function UpdateTexture() {
|
||||
const texture = scene.CurrTexture;
|
||||
const val = textureAdjustment.value;
|
||||
texture.wrapS = val.wrapS;
|
||||
texture.wrapT = val.wrapT;
|
||||
texture.anisotropy = 16;
|
||||
texture.rotation = val.rotation;
|
||||
texture.repeat.set(val.repeatX, val.repeatY);
|
||||
texture.offset.set(val.moveX, val.moveY);
|
||||
texture.needsUpdate = true;
|
||||
|
||||
scene.Update();
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
if (!materialInfo.inputText) return;
|
||||
const json = JSON.parse(materialInfo.inputText);
|
||||
@@ -286,10 +273,10 @@ async function HandleUpload() {
|
||||
else {
|
||||
// 遍历纹理链接列表,更改纹理后将材质序列化,然后还原场景
|
||||
let idx = 0;
|
||||
for (const src of _textureSrc.value) {
|
||||
for (const src of textureSrc.value) {
|
||||
await scene.ChangeTextureFromUrlAsync(src);
|
||||
const mat = {
|
||||
name: materialInfo.materialName + ++idx,
|
||||
name: textureSrc.value.length > 1 ? materialInfo.materialName + ++idx : materialInfo.materialName,
|
||||
logo: await scene.GenerateMaterialLogoAsync(),
|
||||
// jsonString -> Deflate -> BinaryString -> Base64
|
||||
file: ToDeflatedBase64(await scene.SerializeMaterialAsync())
|
||||
@@ -298,7 +285,7 @@ async function HandleUpload() {
|
||||
}
|
||||
}
|
||||
|
||||
await scene.ChangeTextureFromUrlAsync(_textureSrc.value[0]);
|
||||
await scene.ChangeTextureFromUrlAsync(textureSrc.value[0]);
|
||||
emits('submit', result);
|
||||
return result;
|
||||
} finally {
|
||||
|
@@ -58,7 +58,7 @@ async function HandleUpdateConfig() {
|
||||
else { editMode.value = false; }
|
||||
if (config.textureSrc) {
|
||||
textureSrc.value = Array.from(config.textureSrc);
|
||||
await scene.ChangeTextureFromUrlAsync(textureSrc.value[0]);
|
||||
await scene.ChangeTextureFromUrlAsync(textureSrc.value[0]); // 这一行是保证首次Mount组件时纹理能够立刻刷新
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user