Skip to content

Commit 5abd2f4

Browse files
committed
feat: implement project and site
1 parent 1e90907 commit 5abd2f4

File tree

7 files changed

+310
-20
lines changed

7 files changed

+310
-20
lines changed

packages/clay/src/elements/Walls/SimpleWall/example.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const model = new CLAY.Model();
3333
model.wasm = { path: "https://unpkg.com/[email protected]/", absolute: true };
3434
await model.init();
3535

36+
const project = new CLAY.Project(model);
37+
const site = new CLAY.Site(model, project);
38+
3639
const simpleWallType = new CLAY.SimpleWallType(model);
3740

3841
const wall1 = simpleWallType.addInstance();
@@ -48,6 +51,9 @@ wall2.startPoint = new THREE.Vector2(0, -2);
4851
wall2.endPoint = new THREE.Vector2(0, 3);
4952
wall2.update(true);
5053

54+
site.children.add(wall1.attributes.expressID);
55+
site.children.add(wall2.attributes.expressID);
56+
5157
simpleWallType.addCorner({
5258
wall1,
5359
wall2,
@@ -198,23 +204,21 @@ const button = BUI.Component.create<BUI.PanelSection>(() => {
198204

199205
document.body.append(button);
200206

201-
// window.addEventListener("keydown", async (e) => {
202-
// if (e.code === "KeyP") {
203-
// simpleWallType.attributes = {};
204-
// console.log("hey");
205-
// if (model._modelID === undefined) {
206-
// throw new Error("Malformed model!");
207-
// }
208-
// // TODO: Fix memory leak
209-
// const asdf = model._ifcAPI.SaveModel(model._modelID);
210-
//
211-
// model._ifcAPI.Dispose();
212-
// model._ifcAPI = null as any;
213-
// model._ifcAPI = new WEBIFC.IfcAPI();
214-
//
215-
// await model.init();
216-
// model._modelID = model._ifcAPI.OpenModel(asdf, {
217-
// TAPE_SIZE: 5000000, // 5MB
218-
// });
219-
// }
220-
// });
207+
window.addEventListener("keydown", async (e) => {
208+
if (e.code === "KeyP") {
209+
simpleWallType.attributes = {};
210+
console.log("hey");
211+
if (model._modelID === undefined) {
212+
throw new Error("Malformed model!");
213+
}
214+
// TODO: Fix memory leak
215+
const asdf = model._ifcAPI.SaveModel(model._modelID);
216+
217+
const a = document.createElement("a");
218+
const name = "example.ifc";
219+
a.href = URL.createObjectURL(new File([asdf], name));
220+
a.download = name;
221+
a.click();
222+
a.remove();
223+
}
224+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { IFC4X3 as IFC, Handle } from "web-ifc";
2+
import { v4 as uuidv4 } from "uuid";
3+
import { ClayObject, Model } from "../../core";
4+
5+
export class ElementChildren extends ClayObject {
6+
attributes: IFC.IfcRelContainedInSpatialStructure;
7+
ids = new Set<number>();
8+
9+
constructor(
10+
model: Model,
11+
ownerHistory: IFC.IfcOwnerHistory,
12+
element: IFC.IfcSpatialElement,
13+
) {
14+
super(model);
15+
this.attributes = new IFC.IfcRelContainedInSpatialStructure(
16+
new IFC.IfcGloballyUniqueId(uuidv4()),
17+
ownerHistory,
18+
null,
19+
null,
20+
[],
21+
element,
22+
);
23+
24+
this.update();
25+
}
26+
27+
add(itemID: number) {
28+
if (this.ids.has(itemID)) {
29+
return;
30+
}
31+
this.attributes.RelatedElements.push(new Handle(itemID));
32+
this.ids.add(itemID);
33+
this.update();
34+
}
35+
36+
remove(itemID: number) {
37+
if (!this.ids.has(itemID)) {
38+
return;
39+
}
40+
const children = this.attributes.RelatedElements as Handle<any>[];
41+
this.attributes.RelatedElements = children.filter(
42+
(item) => item.value !== itemID,
43+
);
44+
this.ids.delete(itemID);
45+
this.update();
46+
}
47+
48+
update() {
49+
this.model.set(this.attributes);
50+
}
51+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { IFC4X3 as IFC } from "web-ifc";
2+
import { v4 as uuidv4 } from "uuid";
3+
import * as THREE from "three";
4+
import { ClayObject, Model } from "../../core";
5+
import { ClippingPlaneType } from "../../elements";
6+
import { IfcUtils } from "../../utils/ifc-utils";
7+
import { SpatialChildren } from "../SpatialChildren";
8+
9+
export class Project extends ClayObject {
10+
attributes: IFC.IfcProject;
11+
12+
ownerHistory: IFC.IfcOwnerHistory;
13+
14+
spatialChildren: SpatialChildren;
15+
16+
constructor(model: Model) {
17+
super(model);
18+
19+
if (!this.model.types.has("clipping-planes")) {
20+
this.model.types.set("clipping-planes", new ClippingPlaneType(model));
21+
}
22+
23+
const organization = new IFC.IfcOrganization(
24+
null,
25+
new IFC.IfcLabel("That Open Company"),
26+
null,
27+
null,
28+
null,
29+
);
30+
31+
const person = new IFC.IfcPerson(
32+
null,
33+
null,
34+
null,
35+
null,
36+
null,
37+
null,
38+
null,
39+
null,
40+
);
41+
42+
const personAndOrganization = new IFC.IfcPersonAndOrganization(
43+
person,
44+
organization,
45+
null,
46+
);
47+
48+
const application = new IFC.IfcApplication(
49+
organization,
50+
new IFC.IfcLabel("2.4.0"),
51+
new IFC.IfcLabel("CLAY"),
52+
new IFC.IfcLabel("CLAY"),
53+
);
54+
55+
this.ownerHistory = new IFC.IfcOwnerHistory(
56+
personAndOrganization,
57+
application,
58+
null,
59+
IFC.IfcChangeActionEnum.NOTDEFINED,
60+
null,
61+
null,
62+
null,
63+
new IFC.IfcTimeStamp(new Date().getTime()),
64+
);
65+
66+
const context = new IFC.IfcGeometricRepresentationContext(
67+
null,
68+
null,
69+
new IFC.IfcDimensionCount(3),
70+
new IFC.IfcReal(1.0e-5),
71+
new IFC.IfcAxis2Placement3D(
72+
IfcUtils.point(new THREE.Vector3()),
73+
null,
74+
null,
75+
),
76+
null,
77+
);
78+
79+
const lengthUnit = new IFC.IfcSIUnit(
80+
IFC.IfcUnitEnum.LENGTHUNIT,
81+
null,
82+
IFC.IfcSIUnitName.METRE,
83+
);
84+
85+
const areaUnit = new IFC.IfcSIUnit(
86+
IFC.IfcUnitEnum.AREAUNIT,
87+
null,
88+
IFC.IfcSIUnitName.SQUARE_METRE,
89+
);
90+
91+
const volumeUnit = new IFC.IfcSIUnit(
92+
IFC.IfcUnitEnum.AREAUNIT,
93+
null,
94+
IFC.IfcSIUnitName.SQUARE_METRE,
95+
);
96+
97+
const units = new IFC.IfcUnitAssignment([lengthUnit, areaUnit, volumeUnit]);
98+
99+
this.attributes = new IFC.IfcProject(
100+
new IFC.IfcGloballyUniqueId(uuidv4()),
101+
this.ownerHistory,
102+
null,
103+
null,
104+
null,
105+
null,
106+
null,
107+
[context],
108+
units,
109+
);
110+
111+
this.model.set(this.attributes);
112+
113+
this.spatialChildren = new SpatialChildren(
114+
model,
115+
this.ownerHistory,
116+
this.attributes,
117+
);
118+
}
119+
120+
update(): void {
121+
this.model.set(this.attributes);
122+
}
123+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { IFC4X3 as IFC } from "web-ifc";
2+
import { v4 as uuidv4 } from "uuid";
3+
import { ClayObject, Model } from "../../core";
4+
import { SpatialChildren } from "../SpatialChildren";
5+
import { ElementChildren } from "../ElementChildren";
6+
import { Project } from "../Project";
7+
import { IfcUtils } from "../../utils/ifc-utils";
8+
9+
export class Site extends ClayObject {
10+
attributes: IFC.IfcSite;
11+
12+
spatialChildren: SpatialChildren;
13+
14+
children: ElementChildren;
15+
16+
constructor(model: Model, project: Project) {
17+
super(model);
18+
19+
this.attributes = new IFC.IfcSite(
20+
new IFC.IfcGloballyUniqueId(uuidv4()),
21+
project.ownerHistory,
22+
null,
23+
null,
24+
null,
25+
IfcUtils.localPlacement(),
26+
null,
27+
null,
28+
IFC.IfcElementCompositionEnum.ELEMENT,
29+
null,
30+
null,
31+
null,
32+
null,
33+
null,
34+
);
35+
36+
this.model.set(this.attributes);
37+
38+
project.spatialChildren.add(this.attributes.expressID);
39+
40+
this.spatialChildren = new SpatialChildren(
41+
model,
42+
project.ownerHistory,
43+
this.attributes,
44+
);
45+
46+
this.children = new ElementChildren(
47+
model,
48+
project.ownerHistory,
49+
this.attributes,
50+
);
51+
}
52+
53+
update(): void {
54+
this.model.set(this.attributes);
55+
}
56+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { IFC4X3 as IFC, Handle } from "web-ifc";
2+
import { v4 as uuidv4 } from "uuid";
3+
import { ClayObject, Model } from "../../core";
4+
5+
export class SpatialChildren extends ClayObject {
6+
attributes: IFC.IfcRelAggregates;
7+
ids = new Set<number>();
8+
9+
constructor(
10+
model: Model,
11+
ownerHistory: IFC.IfcOwnerHistory,
12+
element: IFC.IfcObjectDefinition,
13+
) {
14+
super(model);
15+
this.attributes = new IFC.IfcRelAggregates(
16+
new IFC.IfcGloballyUniqueId(uuidv4()),
17+
ownerHistory,
18+
null,
19+
null,
20+
element,
21+
[],
22+
);
23+
24+
this.update();
25+
}
26+
27+
add(itemID: number) {
28+
if (this.ids.has(itemID)) {
29+
return;
30+
}
31+
this.attributes.RelatedObjects.push(new Handle(itemID));
32+
this.ids.add(itemID);
33+
this.update();
34+
}
35+
36+
remove(itemID: number) {
37+
if (!this.ids.has(itemID)) {
38+
return;
39+
}
40+
const children = this.attributes.RelatedObjects as Handle<any>[];
41+
this.attributes.RelatedObjects = children.filter(
42+
(item) => item.value !== itemID,
43+
);
44+
this.ids.delete(itemID);
45+
this.update();
46+
}
47+
48+
update() {
49+
this.model.set(this.attributes);
50+
}
51+
}

packages/clay/src/general/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./Project";
2+
export * from "./Site";
3+
export * from "./SpatialChildren";
4+
export * from "./ElementChildren";

packages/clay/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./primitives";
22
export * from "./elements";
3+
export * from "./general";
34
export * from "./utils";
45
export * from "./elements";
56
export * from "./geometries";

0 commit comments

Comments
 (0)