Skip to content

Commit e9f7dcf

Browse files
author
rrdls
committed
feat: refactoring
1 parent 8376fbb commit e9f7dcf

3 files changed

Lines changed: 87 additions & 78 deletions

File tree

resources/openbim-clay.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84318,6 +84318,7 @@ class SimpleWall extends Element {
8431884318
this.startPoint = new THREE.Vector3(0, 0, 0);
8431984319
this.endPoint = new THREE.Vector3(1, 0, 0);
8432084320
this._openings = new Map();
84321+
this._corners = new Map();
8432184322
this.type = type;
8432284323
const profile = new RectangleProfile(model);
8432384324
this.body = new Extrusion(model, profile);
@@ -84348,34 +84349,33 @@ class SimpleWall extends Element {
8434884349
this.model.set(reps);
8434984350
this.updateGeometryID();
8435084351
super.update(updateGeometry);
84352+
// this.updateAllCorners();
8435184353
}
84352-
extend(wall, isEnd = true) {
84354+
extend(wall, atTheEndPoint = true) {
8435384355
const zDirection = new THREE.Vector3(0, 0, 1);
8435484356
const normalVector = wall.direction.cross(zDirection);
84355-
const correctNormalVector = new THREE.Vector3(normalVector.x, normalVector.z, normalVector.y * -1);
84357+
const correctedNormalVector = new THREE.Vector3(normalVector.x, normalVector.z, normalVector.y * -1);
8435684358
const coplanarPoint = new THREE.Vector3(wall.startPoint.x, wall.startPoint.z, wall.startPoint.y * -1);
84357-
const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(correctNormalVector, coplanarPoint);
84358-
const correctDirection = new THREE.Vector3(this.direction.x * -1, this.direction.z, this.direction.y);
84359-
if (isEnd) {
84360-
correctDirection.negate();
84359+
const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(correctedNormalVector, coplanarPoint);
84360+
const correctedDirection = new THREE.Vector3(this.direction.x * -1, this.direction.z, this.direction.y);
84361+
if (atTheEndPoint) {
84362+
correctedDirection.negate();
8436184363
}
84362-
const origin = isEnd ? this.endPoint : this.startPoint;
84363-
const sign = isEnd ? -1 : 1;
84364+
const origin = atTheEndPoint ? this.endPoint : this.startPoint;
84365+
const sign = atTheEndPoint ? -1 : 1;
8436484366
const rayOriginPoint = new THREE.Vector3(origin.x, origin.z, origin.y * sign);
84365-
const rayAxisWall1 = new THREE.Ray(rayOriginPoint, correctDirection);
84367+
const rayAxisWall1 = new THREE.Ray(rayOriginPoint, correctedDirection);
8436684368
const intersectionPoint = rayAxisWall1.intersectPlane(plane, new THREE.Vector3());
8436784369
if (intersectionPoint) {
84368-
const correctIntersectionPoint = new THREE.Vector3(intersectionPoint === null || intersectionPoint === void 0 ? void 0 : intersectionPoint.x, (intersectionPoint === null || intersectionPoint === void 0 ? void 0 : intersectionPoint.z) * -1, intersectionPoint === null || intersectionPoint === void 0 ? void 0 : intersectionPoint.y);
84369-
if (isEnd) {
84370-
this.endPoint = correctIntersectionPoint;
84370+
const correctedIntersectionPoint = new THREE.Vector3(intersectionPoint === null || intersectionPoint === void 0 ? void 0 : intersectionPoint.x, (intersectionPoint === null || intersectionPoint === void 0 ? void 0 : intersectionPoint.z) * -1, intersectionPoint === null || intersectionPoint === void 0 ? void 0 : intersectionPoint.y);
84371+
if (atTheEndPoint) {
84372+
this.endPoint = correctedIntersectionPoint;
8437184373
}
8437284374
else {
84373-
this.startPoint = correctIntersectionPoint;
84375+
this.startPoint = correctedIntersectionPoint;
8437484376
}
84375-
this.update(true);
8437684377
wall.update(true);
84377-
console.log("correctIntersectionPoint", correctIntersectionPoint);
84378-
return correctIntersectionPoint;
84378+
return correctedIntersectionPoint;
8437984379
}
8438084380
return null;
8438184381
}
@@ -84384,30 +84384,33 @@ class SimpleWall extends Element {
8438484384
if (!intersectionPoint)
8438584385
return;
8438684386
const angle = wall.rotation.z - this.rotation.z;
84387-
const angle2 = Math.asin(this.direction.dot(wall.direction) /
84388-
(this.direction.length() * wall.direction.length()));
84387+
const theta = this.direction.dot(wall.direction) /
84388+
(this.direction.length() * wall.direction.length());
8438984389
let sign = 1;
84390-
if ((angle2 < 0 && atTheEndPoint) || (angle2 > 0 && !atTheEndPoint)) {
84390+
if ((Math.asin(theta) < 0 && atTheEndPoint) ||
84391+
(Math.asin(theta) > 0 && !atTheEndPoint)) {
8439184392
sign = -1;
8439284393
}
8439384394
const width1 = this.type.width;
84394-
const width2 = this.type.width;
84395+
const width2 = wall.type.width;
8439584396
const distance1 = this.midPoint.distanceTo(intersectionPoint);
8439684397
const distance2 = wall.midPoint.distanceTo(intersectionPoint);
84397-
const halfSpace1 = new HalfSpace(this.model);
84398-
halfSpace1.position.x = distance1 - width1 / (2 * Math.sin(angle));
84399-
halfSpace1.rotation.y = angle;
84400-
halfSpace1.rotation.x = Math.PI / 2;
84401-
halfSpace1.update();
84402-
const halfSpace2 = new HalfSpace(this.model);
84403-
halfSpace2.position.x = sign * distance2 + width2 / (2 * Math.sin(angle));
84404-
halfSpace2.rotation.y = angle;
84405-
halfSpace2.rotation.x = -Math.PI / 2;
84406-
halfSpace2.update();
84407-
this.body.addSubtraction(halfSpace1);
84408-
wall.body.addSubtraction(halfSpace2);
84398+
const hsInteriorWall2 = new HalfSpace(this.model);
84399+
hsInteriorWall2.position.x = distance1 - width2 / (2 * Math.sin(angle));
84400+
hsInteriorWall2.rotation.y = angle;
84401+
hsInteriorWall2.rotation.x = Math.PI / 2;
84402+
hsInteriorWall2.update();
84403+
const hsExteriorWall1 = new HalfSpace(this.model);
84404+
hsExteriorWall1.position.x =
84405+
sign * distance2 + width1 / (2 * Math.sin(angle));
84406+
hsExteriorWall1.rotation.y = angle;
84407+
hsExteriorWall1.rotation.x = -Math.PI / 2;
84408+
hsExteriorWall1.update();
84409+
this.body.addSubtraction(hsInteriorWall2);
84410+
wall.body.addSubtraction(hsExteriorWall1);
8440984411
wall.update(true);
84410-
this.update(true);
84412+
const id = wall.attributes.expressID;
84413+
this._corners.set(id, { wall, atTheEndPoint });
8441184414
}
8441284415
addOpening(opening) {
8441384416
super.addOpening(opening);

src/elements/Walls/SimpleWall/index.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@
9292
model.ifcAPI.SetWasmPath("https://unpkg.com/web-ifc@0.0.50/", true);
9393
await model.init();
9494

95-
const simpleWallType1 = new CLAY.SimpleWallType(model);
96-
const simpleWallType2 = new CLAY.SimpleWallType(model);
95+
const simpleWallType = new CLAY.SimpleWallType(model);
9796

98-
const wall = simpleWallType1.addInstance();
99-
100-
const wall2 = simpleWallType2.addInstance();
97+
const wall = simpleWallType.addInstance();
98+
const wall2 = simpleWallType.addInstance();
10199

102100
scene.add(...wall.meshes);
103101
scene.add(...wall2.meshes);
@@ -110,7 +108,7 @@
110108
// wall.addOpening(opening);
111109
// wall.update(true);
112110

113-
wall.startPoint.x = 5;
111+
wall.startPoint.x = -5;
114112
wall.startPoint.y = 0;
115113
wall.endPoint.x = 0;
116114
wall.endPoint.y = 10;
@@ -122,7 +120,8 @@
122120
wall2.endPoint.y = 20;
123121
wall2.update(true);
124122

125-
wall.addCorner(wall2, true);
123+
wall.addCorner(wall2, true); //at the end point => true
124+
wall.update(true);
126125

127126
window.addEventListener("keydown", () => {
128127
wall.removeOpening(opening);

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

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export class SimpleWall extends Element {
2828
{ opening: SimpleOpening; distance: number }
2929
>();
3030

31+
private _corners = new Map<
32+
number,
33+
{ wall: SimpleWall; atTheEndPoint: boolean }
34+
>();
35+
3136
get length() {
3237
return this.startPoint.distanceTo(this.endPoint);
3338
}
@@ -98,14 +103,13 @@ export class SimpleWall extends Element {
98103
this.model.set(reps);
99104
this.updateGeometryID();
100105
super.update(updateGeometry);
106+
// this.updateAllCorners();
101107
}
102108

103-
extend(wall: SimpleWall, isEnd = true) {
109+
extend(wall: SimpleWall, atTheEndPoint = true) {
104110
const zDirection = new THREE.Vector3(0, 0, 1);
105-
106111
const normalVector = wall.direction.cross(zDirection);
107-
108-
const correctNormalVector = new THREE.Vector3(
112+
const correctedNormalVector = new THREE.Vector3(
109113
normalVector.x,
110114
normalVector.z,
111115
normalVector.y * -1
@@ -118,54 +122,52 @@ export class SimpleWall extends Element {
118122
);
119123

120124
const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(
121-
correctNormalVector,
125+
correctedNormalVector,
122126
coplanarPoint
123127
);
124128

125-
const correctDirection = new THREE.Vector3(
129+
const correctedDirection = new THREE.Vector3(
126130
this.direction.x * -1,
127131
this.direction.z,
128132
this.direction.y
129133
);
130134

131-
if (isEnd) {
132-
correctDirection.negate();
135+
if (atTheEndPoint) {
136+
correctedDirection.negate();
133137
}
134138

135-
const origin = isEnd ? this.endPoint : this.startPoint;
136-
const sign = isEnd ? -1 : 1;
139+
const origin = atTheEndPoint ? this.endPoint : this.startPoint;
140+
const sign = atTheEndPoint ? -1 : 1;
137141

138142
const rayOriginPoint = new THREE.Vector3(
139143
origin.x,
140144
origin.z,
141145
origin.y * sign
142146
);
143147

144-
const rayAxisWall1 = new THREE.Ray(rayOriginPoint, correctDirection);
148+
const rayAxisWall1 = new THREE.Ray(rayOriginPoint, correctedDirection);
145149

146150
const intersectionPoint = rayAxisWall1.intersectPlane(
147151
plane,
148152
new THREE.Vector3()
149153
);
150154

151155
if (intersectionPoint) {
152-
const correctIntersectionPoint = new THREE.Vector3(
156+
const correctedIntersectionPoint = new THREE.Vector3(
153157
intersectionPoint?.x,
154158
intersectionPoint?.z * -1,
155159
intersectionPoint?.y
156160
);
157161

158-
if (isEnd) {
159-
this.endPoint = correctIntersectionPoint;
162+
if (atTheEndPoint) {
163+
this.endPoint = correctedIntersectionPoint;
160164
} else {
161-
this.startPoint = correctIntersectionPoint;
165+
this.startPoint = correctedIntersectionPoint;
162166
}
163167

164-
this.update(true);
165168
wall.update(true);
166169

167-
console.log("correctIntersectionPoint", correctIntersectionPoint);
168-
return correctIntersectionPoint;
170+
return correctedIntersectionPoint;
169171
}
170172
return null;
171173
}
@@ -176,37 +178,42 @@ export class SimpleWall extends Element {
176178

177179
const angle = wall.rotation.z - this.rotation.z;
178180

179-
const angle2 = Math.asin(
181+
const theta =
180182
this.direction.dot(wall.direction) /
181-
(this.direction.length() * wall.direction.length())
182-
);
183+
(this.direction.length() * wall.direction.length());
183184

184185
let sign = 1;
185-
if ((angle2 < 0 && atTheEndPoint) || (angle2 > 0 && !atTheEndPoint)) {
186+
if (
187+
(Math.asin(theta) < 0 && atTheEndPoint) ||
188+
(Math.asin(theta) > 0 && !atTheEndPoint)
189+
) {
186190
sign = -1;
187191
}
188192

189193
const width1 = this.type.width;
190-
const width2 = this.type.width;
194+
const width2 = wall.type.width;
191195
const distance1 = this.midPoint.distanceTo(intersectionPoint);
192196
const distance2 = wall.midPoint.distanceTo(intersectionPoint);
193197

194-
const halfSpace1 = new HalfSpace(this.model);
195-
halfSpace1.position.x = distance1 - width1 / (2 * Math.sin(angle));
196-
halfSpace1.rotation.y = angle;
197-
halfSpace1.rotation.x = Math.PI / 2;
198-
halfSpace1.update();
199-
200-
const halfSpace2 = new HalfSpace(this.model);
201-
halfSpace2.position.x = sign * distance2 + width2 / (2 * Math.sin(angle));
202-
halfSpace2.rotation.y = angle;
203-
halfSpace2.rotation.x = -Math.PI / 2;
204-
halfSpace2.update();
205-
206-
this.body.addSubtraction(halfSpace1);
207-
wall.body.addSubtraction(halfSpace2);
198+
const hsInteriorWall2 = new HalfSpace(this.model);
199+
hsInteriorWall2.position.x = distance1 - width2 / (2 * Math.sin(angle));
200+
hsInteriorWall2.rotation.y = angle;
201+
hsInteriorWall2.rotation.x = Math.PI / 2;
202+
hsInteriorWall2.update();
203+
204+
const hsExteriorWall1 = new HalfSpace(this.model);
205+
hsExteriorWall1.position.x =
206+
sign * distance2 + width1 / (2 * Math.sin(angle));
207+
hsExteriorWall1.rotation.y = angle;
208+
hsExteriorWall1.rotation.x = -Math.PI / 2;
209+
hsExteriorWall1.update();
210+
211+
this.body.addSubtraction(hsInteriorWall2);
212+
wall.body.addSubtraction(hsExteriorWall1);
208213
wall.update(true);
209-
this.update(true);
214+
215+
const id = wall.attributes.expressID;
216+
this._corners.set(id, { wall, atTheEndPoint });
210217
}
211218

212219
addOpening(opening: SimpleOpening) {

0 commit comments

Comments
 (0)