@@ -4,7 +4,9 @@ import Stats from "stats.js";
44import * as OBC from "@thatopen/components" ;
55
66import * as WEBIFC from "web-ifc" ;
7+ import { ParametricGeometries } from "three/examples/jsm/geometries/ParametricGeometries" ;
78import * as CLAY from "../../.." ;
9+ import plane = ParametricGeometries . plane ;
810
911const container = document . getElementById ( "container" ) ! ;
1012
@@ -47,40 +49,100 @@ const simpleWallType = new CLAY.SimpleWallType(model);
4749const wall1 = simpleWallType . addInstance ( ) ;
4850world . scene . three . add ( ...wall1 . meshes ) ;
4951wall1 . startPoint = new THREE . Vector2 ( 0 , 0 ) ;
50- wall1 . endPoint = new THREE . Vector2 ( 1 , 0 ) ;
52+ wall1 . endPoint = new THREE . Vector2 ( 0 , 1 ) ;
5153wall1 . update ( true ) ;
5254wall1 . 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
6062site . 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
7274simpleWallType . updateCorners ( ) ;
7375
7476world . 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();
0 commit comments