修复材质导出问题,添加库打包模式

This commit is contained in:
2025-04-15 09:35:54 +08:00
parent 0929d5b80c
commit cfbfda520d
11 changed files with 26706 additions and 116 deletions

View File

@@ -2,7 +2,7 @@
import MaterialView from './components/MaterialView.vue';
// 禁用右键菜单
document.addEventListener('contextmenu', (e) => e.preventDefault());
// document.addEventListener('contextmenu', (e) => e.preventDefault());
</script>

View File

@@ -1,9 +1,22 @@
import { CADFiler, Database, DuplicateRecordCloning, PhysicalMaterialRecord } from "webcad_ue4_api";
import { CADFactory, CADFiler, CADObject, Database, DuplicateRecordCloning, ObjectId, PhysicalMaterialRecord } from "webcad_ue4_api";
// TODO: Danger: 注意入侵性代码
// 疑似是WebCAD中的漏洞当传入new Database()时,
// Database中的filer.ReadObject方法并不会为CadObject.objectId赋值
// 导致后续的CadObject.Id.Index发生空指针异常
// 因此需要修改CAD中的Database.AllocationObjectId尝试手动赋值
// @ts-ignore
Database.prototype.AllocationObjectId = function (this: Database, object: CADObject) {
if (object.Id === undefined) object.objectId = new ObjectId(undefined, undefined);
// @ts-ignore
object.Id.Index = this.idIndex++;
// @ts-ignore
this.idMap.set(object.Id.Index, object.Id);
}
export function MaterialOut(material: PhysicalMaterialRecord): string
{
let db = new Database();
debugger;
db.WblockCloneObejcts(
[material],
db.MaterialTable,

View File

@@ -11,7 +11,7 @@
</template>
<script setup lang='ts'>
import { type Property } from 'csstype';
import type { Property } from 'csstype';
import { computed } from 'vue';
const props = withDefaults(defineProps<{

View File

@@ -13,6 +13,9 @@ import CfFlex from './CfFlex.vue';
const scene = useScene();
const container = useTemplateRef<HTMLElement>('container');
// 禁用右键菜单
document.addEventListener('contextmenu', (e) => e.preventDefault());
onMounted(() => {
scene.Initial(container.value);
});

View File

@@ -0,0 +1,7 @@
export function DownloadFile(fileName: string, blob: Blob) {
const tempLink = document.createElement('a');
tempLink.href = URL.createObjectURL(blob as Blob);
tempLink.download = fileName;
tempLink.click();
URL.revokeObjectURL(tempLink.href);
}

5
src/lib/index.ts Normal file
View File

@@ -0,0 +1,5 @@
import MaterialView from "../components/MaterialView.vue";
export {
MaterialView
}

View File

@@ -95,19 +95,10 @@ export const useScene = defineStore('scene', () => {
materialName: string;
}
async function UploadMaterialAsync(request: UploadMaterialRequest) {
const logoPath = await HandleUpdateLogo();
// TODO: Warn: 是否要生成logo路径
// const logoPath = await HandleUpdateLogo();
const matJson = MaterialOut(Material.value as PhysicalMaterialRecord);
const data = await PostJson(MaterialUrls.create, {
dir_id: request,
name: request.materialName,
logo: logoPath,
// jsonString -> Deflate -> BinaryString -> Base64
file: btoa(String.fromCharCode(...await DeflateAsync(matJson))),
zip_type: 'gzip',
});
if (data.err_code !== RequestStatus.Ok) {
throw new Error(data.err_msg);
}
console.log(matJson);
}
async function HandleUpdateLogo() {