更新纹理替换方法,添加材质与纹理绑定逻辑
This commit is contained in:
parent
efb220612e
commit
12676b8726
@ -1,7 +1,7 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
import { MaterialEditor } from "../common/MaterialEditor";
|
import { MaterialEditor } from "../common/MaterialEditor";
|
||||||
import { ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api";
|
import { Database, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api";
|
||||||
import { LoadImageFromUrl } from "../helpers/helper.imageLoader";
|
import { LoadImageFromUrl } from "../helpers/helper.imageLoader";
|
||||||
import { Texture } from "three";
|
import { Texture } from "three";
|
||||||
import { materialRenderer } from "../common/MaterialRenderer";
|
import { materialRenderer } from "../common/MaterialRenderer";
|
||||||
@ -9,6 +9,7 @@ import { MaterialOut } from "../common/MaterialSerializer";
|
|||||||
|
|
||||||
export const useScene = defineStore('scene', () => {
|
export const useScene = defineStore('scene', () => {
|
||||||
let _editor: MaterialEditor | undefined;
|
let _editor: MaterialEditor | undefined;
|
||||||
|
let _database: Database | undefined;
|
||||||
const _currGeometry = ref<string>('球');
|
const _currGeometry = ref<string>('球');
|
||||||
const _currTexture = ref<Texture>();
|
const _currTexture = ref<Texture>();
|
||||||
const CurrGeometry = computed({
|
const CurrGeometry = computed({
|
||||||
@ -25,8 +26,14 @@ export const useScene = defineStore('scene', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 初始化Database
|
||||||
|
_database = new Database();
|
||||||
|
_database.hm.Enable = false; // 关闭历史记录功能
|
||||||
|
Material.value.Name = _database.MaterialTable.AllocateName(); // 使用Database为材质分配材质名
|
||||||
|
_database.MaterialTable.Add(Material.value as PhysicalMaterialRecord);
|
||||||
|
|
||||||
// 为Material配置一个ObjectId,否则其无法被序列化
|
// 为Material配置一个ObjectId,否则其无法被序列化
|
||||||
Material.value.objectId = new ObjectId(undefined, undefined);
|
// Material.value.objectId = new ObjectId(undefined, undefined);
|
||||||
|
|
||||||
_editor = MaterialEditor.GetInstance();
|
_editor = MaterialEditor.GetInstance();
|
||||||
Geometries.value = Array.from(_editor.Geometrys.keys());
|
Geometries.value = Array.from(_editor.Geometrys.keys());
|
||||||
@ -47,6 +54,8 @@ export const useScene = defineStore('scene', () => {
|
|||||||
Material.value.GoodBye();
|
Material.value.GoodBye();
|
||||||
_editor?.Dispose();
|
_editor?.Dispose();
|
||||||
_editor = undefined;
|
_editor = undefined;
|
||||||
|
_database.Destroy();
|
||||||
|
_database = undefined;
|
||||||
window.onresize = undefined;
|
window.onresize = undefined;
|
||||||
|
|
||||||
// 释放Singleton
|
// 释放Singleton
|
||||||
@ -73,13 +82,20 @@ export const useScene = defineStore('scene', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ChangeTextureAsync(url: string) {
|
async function ChangeTextureAsync(url: string) {
|
||||||
const record = new TextureTableRecord();
|
|
||||||
record.objectId = new ObjectId(undefined, record);
|
|
||||||
|
|
||||||
const img = await LoadImageFromUrl(url);
|
const img = await LoadImageFromUrl(url);
|
||||||
|
|
||||||
|
// 关联贴图
|
||||||
|
const db = Material.value.Db;
|
||||||
|
const record = new TextureTableRecord();
|
||||||
|
// record.objectId = new ObjectId(undefined, record);
|
||||||
|
record.Name = db.TextureTable.AllocateName();
|
||||||
|
db.TextureTable.Add(record);
|
||||||
|
|
||||||
|
// 设置Store
|
||||||
_currTexture.value = record['texture'] as Texture;
|
_currTexture.value = record['texture'] as Texture;
|
||||||
_currTexture.value.image = img;
|
_currTexture.value.image = img;
|
||||||
|
|
||||||
|
// 替换map
|
||||||
Material.value.map = img ? record.Id : undefined;
|
Material.value.map = img ? record.Id : undefined;
|
||||||
_currTexture.value.needsUpdate = true;
|
_currTexture.value.needsUpdate = true;
|
||||||
await UpdateMaterialAsync();
|
await UpdateMaterialAsync();
|
||||||
@ -99,9 +115,8 @@ export const useScene = defineStore('scene', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function SerializeMaterialAsync() {
|
async function SerializeMaterialAsync() {
|
||||||
// TODO: Warn: 是否要生成logo路径?
|
|
||||||
// const logoPath = await HandleUpdateLogo();
|
|
||||||
const matJson = MaterialOut(Material.value as PhysicalMaterialRecord);
|
const matJson = MaterialOut(Material.value as PhysicalMaterialRecord);
|
||||||
|
console.log(matJson);
|
||||||
return matJson;
|
return matJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user