@@ -22,6 +22,8 @@ interface WallCorner extends WallCornerConfig {
2222export class SimpleWallCornerer {
2323 list = new Map < number , Map < number , WallCorner > > ( ) ;
2424
25+ private _temp = new THREE . Object3D ( ) ;
26+
2527 add ( config : WallCornerConfig ) {
2628 const id1 = config . wall1 . attributes . expressID ;
2729 const id2 = config . wall2 . attributes . expressID ;
@@ -58,14 +60,16 @@ export class SimpleWallCornerer {
5860 // B) Each point of the wall are on one side of this wall
5961 // In that case, keep the point specified in priority
6062
63+ wall1 . transformation . updateMatrix ( ) ;
64+
6165 const dir1 = wall1 . direction ;
6266 const dir2 = wall2 . direction ;
6367 if ( dir1 . equals ( dir2 ) ) {
6468 // Same direction, so walls can't intersect
6569 return ;
6670 }
6771
68- const { plane } = wall1 . getPlane ( to ) ;
72+ const { plane, p1 } = wall1 . getPlane ( to ) ;
6973 if ( plane === null ) {
7074 // Malformed wall (e.g. zero length)
7175 return ;
@@ -77,92 +81,68 @@ export class SimpleWallCornerer {
7781 const extendStart = priority === "start" ;
7882
7983 const pointToExtend = extendStart ? start : end ;
80- if ( plane . distanceToPoint ( pointToExtend ) = == 0 ) {
84+ if ( plane . distanceToPoint ( pointToExtend ) ! == 0 ) {
8185 // Point is already aligned with wall
82- return ;
83- }
86+ const origin = extendStart ? end : start ;
87+ const direction = extendStart ? start : end ;
88+ direction . sub ( origin ) ;
8489
85- const origin = extendStart ? end : start ;
86- const direction = extendStart ? start : end ;
87- direction . sub ( origin ) ;
90+ const ray = new THREE . Ray ( origin , direction ) ;
8891
89- const ray = new THREE . Ray ( origin , direction ) ;
92+ const intersection = ray . intersectPlane ( plane , new THREE . Vector3 ( ) ) ;
9093
91- const intersection = ray . intersectPlane ( plane , new THREE . Vector3 ( ) ) ;
94+ if ( intersection === null ) {
95+ return ;
96+ }
9297
93- if ( intersection === null ) {
94- return ;
98+ const offsetDist = offset === "auto" ? wall2 . type . width : offset ;
99+ const factor = extendStart ? - 1 : 1 ;
100+ const offsetVec = dir2 . multiplyScalar ( offsetDist * factor ) ;
101+ intersection . add ( offsetVec ) ;
102+
103+ const extended = extendStart ? wall2 . startPoint : wall2 . endPoint ;
104+ extended . x = intersection . x ;
105+ extended . y = intersection . z ;
106+
107+ wall2 . update ( ) ;
95108 }
96109
97- const offsetDist = offset === "auto" ? wall2 . type . width : offset ;
98- const factor = extendStart ? - 1 : 1 ;
99- const offsetVec = dir2 . multiplyScalar ( offsetDist * factor ) ;
100- intersection . add ( offsetVec ) ;
101-
102- const extended = extendStart ? wall2 . startPoint : wall2 . endPoint ;
103- extended . x = intersection . x ;
104- extended . y = intersection . z ;
105-
106- // if (corner.cut && corner.cutDirection) {
107- // if (!corner.halfSpace) {
108- // const halfSpace = new HalfSpace(wall1.model);
109- // corner.halfSpace = halfSpace;
110- // wall2.body.addSubtraction(halfSpace);
111- // }
112- //
113- // const halfSpace = corner.halfSpace as HalfSpace;
114- //
115- // const temp = new THREE.Mesh(
116- // new THREE.PlaneGeometry(10, 10, 10),
117- // new THREE.MeshLambertMaterial({
118- // color: "blue",
119- // }),
120- // );
121- //
122- // const temp2 = new THREE.Object3D();
123- // temp2.position.copy(p1);
124- // const p4 = p1.clone().add(plane.normal);
125- // temp2.lookAt(p4);
126- //
127- // temp2.applyMatrix4(new THREE.Matrix4().makeRotationX(-Math.PI / 2));
128- // temp2.applyMatrix4(new THREE.Matrix4().makeRotationY(Math.PI / 2));
129- // temp2.applyMatrix4(new THREE.Matrix4().makeRotationX(Math.PI / 2));
130- //
131- // temp.applyMatrix4(temp2.matrix);
132- //
133- // // temp.updateMatrix();
134- //
135- // const temp3 = new THREE.Object3D();
136- // const transform = wall2.transformation.matrix.clone();
137- // transform.invert();
138- //
139- // temp3.applyMatrix4(transform);
140- // temp3.applyMatrix4(new THREE.Matrix4().makeRotationZ(Math.PI / 2));
141- // temp.applyMatrix4(temp3.matrix);
142- //
143- // // const temp4 = new THREE.Object3D();
144- // // temp4.position.copy(p1);
145- // // temp4.applyMatrix4(transform);
146- //
147- // // const obj = MathUtils.getTempObject3DToDisplayIfcCoords();
148- // // obj.add(temp);
149- // // wall1.meshes[0].parent.add(obj);
150- //
151- // // halfSpace.position.copy(temp.position);
152- // // halfSpace.rotation.copy(temp.rotation);
153- //
154- // // const transform = wall2.getTransform();
155- // // transform.invert();
156- // // halfSpace.applyTransform(transform);
157- //
158- // // halfSpace.rotation.y = Math.PI / 2;
159- // // halfSpace.position.x = 0.25;
160- //
161- // halfSpace.transformation.rotation.copy(temp.rotation);
162- // halfSpace.transformation.position.copy(temp.position);
163- //
164- // halfSpace.update();
165- // }
110+ if ( corner . cut && corner . cutDirection ) {
111+ if ( ! corner . halfSpace ) {
112+ const halfSpace = new HalfSpace ( wall1 . model ) ;
113+ corner . halfSpace = halfSpace ;
114+ wall2 . body . addSubtraction ( halfSpace ) ;
115+ }
116+
117+ const halfSpace = corner . halfSpace as HalfSpace ;
118+
119+ const rotation = new THREE . Vector3 ( 0 , 0 , 1 ) ;
120+
121+ this . _temp . position . copy ( p1 ) ;
122+ const factor = corner . cutDirection === "interior" ? - 1 : 1 ;
123+ const minusNormal = plane . normal . clone ( ) . multiplyScalar ( factor ) ;
124+ this . _temp . lookAt ( p1 . clone ( ) . add ( minusNormal ) ) ;
125+ this . _temp . updateMatrix ( ) ;
126+
127+ const planeRotation = new THREE . Matrix4 ( ) ;
128+ planeRotation . extractRotation ( this . _temp . matrix ) ;
129+ rotation . applyMatrix4 ( planeRotation ) ;
130+
131+ wall2 . transformation . updateMatrix ( ) ;
132+ const wallRotation = new THREE . Matrix4 ( ) ;
133+ const inverseWall = wall2 . transformation . matrix . clone ( ) ;
134+ inverseWall . invert ( ) ;
135+ wallRotation . extractRotation ( inverseWall ) ;
136+ rotation . applyMatrix4 ( wallRotation ) ;
137+
138+ const position = this . _temp . position . clone ( ) ;
139+ position . applyMatrix4 ( inverseWall ) ;
140+
141+ halfSpace . transformation . position . copy ( position ) ;
142+ halfSpace . direction . copy ( rotation ) . normalize ( ) ;
143+
144+ halfSpace . update ( ) ;
145+ }
166146
167147 wall2 . update ( true ) ;
168148 }
0 commit comments