更新打包配置,完善组件入参模式,新增事件总线

This commit is contained in:
2025-05-08 11:34:35 +08:00
parent cfbfda520d
commit 4a648c2f97
14 changed files with 1091 additions and 26609 deletions

18
src/stores/eventStore.ts Normal file
View File

@@ -0,0 +1,18 @@
import { defineStore } from "pinia";
export const useEvent = defineStore('event', () => {
const events: Partial<Record<EventNames, Function[]>> = {};
function Subscribe(name: EventNames, callback: Function) {
events[name] = events[name] || [];
events[name].push(callback);
}
function Publish(name: EventNames, ...args: any[]) {
events[name]?.forEach(e => e(...args));
}
return { Subscribe, Publish };
});
export type EventNames = 'submit' | 'update-texture'

View File

@@ -1,14 +1,11 @@
import { defineStore } from "pinia";
import { computed, ref, watch } from "vue";
import { computed, ref } from "vue";
import { MaterialEditor } from "../common/MaterialEditor";
import { Database, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api";
import { ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api";
import { LoadImageFromUrl } from "../helpers/helper.imageLoader";
import { Texture } from "three";
import { materialRenderer } from "../common/MaterialRenderer";
import { ImgsUrl, MaterialUrls } from "../api/Api";
import { Post, PostJson, RequestStatus } from "../api/Request";
import { MaterialOut } from "../common/MaterialSerializer";
import { DeflateAsync } from "../helpers/helper.compression";
export const useScene = defineStore('scene', () => {
let _editor: MaterialEditor;
@@ -72,7 +69,7 @@ export const useScene = defineStore('scene', () => {
_currTexture.value = record['texture'] as Texture;
_currTexture.value.image = img;
Material.value.map = record.Id;
Material.value.map = img ? record.Id : undefined;
_currTexture.value.needsUpdate = true;
await UpdateMaterialAsync();
}
@@ -90,31 +87,28 @@ export const useScene = defineStore('scene', () => {
Update();
}
interface UploadMaterialRequest {
dirId: string;
materialName: string;
}
async function UploadMaterialAsync(request: UploadMaterialRequest) {
async function SerializeMaterialAsync() {
// TODO: Warn: 是否要生成logo路径
// const logoPath = await HandleUpdateLogo();
const matJson = MaterialOut(Material.value as PhysicalMaterialRecord);
console.log(matJson);
return matJson;
}
async function HandleUpdateLogo() {
async function GenerateMaterialLogoAsync() {
const blob = await materialRenderer.getBlob(Material.value.Material);
const file = new File([blob], "blob.png", { type: blob.type });
return blob;
// const file = new File([blob], "blob.png", { type: blob.type });
const formData = new FormData();
formData.append("file", file);
// const formData = new FormData();
// formData.append("file", file);
let data = await Post(ImgsUrl.logo, formData);
// let data = await Post(ImgsUrl.logo, formData);
let logoPath = "";
if (data.err_code === RequestStatus.Ok) {
logoPath = data.images.path;
}
return logoPath;
// let logoPath = "";
// if (data.err_code === RequestStatus.Ok) {
// logoPath = data.images.path;
// }
// return logoPath;
}
return {
@@ -126,7 +120,8 @@ export const useScene = defineStore('scene', () => {
UpdateMaterialAsync,
ChangeTextureAsync,
UpdateTexture,
UploadMaterialAsync,
SerializeMaterialAsync,
GenerateMaterialLogoAsync
};
});
@@ -138,4 +133,8 @@ export type TextureAdjustment = {
repeatY: number,
moveX: number,
moveY: number
}
export interface UploadMaterialRequest {
dirId: string;
materialName: string;
}