Skip to content

Commit f7a8f80

Browse files
committed
Get properties with double click
1 parent 7d8253f commit f7a8f80

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

examples/simple-html/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ inputElement.addEventListener('change', loadIfc, false);
2222
document.body.appendChild(inputElement);
2323

2424
window.onmousemove = viewer.preselect;
25+
window.ondblclick = viewer.select;
2526

2627
//Setup UI
2728
const loadButton = createSideMenuButton('./resources/folder-icon.svg');

viewer/src/components/raycaster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class IFCRaycaster {
1515
this.raycaster.firstHitOnly = true;
1616
}
1717

18-
castRay(event: any, onHit: (event: any, item: THREE.Intersection) => void ) {
18+
castRay(event: any, onHit: (event: any, item: THREE.Intersection) => any ) {
1919
this.raycaster.setFromCamera(this.mouse, this.camera);
2020
const result = this.raycaster.intersectObjects(this.ifcModels);
2121
if(result.length > 0) onHit(event, result[0]);

viewer/src/core/IFC/ifc-manager.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,36 @@ export class IfcManager {
99
private caster: IFCRaycaster;
1010
private scene: THREE.Scene;
1111
private preselection: IfcSelection;
12-
// private selection: IfcSelection;
12+
private selection: IfcSelection;
13+
1314
private preselectMat = new THREE.MeshLambertMaterial({
1415
color: 0xffccff,
1516
transparent: true,
1617
opacity: 0.5,
17-
depthTest: false
18-
});
18+
depthTest: false,
19+
side: THREE.DoubleSide
20+
});
21+
22+
private selectMat = new THREE.MeshLambertMaterial({
23+
color: 0xff33ff,
24+
transparent: true,
25+
opacity: 0.3,
26+
depthTest: false,
27+
side: THREE.DoubleSide
28+
});
1929

20-
constructor(ifc_objects: THREE.Object3D[], scene: THREE.Scene, camera: THREE.PerspectiveCamera, mouse: THREE.Vector2) {
30+
constructor(
31+
ifc_objects: THREE.Object3D[],
32+
scene: THREE.Scene,
33+
camera: THREE.PerspectiveCamera,
34+
mouse: THREE.Vector2
35+
) {
2136
this.loader = new IFCLoader();
2237
this.models = ifc_objects;
2338
this.scene = scene;
2439
this.caster = new IFCRaycaster(this.models, camera, mouse);
2540
this.preselection = new IfcSelection(this.loader, this.scene, this.preselectMat);
26-
// this.selection = new IfcSelection(this.loader, this.models);
41+
this.selection = new IfcSelection(this.loader, this.scene, this.selectMat);
2742
}
2843

2944
async loadIfc(file: File, scene: THREE.Scene) {
@@ -43,6 +58,7 @@ export class IfcManager {
4358
this.caster.castRay(event, this.preselection.select);
4459
}
4560

46-
47-
setModelDisplay() {}
61+
select(event: any) {
62+
this.caster.castRay(event, this.selection.selectProps);
63+
}
4864
}

viewer/src/core/IFC/selection.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,25 @@ export class IfcSelection {
2222
this.selected = item.faceIndex;
2323
const mesh = item.object as IfcMesh;
2424
const id = this.ifcLoader.getExpressId(mesh.geometry, item.faceIndex);
25-
if (id == undefined) return;
25+
if (id == undefined) return null;
2626
this.removePreviousSelection(mesh);
2727
this.modelID = mesh.modelID;
2828
this.newSelection(id);
29+
return id;
30+
}
31+
32+
selectProps = (event: any, item: THREE.Intersection) => {
33+
const id = this.select(event, item);
34+
if(id) return this.getProperties(id);
35+
return null;
36+
}
37+
38+
getProperties(id: number){
39+
const props = this.ifcLoader.getItemProperties(this.modelID, id);
40+
props.psets = this.ifcLoader.getPropertySets(this.modelID, id, true);
41+
props.type = this.ifcLoader.getTypeProperties(this.modelID, id);
42+
console.log(props);
43+
return props;
2944
}
3045

3146
newSelection = (id: number) => {

viewer/src/core/viewer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export class Viewer {
118118
this.ifcManager.preselect(event);
119119
}
120120

121+
select = (event: any) => {
122+
this.ifcManager.select(event);
123+
}
124+
121125
get ifcObjects() {
122126
return this.ifc_objects;
123127
};

0 commit comments

Comments
 (0)