Skip to content

Commit f5551d9

Browse files
committed
feat: make halfspaces work as expected in draft
1 parent 96cc12b commit f5551d9

File tree

2 files changed

+113
-28
lines changed

2 files changed

+113
-28
lines changed

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

Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import Stats from "stats.js";
44
import * as OBC from "@thatopen/components";
55

66
import * as WEBIFC from "web-ifc";
7+
import { ParametricGeometries } from "three/examples/jsm/geometries/ParametricGeometries";
78
import * as CLAY from "../../..";
9+
import plane = ParametricGeometries.plane;
810

911
const container = document.getElementById("container")!;
1012

@@ -47,40 +49,100 @@ const simpleWallType = new CLAY.SimpleWallType(model);
4749
const wall1 = simpleWallType.addInstance();
4850
world.scene.three.add(...wall1.meshes);
4951
wall1.startPoint = new THREE.Vector2(0, 0);
50-
wall1.endPoint = new THREE.Vector2(1, 0);
52+
wall1.endPoint = new THREE.Vector2(0, 1);
5153
wall1.update(true);
5254
wall1.meshes[0].setColorAt(0, new THREE.Color(1, 0, 0));
53-
54-
const wall2 = simpleWallType.addInstance();
55-
world.scene.three.add(...wall2.meshes);
56-
wall2.startPoint = new THREE.Vector2(0, 0);
57-
wall2.endPoint = new THREE.Vector2(0, 1);
58-
wall2.update(true);
55+
//
56+
// const wall2 = simpleWallType.addInstance();
57+
// world.scene.three.add(...wall2.meshes);
58+
// wall2.startPoint = new THREE.Vector2(0, 0);
59+
// wall2.endPoint = new THREE.Vector2(0, 1);
60+
// wall2.update(true);
5961

6062
site.children.add(wall1.attributes.expressID);
61-
site.children.add(wall2.attributes.expressID);
62-
63-
simpleWallType.addCorner({
64-
wall1,
65-
wall2,
66-
to: "interior",
67-
cut: "interior",
68-
cutDirection: "interior",
69-
priority: "start",
70-
});
63+
// site.children.add(wall2.attributes.expressID);
64+
65+
// simpleWallType.addCorner({
66+
// wall1,
67+
// wall2,
68+
// to: "interior",
69+
// cut: "interior",
70+
// cutDirection: "interior",
71+
// priority: "start",
72+
// });
7173

7274
simpleWallType.updateCorners();
7375

7476
world.camera.controls.fitToSphere(wall1.meshes[0], false);
7577

76-
const simpleOpeningType = new CLAY.SimpleOpeningType(model);
77-
const opening = simpleOpeningType.addInstance();
78-
// world.scene.three.add(...opening.meshes);
79-
console.log(simpleOpeningType);
80-
opening.transformation.position.x += 1;
81-
82-
await wall1.addSubtraction(opening, true);
83-
wall1.update(true);
78+
// const simpleOpeningType = new CLAY.SimpleOpeningType(model);
79+
// const opening = simpleOpeningType.addInstance();
80+
// // world.scene.three.add(...opening.meshes);
81+
// console.log(simpleOpeningType);
82+
// opening.transformation.position.x += 1;
83+
//
84+
// await wall1.addSubtraction(opening, true);
85+
// wall1.update(true);
86+
87+
const test = new THREE.Mesh(
88+
new THREE.PlaneGeometry(),
89+
new THREE.MeshLambertMaterial({
90+
color: "blue",
91+
transparent: true,
92+
opacity: 0.3,
93+
side: 2,
94+
}),
95+
);
96+
97+
const wallAxis = new THREE.AxesHelper();
98+
wallAxis.material.depthTest = false;
99+
wallAxis.material.transparent = true;
100+
wall1.transformation.add(wallAxis);
101+
world.scene.three.add(wall1.transformation);
102+
103+
world.scene.three.add(test);
104+
test.position.set(0.5, 0.5, 0.5);
105+
test.lookAt(0, 0, 0);
106+
test.updateMatrix();
107+
108+
const halfSpace = new CLAY.HalfSpace(model);
109+
wall1.body.addSubtraction(halfSpace);
110+
111+
function updatePlane() {
112+
const delta = 0.000000001;
113+
const vector = new THREE.Vector3(0, 0, 1);
114+
115+
const planeRotation = new THREE.Matrix4();
116+
planeRotation.extractRotation(test.matrix);
117+
vector.applyMatrix4(planeRotation);
118+
119+
wall1.transformation.updateMatrix();
120+
const rotation = new THREE.Matrix4();
121+
const inverseWall = wall1.transformation.matrix.clone();
122+
inverseWall.invert();
123+
rotation.extractRotation(inverseWall);
124+
vector.applyMatrix4(rotation);
125+
126+
const position = test.position.clone();
127+
position.applyMatrix4(inverseWall);
128+
129+
halfSpace.transformation.position.copy(position);
130+
halfSpace.direction.copy(vector).normalize();
131+
132+
halfSpace.update();
133+
wall1.update(true);
134+
}
135+
136+
updatePlane();
137+
138+
function animate() {
139+
test.rotation.x += Math.PI / 180;
140+
test.updateMatrix();
141+
updatePlane();
142+
requestAnimationFrame(animate);
143+
}
144+
145+
animate();
84146

