2025-05-08 11:34:35 +08:00
|
|
|
import { createApp, type App as VueApp } from 'vue'
|
|
|
|
|
|
|
|
|
|
import App from '../App.vue'
|
|
|
|
|
import '../assets/main.css'
|
2025-05-09 16:31:28 +08:00
|
|
|
import { createPinia, disposePinia } from 'pinia';
|
2025-05-08 11:34:35 +08:00
|
|
|
import { ConfigureLibOutput, type LibOutputConfig } from './libOutputConfig';
|
|
|
|
|
import { useEvent } from '../stores/eventStore';
|
2025-05-09 16:31:28 +08:00
|
|
|
import { useScene, useSceneRaw } from '../stores/sceneStore';
|
|
|
|
|
import { DeflateAsync } from '../helpers/helper.compression';
|
2025-05-08 11:34:35 +08:00
|
|
|
|
|
|
|
|
let app: VueApp<Element> = undefined;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 挂载材质编辑器到指定元素
|
|
|
|
|
* @param element 要挂载的HTML元素
|
|
|
|
|
* @param options 程序配置
|
|
|
|
|
*/
|
|
|
|
|
export function Mount(element: Element, options: Partial<LibOutputConfig>) {
|
|
|
|
|
ConfigureLibOutput(options);
|
|
|
|
|
|
|
|
|
|
const pinia = createPinia();
|
|
|
|
|
app = createApp(App);
|
|
|
|
|
app.use(pinia)
|
|
|
|
|
.mount(element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 对程序配置进行更改 */
|
|
|
|
|
export function Configure(options: Partial<LibOutputConfig>) {
|
|
|
|
|
ConfigureLibOutput(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 卸载已经挂载的DOM */
|
|
|
|
|
export function Unmount() {
|
|
|
|
|
app.unmount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 手动进行材质提交 */
|
|
|
|
|
export function Submit() {
|
|
|
|
|
useEvent().Publish('submit');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 更新材质贴图 */
|
|
|
|
|
export function UpdateTexture() {
|
|
|
|
|
useEvent().Publish('update-texture');
|
2025-05-09 16:31:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function SubmitRawAsync(options: { textureSrc: string }): Promise<{ file: string }>
|
|
|
|
|
{
|
2025-05-09 17:27:58 +08:00
|
|
|
let pinia = createPinia();
|
|
|
|
|
const scene = useSceneRaw(pinia);
|
2025-05-09 16:31:28 +08:00
|
|
|
|
|
|
|
|
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();
|
2025-05-09 17:27:58 +08:00
|
|
|
disposePinia(pinia);
|
2025-05-09 16:31:28 +08:00
|
|
|
return {
|
|
|
|
|
file: json
|
|
|
|
|
};
|
2025-05-08 11:34:35 +08:00
|
|
|
}
|