添加静默提交功能

This commit is contained in:
陈梓阳 2025-05-09 16:31:28 +08:00
parent ce3dc618d0
commit 835cdba82d
7 changed files with 34 additions and 16 deletions

View File

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

View File

@ -27,7 +27,7 @@ async function textureRenderUpdate(textureRecord:TextureTableRecord){
/**
*
*/
export class MaterialEditor extends Singleton
export class MaterialEditor
{
Geometrys: Map<string, Geometry | BufferGeometry>;
@ -40,9 +40,8 @@ export class MaterialEditor extends Singleton
private _MeshMaterial: MeshPhysicalMaterial = new MeshPhysicalMaterial({});
//构造
private constructor()
constructor()
{
super();
this.initGeometrys();
this.LoadDefaultExr();

View File

@ -1,6 +1,5 @@
import { ImageLoader } from "three";
let loader = new ImageLoader();
export async function LoadImageFromUrl(url: string): Promise<HTMLImageElement>
{
return new Promise<HTMLImageElement>(async (res, rej) =>
@ -11,6 +10,7 @@ export async function LoadImageFromUrl(url: string): Promise<HTMLImageElement>
return;
};
var loader = new ImageLoader();
loader.load(url,
img => res(img), e => { },
err => res(undefined)

View File

@ -2,9 +2,11 @@ import { createApp, type App as VueApp } from 'vue'
import App from '../App.vue'
import '../assets/main.css'
import { createPinia } from 'pinia';
import { createPinia, disposePinia } from 'pinia';
import { ConfigureLibOutput, type LibOutputConfig } from './libOutputConfig';
import { useEvent } from '../stores/eventStore';
import { useScene, useSceneRaw } from '../stores/sceneStore';
import { DeflateAsync } from '../helpers/helper.compression';
let app: VueApp<Element> = undefined;
@ -41,3 +43,20 @@ export function Submit() {
export function UpdateTexture() {
useEvent().Publish('update-texture');
}
export async function SubmitRawAsync(options: { textureSrc: string }): Promise<{ file: string }>
{
const scene = useSceneRaw();
const virtualDom = document.createElement('div');
virtualDom.style.display = 'none';
scene.Initial(virtualDom);
await scene.ChangeTextureAsync(options.textureSrc);
var json = btoa(String.fromCharCode(...await DeflateAsync(await scene.SerializeMaterialAsync())));
scene.Dispose();
virtualDom.remove();
return {
file: json
};
}

View File

@ -1,9 +1,10 @@
import { Mount, Unmount, Submit, UpdateTexture, Configure } from "./entry";
import { Mount, Unmount, Submit, UpdateTexture, Configure, SubmitRawAsync } from "./entry";
export {
Mount,
Unmount,
Submit,
UpdateTexture,
Configure
Configure,
SubmitRawAsync
}

View File

@ -19,4 +19,4 @@ export const useEvent = defineStore('event', () => {
return { Subscribe, Publish, Unsubscribe };
});
export type EventNames = 'submit' | 'update-texture'
export type EventNames = 'submit' | 'update-texture';

View File

@ -7,7 +7,7 @@ import { Texture } from "three";
import { materialRenderer } from "../common/MaterialRenderer";
import { MaterialOut } from "../common/MaterialSerializer";
export const useScene = defineStore('scene', () => {
const sceneSetup = () => {
let _editor: MaterialEditor | undefined;
let _database: Database | undefined;
const _currGeometry = ref<string>('球');
@ -35,7 +35,7 @@ export const useScene = defineStore('scene', () => {
// 为Material配置一个ObjectId否则其无法被序列化
// Material.value.objectId = new ObjectId(undefined, undefined);
_editor = MaterialEditor.GetInstance();
_editor = new MaterialEditor();
Geometries.value = Array.from(_editor.Geometrys.keys());
_currGeometry.value = _editor.CurGeometryName;
@ -50,16 +50,12 @@ export const useScene = defineStore('scene', () => {
}
function Dispose() {
console.log("Disposing...");
Material.value.GoodBye();
_editor?.Dispose();
_editor = undefined;
_database.Destroy();
_database = undefined;
window.onresize = undefined;
// 释放Singleton
MaterialEditor.ReleaseInstance();
}
function ChangeGeometry(geoName: string) {
@ -150,7 +146,10 @@ export const useScene = defineStore('scene', () => {
GenerateMaterialLogoAsync,
Dispose
};
});
};
export const useScene = defineStore('scene', sceneSetup);
export const useSceneRaw = defineStore('sceneRaw', sceneSetup); // 独立场景,用来静默执行材质序列化
export type TextureAdjustment = {
wrapS: number,