Skip to content

Commit bfc4868

Browse files
committed
feat: progress making library work only with three.js coords
1 parent 076fc9d commit bfc4868

File tree

15 files changed

+79
-234
lines changed

15 files changed

+79
-234
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,7 @@ export abstract class ClayElement extends ClayObject3D {
204204
placement.RelativePlacement,
205205
) as IFC.IfcAxis2Placement3D;
206206

207-
IfcUtils.setAxis2Placement(
208-
this.model,
209-
relPlacement,
210-
this.position,
211-
this.rotation,
212-
);
207+
IfcUtils.setAxis2Placement(this.model, relPlacement, this.transformation);
213208

214209
this.model.set(this.attributes);
215210
}

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

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,7 @@ import { ClayObject } from "../Object";
66
*/
77
export abstract class ClayObject3D extends ClayObject {
88
/**
9-
* Position of this element in 3D space.
9+
* Object representing the transformation of the object in 3D space.
1010
*/
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-
}
11+
transformation = new THREE.Object3D();
5012
}

packages/clay/src/elements/CurtainWalls/SimpleCurtainWall/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class SimpleCurtainWallType extends StaticClayElementType<SimpleCurtainWa
310310
if (currentColumn === 0) {
311311
const sideAMember = this.sideAMembers[currentRow];
312312
sideAMember.body.profile.dimension.x = this.frameWidth;
313-
sideAMember.body.profile.position.y = memberWidth / 2;
313+
sideAMember.body.profile.transformation.position.y = memberWidth / 2;
314314
sideAMember.body.depth = plateHeight;
315315
sideAMember.body.position.x = this.startPoint.x;
316316
sideAMember.body.position.y = this.startPoint.y;
@@ -391,7 +391,8 @@ export class SimpleCurtainWallType extends StaticClayElementType<SimpleCurtainWa
391391

392392
if (currentColumn === this.numberOfColumns - 1) {
393393
const sideBMember = this.sideBMembers[currentRow];
394-
sideBMember.body.profile.position.y = -1 * (memberWidth / 2);
394+
sideBMember.body.profile.transformation.position.y =
395+
-1 * (memberWidth / 2);
395396
sideBMember.body.profile.dimension.x = this.frameWidth;
396397
sideBMember.body.depth = plateHeight;
397398
sideBMember.body.position.x = this.endPoint.x;
@@ -440,11 +441,11 @@ export class SimpleCurtainWallType extends StaticClayElementType<SimpleCurtainWa
440441

441442
if (currentColumn === 0 || currentColumn === this.numberOfColumns - 1) {
442443
plate.body.profile.dimension.y = plateWidth - memberWidth / 2;
443-
plate.body.profile.position.y = memberWidth / 4;
444+
plate.body.profile.transformation.position.y = memberWidth / 4;
444445
}
445446

446447
if (currentColumn === this.numberOfColumns - 1) {
447-
plate.body.profile.position.y = -memberWidth / 4;
448+
plate.body.profile.transformation.position.y = -memberWidth / 4;
448449
}
449450

450451
plate.body.profile.update();

packages/clay/src/elements/Members/SimpleMember/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class SimpleMember extends ClayElement {
2727
const profile = new RectangleProfile(model);
2828
profile.dimension.x = this.depth;
2929
profile.dimension.y = this.width;
30-
profile.position = new THREE.Vector3(0, 0, 5);
30+
profile.transformation.position.set(0, 0, 5);
3131
profile.update();
3232

3333
this.body = new Extrusion(model, profile);

packages/clay/src/elements/Plates/SimplePlate/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { IFC4X3 as IFC } from "web-ifc";
22
import { v4 as uuidv4 } from "uuid";
3-
import * as THREE from "three";
43
import { ClayElement, Model } from "../../../../core";
54

65
import { SimplePlateType } from "..";
@@ -24,7 +23,7 @@ export class SimplePlate extends ClayElement {
2423
profile.dimension.x = 0.0833333333333333;
2524
profile.dimension.y = 1.9238;
2625
profile.dimension.z = 1;
27-
profile.position = new THREE.Vector3(0, 0, 0);
26+
profile.transformation.position.set(0, 0, 0);
2827
profile.update();
2928

3029
this.body = new Extrusion(model, profile);

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

Lines changed: 25 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ world.scene.three.background = null;
2929
const grids = components.get(OBC.Grids);
3030
grids.create(world);
3131

32+
const axis = new THREE.AxesHelper();
33+
axis.material.depthTest = false;
34+
axis.material.transparent = true;
35+
world.scene.three.add(axis);
36+
3237
const model = new CLAY.Model();
3338
model.wasm = { path: "https://unpkg.com/[email protected]/", absolute: true };
3439
await model.init();
@@ -40,121 +45,23 @@ const simpleWallType = new CLAY.SimpleWallType(model);
4045

4146
const wall1 = simpleWallType.addInstance();
4247
world.scene.three.add(...wall1.meshes);
43-
wall1.startPoint = new THREE.Vector2(0, 0);
44-
wall1.endPoint = new THREE.Vector2(1, 0);
48+
// wall1.startPoint = new THREE.Vector2(0, 0);
49+
// wall1.endPoint = new THREE.Vector2(1, 0);
4550
wall1.update(true);
46-
wall1.meshes[0].setColorAt(0, new THREE.Color(1, 0, 0));
47-
48-
const wall2 = simpleWallType.addInstance();
49-
world.scene.three.add(...wall2.meshes);
50-
wall2.startPoint = new THREE.Vector2(0, 0);
51-
wall2.endPoint = new THREE.Vector2(0, 1);
52-
wall2.update(true);
51+
// wall1.meshes[0].setColorAt(0, new THREE.Color(1, 0, 0));
5352

5453
site.children.add(wall1.attributes.expressID);
55-
site.children.add(wall2.attributes.expressID);
56-
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-
}
125-
});
126-
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-
// });
146-
147-
await simpleWallType.updateCorners();
14854

14955
world.camera.controls.fitToSphere(wall1.meshes[0], false);
15056

151-
// const simpleOpeningType = new CLAY.SimpleOpeningType(model);
152-
// const opening = simpleOpeningType.addInstance();
153-
// scene.add(...opening.meshes);
154-
// console.log(simpleOpeningType);
57+
const simpleOpeningType = new CLAY.SimpleOpeningType(model);
58+
const opening = simpleOpeningType.addInstance();
59+
world.scene.three.add(...opening.meshes);
60+
console.log(simpleOpeningType);
61+
opening.transformation.position.x += 1;
15562

156-
// await wall1.addSubtraction(opening, true);
157-
// wall1.update(true);
63+
await wall1.addSubtraction(opening, true);
64+
wall1.update(true);
15865

15966
// Stats
16067

@@ -183,17 +90,15 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
18390
) => {
18491
wall1.startPoint.x = event.target.value;
18592
wall1.update(true);
186-
updatePlane();
187-
simpleWallType.updateCorners();
93+
// simpleWallType.updateCorners();
18894
}}"></bim-number-input>
18995
190-
<bim-number-input slider step="0.1" label="Start Y" vertical="true" value="${wall1.startPoint.y}" @change="${(
96+
<bim-number-input slider step="0.1" label="Start Z" vertical="true" value="${wall1.startPoint.y}" @change="${(
19197
event: any,
19298
) => {
19399
wall1.startPoint.y = event.target.value;
194100
wall1.update(true);
195-
updatePlane();
196-
simpleWallType.updateCorners();
101+
// simpleWallType.updateCorners();
197102
}}"></bim-number-input>
198103
199104
</div>
@@ -205,17 +110,15 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
205110
) => {
206111
wall1.endPoint.x = event.target.value;
207112
wall1.update(true);
208-
updatePlane();
209-
simpleWallType.updateCorners();
113+
// simpleWallType.updateCorners();
210114
}}"></bim-number-input>
211115
212-
<bim-number-input slider step="0.1" label="End Y" vertical="true" value="${wall1.endPoint.y}" @change="${(
116+
<bim-number-input slider step="0.1" label="End Z" vertical="true" value="${wall1.endPoint.y}" @change="${(
213117
event: any,
214118
) => {
215119
wall1.endPoint.y = event.target.value;
216120
wall1.update(true);
217-
updatePlane();
218-
simpleWallType.updateCorners();
121+
// simpleWallType.updateCorners();
219122
}}"></bim-number-input>
220123
221124
@@ -224,38 +127,32 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
224127
<bim-number-input slider step="0.05" label="Elevation" value="${wall1.elevation}" @change="${(
225128
event: any,
226129
) => {
227-
opening.position.z = event.target.value;
228-
opening.update();
229-
wall1.elevation = event.target.value;
130+
wall1.transformation.position.y = event.target.value;
230131
wall1.update(true);
231-
updatePlane();
232-
simpleWallType.updateCorners();
233132
}}"></bim-number-input>
234133
235134
<bim-number-input slider step="0.01" label="Offset" value="${wall1.offset}" @change="${(
236135
event: any,
237136
) => {
238137
wall1.offset = event.target.value;
239138
wall1.update(true);
240-
wall2.offset = event.target.value;
241-
wall2.update(true);
242-
simpleWallType.updateCorners();
139+
// simpleWallType.updateCorners();
243140
}}"></bim-number-input>
244141
245142
<bim-number-input slider step="0.05" label="Thickness" value="${simpleWallType.width}" @change="${(
246143
event: any,
247144
) => {
248145
simpleWallType.width = event.target.value;
249146
simpleWallType.update(true);
250-
simpleWallType.updateCorners();
147+
// simpleWallType.updateCorners();
251148
}}"></bim-number-input>
252149
253150
<bim-number-input slider step="0.05" label="Height" value="${wall1.height}" @change="${(
254151
event: any,
255152
) => {
256153
wall1.height = event.target.value;
257154
wall1.update(true);
258-
simpleWallType.updateCorners();
155+
// simpleWallType.updateCorners();
259156
}}"></bim-number-input>
260157
261158
</bim-panel-section>

