Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates FragmentManager.load #385

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"dev": "vite --host",
"build-core": "yarn workspace @thatopen/components build",
"build-front": "yarn workspace @thatopen/components-front build",
"build-libraries": "yarn build-core && yarn build-front",
"build-examples": "vite build --config ./vite.config-examples.ts",
"build": "yarn build-examples && yarn build-core && yarn build-front"
"build": "yarn build-examples && yarn build-libraries"
},
"license": "MIT",
"homepage": "https://github.com/ThatOpen/engine_components#readme",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class FragmentStreamLoader
const groupArrayBuffer = await groupData.arrayBuffer();
const groupBuffer = new Uint8Array(groupArrayBuffer);
const fragments = this.components.get(OBC.FragmentManager);
const group = fragments.load(groupBuffer, coordinate);
const group = fragments.load(groupBuffer, { coordinate });
this.world.scene.three.add(group);

const { opaque, transparent } = group.geometryIDs;
Expand Down Expand Up @@ -242,7 +242,7 @@ export class FragmentStreamLoader
const fetched = await fetch(this.url + indexesFile);
const rels = await fetched.text();
const indexer = this.components.get(OBC.IfcRelationsIndexer);
indexer.relationMaps[group.uuid] = indexer.getRelationsMapFromJSON(rels);
indexer.setRelationMap(group, indexer.getRelationsMapFromJSON(rels));
}

this.culler.needsUpdate = true;
Expand Down
36 changes: 31 additions & 5 deletions packages/components/src/fragments/FragmentManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Fragment, FragmentsGroup, Serializer } from "@thatopen/fragments";
import * as THREE from "three";
import * as FRAGS from "@thatopen/fragments";
import { Component, Components, Event, Disposable } from "../../core";
import { RelationsMap } from "../../ifc/IfcRelationsIndexer/src/types";
import { IfcRelationsIndexer } from "../../ifc/IfcRelationsIndexer";

/**
* Object that can efficiently load binary files that contain
Expand Down Expand Up @@ -76,12 +79,28 @@ export class FragmentManager extends Component implements Disposable {
}

/**
* Loads one or many fragments into the scene.
* @param data - the bytes containing the data for the fragments to load.
* @param coordinate - whether this fragmentsgroup should be federated with the others.
* @returns the list of IDs of the loaded fragments.
* Loads a binar file that contain fragment geometry.
* @param data - The binary data to load.
* @param config - Optional configuration for loading.
* @param config.coordinate - Whether to apply coordinate transformation. Default is true.
* @param config.properties - Ifc properties to set on the loaded fragments. Not to be used when streaming.
* @returns The loaded FragmentsGroup.
*/
load(data: Uint8Array, coordinate = true) {
load(
data: Uint8Array,
config?: Partial<{
coordinate: boolean;
properties: FRAGS.IfcProperties;
relationsMap: RelationsMap;
}>,
) {
const defaultConfig: {
coordinate: boolean;
properties?: FRAGS.IfcProperties;
relationsMap?: RelationsMap;
} = { coordinate: true };
const _config = { ...defaultConfig, config };
const { coordinate, properties, relationsMap } = _config;
const model = this._loader.import(data);
for (const fragment of model.items) {
fragment.group = model;
Expand All @@ -91,6 +110,13 @@ export class FragmentManager extends Component implements Disposable {
this.coordinate([model]);
}
this.groups.set(model.uuid, model);
if (properties) {
model.setLocalProperties(properties);
}
if (relationsMap) {
const indexer = this.components.get(IfcRelationsIndexer);
indexer.setRelationMap(model, relationsMap);
}
this.onFragmentsLoaded.trigger(model);
return model;
}
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/ifc/IfcRelationsIndexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export class IfcRelationsIndexer extends Component implements Disposable {
if (!model.hasProperties)
throw new Error("FragmentsGroup properties not found");

const relationsMap: RelationsMap = new Map();
let relationsMap = this.relationMaps[model.uuid];
if (relationsMap) {
return relationsMap;
}
relationsMap = new Map();

for (const rel of this._ifcRels) {
await IfcPropertiesUtils.getRelationMap(
Expand Down Expand Up @@ -349,3 +353,5 @@ export class IfcRelationsIndexer extends Component implements Disposable {
this.onDisposed.reset();
}
}

export type { InverseAttribute } from "./src/types";