85147
// Stats
86148

@@ -109,6 +171,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
109171
) => {
110172
wall1.startPoint.x = event.target.value;
111173
wall1.update(true);
174+
updatePlane();
112175
simpleWallType.updateCorners();
113176
114177
// simpleWallType.updateCorners();
@@ -119,6 +182,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
119182
) => {
120183
wall1.startPoint.y = event.target.value;
121184
wall1.update(true);
185+
updatePlane();
122186
simpleWallType.updateCorners();
123187
124188
console.log("hey");
@@ -135,6 +199,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
135199
) => {
136200
wall1.endPoint.x = event.target.value;
137201
wall1.update(true);
202+
updatePlane();
138203
simpleWallType.updateCorners();
139204
140205
// simpleWallType.updateCorners();
@@ -145,6 +210,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
145210
) => {
146211
wall1.endPoint.y = event.target.value;
147212
wall1.update(true);
213+
updatePlane();
148214
simpleWallType.updateCorners();
149215
150216
// simpleWallType.updateCorners();
@@ -158,6 +224,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
158224
) => {
159225
wall1.transformation.position.y = event.target.value;
160226
wall1.update(true);
227+
updatePlane();
161228
simpleWallType.updateCorners();
162229
}}"></bim-number-input>
163230
@@ -166,6 +233,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
166233
) => {
167234
wall1.offset = event.target.value;
168235
wall1.update(true);
236+
updatePlane();
169237
simpleWallType.updateCorners();
170238
171239
// simpleWallType.updateCorners();
@@ -184,6 +252,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
184252
) => {
185253
wall1.height = event.target.value;
186254
wall1.update(true);
255+
updatePlane();
187256
simpleWallType.updateCorners();
188257
189258
// simpleWallType.updateCorners();

packages/clay/src/geometries/HalfSpace/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as THREE from "three";
12
import { IFC4X3 as IFC } from "web-ifc";
23
import { Model, ClayGeometry } from "../../core";
34

@@ -7,6 +8,8 @@ import { IfcUtils } from "../../utils/ifc-utils";
78
export class HalfSpace extends ClayGeometry {
89
attributes: IFC.IfcHalfSpaceSolid | IFC.IfcBooleanClippingResult;
910

11+
direction = new THREE.Vector3();
12+
1013
core: IFC.IfcHalfSpaceSolid;
1114

1215
constructor(model: Model) {
@@ -36,9 +39,22 @@ export class HalfSpace extends ClayGeometry {
3639

3740
const placement = this.model.get(plane.Position);
3841

39-
IfcUtils.setAxis2Placement(this.model, placement, this.transformation);
42+
const location = this.model.get(
43+
placement.Location,
44+
) as IFC.IfcCartesianPoint;
4045

41-
this.model.set(this.core);
42-
this.attributes = this.core;
46+
const position = MathUtils.toIfcCoords(this.transformation.position);
47+
const direction = MathUtils.toIfcCoords(this.direction);
48+
49+
location.Coordinates[0].value = position.x;
50+
location.Coordinates[1].value = position.y;
51+
location.Coordinates[2].value = position.z;
52+
this.model.set(location);
53+
54+
const zDirection = this.model.get(placement.Axis);
55+
zDirection.DirectionRatios[0].value = direction.x;
56+
zDirection.DirectionRatios[1].value = direction.y;
57+
zDirection.DirectionRatios[2].value = direction.z;
58+
this.model.set(zDirection);
4359
}
4460
}

0 commit comments

Comments
 (0)