Skip to content

Commit b8de28a

Browse files
author
rrdls
committed
feat: create wall based in two points
1 parent 0064138 commit b8de28a

11 files changed

Lines changed: 806 additions & 217 deletions

File tree

resources/openbim-clay.js

Lines changed: 288 additions & 109 deletions
Large diffs are not rendered by default.

src/base/index.ts

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,81 @@ export class Base {
2121
};
2222
}
2323

24-
public guid(value: string) {
24+
calculateEndPoint(
25+
startPoint: number[],
26+
direction: number[],
27+
magnitude: number,
28+
) {
29+
const vectorMagnitude = Math.sqrt(
30+
direction[0] ** 2 + direction[1] ** 2 + direction[2] ** 2,
31+
);
32+
const unitVector = direction.map(
33+
(component) => component / vectorMagnitude,
34+
);
35+
const displacementVector = unitVector.map(
36+
(component) => component * magnitude,
37+
);
38+
return [
39+
startPoint[0] + displacementVector[0],
40+
startPoint[1] + displacementVector[1],
41+
startPoint[2] + displacementVector[2],
42+
];
43+
}
44+
45+
pointsDistance(firstPoint: number[], secondPoint: number[]) {
46+
const dx = firstPoint[0] - secondPoint[0];
47+
const dy = firstPoint[1] - secondPoint[1];
48+
return Math.sqrt(dx * dx + dy * dy);
49+
}
50+
51+
representationContext() {
52+
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcRepresentationContext>(
53+
this.ifcAPI,
54+
this.modelID,
55+
WEBIFC.IFCREPRESENTATIONCONTEXT,
56+
this.label("Body"),
57+
this.label("Model"),
58+
);
59+
}
60+
61+
productDefinitionShape(representations: WEBIFC.IFC4X3.IfcRepresentation[]) {
62+
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcProductDefinitionShape>(
63+
this.ifcAPI,
64+
this.modelID,
65+
WEBIFC.IFCPRODUCTDEFINITIONSHAPE,
66+
this.label(""),
67+
this.label(""),
68+
representations,
69+
);
70+
}
71+
72+
shapeRepresentation(
73+
identifier: string,
74+
type: string,
75+
representation: WEBIFC.IFC4X3.IfcRepresentationItem,
76+
) {
77+
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcShapeRepresentation>(
78+
this.ifcAPI,
79+
this.modelID,
80+
WEBIFC.IFCSHAPEREPRESENTATION,
81+
this.representationContext(),
82+
this.label(identifier),
83+
this.label(type),
84+
[representation],
85+
);
86+
}
87+
88+
polyline(points: number[][]) {
89+
const listOfPoints = points.map((point) => this.cartesianPoint(point));
90+
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcPolyline>(
91+
this.ifcAPI,
92+
this.modelID,
93+
WEBIFC.IFCPOLYLINE,
94+
listOfPoints,
95+
);
96+
}
97+
98+
guid(value: string) {
2599
return createIfcType<typeof WEBIFC.IFC4X3.IfcGloballyUniqueId>(
26100
this.ifcAPI,
27101
this.modelID,
@@ -30,7 +104,7 @@ export class Base {
30104
);
31105
}
32106

33-
public identifier(value: string) {
107+
identifier(value: string) {
34108
return createIfcType<typeof WEBIFC.IFC4X3.IfcIdentifier>(
35109
this.ifcAPI,
36110
this.modelID,
@@ -39,7 +113,7 @@ export class Base {
39113
);
40114
}
41115

42-
public real(value: number) {
116+
real(value: number) {
43117
return createIfcType<typeof WEBIFC.IFC4X3.IfcReal>(
44118
this.ifcAPI,
45119
this.modelID,
@@ -48,7 +122,7 @@ export class Base {
48122
);
49123
}
50124

51-
public label(text: string) {
125+
label(text: string) {
52126
return createIfcType<typeof WEBIFC.IFC4X3.IfcLabel>(
53127
this.ifcAPI,
54128
this.modelID,
@@ -57,7 +131,7 @@ export class Base {
57131
);
58132
}
59133

60-
public length(value: number) {
134+
length(value: number) {
61135
return createIfcType<typeof WEBIFC.IFC4X3.IfcLengthMeasure>(
62136
this.ifcAPI,
63137
this.modelID,
@@ -66,7 +140,7 @@ export class Base {
66140
);
67141
}
68142

69-
public positiveLength(value: number) {
143+
positiveLength(value: number) {
70144
return createIfcType<typeof WEBIFC.IFC4X3.IfcPositiveLengthMeasure>(
71145
this.ifcAPI,
72146
this.modelID,
@@ -75,7 +149,7 @@ export class Base {
75149
);
76150
}
77151

78-
public objectPlacement(
152+
objectPlacement(
79153
placementRelTo: WEBIFC.IFC4X3.IfcObjectPlacement | null = null,
80154
) {
81155
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcObjectPlacement>(
@@ -86,28 +160,7 @@ export class Base {
86160
);
87161
}
88162

89-
public opening(
90-
guid: string,
91-
placement: WEBIFC.IFC4X3.IfcObjectPlacement,
92-
mesh: WEBIFC.IFC4X3.IfcProductRepresentation,
93-
) {
94-
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcOpeningElement>(
95-
this.ifcAPI,
96-
this.modelID,
97-
WEBIFC.IFCOPENINGELEMENT,
98-
this.guid(guid),
99-
null,
100-
this.label("name"),
101-
null,
102-
this.label("label"),
103-
placement,
104-
mesh,
105-
this.identifier("sadf"),
106-
null,
107-
);
108-
}
109-
110-
public direction(values: number[]) {
163+
direction(values: number[]) {
111164
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcDirection>(
112165
this.ifcAPI,
113166
this.modelID,
@@ -116,7 +169,7 @@ export class Base {
116169
);
117170
}
118171

119-
public cartesianPoint(values: number[]) {
172+
cartesianPoint(values: number[]) {
120173
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcCartesianPoint>(
121174
this.ifcAPI,
122175
this.modelID,
@@ -125,15 +178,15 @@ export class Base {
125178
);
126179
}
127180

128-
public point() {
181+
point() {
129182
return createIfcEntity<typeof WEBIFC.IFC4X3.IfcPoint>(
130183
this.ifcAPI,
131184
this.modelID,
132185
WEBIFC.IFCCARTESIANPOINT,
133186
);
134187
}
135188

136-
public axis2Placement2D(
189+
axis2Placement2D(
137190
location: number[] | WEBIFC.IFC4X3.IfcCartesianPoint,
138191
direction: number[] | WEBIFC.IFC4X3.IfcDirection | null = null,
139192
) {
@@ -148,13 +201,15 @@ export class Base {
148201
);
149202
}
150203

151-
public axis2Placement3D(
204+
axis2Placement3D(
205+
location: number[] | WEBIFC.IFC4X3.IfcCartesianPoint,
152206
axis: number[] | WEBIFC.IFC4X3.IfcDirection | null = null,
153207
direction: number[] | WEBIFC.IFC4X3.IfcDirection | null = null,
154208
) {
155-
const location = this.point();
209+
if (Array.isArray(location)) location = this.cartesianPoint(location);
156210
if (Array.isArray(axis)) axis = this.direction(axis);
157211
if (Array.isArray(direction)) direction = this.direction(direction);
212+
158213
const placement = createIfcEntity<typeof WEBIFC.IFC4X3.IfcAxis2Placement3D>(
159214
this.ifcAPI,
160215
this.modelID,
@@ -166,7 +221,7 @@ export class Base {
166221
return { placement, location };
167222
}
168223

169-
public bool(
224+
bool(
170225
firstOperand: WEBIFC.IFC4X3.IfcBooleanOperand,
171226
secondOperand: WEBIFC.IFC4X3.IfcBooleanOperand,
172227
) {
@@ -180,7 +235,7 @@ export class Base {
180235
);
181236
}
182237

183-
public vector(values: number[], type: keyof Types) {
238+
vector(values: number[], type: keyof Types) {
184239
if (!this.types[type]) throw new Error(`Type not found: ${type}`);
185240
const action = this.types[type];
186241
return values.map((value) => action(value));

src/families/Opening/index.html

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 opening = new CLAY.Opening(ifcAPI, modelID);
96+
97+
scene.add(opening.mesh);
98+
99+
// // Set up GUI
100+
101+
const settings = {
102+
transformMode: "translate",
103+
};
104+
105+
const camera = components.camera.get();
106+
107+
const gui = new dat.GUI();
108+
gui.add(opening, "width").min(0).max(30).step(0.1);
109+
gui.add(opening, "height").min(0).max(30).step(0.1);
110+
gui.add(opening, "thickness").min(0).max(30).step(0.1);
111+
112+
const stats = new Stats();
113+
stats.showPanel(2);
114+
document.body.append(stats.dom);
115+
stats.dom.style.left = "0px";
116+
const renderer = components.renderer;
117+
renderer.onBeforeUpdate.add(() => stats.begin());
118+
renderer.onAfterUpdate.add(() => stats.end());
119+
</script>

0 commit comments

Comments
 (0)