Skip to content

Commit 076fc9d

Browse files
committed
feat: progress with walls
1 parent 5abd2f4 commit 076fc9d

File tree

16 files changed

+238
-251
lines changed

16 files changed

+238
-251
lines changed

packages/clay/src/core/Elements/Element/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,17 @@ import { Model } from "../../Model";
88
import { ClayElementType } from "../ElementType";
99
import { IfcUtils } from "../../../utils/ifc-utils";
1010
import { ClayGeometry } from "../../Geometry";
11+
import { ClayObject3D } from "../../Object3D";
1112

1213
/**
1314
* Any object with a physical representation in the IFC. It corresponds to the IFCELEMENT entity in the IFC schema.
1415
*/
15-
export abstract class ClayElement extends ClayObject {
16+
export abstract class ClayElement extends ClayObject3D {
1617
/**
1718
* {@link ClayObject.attributes}
1819
*/
1920
abstract attributes: IFC.IfcElement;
2021

21-
/**
22-
* Position of this element in 3D space.
23-
*/
24-
position = new THREE.Vector3();
25-
26-
/**
27-
* Rotation of this element in 3D space.
28-
*/
29-
rotation = new THREE.Euler();
30-
3122
/**
3223
* The type of this element.
3324
*/

packages/clay/src/core/Geometry/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { IFC4X3 as IFC } from "web-ifc";
22
import { ClayObject } from "../Object";
3+
import { ClayObject3D } from "../Object3D";
34

45
/**
56
* An object that represents an IFC geometry that can represent one or many IfcElements in 3D. It supports boolean operations.
67
*/
7-
export abstract class ClayGeometry extends ClayObject {
8+
export abstract class ClayGeometry extends ClayObject3D {
89
/**
910
* {@link ClayObject.attributes}. It can either be an IFC geometry, or the result of a boolean operation.
1011
*/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as THREE from "three";
2+
import { ClayObject } from "../Object";
3+
4+
/**
5+
* Base object for all Clay objects with a transformation in 3D space.
6+
*/
7+
export abstract class ClayObject3D extends ClayObject {
8+
/**
9+
* Position of this element in 3D space.
10+
*/
11+
position = new THREE.Vector3();
12+
13+
/**
14+
* Rotation of this element in 3D space.
15+
*/
16+
rotation = new THREE.Euler();
17+
18+
/**
19+
* Gets the transform of this object as a THREE.Matrix4.
20+
*/
21+
getTransform() {
22+
const temp = new THREE.Object3D();
23+
temp.position.copy(this.position);
24+
temp.rotation.copy(this.rotation);
25+
temp.updateMatrix();
26+
return temp.matrix;
27+
}
28+
29+
/**
30+
* Sets the transform of this object given a THREE.Matrix4.
31+
*/
32+
setTransform(transform: THREE.Matrix4) {
33+
const quat = new THREE.Quaternion();
34+
const scale = new THREE.Vector3();
35+
transform.decompose(this.position, quat, scale);
36+
this.rotation.setFromQuaternion(quat);
37+
}
38+
39+
/**
40+
* Applies the transform of this object given a THREE.Matrix4.
41+
*/
42+
applyTransform(transform: THREE.Matrix4) {
43+
const currentTransform = this.getTransform();
44+
currentTransform.multiply(transform);
45+
const quat = new THREE.Quaternion();
46+
const scale = new THREE.Vector3();
47+
currentTransform.decompose(this.position, quat, scale);
48+
this.setTransform(currentTransform);
49+
}
50+
}

packages/clay/src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from "./Model";
22
export * from "./Elements";
33
export * from "./Geometry";
44
export * from "./Object";
5+
export * from "./Object3D";
56
export * from "./Event";

packages/clay/src/elements/Openings/ClippingPlane/index.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/clay/src/elements/Openings/ClippingPlane/src/index.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from "./SimpleOpening";
2-
export * from "./ClippingPlane";

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

Lines changed: 100 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,121 @@ const simpleWallType = new CLAY.SimpleWallType(model);
4040

4141
const wall1 = simpleWallType.addInstance();
4242
world.scene.three.add(...wall1.meshes);
43-
wall1.startPoint = new THREE.Vector2(1, 1);
44-
wall1.endPoint = new THREE.Vector2(3, 0);
43+
wall1.startPoint = new THREE.Vector2(0, 0);
44+
wall1.endPoint = new THREE.Vector2(1, 0);
4545
wall1.update(true);
4646
wall1.meshes[0].setColorAt(0, new THREE.Color(1, 0, 0));
4747

4848
const wall2 = simpleWallType.addInstance();
4949
world.scene.three.add(...wall2.meshes);
50-
wall2.startPoint = new THREE.Vector2(0, -2);
51-
wall2.endPoint = new THREE.Vector2(0, 3);
50+
wall2.startPoint = new THREE.Vector2(0, 0);
51+
wall2.endPoint = new THREE.Vector2(0, 1);
5252
wall2.update(true);
5353

5454
site.children.add(wall1.attributes.expressID);
5555
site.children.add(wall2.attributes.expressID);
5656

57-
simpleWallType.addCorner({
58-
wall1,
59-
wall2,
60-
to: "interior",
61-
cut: "interior",
62-
cutDirection: "interior",
63-
priority: "end",
57+
const halfSpace = new CLAY.HalfSpace(model);
58+
wall1.body.addSubtraction(halfSpace);
59+
60+
const mesh = new THREE.Mesh(
61+
new THREE.PlaneGeometry(2, 2, 2),
62+
new THREE.MeshLambertMaterial({
63+
color: "blue",
64+
transparent: true,
65+
opacity: 0.6,
66+
side: 2,
67+
}),
68+
);
69+
70+
world.scene.three.add(mesh);
71+
72+
mesh.position.set(1, 1, 0);
73+
mesh.lookAt(0.5, 0, 0.5);
74+
75+
const offset = 0.5;
76+
77+
function updatePlane() {
78+
const p = CLAY.MathUtils.toThreeCoords(wall1.midPoint);
79+
const d = CLAY.MathUtils.toThreeCoords(wall1.direction);
80+
d.multiplyScalar(offset);
81+
p.add(d);
82+
mesh.position.copy(p);
83+
const start = CLAY.MathUtils.toThreeCoords(wall1.startPoint3D);
84+
mesh.lookAt(start);
85+
}
86+
87+
// updatePlane();
88+
89+
// halfSpace.rotation.y = Math.PI / 2;
90+
// halfSpace.position.x = 0.5;
91+
92+
console.log(halfSpace.rotation);
93+
console.log(mesh.rotation);
94+
95+
// halfSpace.position.copy(CLAY.MathUtils.toIfcCoords(mesh.position));
96+
// halfSpace.rotation.copy(CLAY.MathUtils.toIfcCoords(mesh.rotation));
97+
98+
function updateHalfSpace() {
99+
halfSpace.rotation.x = mesh.rotation.x - Math.PI / 2;
100+
halfSpace.rotation.y = -mesh.rotation.y;
101+
halfSpace.rotation.z = mesh.rotation.z - Math.PI / 2;
102+
103+
const midPoint = CLAY.MathUtils.toThreeCoords(wall1.midPoint);
104+
const position = mesh.position.clone().sub(midPoint);
105+
const truePosition = CLAY.MathUtils.toIfcCoords(position);
106+
halfSpace.position.copy(truePosition);
107+
108+
halfSpace.update();
109+
wall1.update(true);
110+
}
111+
112+
window.addEventListener("keydown", (e) => {
113+
if (e.code === "KeyA") {
114+
mesh.rotation.x += (Math.PI / 180) * 5;
115+
updateHalfSpace();
116+
}
117+
if (e.code === "KeyS") {
118+
mesh.rotation.y += (Math.PI / 180) * 5;
119+
updateHalfSpace();
120+
}
121+
if (e.code === "KeyD") {
122+
mesh.rotation.z += (Math.PI / 180) * 5;
123+
updateHalfSpace();
124+
}
64125
});
65126

66-
simpleWallType.addCorner({
67-
wall1: wall2,
68-
wall2: wall1,
69-
to: "interior",
70-
cut: "exterior",
71-
cutDirection: "interior",
72-
priority: "start",
73-
});
127+
updateHalfSpace();
128+
129+
// simpleWallType.addCorner({
130+
// wall1,
131+
// wall2,
132+
// to: "interior",
133+
// cut: "interior",
134+
// cutDirection: "interior",
135+
// priority: "end",
136+
// });
137+
//
138+
// simpleWallType.addCorner({
139+
// wall1: wall2,
140+
// wall2: wall1,
141+
// to: "interior",
142+
// cut: "exterior",
143+
// cutDirection: "interior",
144+
// priority: "start",
145+
// });
74146

75147
await simpleWallType.updateCorners();
76148

77149
world.camera.controls.fitToSphere(wall1.meshes[0], false);
78150

79-
const simpleOpeningType = new CLAY.SimpleOpeningType(model);
80-
const opening = simpleOpeningType.addInstance();
151+
// const simpleOpeningType = new CLAY.SimpleOpeningType(model);
152+
// const opening = simpleOpeningType.addInstance();
81153
// scene.add(...opening.meshes);
82154
// console.log(simpleOpeningType);
83155

84-
await wall1.addSubtraction(opening, true);
85-
wall1.update(true);
156+
// await wall1.addSubtraction(opening, true);
157+
// wall1.update(true);
86158

87159
// Stats
88160

@@ -111,6 +183,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
111183
) => {
112184
wall1.startPoint.x = event.target.value;
113185
wall1.update(true);
186+
updatePlane();
114187
simpleWallType.updateCorners();
115188
}}"></bim-number-input>
116189
@@ -119,6 +192,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
119192
) => {
120193
wall1.startPoint.y = event.target.value;
121194
wall1.update(true);
195+
updatePlane();
122196
simpleWallType.updateCorners();
123197
}}"></bim-number-input>
124198
@@ -131,6 +205,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
131205
) => {
132206
wall1.endPoint.x = event.target.value;
133207
wall1.update(true);
208+
updatePlane();
134209
simpleWallType.updateCorners();
135210
}}"></bim-number-input>
136211
@@ -139,6 +214,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
139214
) => {
140215
wall1.endPoint.y = event.target.value;
141216
wall1.update(true);
217+
updatePlane();
142218
simpleWallType.updateCorners();
143219
}}"></bim-number-input>
144220
@@ -152,6 +228,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
152228
opening.update();
153229
wall1.elevation = event.target.value;
154230
wall1.update(true);
231+
updatePlane();
155232
simpleWallType.updateCorners();
156233
}}"></bim-number-input>
157234

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
SimpleWallCornerer,
77
WallCornerConfig,
88
} from "./src/simple-wall-cornerer";
9-
import { ClippingPlaneType } from "../../Openings";
109

1110
export * from "./src";
1211

@@ -20,10 +19,6 @@ export class SimpleWallType extends DynamicClayElementType<SimpleWall> {
2019
constructor(model: Model) {
2120
super(model);
2221

23-
if (!this.model.types.has("clipping-planes")) {
24-
this.model.types.set("clipping-planes", new ClippingPlaneType(model));
25-
}
26-
2722
this.attributes = new IFC.IfcWallType(
2823
new IFC.IfcGloballyUniqueId(uuidv4()),
2924
null,

0 commit comments

Comments
 (0)