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

Recompute sector bounds when nodes are transformed #3391

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3178dfe
Initial structure for dynamic sector bounds
eiriklegernaes Dec 28, 2022
b91ef37
Improve CustomSectorBounds implementation
eiriklegernaes Dec 28, 2022
17d0871
Fix error in bookkeeping
eiriklegernaes Dec 28, 2022
0237956
Merge branch 'reveal_master' into recompute_sector_bounds_when_nodes_…
eiriklegernaes May 12, 2023
956d187
Initial test setup
eiriklegernaes May 22, 2023
469533a
Improve testing
eiriklegernaes Jun 12, 2023
c1f9082
Add test for TreeIndexToSectorsMap
eiriklegernaes Jun 12, 2023
20ee375
Fix doc typo
eiriklegernaes Jun 12, 2023
9e71f02
Merge branch 'reveal_master' into recompute_sector_bounds_when_nodes_…
eiriklegernaes Jun 12, 2023
b178d71
Minor cleanup
eiriklegernaes Jun 16, 2023
6de9e4f
Merge branch 'reveal_master' into recompute_sector_bounds_when_nodes_…
eiriklegernaes Jun 16, 2023
52bdc9c
Update reveal.api.md
eiriklegernaes Jun 16, 2023
41ac31a
Merge branch 'reveal_master' into recompute_sector_bounds_when_nodes_…
eiriklegernaes Jun 26, 2023
f88cfc5
Make node bounding box optional, and update tests
eiriklegernaes Jun 27, 2023
a4092c4
Merge branch 'reveal_master' into recompute_sector_bounds_when_nodes_…
eiriklegernaes Jun 27, 2023
4ada135
Minor refactor and cleanup
eiriklegernaes Jun 29, 2023
0676fc6
Merge branch 'reveal_master' into recompute_sector_bounds_when_nodes_…
eiriklegernaes Jun 29, 2023
dd414e3
Merge branch 'master' into recompute_sector_bounds_when_nodes_are_tra…
christjt Jun 30, 2023
53e6ba2
Merge branch 'master' into recompute_sector_bounds_when_nodes_are_tra…
christjt Jun 30, 2023
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
1 change: 1 addition & 0 deletions viewer/packages/cad-geometry-loaders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@reveal/model-base": "workspace:*",
"@reveal/rendering": "workspace:*",
"@reveal/sector-loader": "workspace:*",
"@reveal/sector-parser": "workspace:*",
"@reveal/utilities": "workspace:*"
}
}
14 changes: 14 additions & 0 deletions viewer/packages/cad-geometry-loaders/src/CadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { File3dFormat, ModelIdentifier } from '@reveal/data-providers';
import { MetricsLogger } from '@reveal/metrics';
import { CadModelBudget, defaultDesktopCadModelBudget } from './CadModelBudget';
import { CadModelFactory, CadModelSectorLoadStatistics, CadNode, GeometryFilter } from '@reveal/cad-model';
import { RevealGeometryCollectionType } from '@reveal/sector-parser';

export class CadManager {
private readonly _materialManager: CadMaterialManager;
Expand Down Expand Up @@ -102,6 +103,19 @@ export class CadManager {
}

this.markNeedsRedraw();

// Update mapping from tree indices to sector ids
if (!cadModel.treeIndexToSectorsMap.isCompleted(sector.metadata.id, RevealGeometryCollectionType.TriangleMesh)) {
if (sector.group?.children.length === 1) {
const treeIndices = sector.group.children[0].userData?.treeIndices as Map<number, number> | undefined;
if (treeIndices !== undefined) {
for (const treeIndex of treeIndices.keys()) {
cadModel.treeIndexToSectorsMap.set(treeIndex, sector.metadata.id);
}
cadModel.treeIndexToSectorsMap.markCompleted(sector.metadata.id, RevealGeometryCollectionType.TriangleMesh);
}
}
}
eiriklegernaes marked this conversation as resolved.
Show resolved Hide resolved
};

