Skip to content

Commit

Permalink
Merge pull request #20 from RyugaRyuzaki/develop
Browse files Browse the repository at this point in the history
integrate raycaster, elementproperty
  • Loading branch information
RyugaRyuzaki authored Jun 8, 2024
2 parents dafe116 + 9ef7141 commit e0065c9
Show file tree
Hide file tree
Showing 100 changed files with 2,656 additions and 876 deletions.
48 changes: 48 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
"axios": "^1.6.8",
"bim-fragment": "^1.4.2",
"camera-controls": "^2.8.3",
"class-variance-authority": "^0.7.0",
"clay": "file:packages/clay",
Expand Down Expand Up @@ -72,4 +73,4 @@
"vite-plugin-glsl": "^1.3.0",
"vite-plugin-svgr": "^3.3.0"
}
}
}
14 changes: 14 additions & 0 deletions packages/clay/package-lock.json

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

1 change: 1 addition & 0 deletions packages/clay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"three-stdlib": "^2.29.6",
"earcut": "^2.2.4",
"uuid": "^9.0.1",
"bim-fragment": "^1.4.2",
"web-ifc": "^0.0.54"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/clay/src/base/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export class Model {
} else {
foundItem = item;
}

if (!foundItem) {
return;
}
if (recursive) {
for (const key in foundItem) {
// @ts-ignore
Expand All @@ -72,7 +74,6 @@ export class Model {
}
}
}

this.ifcAPI.DeleteLine(this.modelID, foundItem.expressID);
}

Expand Down
10 changes: 0 additions & 10 deletions packages/clay/src/elements/Beam/SimpleBeam/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export * from "./src";

