Skip to content

Commit 936a5a4

Browse files
feat: create Slabs Family
Slabs family created with SimpleSlab.
1 parent 295c8c6 commit 936a5a4

4 files changed

Lines changed: 376 additions & 1 deletion

File tree

resources/openbim-clay.js

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55316,4 +55316,93 @@ class SimpleWall extends Family {
5531655316
}
5531755317
}
5531855318

55319-
export { Base, Breps, BufferManager, Control, Extrusion, Faces, IdIndexMap, Lines, Opening, Primitive, Raycaster, RectangleProfile, Selector, SimpleWall, Snapper, Vector, Vertices };
55319+
class SimpleSlab extends Family {
55320+
ifcAPI;
55321+
modelID;
55322+
_width = 5;
55323+
_height = 3;
55324+
_thickness = 0.25;
55325+
geometries;
55326+
mesh = null;
55327+
base;
55328+
wall;
55329+
_subtract;
55330+
constructor(ifcAPI, modelID, args = {
55331+
profile: {
55332+
position: [0, 0],
55333+
xDim: 5,
55334+
yDim: 3,
55335+
},
55336+
extrusion: {
55337+
direction: [0, 0, 1],
55338+
position: [0, 0, 0],
55339+
depth: 0.25,
55340+
},
55341+
}) {
55342+
super();
55343+
this.ifcAPI = ifcAPI;
55344+
this.modelID = modelID;
55345+
this.modelID = modelID;
55346+
this.ifcAPI = ifcAPI;
55347+
this.base = new Base(this.ifcAPI, this.modelID);
55348+
this.geometries = this.createGeometries(args);
55349+
this.mesh = this.geometries.extrusion.mesh;
55350+
this._subtract = { extrusion: { solid: this.geometries.extrusion.solid } };
55351+
this.wall = this.create();
55352+
this.geometries.extrusion.ids.push(this.wall.expressID);
55353+
}
55354+
createGeometries(args) {
55355+
const rectangleProfile = new RectangleProfile(this.ifcAPI, this.modelID, args.profile);
55356+
const extrusion = new Extrusion(this.ifcAPI, this.modelID, rectangleProfile.profile, args.extrusion);
55357+
return {
55358+
profile: rectangleProfile,
55359+
extrusion,
55360+
};
55361+
}
55362+
get thickness() {
55363+
return this._thickness;
55364+
}
55365+
set thickness(value) {
55366+
this._thickness = value;
55367+
this.geometries.extrusion.solid.Depth.value = value;
55368+
this.ifcAPI.WriteLine(this.modelID, this.geometries.extrusion.solid);
55369+
this.geometries.extrusion.regenerate();
55370+
}
55371+
get width() {
55372+
return this._width;
55373+
}
55374+
set width(value) {
55375+
this._width = value;
55376+
this.geometries.profile.profile.XDim.value = value;
55377+
this.ifcAPI.WriteLine(this.modelID, this.geometries.profile.profile);
55378+
this.geometries.extrusion.regenerate();
55379+
}
55380+
get height() {
55381+
return this._height;
55382+
}
55383+
set height(value) {
55384+
this._height = value;
55385+
this.geometries.profile.profile.YDim.value = value;
55386+
this.ifcAPI.WriteLine(this.modelID, this.geometries.profile.profile);
55387+
this.geometries.extrusion.regenerate();
55388+
}
55389+
get toSubtract() {
55390+
return this._subtract;
55391+
}
55392+
subtract(extrusion) {
55393+
const bool = this.base.bool(this._subtract.extrusion.solid, extrusion.solid);
55394+
this._subtract = { extrusion: { solid: bool } };
55395+
this.wall.Representation = bool;
55396+
this.ifcAPI.WriteLine(this.modelID, this.wall);
55397+
this.mesh = this.geometries.extrusion.mesh;
55398+
this.geometries.extrusion.regenerate();
55399+
}
55400+
create() {
55401+
const wall = createIfcEntity(this.ifcAPI, this.modelID, IFCWALL, this.base.guid(v4()), null, this.base.label("Simple Slab"), null, this.base.label("Simple Slab"), this.base.objectPlacement(), this.geometries.extrusion
55402+
.solid, this.base.identifier("Simple Slab"), null);
55403+
this.ifcAPI.WriteLine(this.modelID, wall);
55404+
return wall;
55405+
}
55406+
}
55407+
55408+
export { Base, Breps, BufferManager, Control, Extrusion, Faces, IdIndexMap, Lines, Opening, Primitive, Raycaster, RectangleProfile, Selector, SimpleWall, SimpleSlab, Snapper, Vector, Vertices };
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
8+
/>
9+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
10+
<link rel="stylesheet" href="../../../resources/styles.css" />
11+
<link
12+
rel="stylesheet"
13+
href="https://fonts.googleapis.com/icon?family=Material+Icons"
14+
/>
15+
<link
16+
rel="icon"
17+
type="image/x-icon"
18+
href="../../../resources/favicon.ico"
19+
/>
20+
<title>Tools Component</title>
21+
<style>
22+
body {
23+
margin: 0;
24+
padding: 0;
25+
}
26+
27+
.full-screen {
28+
width: 100vw;
29+
height: 100vh;
30+
position: relative;
31+
overflow: hidden;
32+
}
33+
</style>
34+
</head>
35+
<body>
36+
<div class="full-screen" id="container"></div>
37+
<script type="importmap">
38+
{
39+
"imports": {
40+
"three": "https://unpkg.com/three@0.152.2/build/three.module.js",
41+
"openbim-components": "../../../../resources/openbim-components.js",
42+
"openbim-clay": "../../../../resources/openbim-clay.js",
43+
"web-ifc": "../../../../node_modules/web-ifc/web-ifc-api.js",
44+
"stats.js/src/Stats.js": "https://unpkg.com/stats-js@1.0.1/src/Stats.js",
45+
"three/examples/jsm/libs/lil-gui.module.min": "https://unpkg.com/three@0.152.2/examples/jsm/libs/lil-gui.module.min.js",
46+
"three/examples/jsm/controls/TransformControls": "https://unpkg.com/three@0.135.0/examples/jsm/controls/TransformControls.js"
47+
}
48+
}
49+
</script>
50+
</body>
51+
</html>
52+
<script type="module">
53+
import * as THREE from "three";
54+
import * as OBC from "openbim-components";
55+
import * as CLAY from "openbim-clay";
56+
import * as WEBIFC from "web-ifc";
57+
58+
import Stats from "stats.js/src/Stats.js";
59+
import * as dat from "three/examples/jsm/libs/lil-gui.module.min";
60+
import { TransformControls } from "three/examples/jsm/controls/TransformControls";
61+
62+
const container = document.getElementById("container");
63+
64+
const components = new OBC.Components();
65+
66+
components.scene = new OBC.SimpleScene(components);
67+
components.renderer = new OBC.PostproductionRenderer(components, container);
68+
components.camera = new OBC.SimpleCamera(components);
69+
components.raycaster = new OBC.SimpleRaycaster(components);
70+
71+
components.init();
72+
73+
components.renderer.postproduction.enabled = true;
74+
75+
const scene = components.scene.get();
76+
77+
components.camera.controls.setLookAt(12, 6, 8, 0, 0, -10);
78+
79+
components.scene.setup();
80+
81+
const grid = new OBC.SimpleGrid(components, new THREE.Color(0x666666));
82+
83+
const customEffects = components.renderer.postproduction.customEffects;
84+
customEffects.excludedMeshes.push(grid.get());
85+
86+
// // IFC API
87+
88+
const ifcAPI = new WEBIFC.IfcAPI();
89+
90+
ifcAPI.SetWasmPath("../../../../node_modules/web-ifc/", false);
91+
await ifcAPI.Init();
92+
93+
const modelID = ifcAPI.CreateModel({ schema: WEBIFC.Schemas.IFC4X3 });
94+
95+
const slab = new CLAY.SimpleSlab(ifcAPI, modelID);
96+
97+
const opening1 = new CLAY.Opening(ifcAPI, modelID, {
98+
profile: {
99+
position: [-1, 0],
100+
xDim: 2,
101+
yDim: 2,
102+
},
103+
extrusion: {
104+
direction: [0, 0, 10],
105+
position: [0, 0, 0],
106+
depth: 1,
107+
},
108+
});
109+
110+
slab.subtract(opening1.toSubtract.extrusion);
111+
scene.add(slab.mesh);
112+
113+
// scene.add(opening.mesh);
114+
115+
// // Set up GUI
116+
const settings = {
117+
transformMode: "translate",
118+
};
119+
120+
const camera = components.camera.get();
121+
122+
const gui = new dat.GUI();
123+
gui.add(slab, "width").min(0).max(30).step(0.1);
124+
gui.add(slab, "height").min(0).max(30).step(0.1);
125+
gui.add(slab, "thickness").min(0).max(30).step(0.1);
126+
127+
const stats = new Stats();
128+
stats.showPanel(2);
129+
document.body.append(stats.dom);
130+
stats.dom.style.left = "0px";
131+
const renderer = components.renderer;
132+
renderer.onBeforeUpdate.add(() => stats.begin());
133+
renderer.onAfterUpdate.add(() => stats.end());
134+
</script>
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import * as WEBIFC from "web-ifc";
2+
import * as THREE from "three";
3+
import { v4 as uuidv4 } from "uuid";
4+
import { createIfcEntity } from "../../../utils/generics";
5+
import { Base } from "../../../base";
6+
import { Family, Subtract } from "../../Family";
7+
import {
8+
Extrusion,
9+
RectangleProfile,
10+
ExtrusionArgs,
11+
RectangleProfileArgs,
12+
} from "../../../geometries";
13+
14+
type Geometries = {
15+
profile: RectangleProfile;
16+
extrusion: Extrusion;
17+
};
18+
19+
type SimpleSlabArgs = {
20+
profile: RectangleProfileArgs;
21+
extrusion: ExtrusionArgs;
22+
};
23+
24+
export class SimpleSlab extends Family {
25+
private _width: number = 1;
26+
private _height: number = 1;
27+
private _thickness: number = 0.25;
28+
private geometries: Geometries;
29+
public mesh: THREE.InstancedMesh | null = null;
30+
private base: Base;
31+
private slab: WEBIFC.IFC4X3.IfcSlab;
32+
private _subtract: Subtract;
33+
34+
constructor(
35+
public ifcAPI: WEBIFC.IfcAPI,
36+
public modelID: number,
37+
args: SimpleSlabArgs = {
38+
profile: {
39+
position: [0, 0],
40+
xDim: 5,
41+
yDim: 3,
42+
},
43+
extrusion: {
44+
direction: [0, 0, 1],
45+
position: [0, 0, 0],
46+
depth: 5,
47+
},
48+
},
49+
) {
50+
super();
51+
this.modelID = modelID;
52+
this.ifcAPI = ifcAPI;
53+
this.base = new Base(this.ifcAPI, this.modelID);
54+
this.geometries = this.createGeometries(args);
55+
this.mesh = this.geometries.extrusion.mesh;
56+
this._subtract = { extrusion: { solid: this.geometries.extrusion.solid } };
57+
this.slab = this.create();
58+
this.geometries.extrusion.ids.push(this.slab.expressID);
59+
}
60+
61+
private createGeometries(args: SimpleSlabArgs) {
62+
const rectangleProfile = new RectangleProfile(
63+
this.ifcAPI,
64+
this.modelID,
65+
args.profile,
66+
);
67+
68+
const extrusion = new Extrusion(
69+
this.ifcAPI,
70+
this.modelID,
71+
rectangleProfile.profile,
72+
args.extrusion,
73+
);
74+
75+
return {
76+
profile: rectangleProfile,
77+
extrusion,
78+
};
79+
}
80+
81+
public get thickness() {
82+
return this._thickness;
83+
}
84+
85+
public set thickness(value) {
86+
this._thickness = value;
87+
this.geometries.extrusion.solid.Depth.value = value;
88+
this.ifcAPI.WriteLine(this.modelID, this.geometries.extrusion.solid);
89+
this.geometries.extrusion.regenerate();
90+
}
91+
92+
public get width() {
93+
return this._width;
94+
}
95+
96+
public set width(value) {
97+
this._width = value;
98+
this.geometries.profile.profile.XDim.value = value;
99+
this.ifcAPI.WriteLine(this.modelID, this.geometries.profile.profile);
100+
this.geometries.extrusion.regenerate();
101+
}
102+
103+
public get height() {
104+
return this._height;
105+
}
106+
107+
public set height(value) {
108+
this._height = value;
109+
this.geometries.profile.profile.YDim.value = value;
110+
this.ifcAPI.WriteLine(this.modelID, this.geometries.profile.profile);
111+
this.geometries.extrusion.regenerate();
112+
}
113+
114+
public get toSubtract(): Subtract {
115+
return this._subtract;
116+
}
117+
118+
public subtract(extrusion: Extrusion) {
119+
const bool = this.base.bool(
120+
this._subtract.extrusion.solid as WEBIFC.IFC4X3.IfcBooleanOperand,
121+
extrusion.solid,
122+
) as unknown as WEBIFC.IFC4X3.IfcProductRepresentation;
123+
this._subtract = { extrusion: { solid: bool } };
124+
this.slab.Representation = bool;
125+
this.ifcAPI.WriteLine(this.modelID, this.slab);
126+
this.mesh = this.geometries.extrusion.mesh;
127+
this.geometries.extrusion.regenerate();
128+
}
129+
130+
protected create(): WEBIFC.IFC4X3.IfcSlab {
131+
const slab = createIfcEntity<typeof WEBIFC.IFC4X3.IfcSlab>(
132+
this.ifcAPI,
133+
this.modelID,
134+
WEBIFC.IFCSLAB,
135+
this.base.guid(uuidv4()),
136+
null,
137+
this.base.label("Simple Slab"),
138+
null,
139+
this.base.label("Simple Slab"),
140+
this.base.objectPlacement(),
141+
this.geometries.extrusion
142+
.solid as unknown as WEBIFC.IFC4X3.IfcProductRepresentation,
143+
this.base.identifier("Simple Slab"),
144+
null,
145+
);
146+
147+
this.ifcAPI.WriteLine(this.modelID, slab);
148+
149+
return slab;
150+
}
151+
}

src/families/Slabs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./SimpleSlab";

0 commit comments

Comments
 (0)