this._subscription.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as THREE from 'three';
import { Mock } from 'moq.ts';
import { Materials, StyledTreeIndexSets } from '@reveal/rendering';
import { MultiBufferBatchingManager } from './MultiBufferBatchingManager';
import { TreeIndexToSectorsMap } from '../utilities/TreeIndexToSectorsMap';
import sum from 'lodash/sum';
import { IndexSet } from '@reveal/utilities';

Expand All @@ -22,7 +23,14 @@ describe(MultiBufferBatchingManager.name, () => {
inFront: new IndexSet(),
visible: new IndexSet()
};
manager = new MultiBufferBatchingManager(geometryGroup, materials, styledIndexSets, 1024, numberOfInstanceBuffers);
manager = new MultiBufferBatchingManager(
geometryGroup,
materials,
styledIndexSets,
new TreeIndexToSectorsMap(),
1024,
numberOfInstanceBuffers
);
});

test('batchGeometries() first time adds new geometry to group', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@reveal/utilities';
import { GeometryBufferUtils } from '../utilities/GeometryBufferUtils';
import { getShaderMaterial } from '../utilities/getShaderMaterial';
import { TreeIndexToSectorsMap } from '../utilities/TreeIndexToSectorsMap';
import { DrawCallBatchingManager } from './DrawCallBatchingManager';

/**
Expand Down Expand Up @@ -68,6 +69,7 @@ export class MultiBufferBatchingManager implements DrawCallBatchingManager {
batchGroup: Group,
materials: Materials,
styleTreeIndexSets: StyledTreeIndexSets,
private readonly treeIndexToSectorsMap: TreeIndexToSectorsMap,
private readonly initialBufferSize = 1024,
private readonly numberOfInstanceBatches = 2
) {
Expand All @@ -89,7 +91,7 @@ export class MultiBufferBatchingManager implements DrawCallBatchingManager {
if (parsedGeometry.instanceId === undefined) {
return;
}
this.processGeometries(parsedGeometry as Required<ParsedGeometry>, sectorBatch);
this.processGeometries(parsedGeometry as Required<ParsedGeometry>, sectorBatch, sectorId);
});
}

Expand Down Expand Up @@ -160,9 +162,10 @@ export class MultiBufferBatchingManager implements DrawCallBatchingManager {
}
}

private processGeometries(parsedGeometry: Required<ParsedGeometry>, sectorBatch: SectorBatch) {
private processGeometries(parsedGeometry: Required<ParsedGeometry>, sectorBatch: SectorBatch, sectorId: number) {
const instanceBatch = this.getOrCreateInstanceBatch(parsedGeometry);
this.batchInstanceAttributes(parsedGeometry.geometryBuffer, parsedGeometry.instanceId, instanceBatch, sectorBatch);
this.updateTreeIndexToSectorsMap(parsedGeometry, sectorId);
}

private batchInstanceAttributes(
Expand Down Expand Up @@ -220,6 +223,23 @@ export class MultiBufferBatchingManager implements DrawCallBatchingManager {
}
}

private updateTreeIndexToSectorsMap(parsedGeometry: ParsedGeometry, sectorId: number) {
const sourceInstanceAttributes = GeometryBufferUtils.getAttributes(
parsedGeometry.geometryBuffer,
InterleavedBufferAttribute
);
const treeIndexInterleavedAttribute = this.getTreeIndexAttribute(sourceInstanceAttributes);

// Update mapping from tree indices to sector ids
if (!this.treeIndexToSectorsMap.isCompleted(sectorId, parsedGeometry.type)) {
eiriklegernaes marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 0; i < treeIndexInterleavedAttribute.count; i++) {
const treeIndex = treeIndexInterleavedAttribute.getX(i);
this.treeIndexToSectorsMap.set(treeIndex, sectorId);
}
this.treeIndexToSectorsMap.markCompleted(sectorId, parsedGeometry.type);
}
}

private reallocateBufferGeometry({ buffer, mesh }: BatchBuffer) {
const defragmentedBufferGeometry = this.createDefragmentedBufferGeometry(mesh.geometry, buffer);
mesh.geometry.dispose();
Expand Down
Loading