Skip to content

Commit

Permalink
Merge pull request #23 from RyugaRyuzaki/develop
Browse files Browse the repository at this point in the history
add change length, Pset, type
  • Loading branch information
RyugaRyuzaki authored Jun 10, 2024
2 parents bf4c84b + fdec8cd commit 6dceb89
Show file tree
Hide file tree
Showing 79 changed files with 1,240 additions and 529 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dexie": "^4.0.4",
"earcut": "^2.2.4",
"flatbuffers": "^24.3.25",
"lodash": "^4.17.21",
"lucide-react": "^0.376.0",
"mitt": "^3.0.0",
"n8ao": "^1.8.2",
Expand All @@ -51,6 +52,7 @@
},
"devDependencies": {
"@types/earcut": "^2.1.4",
"@types/lodash": "^4.17.5",
"@types/node": "^20.11.25",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
Expand Down
44 changes: 39 additions & 5 deletions packages/clay/src/elements/Beam/SimpleBeam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {Element} from "../../../Elements";
import {
Extrusion,
Profile,
RectangleProfile,
ClayGeometry,
RectangleProfile,
IShapeProfile,
} from "../../../../geometries";
import {Fragment} from "../../../../fragment";
import {BVH, Fragment} from "../../../../fragment";
import {SimpleBeamType} from "..";
export class SimpleBeam extends Element {
attributes: IFC.IfcElement;

type: SimpleBeamType;
body: Extrusion<Profile>;

Expand Down Expand Up @@ -70,7 +70,6 @@ export class SimpleBeam extends Element {

this.model.set(this.attributes);
}
updateProfile() {}
update(updateGeometry = false) {
const rotationY =
Math.atan2(this.direction.y, this.direction.x) + Math.PI / 2;
Expand All @@ -81,10 +80,45 @@ export class SimpleBeam extends Element {
const reps = this.model.get(shape.Representations[0]);
reps.Items = [this.body.attributes];
this.model.set(reps);

this.updateGeometryID();
super.update(updateGeometry);
}
updateLocation = (update: any) => {
const {start, end} = update;
if (!start || !end) return;
this.startPoint.x = start.x;
this.startPoint.y = -start.z;
this.startPoint.z = start.y;
this.endPoint.x = end.x;
this.endPoint.y = -end.z;
this.endPoint.z = end.y;
this.update(true);
this.updateFragment();
};
updateDrawLine(start: THREE.Vector3, end: THREE.Vector3) {
this.startPoint.x = start.x;
this.startPoint.y = -start.z;
this.startPoint.z = start.y;
this.endPoint.x = end.x;
this.endPoint.y = -end.z;
this.endPoint.z = end.y;
this.update(true);
}
updateDrawArc(start: THREE.Vector3, end: THREE.Vector3) {
this.startPoint.x = start.x;
this.startPoint.y = -start.z;
this.startPoint.z = start.y;
this.endPoint.x = end.x;
this.endPoint.y = -end.z;
this.endPoint.z = end.y;
this.update(true);
}
updateOffsetLevel() {
//@ts-ignore
const {height} = this.type.profile;
if (!height) return;
this.body.position.y = -height / 2;
}
private updateGeometryID() {
const modelID = this.model.modelID;
const id = this.attributes.expressID;
Expand Down
11 changes: 2 additions & 9 deletions packages/clay/src/elements/Column/SimpleColumn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import {IFC4X3 as IFC} from "web-ifc";
import {Model} from "../../../../base";
import {IfcUtils} from "../../../../utils";
import {Element} from "../../../Elements";
import {
Extrusion,
RectangleProfile,
ClayGeometry,
Profile,
} from "../../../../geometries";
import {Extrusion, ClayGeometry, Profile} from "../../../../geometries";
import {SimpleColumnType} from "../index";
import {Fragment} from "../../../../fragment";

Expand All @@ -25,8 +20,6 @@ export class SimpleColumn extends Element {
constructor(model: Model, type: SimpleColumnType) {
super(model, type);
this.type = type;
this.type.profile = new RectangleProfile(model);
this.type.updateProfile();
this.body = new Extrusion(model, this.type.profile);
const id = this.body.attributes.expressID;
this.type.geometries.set(id, this.body);
Expand All @@ -51,7 +44,7 @@ export class SimpleColumn extends Element {

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

updateLocation!: (update: any) => void;
update(updateGeometry = false) {
this.body.depth = this.height;
this.body.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export class SimpleCurtainWall extends Element {

this.model.set(this.attributes);
}
updateLocation!: (update: any) => void;
}
27 changes: 27 additions & 0 deletions packages/clay/src/elements/Elements/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export abstract class Element extends ClayObject {
}
return meshes;
}
abstract updateLocation: (update: any) => void;

protected constructor(model: Model, type: ElementType) {
super(model);
this.type = type;
Expand Down Expand Up @@ -167,4 +169,29 @@ export abstract class Element extends ClayObject {
geometry.setIndex(Array.from(index));
return geometry as IndexedGeometry;
}
updateFragment() {
if (!this.geometries || !this.type) return;
for (const id of this.geometries) {
const fragment0 = this.type.fragments.get(id);
const fragment = this.type.clones.get(id);
if (!fragment || !fragment0) continue;
BVH.dispose(fragment.mesh.geometry);
fragment.mesh.geometry.dispose();
(fragment.mesh.geometry as any) = null;
const geometry = fragment0.mesh.geometry.clone();
BVH.apply(geometry);
fragment.mesh.geometry = geometry;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
for (let i = 0; i < fragment0.mesh.count; i++) {
fragment0.mesh.getMatrixAt(i, matrix);
fragment.mesh.setMatrixAt(i, matrix);
if (fragment0.mesh.instanceColor) {
fragment0.mesh.getColorAt(i, color);
fragment0.mesh.setColorAt(i, color);
}
fragment.update();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export class SimpleFurniture extends Element {

this.model.set(this.attributes);
}
updateLocation!: (update: any) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ export class SimpleMember extends Element {
);
this.model.set(this.attributes);
}
updateLocation!: (update: any) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export class SimpleOpening extends Element {

this.model.set(this.attributes);
}
updateLocation!: (update: any) => void;
}
1 change: 1 addition & 0 deletions packages/clay/src/elements/Plates/SimplePlate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ export class SimplePlate extends Element {

this.model.set(this.attributes);
}
updateLocation!: (update: any) => void;
}
1 change: 1 addition & 0 deletions packages/clay/src/elements/Slabs/SimpleSlab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export class SimpleSlab extends Element {
this.body.update();
super.update(updateGeometry);
}
updateLocation!: (update: any) => void;
}
15 changes: 13 additions & 2 deletions packages/clay/src/elements/Walls/SimpleWall/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Extrusion, HalfSpace, RectangleProfile} from "../../../../geometries";
import {SimpleWallType} from "../index";
import {SimpleOpening} from "../../../Openings";
import {ClayGeometry} from "../../../../geometries/Geometry";
import {Fragment} from "../../../../fragment";
import {BVH, Fragment} from "../../../../fragment";

export class SimpleWall extends Element {
attributes: IFC.IfcWall;
Expand Down Expand Up @@ -83,7 +83,18 @@ export class SimpleWall extends Element {

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

updateLocation = (update: any) => {
const {start, end} = update;
if (!start || !end) return;
this.startPoint.x = start.x;
this.startPoint.y = -start.z;
this.startPoint.z = start.y;
this.endPoint.x = end.x;
this.endPoint.y = -end.z;
this.endPoint.z = end.y;
this.update(true, true);
this.updateFragment();
};
update(updateGeometry = false, updateCorners = false) {
this.updateAllOpenings();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export class SimpleWindow extends Element {

this.model.set(this.attributes);
}
updateLocation!: (update: any) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Handle, IFC4X3 as IFC} from "web-ifc";
import {Profile} from "../Profile";
import {Model} from "../../../base";
import {IfcUtils} from "../../../utils";
import {IIfcBaseConfig} from "../../../elements";

export class ArbitraryClosedProfile extends Profile {
attributes: IFC.IfcArbitraryClosedProfileDef;
Expand All @@ -24,9 +25,13 @@ export class ArbitraryClosedProfile extends Profile {
);
this.model.set(this.attributes);
}
updateProfile = (_update: any) => {};
addPoint(x: number, y: number, z: number) {
const point = new THREE.Vector3(x, y, z);
updateProfile = (update: THREE.Vector3[]) => {
for (let i = 0; i < update.length; i++) {
this.addPoint(update[i]);
}
};

addPoint(point: THREE.Vector3) {
const ifcPoint = IfcUtils.point(point);

const polyLine = this.model.get(
Expand Down Expand Up @@ -72,4 +77,7 @@ export class ArbitraryClosedProfile extends Profile {
this.model.set(point);
}
};
getInfo = () => {
return {} as IIfcBaseConfig;
};
}
45 changes: 45 additions & 0 deletions packages/clay/src/geometries/Profiles/IShapeProfile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as THREE from "three";
import {Model} from "../../../base";
import {ArbitraryClosedProfile} from "../ArbitraryClosedProfile";
import {IIfcBaseConfig} from "../../../elements";

export interface IIShapeConfig {
bw: number;
hw: number;
bf: number;
hf: number;
}

export class IShapeProfile extends ArbitraryClosedProfile {
height = 0;
width = 0;

constructor(model: Model, config: IIShapeConfig) {
super(model);
const {bw, hw, hf} = config;
this.height = hw + hf * 2;
this.width = bw;
this.updateProfile(this.updateIShape(config));
}
private updateIShape(update: IIShapeConfig) {
const {bw, hw, bf, hf} = update;
const points: THREE.Vector3[] = [];
points.push(new THREE.Vector3(bf / 2, hw / 2 + hf, 0));
points.push(new THREE.Vector3(bf / 2, hw / 2, 0));
points.push(new THREE.Vector3(bw / 2, hw / 2, 0));
points.push(new THREE.Vector3(bw / 2, -hw / 2, 0));
points.push(new THREE.Vector3(bf / 2, -hw / 2, 0));
points.push(new THREE.Vector3(bf / 2, -hw / 2 - hf, 0));
points.push(new THREE.Vector3(-bf / 2, -hw / 2 - hf, 0));
points.push(new THREE.Vector3(-bf / 2, -hw / 2, 0));
points.push(new THREE.Vector3(-bw / 2, -hw / 2, 0));
points.push(new THREE.Vector3(-bw / 2, hw / 2, 0));
points.push(new THREE.Vector3(-bf / 2, hw / 2, 0));
points.push(new THREE.Vector3(-bf / 2, hw / 2 + hf, 0));
points.push(new THREE.Vector3(bf / 2, hw / 2 + hf, 0));
return points;
}
getInfo = () => {
return {} as IIfcBaseConfig;
};
}
2 changes: 2 additions & 0 deletions packages/clay/src/geometries/Profiles/Profile/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as WEBIFC from "web-ifc";
import {ClayObject} from "../../../base/clay-object";
import {IIfcBaseConfig} from "../../../elements";

export abstract class Profile extends ClayObject {
abstract attributes: WEBIFC.IFC4X3.IfcProfileDef;
abstract update: () => void;
abstract updateProfile: (update: any) => void;
abstract getInfo: () => IIfcBaseConfig;
}
Loading

0 comments on commit 6dceb89

Please sign in to comment.