export class SimpleBeamType extends DynamicElementType<SimpleBeam> {
attributes: IFC4X3.IfcBeamType;
width = 0.2;
height = 0.4;
constructor(model: Model, config: IIfcBaseConfig, public profile: Profile) {
super(model);
const {Name, Description, ObjectType} = config;
Expand All @@ -28,14 +26,6 @@ export class SimpleBeamType extends DynamicElementType<SimpleBeam> {
IFC.IfcBeamTypeEnum.BEAM
);
}
updateProfile() {
const update = {
width: this.width,
height: this.height,
offsetY: -this.height / 2,
};
this.profile.updateProfile(update);
}
protected createElement() {
return new SimpleBeam(this.model, this);
}
Expand Down
15 changes: 10 additions & 5 deletions packages/clay/src/elements/Beam/SimpleBeam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class SimpleBeam extends Element {
constructor(model: Model, type: SimpleBeamType) {
super(model, type);
this.type = type;
this.rotation.x = Math.PI / 2;
this.position = this.startPoint;
this.body = new Extrusion(model, this.type.profile);
const id = this.body.attributes.expressID;
this.type.geometries.set(id, this.body);
Expand All @@ -54,7 +56,7 @@ export class SimpleBeam extends Element {
this.body.attributes,
]);

this.attributes = new IFC.IfcWall(
this.attributes = new IFC.IfcBeam(
new IFC.IfcGloballyUniqueId(uuidv4()),
this.model.IfcOwnerHistory,
null,
Expand All @@ -65,13 +67,16 @@ export class SimpleBeam extends Element {
null,
null
);
this.rotation.x = Math.PI / 2;
this.position = this.startPoint;

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

updateProfile() {}
update(updateGeometry = false) {
this.body.updateBeam(this.length, this.direction);
const rotationY =
Math.atan2(this.direction.y, this.direction.x) + Math.PI / 2;
this.rotation.y = rotationY;
this.body.depth = this.length;
this.body.update();
const shape = this.model.get(this.attributes.Representation);
const reps = this.model.get(shape.Representations[0]);
reps.Items = [this.body.attributes];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export abstract class DynamicElementType<
this.elements.set(id, element);
return element;
}

deleteInstance(id: number) {
const element = this.elements.get(id);
if (!element) {
Expand All @@ -48,6 +47,9 @@ export abstract class DynamicElementType<
}
geometry.delete();
this.geometries.delete(id);
const clone = this.clones.get(id);
if (!clone) continue;
clone.dispose();
}
}

Expand Down
28 changes: 19 additions & 9 deletions packages/clay/src/elements/Elements/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ElementType} from "../ElementType";
import {IfcUtils} from "../../../utils/ifc-utils";
import {SimpleOpening} from "../../Openings";
import {IndexedGeometry, FragmentMesh} from "../../../fragment";
import {BVH} from "../../../fragment/bvh";

export abstract class Element extends ClayObject {
abstract attributes: IFC.IfcElement;
Expand Down Expand Up @@ -39,7 +40,17 @@ export abstract class Element extends ClayObject {
}
return meshes;
}

get clones() {
const meshes: FragmentMesh[] = [];
for (const id of this.geometries) {
const fragment = this.type.clones.get(id);
if (!fragment) {
throw new Error("Fragment not found!");
}
meshes.push(fragment.mesh);
}
return meshes;
}
protected constructor(model: Model, type: ElementType) {
super(model);
this.type = type;
Expand All @@ -57,26 +68,25 @@ export abstract class Element extends ClayObject {
const geomID = geometry.geometryExpressID;
const transformArray = geometry.flatTransformation;
const fragment = this.type.fragments.get(geomID);
if (!fragment) {
throw new Error("Fragment not found!");
}
if (!fragment) throw new Error("Fragment not found!");
const instances = fragment.getInstancesIDs(id);
if (!instances) {
throw new Error("Instances not found!");
}
if (!instances) throw new Error("Instances not found!");
tempMatrix.fromArray(transformArray);
for (const instance of instances) {
fragment.mesh.setMatrixAt(instance, tempMatrix);
fragment.mesh.instanceMatrix.needsUpdate = true;
}
fragment.mesh.instanceMatrix.needsUpdate = true;

if (updateGeometry) {
BVH.dispose(fragment.mesh.geometry);
fragment.mesh.geometry.dispose();
(fragment.mesh.geometry as any) = null;
const data = this.model.ifcAPI.GetGeometry(modelID, geomID);
fragment.mesh.geometry = this.ifcToThreeGeometry(data);
const size = fragment.mesh.geometry.index.count;
fragment.mesh.geometry.clearGroups();
fragment.mesh.geometry.addGroup(0, size);
BVH.apply(fragment.mesh.geometry);
fragment.mesh.frustumCulled = false;
}
}
});
Expand Down
14 changes: 13 additions & 1 deletion packages/clay/src/elements/Elements/ElementType/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ export abstract class ElementType<
T extends Element = Element
> extends ClayObject {
abstract attributes: IFC.IfcElementType;

geometries = new Map<number, ClayGeometry>();

elements = new Map<number, T>();

fragments = new Map<number, Fragment>();
clones = new Map<number, Fragment>();

get typeUuid() {
return this.attributes!.GlobalId.value;
}
get typeName() {
return this.attributes!.Name!.value || "";
}

abstract addInstance(): T;

Expand All @@ -27,4 +34,9 @@ export abstract class ElementType<
fragment.mesh.frustumCulled = false;
return fragment;
}
dispose() {
for (const [id, _element] of this.elements) {
this.deleteInstance(id);
}
}
}
2 changes: 1 addition & 1 deletion packages/clay/src/fragment/bvh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BufferGeometry, Mesh } from "three";
import {BufferGeometry, Mesh} from "three";
import {
computeBoundsTree,
disposeBoundsTree,
Expand Down
23 changes: 22 additions & 1 deletion packages/clay/src/fragment/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class Fragment {
this.mesh = new FragmentMesh(geometry, material, count, this);
this.id = this.mesh.uuid;
this.capacity = count;
this.mesh.count = 0;

if (this.mesh.geometry.index.count) {
BVH.apply(this.mesh.geometry);
Expand Down Expand Up @@ -436,4 +435,26 @@ export class Fragment {
this.mesh.setColorAt(instanceID2, color1);
}
}
static clone(fragment: Fragment) {
const {mesh, instanceToItem, itemToInstances, capacity, ids} = fragment;
const geometry = mesh.geometry.clone();
BVH.apply(geometry);
const clone = new Fragment(geometry, mesh.material, mesh.count);
clone.instanceToItem = instanceToItem;
clone.itemToInstances = itemToInstances;
clone.ids = ids;
clone.capacity = capacity;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
for (let i = 0; i < mesh.count; i++) {
mesh.getMatrixAt(i, matrix);
clone.mesh.setMatrixAt(i, matrix);
if (mesh.instanceColor) {
mesh.getColorAt(i, color);
clone.mesh.setColorAt(i, color);
}
clone.update();
}
return clone;
}
}
1 change: 1 addition & 0 deletions packages/clay/src/fragment/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./base-types";
export * from "./fragment-mesh";
export * from "./fragment";
export * from "./bvh";
7 changes: 1 addition & 6 deletions packages/clay/src/geometries/Extrusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ export class Extrusion<T extends Profile> extends ClayGeometry {

this.update();
}
updateBeam(length: number, direction: THREE.Vector3) {
const rotationY = Math.atan2(direction.y, direction.x) + Math.PI / 2;
this.rotation.y = rotationY;
this.depth = length;
this.update();
}

update() {
const placement = this.model.get(this.core.Position);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import {Profile} from "../Profile";
import {Model} from "../../../base";
import {IfcUtils} from "../../../utils/ifc-utils";

export interface IRectangleConfig {
width: number;
height: number;
offsetY?: number;
}

export class RectangleProfile extends Profile {
attributes: IFC.IfcRectangleProfileDef;

Expand Down Expand Up @@ -32,7 +38,7 @@ export class RectangleProfile extends Profile {

this.model.set(this.attributes);
}
updateProfile = (update: any) => {
updateProfile = (update: IRectangleConfig) => {
const {width, height, offsetY} = update;
if (width) this.dimension.x = width;
if (height) this.dimension.y = height;
Expand Down
1 change: 1 addition & 0 deletions packages/clay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./elements";
export * from "./utils";
export * from "./elements";
export * from "./geometries";
export * from "./fragment";
export * from "./base";
Loading

0 comments on commit e0065c9

Please sign in to comment.