Skip to content

Commit

Permalink
wip: area clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslav-tk committed Dec 16, 2024
1 parent 806d7fc commit 2b046d1
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/apps/permits/demoPermitConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const config: IPermitsConfig = {
'@demo': () => import('../../catalogs/demoCatalog.js'),
},
layers: {
tiles3d: ['@cesium/googlePhotorealistic'],
// tiles3d: ['@cesium/googlePhotorealistic'],
// models: ['@demo/sofa', '@demo/thatopensmall'],
imageries: ['@geoadmin/pixel-karte-farbe'],
// terrain: '@geoadmin/terrain',
Expand Down
12 changes: 11 additions & 1 deletion src/apps/permits/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import type {IPermitsConfig} from './ingv-config-permits.js';
import '../../plugins/cesium/ngv-plugin-cesium-widget';
import '../../plugins/cesium/ngv-plugin-cesium-upload';
import '../../plugins/cesium/ngv-plugin-cesium-model-interact';
import '../../plugins/cesium/ngv-plugin-cesium-slicing';
import type {CesiumWidget, DataSourceCollection} from '@cesium/engine';

import {PrimitiveCollection} from '@cesium/engine';
import {PrimitiveCollection, CustomDataSource} from '@cesium/engine';
import type {ViewerInitializedDetails} from '../../plugins/cesium/ngv-plugin-cesium-widget.js';

@customElement('ngv-app-permits')
Expand All @@ -26,6 +27,7 @@ export class NgvAppPermits extends ABaseApp<IPermitsConfig> {
private uploadedModelsCollection: PrimitiveCollection =
new PrimitiveCollection();
private dataSourceCollection: DataSourceCollection;
private slicingDataSource: CustomDataSource = new CustomDataSource();

private storeOptions = {
localStoreKey: 'permits-localStoreModels',
Expand Down Expand Up @@ -74,6 +76,11 @@ export class NgvAppPermits extends ABaseApp<IPermitsConfig> {
.storeOptions="${this.storeOptions}"
.options="${{listTitle: 'Uploaded models'}}"
></ngv-plugin-cesium-model-interact>
<ngv-plugin-cesium-slicing
.viewer="${this.viewer}"
.tiles3dCollection="${this.collections.tiles3d}"
.slicingDataSource="${this.slicingDataSource}"
></ngv-plugin-cesium-slicing>
`
: ''}
</div>
Expand All @@ -85,6 +92,9 @@ export class NgvAppPermits extends ABaseApp<IPermitsConfig> {
this.viewer.scene.primitives.add(this.uploadedModelsCollection);
this.dataSourceCollection = evt.detail.dataSourceCollection;
this.collections = evt.detail.primitiveCollections;
this.dataSourceCollection
.add(this.slicingDataSource)
.catch((e) => console.error(e));
}}
></ngv-plugin-cesium-widget>
</ngv-structure-app>
Expand Down
22 changes: 17 additions & 5 deletions src/plugins/cesium/interactionHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {

Check failure on line 1 in src/plugins/cesium/interactionHelpers.ts

View workflow job for this annotation

GitHub Actions / Basic checks

Imports "Cesium3DTileset", "CustomDataSource", "Globe", "Model", "PrimitiveCollection" and "Scene" are only used as type
Cesium3DTileset,
ClippingPolygonCollection,
CustomDataSource, Globe,
CustomDataSource,
Globe,
Model,
PrimitiveCollection,
Scene
Scene,
} from '@cesium/engine';
import {
ArcType,
Expand Down Expand Up @@ -528,7 +529,10 @@ export function getClippingPolygon(model: INGVCesiumModel): ClippingPolygon {
});
}

export function applyClippingTo3dTileset(tileset: Cesium3DTileset, models: INGVCesiumModel[]): void {
export function applyClippingTo3dTileset(
tileset: Cesium3DTileset,
models: INGVCesiumModel[],
): void {
const polygons: ClippingPolygon[] = [];
models.forEach((m) => {
if (m.id.tilesClipping) {
Expand All @@ -540,7 +544,11 @@ export function applyClippingTo3dTileset(tileset: Cesium3DTileset, models: INGVC
});
}

export function updateModelClipping(model: INGVCesiumModel, tiles3dCollection: PrimitiveCollection, globe: Globe): void {
export function updateModelClipping(
model: INGVCesiumModel,
tiles3dCollection: PrimitiveCollection,
globe: Globe,
): void {
if ((!tiles3dCollection?.length && !globe) || !model?.ready) return;
const polygon = model.id.clippingPolygon;
const newPolygon = getClippingPolygon(model);
Expand Down Expand Up @@ -585,7 +593,11 @@ export function updateModelClipping(model: INGVCesiumModel, tiles3dCollection: P
model.id.clippingPolygon = newPolygon;
}

export function removeClippingFrom3dTilesets(model: INGVCesiumModel, tiles3dCollection: PrimitiveCollection, globe: Globe): void {
export function removeClippingFrom3dTilesets(
model: INGVCesiumModel,
tiles3dCollection: PrimitiveCollection,
globe: Globe,
): void {
if ((!tiles3dCollection?.length && !globe) || !model.ready) return;
const polygon = model.id.clippingPolygon;
if (tiles3dCollection?.length) {
Expand Down
44 changes: 35 additions & 9 deletions src/plugins/cesium/ngv-plugin-cesium-model-interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
PrimitiveCollection,
DataSourceCollection,
Cartesian2,
Cesium3DTileset
Cesium3DTileset,
} from '@cesium/engine';
import {
Model,
Expand Down Expand Up @@ -38,7 +38,7 @@ import type {BBoxStyles} from './interactionHelpers.js';
import {
applyClippingTo3dTileset,
removeClippingFrom3dTilesets,
updateModelClipping
updateModelClipping,
} from './interactionHelpers.js';
import {
getHorizontalMoveVector,
Expand Down Expand Up @@ -123,7 +123,11 @@ export class NgvPluginCesiumModelInteract extends LitElement {
this.primitiveCollection.primitiveAdded.addEventListener(
(model: INGVCesiumModel) => {
this.onPrimitivesChanged();
updateModelClipping(model, this.tiles3dCollection, this.viewer.scene.globe);
updateModelClipping(
model,
this.tiles3dCollection,
this.viewer.scene.globe,
);
},
);
this.primitiveCollection.primitiveRemoved.addEventListener(
Expand Down Expand Up @@ -198,15 +202,29 @@ export class NgvPluginCesiumModelInteract extends LitElement {
const normal = Ellipsoid.WGS84.geodeticSurfaceNormal(this.moveStart);
this.movePlane = Plane.fromPointNormal(this.moveStart, normal);

if (this.chosenModel?.id.tilesClipping || this.chosenModel?.id.terrainClipping) {
removeClippingFrom3dTilesets(this.chosenModel, this.tiles3dCollection, this.viewer.scene.globe);
if (
this.chosenModel?.id.tilesClipping ||
this.chosenModel?.id.terrainClipping
) {
removeClippingFrom3dTilesets(
this.chosenModel,
this.tiles3dCollection,
this.viewer.scene.globe,
);
}
}
}
onLeftUp(): void {
if (this.grabType) {
if (this.chosenModel?.id.tilesClipping || this.chosenModel?.id.terrainClipping) {
updateModelClipping(this.chosenModel, this.tiles3dCollection, this.viewer.scene.globe);
if (
this.chosenModel?.id.tilesClipping ||
this.chosenModel?.id.terrainClipping
) {
updateModelClipping(
this.chosenModel,
this.tiles3dCollection,
this.viewer.scene.globe,
);
}
this.viewer.scene.screenSpaceCameraController.enableInputs = true;
this.grabType = undefined;
Expand Down Expand Up @@ -414,7 +432,11 @@ export class NgvPluginCesiumModelInteract extends LitElement {
});
this.primitiveCollection.add(model);
model.readyEvent.addEventListener(() =>
updateModelClipping(model, this.tiles3dCollection, this.viewer.scene.globe),
updateModelClipping(
model,
this.tiles3dCollection,
this.viewer.scene.globe,
),
);
}),
);
Expand Down Expand Up @@ -449,7 +471,11 @@ export class NgvPluginCesiumModelInteract extends LitElement {
@clippingChange=${(evt: {detail: ClippingChangeDetail}) => {
this.chosenModel.id.terrainClipping = evt.detail.terrainClipping;
this.chosenModel.id.tilesClipping = evt.detail.tilesClipping;
updateModelClipping(this.chosenModel, this.tiles3dCollection, this.viewer.scene.globe);
updateModelClipping(
this.chosenModel,
this.tiles3dCollection,
this.viewer.scene.globe,
);
}}
@done="${() => {
this.chosenModel = undefined;
Expand Down
Loading

0 comments on commit 2b046d1

Please sign in to comment.