Skip to content

Commit

Permalink
feat: make halfspaces work as expected in draft
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Oct 6, 2024
1 parent 96cc12b commit f5551d9
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 28 deletions.
119 changes: 94 additions & 25 deletions packages/clay/src/elements/Walls/SimpleWall/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import Stats from "stats.js";
import * as OBC from "@thatopen/components";

import * as WEBIFC from "web-ifc";
import { ParametricGeometries } from "three/examples/jsm/geometries/ParametricGeometries";
import * as CLAY from "../../..";
import plane = ParametricGeometries.plane;

const container = document.getElementById("container")!;

Expand Down Expand Up @@ -47,40 +49,100 @@ 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(1, 0);
wall1.endPoint = new THREE.Vector2(0, 1);
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);

simpleWallType.addCorner({
wall1,
wall2,
to: "interior",
cut: "interior",
cutDirection: "interior",
priority: "start",
});
// site.children.add(wall2.attributes.expressID);

// simpleWallType.addCorner({
// wall1,
// wall2,
// to: "interior",
// cut: "interior",
// cutDirection: "interior",
// 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 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

Expand Down Expand Up @@ -109,6 +171,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.startPoint.x = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
// simpleWallType.updateCorners();
Expand All @@ -119,6 +182,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.startPoint.y = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
console.log("hey");
Expand All @@ -135,6 +199,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.endPoint.x = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
// simpleWallType.updateCorners();
Expand All @@ -145,6 +210,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.endPoint.y = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
// simpleWallType.updateCorners();
Expand All @@ -158,6 +224,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.transformation.position.y = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
}}"></bim-number-input>
Expand All @@ -166,6 +233,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.offset = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
// simpleWallType.updateCorners();
Expand All @@ -184,6 +252,7 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
) => {
wall1.height = event.target.value;
wall1.update(true);
updatePlane();
simpleWallType.updateCorners();
// simpleWallType.updateCorners();
Expand Down
22 changes: 19 additions & 3 deletions packages/clay/src/geometries/HalfSpace/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as THREE from "three";
import { IFC4X3 as IFC } from "web-ifc";
import { Model, ClayGeometry } from "../../core";

Expand All @@ -7,6 +8,8 @@ import { IfcUtils } from "../../utils/ifc-utils";
export class HalfSpace extends ClayGeometry {
attributes: IFC.IfcHalfSpaceSolid | IFC.IfcBooleanClippingResult;

direction = new THREE.Vector3();

core: IFC.IfcHalfSpaceSolid;

constructor(model: Model) {
Expand Down Expand Up @@ -36,9 +39,22 @@ export class HalfSpace extends ClayGeometry {

const placement = this.model.get(plane.Position);

IfcUtils.setAxis2Placement(this.model, placement, this.transformation);
const location = this.model.get(
placement.Location,
) as IFC.IfcCartesianPoint;

this.model.set(this.core);
this.attributes = this.core;
const position = MathUtils.toIfcCoords(this.transformation.position);
const direction = MathUtils.toIfcCoords(this.direction);

location.Coordinates[0].value = position.x;
location.Coordinates[1].value = position.y;
location.Coordinates[2].value = position.z;
this.model.set(location);

const zDirection = this.model.get(placement.Axis);
zDirection.DirectionRatios[0].value = direction.x;
zDirection.DirectionRatios[1].value = direction.y;
zDirection.DirectionRatios[2].value = direction.z;
this.model.set(zDirection);
}
}

0 comments on commit f5551d9

Please sign in to comment.