Skip to content

Commit

Permalink
Close #1020 Move "useXmpData" to EquirectangularAdapter config
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Jul 24, 2023
1 parent bad91ca commit 9b83564
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 23 deletions.
9 changes: 8 additions & 1 deletion docs/guide/adapters/equirectangular.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ There is no need to declare the equirectangular adapter as it is the default one
```js
const viewer = new PhotoSphereViewer.Viewer({
adapter: [PhotoSphereViewer.EquirectangularAdapter, {
resolution: 64, // default
useXmpData: true, // default
}],
panorama: 'path/panorama.jpg',
});
```

## Configuration

#### `useXmpData`

- type: `boolean`
- default `true`

Read real image size from XMP data, must be kept `true` if the panorama has been cropped after shot. This is used for [cropped panorama](#cropped-panorama).

#### `resolution`

- type: `number`
Expand Down
11 changes: 4 additions & 7 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,13 @@ Speed multiplicator for panorama moves. Used for click move, touch move and navb

Speed multiplicator for panorama zooms. Used for mouse wheel, touch pinch and navbar buttons.

#### `useXmpData`
#### ~~`useXmpData`~~

- type: `boolean`
- default `true`

Read real image size from XMP data, must be kept `true` if the panorama has been cropped after shot. This is used for [cropped panorama](./adapters/equirectangular.md#cropped-panorama).
Deprecated : must be configured [on the adapter](./adapters/equirectangular.md#configuration).

#### `panoData`

- type: `object | function<Image, object>`
- type: `object | function<Image, PanoData, PanoData>`

Overrides XMP data found in the panorama file (or if `useXmpData=false`).
All parameters are optional.
Expand All @@ -277,7 +274,7 @@ panoData: {
It can also be a function to dynamically compute the cropping config depending on the loaded image.

```js
panoData: (image) => ({
panoData: (image, xmpData) => ({
fullWidth: image.width,
fullHeight: Math.round(image.width / 2),
croppedWidth: image.width,
Expand Down
19 changes: 14 additions & 5 deletions packages/core/src/adapters/EquirectangularAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BufferGeometry, MathUtils, Mesh, ShaderMaterial, SphereGeometry, Texture } from 'three';
import { PSVError } from '../PSVError';
import type { Viewer } from '../Viewer';
import { SPHERE_RADIUS } from '../data/constants';
import { SYSTEM } from '../data/system';
import { PanoData, PanoDataProvider, TextureData } from '../model';
import { PSVError } from '../PSVError';
import { createTexture, firstNonNull, getConfigParser, getXMPValue, logWarn } from '../utils';
import type { Viewer } from '../Viewer';
import { createTexture, firstNonNull, getConfigParser, getXMPValue, isNil, logWarn } from '../utils';
import { AbstractAdapter } from './AbstractAdapter';

/**
Expand All @@ -16,6 +16,11 @@ export type EquirectangularAdapterConfig = {
* @default 64
*/
resolution?: number;
/**
* read real image size from XMP data
* @default true
*/
useXmpData?: boolean;
/**
* used for equirectangular tiles adapter
* @internal
Expand All @@ -29,6 +34,7 @@ type EquirectangularTexture = TextureData<Texture, string>;
const getConfig = getConfigParser<EquirectangularAdapterConfig>(
{
resolution: 64,
useXmpData: true,
blur: false,
},
{
Expand Down Expand Up @@ -58,6 +64,9 @@ export class EquirectangularAdapter extends AbstractAdapter<string, Texture> {
super(viewer);

this.config = getConfig(config);
if (!isNil(this.viewer.config.useXmpData)) {
this.config.useXmpData = this.viewer.config.useXmpData;
}

this.SPHERE_SEGMENTS = this.config.resolution;
this.SPHERE_HORIZONTAL_SEGMENTS = this.SPHERE_SEGMENTS / 2;
Expand All @@ -74,7 +83,7 @@ export class EquirectangularAdapter extends AbstractAdapter<string, Texture> {
async loadTexture(
panorama: string,
newPanoData: PanoData | PanoDataProvider,
useXmpPanoData = this.viewer.config.useXmpData
useXmpPanoData = this.config.useXmpData
): Promise<EquirectangularTexture> {
if (typeof panorama !== 'string') {
return Promise.reject(new PSVError('Invalid panorama url, are you using the right adapter?'));
Expand All @@ -85,7 +94,7 @@ export class EquirectangularAdapter extends AbstractAdapter<string, Texture> {
const img = await this.viewer.textureLoader.blobToImage(blob);

if (typeof newPanoData === 'function') {
newPanoData = newPanoData(img);
newPanoData = newPanoData(img, xmpPanoData);
}

const panoData = {
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/data/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const DEFAULTS: Required<ParsedViewerConfig> = {
mousemove: true,
mousewheelCtrlKey: false,
touchmoveTwoFingers: false,
useXmpData: true,
useXmpData: null,
panoData: null,
requestHeaders: null,
canvasBackground: '#000',
Expand Down Expand Up @@ -232,6 +232,12 @@ export const CONFIG_PARSERS: ConfigParsers<ViewerConfig, ParsedViewerConfig> = {
}
return navbar;
},
useXmpData: (useXmpData) => {
if (useXmpData !== null) {
logWarn(`Global useXmpData is deprecated, it is now configured on the adapter.`);
}
return useXmpData;
},
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export type PanoData = {
/**
* Function to compute panorama data once the image is loaded
*/
export type PanoDataProvider = (image: HTMLImageElement) => PanoData;
export type PanoDataProvider = (image: HTMLImageElement, xmpData?: PanoData) => PanoData;

/**
* Object defining options for {@link Viewer.setPanorama}
Expand Down Expand Up @@ -313,7 +313,7 @@ export type ViewerConfig = {
mousewheelCtrlKey?: boolean;
/** @default false */
touchmoveTwoFingers?: boolean;
/** @default true */
/** @deprecated configure on EquirectangularAdapter */
useXmpData?: boolean;
panoData?: PanoData | PanoDataProvider;
requestHeaders?: Record<string, string> | ((url: string) => Record<string, string>);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/ViewerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ViewerState {
};

/**
* panorama metadata, if supported
* panorama metadata, if supported
*/
panoData: PanoData = {
fullWidth: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ const getConfig = utils.getConfigParser<EquirectangularTilesAdapterConfig>(
showErrorTile: true,
baseBlur: true,
antialias: true,
blur: false,
debug: false,
blur: false,
useXmpData: false,
},
{
resolution: (resolution) => {
Expand Down Expand Up @@ -138,8 +139,6 @@ export class EquirectangularTilesAdapter extends AbstractAdapter<

this.config = getConfig(config);

this.viewer.config.useXmpData = false;

this.SPHERE_SEGMENTS = this.config.resolution;
this.SPHERE_HORIZONTAL_SEGMENTS = this.SPHERE_SEGMENTS / 2;
this.NB_VERTICES = 2 * this.SPHERE_SEGMENTS * NB_VERTICES_BY_SMALL_FACE
Expand Down Expand Up @@ -221,6 +220,7 @@ export class EquirectangularTilesAdapter extends AbstractAdapter<
if (!this.adapter) {
this.adapter = new EquirectangularAdapter(this.viewer, {
blur: this.config.baseBlur,
useXmpData: false,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const getConfig = utils.getConfigParser<EquirectangularVideoAdapterConfig>(
resolution: 64,
autoplay: false,
muted: false,
useXmpData: false,
blur: false,
},
{
Expand Down
6 changes: 3 additions & 3 deletions packages/little-planet-adapter/src/LittlePlanetAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Position, Size, TextureData, Viewer } from '@photo-sphere-viewer/core';
import type { EquirectangularAdapterConfig, Position, Size, TextureData, Viewer } from '@photo-sphere-viewer/core';
import { EquirectangularAdapter, events } from '@photo-sphere-viewer/core';
import { BufferGeometry, Euler, MathUtils, Matrix4, Mesh, PlaneGeometry, ShaderMaterial, Texture } from 'three';

Expand All @@ -17,8 +17,8 @@ export class LittlePlanetAdapter extends EquirectangularAdapter {

private uniforms: ShaderMaterial['uniforms'];

constructor(viewer: Viewer) {
super(viewer, undefined);
constructor(viewer: Viewer, config?: EquirectangularAdapterConfig) {
super(viewer, config);

this.viewer.state.littlePlanet = true;

Expand Down

0 comments on commit 9b83564

Please sign in to comment.