Skip to content

Commit

Permalink
feat: add model settings
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Oct 2, 2024
1 parent f532a4f commit 1e90907
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
11 changes: 6 additions & 5 deletions packages/clay/src/core/Model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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!");
}
Expand All @@ -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);
}
}
66 changes: 31 additions & 35 deletions packages/clay/src/elements/Walls/SimpleWall/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")!;
Expand Down Expand Up @@ -33,7 +34,7 @@ model.wasm = { path: "https://unpkg.com/[email protected]/", 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);
Expand Down Expand Up @@ -96,48 +97,48 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
return BUI.html`
<bim-panel label="Simple Walls Tutorial" class="options-menu">
<bim-panel-section collapsed label="Controls">
<div style="display: flex; gap: 12px">
<bim-number-input slider step="0.1" label="Start X" vertical="true" value="${wall1.startPoint.x}" @change="${(
event: any,
) => {
wall1.startPoint.x = event.target.value;
wall1.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
<bim-number-input slider step="0.1" label="Start Y" vertical="true" value="${wall1.startPoint.y}" @change="${(
event: any,
) => {
wall1.startPoint.y = event.target.value;
wall1.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
</div>
<div style="display: flex; gap: 12px">
<bim-number-input slider step="0.1" label="End X" vertical="true" value="${wall1.endPoint.x}" @change="${(
event: any,
) => {
wall1.endPoint.x = event.target.value;
wall1.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
<bim-number-input slider step="0.1" label="End Y" vertical="true" value="${wall1.endPoint.y}" @change="${(
event: any,
) => {
wall1.endPoint.y = event.target.value;
wall1.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
</div>
<bim-number-input slider step="0.05" label="Elevation" value="${wall1.elevation}" @change="${(
event: any,
) => {
Expand All @@ -147,7 +148,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
wall1.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
<bim-number-input slider step="0.01" label="Offset" value="${wall1.offset}" @change="${(
event: any,
) => {
Expand All @@ -157,23 +158,23 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
wall2.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
<bim-number-input slider step="0.05" label="Thickness" value="${simpleWallType.width}" @change="${(
event: any,
) => {
simpleWallType.width = event.target.value;
simpleWallType.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
}}"></bim-number-input>
<bim-number-input slider step="0.05" label="Height" value="${wall1.height}" @change="${(
event: any,
) => {
wall1.height = event.target.value;
wall1.update(true);
simpleWallType.updateCorners();
}}"></bim-number-input>
</bim-panel-section>
</bim-panel>
`;
Expand All @@ -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
// });
// }
// });

0 comments on commit 1e90907

Please sign in to comment.