Skip to content

Commit a224dc2

Browse files
committed
Correct all eslint errors
1 parent cb73535 commit a224dc2

File tree

17 files changed

+626
-507
lines changed

17 files changed

+626
-507
lines changed

viewer/.eslintrc.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
module.exports = {
22
env: {
33
browser: true,
4-
es2021: true,
4+
es2021: true
55
},
6-
extends: [
7-
'airbnb-base',
8-
],
6+
extends: ['airbnb-base', 'prettier'],
97
parser: '@typescript-eslint/parser',
108
parserOptions: {
119
ecmaVersion: 12,
12-
sourceType: 'module',
10+
sourceType: 'module'
1311
},
14-
plugins: [
15-
'@typescript-eslint',
16-
],
12+
plugins: ['@typescript-eslint', 'prettier'],
13+
ignorePatterns: ['**/dist/*', '**/node_modules/*'],
1714
rules: {
15+
'prettier/prettier': [
16+
'error',
17+
{
18+
endOfLine: 'auto'
19+
}
20+
],
21+
indent: 'off',
1822
'lines-between-class-members': 'off',
23+
'linebreak-style': 'off',
24+
'no-console': 'off',
25+
'no-param-reassign': 'off',
1926
'eol-last': 'off',
27+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
28+
'class-methods-use-this': 'off',
2029
'import/extensions': [
2130
'error',
2231
'ignorePackages',
2332
{
2433
js: 'never',
25-
ts: 'never',
26-
},
34+
ts: 'never'
35+
}
2736
],
2837
'import/prefer-default-export': 'off',
29-
'no-plusplus': 'off',
38+
'no-plusplus': 'off'
3039
},
3140
settings: {
3241
'import/resolver': {
3342
node: {
34-
extensions: ['.js', '.jsx', '.ts', '.tsx'],
35-
},
36-
},
37-
},
38-
};
43+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts']
44+
}
45+
}
46+
}
47+
};

viewer/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
"cpy-cli": "^3.1.1",
3939
"eslint": "^7.28.0",
4040
"eslint-config-airbnb-base": "^14.2.1",
41+
"eslint-config-prettier": "^8.3.0",
4142
"eslint-plugin-import": "^2.23.4",
43+
"eslint-plugin-prettier": "^3.4.0",
44+
"prettier": "^2.3.1",
4245
"typescript": "^4.2.4"
4346
}
4447
}

viewer/src/IO/dropbox.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component } from '../components';
22
import { Viewer } from '../core';
33

4+
declare const Dropbox: any;
5+
46
type dbChooserResponse = {
57
id: string;
68
name: string;
@@ -12,13 +14,14 @@ type dbChooserResponse = {
1214
};
1315

1416
export class DropboxAPI extends Component {
17+
private cancelMessage = 'The Dropbox communication was cancelled.';
18+
1519
constructor(viewer: Viewer) {
1620
super(viewer);
1721
this.initializeAPI();
1822
}
1923

2024
loadDropboxIfc() {
21-
// @ts-ignore
2225
Dropbox.choose(this.chooserOptions);
2326
}
2427

@@ -28,19 +31,19 @@ export class DropboxAPI extends Component {
2831
const ifcBlob = new Blob([result], { type: 'text/plain' });
2932
const ifcFile = new File([ifcBlob], 'ifcFile');
3033
this.viewer.loadIfc(ifcFile);
31-
}
34+
};
3235

3336
private chooserOptions: object = {
3437
success: this.onDBChooserSuccess,
3538
cancel: this.onDBChooserCancel,
3639
linkType: 'direct',
3740
multiselect: false,
3841
extensions: ['.ifc'],
39-
folderselect: false,
42+
folderselect: false
4043
};
4144

42-
private onDBChooserCancel(files: dbChooserResponse[]) {
43-
console.log('Canceled!');
45+
private onDBChooserCancel(response: dbChooserResponse[]) {
46+
console.log(this.cancelMessage, ' - ', response);
4447
}
4548

4649
private initializeAPI() {

viewer/src/IO/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './dropbox';
1+
export * from './dropbox';

viewer/src/components/axes.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Viewer } from '../core';
33
import { Component } from './component';
44

55
export class Axes extends Component {
6-
axes: THREE.AxesHelper;
6+
axes: THREE.AxesHelper;
77

8-
constructor(viewer: Viewer, size?: number) {
9-
super(viewer);
10-
this.axes = new THREE.AxesHelper(size);
11-
(this.axes.material as THREE.Material).depthTest = false;
12-
this.axes.renderOrder = 2;
13-
viewer.scene.add(this.axes);
14-
}
8+
constructor(viewer: Viewer, size?: number) {
9+
super(viewer);
10+
this.axes = new THREE.AxesHelper(size);
11+
(this.axes.material as THREE.Material).depthTest = false;
12+
this.axes.renderOrder = 2;
13+
viewer.scene.add(this.axes);
14+
}
1515
}

viewer/src/components/component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Viewer } from '../core';
22

33
export abstract class Component {
4-
viewer: Viewer;
4+
viewer: Viewer;
55

6-
protected constructor(viewer: Viewer) {
7-
viewer.addComponent(this);
8-
this.viewer = viewer;
9-
}
6+
protected constructor(viewer: Viewer) {
7+
viewer.addComponent(this);
8+
this.viewer = viewer;
9+
}
1010

11-
update(_delta: number) { }
12-
}
11+
update(_delta: number) {}
12+
}

viewer/src/components/grid.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { Component } from './component';
33
import { Viewer } from '../core';
44

