Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/elements/Slabs/SimpleSlab/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,20 @@
model.ifcAPI.SetWasmPath("https://unpkg.com/web-ifc@0.0.50/", true);
await model.init();

const slab = new CLAY.SimpleSlab(model);
scene.add(slab.mesh);

const opening = new CLAY.Opening(model);
scene.add(opening.mesh);
const simpleSlabType = new CLAY.SimpleSlabType(model);
const slab = simpleSlabType.addInstance();

const opening2 = new CLAY.Opening(model);
opening2.position.x += 2;
opening2.update();
scene.add(opening2.mesh);
slab.body.profile.addPoint(0,0,0);
slab.body.profile.addPoint(4,0,0);
slab.body.profile.addPoint(4,4,0);
slab.body.profile.addPoint(3,5,0);
slab.body.profile.addPoint(1,5,0);
slab.body.profile.addPoint(0,4,0);

slab.geometries.body.addSubtraction(opening.geometries.body);
slab.geometries.body.addSubtraction(opening2.geometries.body);
scene.add(...slab.meshes);

slab.update(true);

const stats = new Stats();
stats.showPanel(2);
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Slabs/SimpleSlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export * from "./src";

export class SimpleSlabType extends DynamicElementType<SimpleSlab> {
attributes: IFC4X3.IfcSlabType;

constructor(model: Model) {
super(model);

Expand Down
12 changes: 6 additions & 6 deletions src/elements/Slabs/SimpleSlab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { Model } from "../../../../base";
import { IfcUtils } from "../../../../utils/ifc-utils";
import { Element } from "../../../Elements";
import { SimpleSlabType } from "../index";
import { Extrusion, RectangleProfile } from "../../../../geometries";
import { Extrusion } from "../../../../geometries";
import { ArbitraryClosedProfile } from "../../../../geometries/Profiles/ArbitraryClosedProfile";

export class SimpleSlab extends Element {
attributes: IFC.IfcSlab;

type: SimpleSlabType;

body: Extrusion<RectangleProfile>;
body: Extrusion<ArbitraryClosedProfile>;

thickness = 0.3;

constructor(model: Model, type: SimpleSlabType) {
super(model, type);
this.type = type;

const profile = new RectangleProfile(model);
this.body = new Extrusion(model, profile);

this.body = new Extrusion(model, new ArbitraryClosedProfile(model));
const id = this.body.attributes.expressID;
this.type.geometries.set(id, this.body);
this.geometries.add(id);
Expand All @@ -40,7 +40,7 @@ export class SimpleSlab extends Element {
null
);

this.update();
this.model.set(this.attributes);
}

update(updateGeometry: boolean = false) {
Expand Down
71 changes: 71 additions & 0 deletions src/geometries/Profiles/ArbitraryClosedProfile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as THREE from "three";
import { Handle, IFC4X3 as IFC } from "web-ifc";
import { Profile } from "../Profile";
import { Model } from "../../../base";
import { IfcUtils } from "../../../utils/ifc-utils";

export class ArbitraryClosedProfile extends Profile {
attributes: IFC.IfcArbitraryClosedProfileDef;

dimension = new THREE.Vector3(1, 1, 0);

rotation = new THREE.Euler(0, 0, 0);

position = new THREE.Vector3(0, 0, 0);

points = new Map<number, THREE.Vector3>();

constructor(model: Model) {
super(model);

this.attributes = new IFC.IfcArbitraryClosedProfileDef(
IFC.IfcProfileTypeEnum.CURVE,
null,
new IFC.IfcPolyline([])
);

this.model.set(this.attributes);
}

addPoint(x: number, y: number, z: number) {
const point = new THREE.Vector3(x,y,z)
const ifcPoint = IfcUtils.point(point);

const polyLine = this.model.get(this.attributes.OuterCurve) as IFC.IfcPolyline;

polyLine.Points.push(ifcPoint)

this.model.set(polyLine)
this.model.set(ifcPoint);
this.points.set(ifcPoint.expressID, point);

this.update();
}

removePoint(id: number) {
this.points.delete(id);
const polyLine = this.model.get(this.attributes.OuterCurve) as IFC.IfcPolyline;
const points = polyLine.Points as Handle<IFC.IfcCartesianPoint>[];
polyLine.Points = points.filter((point) => point.value !== id);
this.model.set(polyLine);
}

update() {
const polyLine = this.model.get(this.attributes.OuterCurve) as IFC.IfcPolyline;

for (const pointRef of polyLine.Points) {
const point = this.model.get(pointRef);

const threePoint = this.points.get(point.expressID);

if (!threePoint) {
throw new Error("Point not found!");
}
const { x, y, z } = threePoint;
point.Coordinates[0].value = x;
point.Coordinates[1].value = y;
point.Coordinates[2].value = z;
this.model.set(point);
}
}
}
1 change: 1 addition & 0 deletions src/geometries/Profiles/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./RectangleProfile";
export * from "./ArbitraryClosedProfile"