-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable creation of custom profiles for slabs (#15)
feat: enable creation of custom profiles for slabs
- Loading branch information
Showing
5 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,19 +89,20 @@ | |
model.ifcAPI.SetWasmPath("https://unpkg.com/[email protected]/", 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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./RectangleProfile"; | ||
export * from "./ArbitraryClosedProfile" |