Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alxart committed Apr 21, 2024
1 parent ad77087 commit 0ae63fd
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 56 deletions.
123 changes: 69 additions & 54 deletions src/realtyScene/realtyScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,64 +143,76 @@ export class RealtyScene {
}

if (newModelOptions) {
const modelStatus = this.plugin.getModelStatus(newModelOptions.modelId);

// если новая модель готова, то показываем ее
if (modelStatus === ModelStatus.Loaded) {
buildingVisibility.set(buildingId, newModelOptions);

if (newState.status === 'visible') {
this.plugin.showModel(newModelOptions.modelId);

// если модель активна, то применяем опции карты и включаем подложку, если нужно
if (
newState.activeModelId !== undefined &&
newState.activeModelId === newModelOptions.modelId
) {
const options =
this.buildings.get(newModelOptions.modelId) ??
this.floors.get(newModelOptions.modelId);

if (options) {
this.setMapOptions(options.mapOptions);
}

if (this.undergroundFloors.has(newModelOptions.modelId)) {
this.switchOnGroundCovering();
}

const floorOptions = this.floors.get(newModelOptions.modelId);
if (floorOptions) {
floorOptions.labelGroups?.forEach((group) => {
this.plugin.addLabelGroup(group, {
buildingId,
floorId: floorOptions.id,
// если текущий этаж - подземный, а новая активная модель не готова,
// то не показываем модели, за исключанием подземного этажа
if (
!prevModelOptions &&
prevState.activeModelId !== undefined &&
this.undergroundFloors.has(prevState.activeModelId) &&
newState.activeModelId !== undefined &&
this.plugin.getModelStatus(newState.activeModelId) !== ModelStatus.Loaded
) {
buildingVisibility.set(buildingId, prevModelOptions);
} else {
const modelStatus = this.plugin.getModelStatus(newModelOptions.modelId);

// если новая модель готова, то показываем ее
if (modelStatus === ModelStatus.Loaded) {
buildingVisibility.set(buildingId, newModelOptions);

if (newState.status === 'visible') {
this.plugin.showModel(newModelOptions.modelId);

// если модель активна, то применяем опции карты и включаем подложку, если нужно
if (
newState.activeModelId !== undefined &&
newState.activeModelId === newModelOptions.modelId
) {
const options =
this.buildings.get(newModelOptions.modelId) ??
this.floors.get(newModelOptions.modelId);

if (options) {
this.setMapOptions(options.mapOptions);
}

if (this.undergroundFloors.has(newModelOptions.modelId)) {
this.switchOnGroundCovering();
}

const floorOptions = this.floors.get(newModelOptions.modelId);
if (floorOptions) {
floorOptions.labelGroups?.forEach((group) => {
this.plugin.addLabelGroup(group, {
buildingId,
floorId: floorOptions.id,
});
});
});
}
}
}
}
} else {
if (modelStatus === ModelStatus.NoModel) {
this.plugin.addModel(newModelOptions, true).then(() => {
if (this.state.status === 'destroyed') {
return;
}

if (this.state.activeModelId !== newModelOptions.modelId) {
return;
}

// откладываем выставление нужного стейта до момента загрузки модели
this.setState({
...newState,
status: this.state.status,
} else {
if (modelStatus === ModelStatus.NoModel) {
this.plugin.addModel(newModelOptions, true).then(() => {
if (this.state.status === 'destroyed') {
return;
}

if (this.state.activeModelId !== newModelOptions.modelId) {
return;
}

// откладываем выставление нужного стейта до момента загрузки модели
this.setState({
...newState,
status: this.state.status,
});
});
});
}
}

// если новые модели не готовы, то пока показываем предыдущие
buildingVisibility.set(buildingId, prevModelOptions);
// если новые модели не готовы, то пока показываем предыдущие
buildingVisibility.set(buildingId, prevModelOptions);
}
}
}
});
Expand Down Expand Up @@ -316,7 +328,10 @@ export class RealtyScene {
}

return this.plugin
.addModels(Array.from(modelsToLoad.values()), Array.from(buildingVisibility.keys()))
.addModels(
Array.from(modelsToLoad.values()),
Array.from(buildingVisibility).map(([_, options]) => options.modelId),
)
.then(() => {
if (this.state.status === 'destroyed') {
return;
Expand Down
3 changes: 2 additions & 1 deletion test/mocks/realtyScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export const REALTY_SCENE: BuildingOptions[] = [
id: '235034',
text: '1-10',
modelUrl: 'zgktechnology1_floor2.glb',
isUnderground: true,
mapOptions: {
center: [47.24524342863023, 56.13449524271827],
center: [47.245244380223404, 56.13440013744883],
pitch: 40,
zoom: 20,
rotation: -57.5,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 45 additions & 1 deletion test/screenshots/plugin.screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const init = async (
page: Page,
opts: Pick<MapOptions, 'center' | 'rotation'> & {
modelsBaseUrl?: string;
groundCoveringColor?: string;
} = {},
) => {
await initMapWithOptions(page, {
Expand All @@ -35,14 +36,16 @@ const init = async (
});

await page.evaluate(
({ modelsBaseUrl }) => {
({ modelsBaseUrl, groundCoveringColor }) => {
window.gltfPlugin = new window.GltfPlugin(window.map, {
modelsLoadStrategy: 'dontWaitAll',
modelsBaseUrl,
groundCoveringColor,
});
},
{
modelsBaseUrl: opts.modelsBaseUrl ?? '',
groundCoveringColor: opts.groundCoveringColor ?? '#F8F8EBCC',
},
);

Expand Down Expand Up @@ -158,6 +161,7 @@ describe('GltfPlugin', () => {
await init(page, {
center: [47.245286302641034, 56.134743473834099],
rotation: 330,
groundCoveringColor: 'rgba(0, 0, 0, 0.8)',
modelsBaseUrl:
'https://disk.2gis.com/digital-twin/models_s3/realty_ads/zgktechnology/',
});
Expand All @@ -171,6 +175,46 @@ describe('GltfPlugin', () => {
await makeSnapshot(page, dirPath, 'add_realty_scene');
});

it('Hide and show a realty scene', async () => {
await page.evaluate(() => {
return window.gltfPlugin.addRealtyScene(window.MOCKS.realtyScene);
});
await waitForReadiness(page);

await page.evaluate(() => {
return window.gltfPlugin.hideRealtyScene();
});
await makeSnapshot(page, dirPath, 'hide_realty_scene');

await page.evaluate(() => {
return window.gltfPlugin.showRealtyScene();
});
await waitForReadiness(page);
await makeSnapshot(page, dirPath, 'show_realty_scene');
});

it('Hide and show an underground realty scene', async () => {
await page.evaluate(() => {
return window.gltfPlugin.addRealtyScene(window.MOCKS.realtyScene, {
buildingId: '03a234cb',
floorId: '235034',
});
});
await waitForReadiness(page);

await page.evaluate(() => {
return window.gltfPlugin.hideRealtyScene();
});
await waitForReadiness(page);
await makeSnapshot(page, dirPath, 'hide_underground_realty_scene');

await page.evaluate(() => {
return window.gltfPlugin.showRealtyScene();
});
await waitForReadiness(page);
await makeSnapshot(page, dirPath, 'show_underground_realty_scene');
});

it('#removeRealtyScene', async () => {
await page.evaluate(() => {
return window.gltfPlugin.addRealtyScene(window.MOCKS.realtyScene);
Expand Down

0 comments on commit 0ae63fd

Please sign in to comment.