修复材质加载与导出

This commit is contained in:
xief committed 2025-05-27 16:54:25 +08:00
1 parent a1a541fff0
commit 16fac2ab19
8 files changed
+50 -197

No files matched your search

+10 -9
View File
@@ -6,8 +6,8 @@ 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';
import { CADFactory, Factory, LayerNode } from 'webcad_ue4_api';
import { CADFactory, LayerNode, PhysicalMaterialRecord, TextureTableRecord } from 'webcad_ue4_api';
import { ToDeflatedBase64 } from '../helpers/helper.material';
let app: VueApp<Element> = undefined;
@@ -16,15 +16,17 @@ let app: VueApp<Element> = undefined;
* @param element 要挂载的HTML元素
* @param options 程序配置
*/
export function Mount(element: Element, options: Partial<LibOutputConfig>) {
ConfigureLibOutput(options);
export function Mount(element: string | Element, options?: Partial<LibOutputConfig>) {
options && ConfigureLibOutput(options);
const pinia = createPinia();
// TODO: Warn: 有BUG,部分实体的构造函数名带_1后缀,原因未知,这会导致CADFactory在创建实体时找不到注册的类名
// @ts-ignore
// console.log(CADFactory.factory.objectNameMap); // 为什么Map中的构造函数名带_1后缀?
console.log(CADFactory['factory'].objectNameMap); // 为什么Map中的构造函数名带_1后缀?
CADFactory.RegisterObjectAlias(LayerNode, "LayerNode");
CADFactory.RegisterObjectAlias(TextureTableRecord, "TextureTableRecord");
CADFactory.RegisterObjectAlias(PhysicalMaterialRecord, "PhysicalMaterialRecord");
app = createApp(App);
app.use(pinia)
@@ -52,8 +54,7 @@ export function UpdateTexture() {
useEvent().Publish('update-texture');
}
export async function SubmitRawAsync(options: { textureSrc: string }): Promise<{ file: string }>
{
export async function SubmitRawAsync(options: { textureSrc: string }): Promise<{ file: string }> {
let pinia = createPinia();
const scene = useSceneRaw(pinia);
@@ -61,8 +62,8 @@ export async function SubmitRawAsync(options: { textureSrc: string }): Promise<{
virtualDom.style.display = 'none';
scene.Initial(virtualDom);
await scene.ChangeTextureFromUrlAsync(options.textureSrc);
var json = btoa(String.fromCharCode(...await DeflateAsync(await scene.SerializeMaterialAsync())));
var json = ToDeflatedBase64(await scene.SerializeMaterialAsync());
scene.Dispose();
virtualDom.remove();
disposePinia(pinia);