Skip to content

Commit 50c837c

Browse files
committed
feat: allow to disable guard to ignore objects far away from the origin
1 parent 6f232a2 commit 50c837c

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

packages/fragments/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thatopen/fragments",
33
"description": "Simple geometric system built on top of Three.js to display 3D BIM data efficiently.",
4-
"version": "3.1.5",
4+
"version": "3.1.6",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",

packages/fragments/src/Importers/IfcImporter/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ export class IfcImporter {
9696
*/
9797
replaceStoreyElevation = true;
9898

99+
/**
100+
* If set, ignores the items that are further away to the origin than this value.
101+
* Keep in mind that if your IFC is correctly georreferenced, this value should never
102+
* be too high. If it's too high, it's either because your file uses absolute coordinates,
103+
* (which is a very bad idea, and usually due to a poor IFC export) or because there are
104+
* objects that are very, very far away (very unlikely).
105+
*/
106+
distanceThreshold: number | null = 100000;
107+
99108
private get builder() {
100109
if (!this._builder) {
101110
throw new Error("Fragments: Builder not initialized");

packages/fragments/src/Importers/IfcImporter/src/geometry/ifc-file-reader.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ export class IfcFileReader {
9191
WEBIFC.IFCEARTHWORKSCUT,
9292
]);
9393

94-
// TODO: Expose this value?
95-
distanceThreshold = 100000; // 100 km
96-
9794
scene: THREE.Scene | null = null;
9895

9996
isolatedMeshes: Set<number> | null = null;
@@ -189,17 +186,20 @@ export class IfcFileReader {
189186
const { transformWithoutScale } = this.removeScale(transformArray);
190187

191188
// Check that the object is not too far away
192-
tempPosition.set(0, 0, 0);
193-
tempPosition.applyMatrix4(transformWithoutScale);
194-
if (
195-
tempPosition.x > this.distanceThreshold ||
196-
tempPosition.y > this.distanceThreshold ||
197-
tempPosition.z > this.distanceThreshold
198-
) {
199-
console.log(
200-
`Object ${element.id} is more than ${this.distanceThreshold} meters away from the origin and will be skipped.`,
201-
);
202-
return;
189+
const distanceThreshold = this._serializer.distanceThreshold;
190+
if (distanceThreshold !== null) {
191+
tempPosition.set(0, 0, 0);
192+
tempPosition.applyMatrix4(transformWithoutScale);
193+
if (
194+
tempPosition.x > distanceThreshold ||
195+
tempPosition.y > distanceThreshold ||
196+
tempPosition.z > distanceThreshold
197+
) {
198+
console.log(
199+
`Object ${element.id} is more than ${distanceThreshold} meters away from the origin and will be skipped.`,
200+
);
201+
return;
202+
}
203203
}
204204

205205
for (let i = 0; i < geometryCount; i++) {

packages/fragments/src/Importers/IfcImporter/src/geometry/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export class IfcGeometryProcessor {
2323
absolute: false,
2424
};
2525

26-
constructor(private _serializer: IfcImporter) {}
26+
private _serializer: IfcImporter;
27+
28+
constructor(_serializer: IfcImporter) {
29+
this._serializer = _serializer;
30+
}
2731

2832
async process(data: GeometriesProcessData) {
2933
const { builder } = data;

packages/fragments/src/Importers/IfcImporter/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ const run = async (serialize: boolean) => {
3232

3333
// Read the file
3434
// const ifcFile = fs.readFileSync(`${name}${extension}`)
35-
const url = "/resources/ifc/test/small-civil-q2.ifc";
35+
const url = "/resources/ifc/test/125_C3D_BIM_M1_K.ifc";
3636
const ifcFile = await fetch(url);
3737
const ifcBuffer = await ifcFile.arrayBuffer();
3838
const typedArray = new Uint8Array(ifcBuffer);
3939

4040
// Serialize the data
4141
// const serializationStart = performance.now()
4242
const serializer = new IfcImporter(); // The serializer can be other than IFC
43+
serializer.distanceThreshold = null;
4344
// serializer.classesToInclude = [{entities: [WEBIFC.IFCWALLSTANDARDCASE, WEBIFC.IFCBUILDINGSTOREY], rels: [WEBIFC.IFCRELCONTAINEDINSPATIALSTRUCTURE]}]
4445
const raw = false;
4546
const conversionStart = performance.now();

0 commit comments

Comments
 (0)