55
export class Grid extends Component {
6-
grid: THREE.GridHelper;
6+
grid: THREE.GridHelper;
77

8-
constructor(viewer: Viewer, size?: number, divisions?: number, colorCenterLine?: THREE.Color, colorGrid?: THREE.Color) {
9-
super(viewer);
10-
this.grid = new THREE.GridHelper(size, divisions, colorCenterLine, colorGrid);
11-
(this.grid.material as THREE.Material).depthTest = false;
12-
this.grid.renderOrder = 0;
13-
viewer.scene.add(this.grid);
14-
}
15-
}
8+
constructor(
9+
viewer: Viewer,
10+
size?: number,
11+
divisions?: number,
12+
colorCenterLine?: THREE.Color,
13+
colorGrid?: THREE.Color
14+
) {
15+
super(viewer);
16+
this.grid = new THREE.GridHelper(size, divisions, colorCenterLine, colorGrid);
17+
(this.grid.material as THREE.Material).depthTest = false;
18+
this.grid.renderOrder = 0;
19+
viewer.scene.add(this.grid);
20+
}
21+
}

viewer/src/components/raycaster.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
import * as THREE from 'three';
22

3+
let planes: any[] = [];
4+
35
export class IFCRaycaster {
46
private camera: THREE.Camera;
57
private ifcModels: THREE.Object3D[];
68
private raycaster: THREE.Raycaster;
79
private canvas: HTMLCanvasElement;
10+
private renderer: THREE.WebGLRenderer;
811

912
constructor(ifcModels: THREE.Object3D[], camera: THREE.Camera, renderer: THREE.WebGLRenderer) {
1013
this.camera = camera;
1114
this.canvas = renderer.domElement;
1215
this.ifcModels = ifcModels;
1316
this.raycaster = new THREE.Raycaster();
17+
this.renderer = renderer;
1418
// @ts-ignore
15-
this.raycaster.firstHitOnly = true;
19+
// this.raycaster.firstHitOnly = true;
1620
}
1721

18-
castRay(event: any, onHit: (event: any, item: THREE.Intersection) => any ) {
19-
const mouse = new THREE.Vector2();
20-
const canvasBounds = this.canvas.getBoundingClientRect();
21-
mouse.x = ((event.clientX - canvasBounds.left) / (canvasBounds.right - canvasBounds.left)) * 2 - 1;
22-
mouse.y = -((event.clientY - canvasBounds.top) / (canvasBounds.bottom - canvasBounds.top)) * 2 + 1;
22+
castRay(event: any, onHit: (_event: any, _item: THREE.Intersection) => any) {
23+
const mouse = this.getMouseProjection(event);
2324
this.raycaster.setFromCamera(mouse, this.camera);
24-
const result = this.raycaster.intersectObjects(this.ifcModels);
25+
const items = this.raycaster.intersectObjects(this.ifcModels);
26+
const result = this.filterClippingPlanes(items);
2527
if (result.length > 0) return onHit(event, result[0]);
28+
return null;
29+
}
30+
31+
private filterClippingPlanes(objs: THREE.Intersection[]) {
32+
if (objs.length <= 0) return objs;
33+
// @ts-ignore
34+
planes = this.camera.planes as any[];
35+
if (!planes) return objs;
36+
if (planes.length <= 0) return objs;
37+
// return objs.filter((elem) => planes.every((elem2) => elem2.distanceToPoint(elem.point) > 0));
38+
return objs.filter(this.filter);
39+
}
40+
41+
private filter(elem: any) {
42+
return planes.every((elem2) => elem2.distanceToPoint(elem.point) > 0);
43+
}
44+
45+
private getMouseProjection(event: any) {
46+
const mouse = new THREE.Vector2();
47+
const bounds = this.canvas.getBoundingClientRect();
48+
mouse.x = ((event.clientX - bounds.left) / (bounds.right - bounds.left)) * 2 - 1;
49+
mouse.y = -((event.clientY - bounds.top) / (bounds.bottom - bounds.top)) * 2 + 1;
50+
return mouse;
2651
}
2752
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ export class IfcManager {
1616
transparent: true,
1717
opacity: 0.5,
1818
depthTest: false,
19-
side: THREE.DoubleSide,
19+
side: THREE.DoubleSide
2020
});
2121

2222
private selectMat = new THREE.MeshLambertMaterial({
2323
color: 0xff33ff,
2424
transparent: true,
2525
opacity: 0.3,
2626
depthTest: false,
27-
side: THREE.DoubleSide,
27+
side: THREE.DoubleSide
2828
});
2929

3030
constructor(
3131
ifcObjects: THREE.Object3D[],
3232
scene: THREE.Scene,
3333
camera: THREE.PerspectiveCamera,
34-
renderer: THREE.WebGLRenderer,
34+
renderer: THREE.WebGLRenderer
3535
) {
3636
this.loader = new IFCLoader();
3737
this.models = ifcObjects;

viewer/src/core/IFC/selection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export class IfcSelection {
1818
}
1919

2020
select = (event: any, item: THREE.Intersection) => {
21-
if (this.selected == item.faceIndex || item.faceIndex == null) return;
21+
if (this.selected === item.faceIndex || item.faceIndex == null) return null;
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 null;
25+
if (id === undefined) return null;
2626
this.removePreviousSelection(mesh);
2727
this.modelID = mesh.modelID;
2828
this.newSelection(id);
@@ -35,12 +35,12 @@ export class IfcSelection {
3535
modelID: this.modelID,
3636
ids: [id],
3737
removePrevious: true,
38-
material: this.material,
38+
material: this.material
3939
});
4040
};
4141

4242
removePreviousSelection(mesh: IfcMesh) {
43-
if (this.modelID != undefined && this.modelID != mesh.modelID) {
43+
if (this.modelID !== undefined && this.modelID !== mesh.modelID) {
4444
this.ifcLoader.removeSubset(this.modelID, this.scene, this.material);
4545
}
4646
}

0 commit comments

Comments
 (0)