From 1e909070fa5b4e97e894f2e694d6d8b081b87af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Gonz=C3=A1lez=20Viegas?= Date: Wed, 2 Oct 2024 17:26:51 +0200 Subject: [PATCH] feat: add model settings --- packages/clay/src/core/Model/index.ts | 11 ++-- .../src/elements/Walls/SimpleWall/example.ts | 66 +++++++++---------- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/packages/clay/src/core/Model/index.ts b/packages/clay/src/core/Model/index.ts index 88e1524..f637c0d 100644 --- a/packages/clay/src/core/Model/index.ts +++ b/packages/clay/src/core/Model/index.ts @@ -11,6 +11,10 @@ export class Model { absolute: false, }; + settings: WEBIFC.LoaderSettings = { + TAPE_SIZE: 5000000, // 5MB + }; + /** * Opaque material of the model. All models have just 1 shared opaque and transparent material. */ @@ -70,9 +74,7 @@ export class Model { await this._ifcAPI.Init(); this._modelID = this._ifcAPI.CreateModel( { schema: WEBIFC.Schemas.IFC4X3 }, - { - TAPE_SIZE: 5000000, // 5MB - }, + this.settings, ); this._context = new WEBIFC.IFC4X3.IfcRepresentationContext( new WEBIFC.IFC4X3.IfcLabel("Default"), @@ -139,7 +141,6 @@ export class Model { * Updates a model. Necessary for applying new boolean operations. */ async update() { - console.log("hey") if (this._modelID === undefined) { throw new Error("Malformed model!"); } @@ -151,6 +152,6 @@ export class Model { this._ifcAPI = new WEBIFC.IfcAPI(); await this.init(); - this._modelID = this._ifcAPI.OpenModel(model); + this._modelID = this._ifcAPI.OpenModel(model, this.settings); } } diff --git a/packages/clay/src/elements/Walls/SimpleWall/example.ts b/packages/clay/src/elements/Walls/SimpleWall/example.ts index 99995aa..e2f2a91 100644 --- a/packages/clay/src/elements/Walls/SimpleWall/example.ts +++ b/packages/clay/src/elements/Walls/SimpleWall/example.ts @@ -3,6 +3,7 @@ import * as BUI from "@thatopen/ui"; import Stats from "stats.js"; import * as OBC from "@thatopen/components"; +import * as WEBIFC from "web-ifc"; import * as CLAY from "../../.."; const container = document.getElementById("container")!; @@ -33,7 +34,7 @@ model.wasm = { path: "https://unpkg.com/web-ifc@0.0.59/", absolute: true }; await model.init(); const simpleWallType = new CLAY.SimpleWallType(model); -// + const wall1 = simpleWallType.addInstance(); world.scene.three.add(...wall1.meshes); wall1.startPoint = new THREE.Vector2(1, 1); @@ -96,9 +97,9 @@ const panel = BUI.Component.create(() => { return BUI.html` - +
- + - + - +
- +
- + - + - - + +
- + - + - + - + }}"> + - +
`; @@ -199,26 +200,21 @@ document.body.append(button); // window.addEventListener("keydown", async (e) => { // if (e.code === "KeyP") { -// const directoryHandle = await window.showDirectoryPicker(); -// async function writeIFC() { -// const buffer = model.ifcAPI.SaveModel(model.modelID); -// -// console.log(buffer); -// -// const fileName = "example.ifc"; -// const fileHandle = await directoryHandle.getFileHandle("example.ifc", { -// create: true, -// }); -// -// // Create a FileSystemWritableFileStream to write to. -// const writable = await fileHandle.createWritable(); -// await writable.truncate(0); -// // Write the contents of the file to the stream. -// await writable.write(buffer); -// // Close the file and write the contents to disk. -// await writable.close(); +// simpleWallType.attributes = {}; +// console.log("hey"); +// if (model._modelID === undefined) { +// throw new Error("Malformed model!"); // } +// // TODO: Fix memory leak +// const asdf = model._ifcAPI.SaveModel(model._modelID); +// +// model._ifcAPI.Dispose(); +// model._ifcAPI = null as any; +// model._ifcAPI = new WEBIFC.IfcAPI(); // -// setInterval(() => writeIFC(), 1000); +// await model.init(); +// model._modelID = model._ifcAPI.OpenModel(asdf, { +// TAPE_SIZE: 5000000, // 5MB +// }); // } // });