From 30a9cbf787af2eab2f10f280cd82026d6a522715 Mon Sep 17 00:00:00 2001 From: cristian sotomayor Date: Thu, 28 Mar 2024 18:58:10 -0700 Subject: [PATCH] Fix after fork update --- src/elements/Slabs/SimpleSlab/index.html | 21 +++--- src/elements/Slabs/SimpleSlab/index.ts | 2 +- src/elements/Slabs/SimpleSlab/src/index.ts | 12 ++-- .../Profiles/ArbitraryClosedProfile/index.ts | 71 +++++++++++++++++++ src/geometries/Profiles/index.ts | 1 + 5 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 src/geometries/Profiles/ArbitraryClosedProfile/index.ts diff --git a/src/elements/Slabs/SimpleSlab/index.html b/src/elements/Slabs/SimpleSlab/index.html index acd95e5..0989bde 100644 --- a/src/elements/Slabs/SimpleSlab/index.html +++ b/src/elements/Slabs/SimpleSlab/index.html @@ -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); diff --git a/src/elements/Slabs/SimpleSlab/index.ts b/src/elements/Slabs/SimpleSlab/index.ts index 0379dce..8dcd5c6 100644 --- a/src/elements/Slabs/SimpleSlab/index.ts +++ b/src/elements/Slabs/SimpleSlab/index.ts @@ -8,7 +8,7 @@ export * from "./src"; export class SimpleSlabType extends DynamicElementType { attributes: IFC4X3.IfcSlabType; - + constructor(model: Model) { super(model); diff --git a/src/elements/Slabs/SimpleSlab/src/index.ts b/src/elements/Slabs/SimpleSlab/src/index.ts index ba6f6cc..8481644 100644 --- a/src/elements/Slabs/SimpleSlab/src/index.ts +++ b/src/elements/Slabs/SimpleSlab/src/index.ts @@ -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; + body: Extrusion; 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); @@ -40,7 +40,7 @@ export class SimpleSlab extends Element { null ); - this.update(); + this.model.set(this.attributes); } update(updateGeometry: boolean = false) { diff --git a/src/geometries/Profiles/ArbitraryClosedProfile/index.ts b/src/geometries/Profiles/ArbitraryClosedProfile/index.ts new file mode 100644 index 0000000..7f266bd --- /dev/null +++ b/src/geometries/Profiles/ArbitraryClosedProfile/index.ts @@ -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(); + + 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[]; + 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); + } + } +} \ No newline at end of file diff --git a/src/geometries/Profiles/index.ts b/src/geometries/Profiles/index.ts index 282c34b..a956d26 100644 --- a/src/geometries/Profiles/index.ts +++ b/src/geometries/Profiles/index.ts @@ -1 +1,2 @@ export * from "./RectangleProfile"; +export * from "./ArbitraryClosedProfile" \ No newline at end of file