packages/clay/src/elements/Walls/SimpleWall/src/simple-wall-cornerer.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as THREE from "three";
22
import { SimpleWall, WallEndPointType, WallPlaneType } from "./simple-wall";
33
import { HalfSpace } from "../../../../geometries";
4-
import { MathUtils } from "../../../../utils";
54

65
export interface WallCornerConfig {
76
wall1: SimpleWall;
@@ -66,7 +65,7 @@ export class SimpleWallCornerer {
6665
return;
6766
}
6867

69-
const { plane, p1, p2, p3 } = wall1.getPlane(to);
68+
const { plane, p1 } = wall1.getPlane(to);
7069
if (plane === null) {
7170
// Malformed wall (e.g. zero length)
7271
return;
@@ -147,7 +146,7 @@ export class SimpleWallCornerer {
147146
// temp.updateMatrix();
148147

149148
const temp3 = new THREE.Object3D();
150-
const transform = wall2.getTransform();
149+
const transform = wall2.transformation.matrix.clone();
151150
transform.invert();
152151

153152
temp3.applyMatrix4(transform);
@@ -172,8 +171,8 @@ export class SimpleWallCornerer {
172171
// halfSpace.rotation.y = Math.PI / 2;
173172
// halfSpace.position.x = 0.25;
174173

175-
halfSpace.rotation.copy(temp.rotation);
176-
halfSpace.position.copy(temp.position);
174+
halfSpace.transformation.rotation.copy(temp.rotation);
175+
halfSpace.transformation.position.copy(temp.position);
177176

178177
halfSpace.update();
179178
}

0 commit comments

Comments
 (0)