添加静默提交功能
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "material-editor",
 | 
					  "name": "material-editor",
 | 
				
			||||||
  "private": true,
 | 
					  "private": true,
 | 
				
			||||||
  "version": "1.0.4",
 | 
					  "version": "1.0.5",
 | 
				
			||||||
  "type": "module",
 | 
					  "type": "module",
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "dev": "vite",
 | 
					    "dev": "vite",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ async function textureRenderUpdate(textureRecord:TextureTableRecord){
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * 材质编辑器
 | 
					 * 材质编辑器
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export class MaterialEditor extends Singleton
 | 
					export class MaterialEditor
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Geometrys: Map<string, Geometry | BufferGeometry>;
 | 
					    Geometrys: Map<string, Geometry | BufferGeometry>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,9 +40,8 @@ export class MaterialEditor extends Singleton
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private _MeshMaterial: MeshPhysicalMaterial = new MeshPhysicalMaterial({});
 | 
					    private _MeshMaterial: MeshPhysicalMaterial = new MeshPhysicalMaterial({});
 | 
				
			||||||
    //构造
 | 
					    //构造
 | 
				
			||||||
    private constructor()
 | 
					    constructor()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super();
 | 
					 | 
				
			||||||
        this.initGeometrys();
 | 
					        this.initGeometrys();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.LoadDefaultExr();
 | 
					        this.LoadDefaultExr();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
import { ImageLoader } from "three";
 | 
					import { ImageLoader } from "three";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let loader = new ImageLoader();
 | 
					 | 
				
			||||||
export async function LoadImageFromUrl(url: string): Promise<HTMLImageElement>
 | 
					export async function LoadImageFromUrl(url: string): Promise<HTMLImageElement>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return new Promise<HTMLImageElement>(async (res, rej) =>
 | 
					    return new Promise<HTMLImageElement>(async (res, rej) =>
 | 
				
			||||||
@@ -11,6 +10,7 @@ export async function LoadImageFromUrl(url: string): Promise<HTMLImageElement>
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var loader = new ImageLoader();
 | 
				
			||||||
        loader.load(url,
 | 
					        loader.load(url,
 | 
				
			||||||
            img => res(img), e => { },
 | 
					            img => res(img), e => { },
 | 
				
			||||||
            err => res(undefined)
 | 
					            err => res(undefined)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,9 +2,11 @@ import { createApp, type App as VueApp } from 'vue'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import App from '../App.vue'
 | 
					import App from '../App.vue'
 | 
				
			||||||
import '../assets/main.css'
 | 
					import '../assets/main.css'
 | 
				
			||||||
import { createPinia } from 'pinia';
 | 
					import { createPinia, disposePinia } from 'pinia';
 | 
				
			||||||
import { ConfigureLibOutput, type LibOutputConfig } from './libOutputConfig';
 | 
					import { ConfigureLibOutput, type LibOutputConfig } from './libOutputConfig';
 | 
				
			||||||
import { useEvent } from '../stores/eventStore';
 | 
					import { useEvent } from '../stores/eventStore';
 | 
				
			||||||
 | 
					import { useScene, useSceneRaw } from '../stores/sceneStore';
 | 
				
			||||||
 | 
					import { DeflateAsync } from '../helpers/helper.compression';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let app: VueApp<Element> = undefined;
 | 
					let app: VueApp<Element> = undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,4 +42,21 @@ export function Submit() {
 | 
				
			|||||||
/** 更新材质贴图 */
 | 
					/** 更新材质贴图 */
 | 
				
			||||||
export function UpdateTexture() {
 | 
					export function UpdateTexture() {
 | 
				
			||||||
    useEvent().Publish('update-texture');
 | 
					    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
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,9 +1,10 @@
 | 
				
			|||||||
import { Mount, Unmount, Submit, UpdateTexture, Configure } from "./entry";
 | 
					import { Mount, Unmount, Submit, UpdateTexture, Configure, SubmitRawAsync } from "./entry";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export {
 | 
					export {
 | 
				
			||||||
    Mount,
 | 
					    Mount,
 | 
				
			||||||
    Unmount,
 | 
					    Unmount,
 | 
				
			||||||
    Submit,
 | 
					    Submit,
 | 
				
			||||||
    UpdateTexture,
 | 
					    UpdateTexture,
 | 
				
			||||||
    Configure
 | 
					    Configure,
 | 
				
			||||||
 | 
					    SubmitRawAsync
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -19,4 +19,4 @@ export const useEvent = defineStore('event', () => {
 | 
				
			|||||||
    return { Subscribe, Publish, Unsubscribe };
 | 
					    return { Subscribe, Publish, Unsubscribe };
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type EventNames = 'submit' | 'update-texture'
 | 
					export type EventNames = 'submit' | 'update-texture';
 | 
				
			||||||
@@ -7,7 +7,7 @@ import { Texture } from "three";
 | 
				
			|||||||
import { materialRenderer } from "../common/MaterialRenderer";
 | 
					import { materialRenderer } from "../common/MaterialRenderer";
 | 
				
			||||||
import { MaterialOut } from "../common/MaterialSerializer";
 | 
					import { MaterialOut } from "../common/MaterialSerializer";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const useScene = defineStore('scene', () => {
 | 
					const sceneSetup = () => {
 | 
				
			||||||
    let _editor: MaterialEditor | undefined;
 | 
					    let _editor: MaterialEditor | undefined;
 | 
				
			||||||
    let _database: Database | undefined;
 | 
					    let _database: Database | undefined;
 | 
				
			||||||
    const _currGeometry = ref<string>('球');
 | 
					    const _currGeometry = ref<string>('球');
 | 
				
			||||||
@@ -35,7 +35,7 @@ export const useScene = defineStore('scene', () => {
 | 
				
			|||||||
        // 为Material配置一个ObjectId,否则其无法被序列化
 | 
					        // 为Material配置一个ObjectId,否则其无法被序列化
 | 
				
			||||||
        // Material.value.objectId = new ObjectId(undefined, undefined);
 | 
					        // Material.value.objectId = new ObjectId(undefined, undefined);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        _editor = MaterialEditor.GetInstance();
 | 
					        _editor = new MaterialEditor();
 | 
				
			||||||
        Geometries.value = Array.from(_editor.Geometrys.keys());
 | 
					        Geometries.value = Array.from(_editor.Geometrys.keys());
 | 
				
			||||||
        _currGeometry.value = _editor.CurGeometryName;
 | 
					        _currGeometry.value = _editor.CurGeometryName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -50,16 +50,12 @@ export const useScene = defineStore('scene', () => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function Dispose() {
 | 
					    function Dispose() {
 | 
				
			||||||
        console.log("Disposing...");
 | 
					 | 
				
			||||||
        Material.value.GoodBye();
 | 
					        Material.value.GoodBye();
 | 
				
			||||||
        _editor?.Dispose();
 | 
					        _editor?.Dispose();
 | 
				
			||||||
        _editor = undefined;
 | 
					        _editor = undefined;
 | 
				
			||||||
        _database.Destroy();
 | 
					        _database.Destroy();
 | 
				
			||||||
        _database = undefined;
 | 
					        _database = undefined;
 | 
				
			||||||
        window.onresize = undefined;
 | 
					        window.onresize = undefined;
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // 释放Singleton
 | 
					 | 
				
			||||||
        MaterialEditor.ReleaseInstance();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function ChangeGeometry(geoName: string) {
 | 
					    function ChangeGeometry(geoName: string) {
 | 
				
			||||||
@@ -150,7 +146,10 @@ export const useScene = defineStore('scene', () => {
 | 
				
			|||||||
        GenerateMaterialLogoAsync,
 | 
					        GenerateMaterialLogoAsync,
 | 
				
			||||||
        Dispose
 | 
					        Dispose
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
});
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const useScene = defineStore('scene', sceneSetup);
 | 
				
			||||||
 | 
					export const useSceneRaw = defineStore('sceneRaw', sceneSetup); // 独立场景,用来静默执行材质序列化
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type TextureAdjustment = {
 | 
					export type TextureAdjustment = {
 | 
				
			||||||
    wrapS: number,
 | 
					    wrapS: number,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user