From 6f14cbe14c8720ddb0678d312c8628b847238fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Gonz=C3=A1lez=20Viegas?= Date: Wed, 9 Oct 2024 13:38:39 +0200 Subject: [PATCH] feat: first working version of exportable wall corners --- .../src/elements/Walls/SimpleWall/example.ts | 119 ++++----------- .../SimpleWall/src/simple-wall-cornerer.ts | 140 ++++++++---------- .../Walls/SimpleWall/src/simple-wall.ts | 12 +- 3 files changed, 92 insertions(+), 179 deletions(-) diff --git a/packages/clay/src/elements/Walls/SimpleWall/example.ts b/packages/clay/src/elements/Walls/SimpleWall/example.ts index 54fe5c9..ae79bea 100644 --- a/packages/clay/src/elements/Walls/SimpleWall/example.ts +++ b/packages/clay/src/elements/Walls/SimpleWall/example.ts @@ -49,101 +49,41 @@ const simpleWallType = new CLAY.SimpleWallType(model); const wall1 = simpleWallType.addInstance(); world.scene.three.add(...wall1.meshes); wall1.startPoint = new THREE.Vector2(0, 0); -wall1.endPoint = new THREE.Vector2(0, 1); +wall1.endPoint = new THREE.Vector2(1, 0); wall1.update(true); wall1.meshes[0].setColorAt(0, new THREE.Color(1, 0, 0)); -// -// const wall2 = simpleWallType.addInstance(); -// world.scene.three.add(...wall2.meshes); -// wall2.startPoint = new THREE.Vector2(0, 0); -// wall2.endPoint = new THREE.Vector2(0, 1); -// wall2.update(true); + +const wall2 = simpleWallType.addInstance(); +world.scene.three.add(...wall2.meshes); +wall2.startPoint = new THREE.Vector2(0, 0); +wall2.endPoint = new THREE.Vector2(0, 1); +wall2.update(true); site.children.add(wall1.attributes.expressID); -// site.children.add(wall2.attributes.expressID); +site.children.add(wall2.attributes.expressID); + +simpleWallType.addCorner({ + wall1, + wall2, + to: "exterior", + cut: "exterior", + cutDirection: "interior", + priority: "start", +}); -// simpleWallType.addCorner({ -// wall1, -// wall2, -// to: "interior", -// cut: "interior", -// cutDirection: "interior", -// priority: "start", -// }); +simpleWallType.addCorner({ + wall1: wall2, + wall2: wall1, + to: "exterior", + cut: "exterior", + cutDirection: "exterior", + priority: "start", +}); simpleWallType.updateCorners(); world.camera.controls.fitToSphere(wall1.meshes[0], false); -// const simpleOpeningType = new CLAY.SimpleOpeningType(model); -// const opening = simpleOpeningType.addInstance(); -// // world.scene.three.add(...opening.meshes); -// console.log(simpleOpeningType); -// opening.transformation.position.x += 1; -// -// await wall1.addSubtraction(opening, true); -// wall1.update(true); - -const test = new THREE.Mesh( - new THREE.PlaneGeometry(), - new THREE.MeshLambertMaterial({ - color: "blue", - transparent: true, - opacity: 0.3, - side: 2, - }), -); - -const wallAxis = new THREE.AxesHelper(); -wallAxis.material.depthTest = false; -wallAxis.material.transparent = true; -wall1.transformation.add(wallAxis); -world.scene.three.add(wall1.transformation); - -world.scene.three.add(test); -test.position.set(0.5, 0.5, 0.5); -test.lookAt(0, 0, 0); -test.updateMatrix(); - -const halfSpace = new CLAY.HalfSpace(model); -wall1.body.addSubtraction(halfSpace); - -function updatePlane() { - const delta = 0.000000001; - const vector = new THREE.Vector3(0, 0, 1); - - const planeRotation = new THREE.Matrix4(); - planeRotation.extractRotation(test.matrix); - vector.applyMatrix4(planeRotation); - - wall1.transformation.updateMatrix(); - const rotation = new THREE.Matrix4(); - const inverseWall = wall1.transformation.matrix.clone(); - inverseWall.invert(); - rotation.extractRotation(inverseWall); - vector.applyMatrix4(rotation); - - const position = test.position.clone(); - position.applyMatrix4(inverseWall); - - halfSpace.transformation.position.copy(position); - halfSpace.direction.copy(vector).normalize(); - - halfSpace.update(); - wall1.update(true); -} - -updatePlane(); - -function animate() { - test.rotation.x += Math.PI / 180; - test.updateMatrix(); - updatePlane(); - requestAnimationFrame(animate); -} - -animate(); - // Stats const stats = new Stats(); @@ -171,7 +111,6 @@ const panel = BUI.Component.create(() => { ) => { wall1.startPoint.x = event.target.value; wall1.update(true); - updatePlane(); simpleWallType.updateCorners(); // simpleWallType.updateCorners(); @@ -182,7 +121,6 @@ const panel = BUI.Component.create(() => { ) => { wall1.startPoint.y = event.target.value; wall1.update(true); - updatePlane(); simpleWallType.updateCorners(); console.log("hey"); @@ -199,7 +137,6 @@ const panel = BUI.Component.create(() => { ) => { wall1.endPoint.x = event.target.value; wall1.update(true); - updatePlane(); simpleWallType.updateCorners(); // simpleWallType.updateCorners(); @@ -210,7 +147,6 @@ const panel = BUI.Component.create(() => { ) => { wall1.endPoint.y = event.target.value; wall1.update(true); - updatePlane(); simpleWallType.updateCorners(); // simpleWallType.updateCorners(); @@ -224,7 +160,6 @@ const panel = BUI.Component.create(() => { ) => { wall1.transformation.position.y = event.target.value; wall1.update(true); - updatePlane(); simpleWallType.updateCorners(); }}"> @@ -233,7 +168,6 @@ const panel = BUI.Component.create(() => { ) => { wall1.offset = event.target.value; wall1.update(true); - updatePlane(); simpleWallType.updateCorners(); // simpleWallType.updateCorners(); @@ -244,7 +178,7 @@ const panel = BUI.Component.create(() => { ) => { simpleWallType.width = event.target.value; simpleWallType.update(true); - // simpleWallType.updateCorners(); + simpleWallType.updateCorners(); }}">