mirror of
https://github.com/mapillary/mapillary-js.git
synced 2026-02-01 14:33:45 +00:00
feat: define and export camera ctor
This commit is contained in:
parent
40a2d5e539
commit
bed7b39f7b
8
src/external/viewer.ts
vendored
8
src/external/viewer.ts
vendored
@ -41,6 +41,14 @@ export { FallbackOptions } from "../viewer/options/FallbackOptions";
|
||||
export { UrlOptions } from "../viewer/options/UrlOptions";
|
||||
export { ViewerOptions } from "../viewer/options/ViewerOptions";
|
||||
|
||||
// Geometry
|
||||
export {
|
||||
CameraConstructor,
|
||||
CameraParameters,
|
||||
CameraUniforms,
|
||||
ICamera,
|
||||
} from "../geometry/interfaces/ICamera";
|
||||
|
||||
// Graph
|
||||
export { Image } from "../graph/Image";
|
||||
export { NavigationDirection } from "../graph/edge/NavigationDirection";
|
||||
|
||||
@ -8,9 +8,9 @@ export abstract class Camera implements ICamera {
|
||||
public readonly parameters: CameraParameters = {};
|
||||
public readonly uniforms: CameraUniforms = {};
|
||||
|
||||
public projectToSfmFunction: string;
|
||||
|
||||
constructor(public readonly type: string) { }
|
||||
constructor(
|
||||
public readonly type: string,
|
||||
public readonly projectToSfmFunction: string) { }
|
||||
|
||||
public abstract bearingFromSfm(_point: number[]): number[];
|
||||
public abstract projectToSfm(_point: number[]): number[];
|
||||
|
||||
@ -97,10 +97,10 @@ vec2 projectToSfm(vec3 bearing, Parameters parameters, Uniforms uniforms) {
|
||||
`;
|
||||
|
||||
export class FisheyeCamera extends Camera {
|
||||
public readonly projectToSfmFunction: string = FISHEYE_PROJECT_FUNCTION;
|
||||
|
||||
constructor(parameters: number[]) {
|
||||
super(FISHEYE_CAMERA_TYPE);
|
||||
super(
|
||||
FISHEYE_CAMERA_TYPE,
|
||||
FISHEYE_PROJECT_FUNCTION);
|
||||
|
||||
const [focal, k1, k2] = parameters;
|
||||
this.parameters.focal = focal;
|
||||
|
||||
@ -90,10 +90,10 @@ vec2 projectToSfm(vec3 bearing, Parameters parameters, Uniforms uniforms) {
|
||||
`;
|
||||
|
||||
export class PerspectiveCamera extends Camera {
|
||||
public readonly projectToSfmFunction: string = PERSPECTIVE_PROJECT_FUNCTION;
|
||||
|
||||
constructor(parameters: number[]) {
|
||||
super(PERSPECTIVE_CAMERA_TYPE);
|
||||
super(
|
||||
PERSPECTIVE_CAMERA_TYPE,
|
||||
PERSPECTIVE_PROJECT_FUNCTION);
|
||||
|
||||
const [focal, k1, k2] = parameters;
|
||||
this.parameters.focal = focal;
|
||||
|
||||
@ -43,9 +43,11 @@ vec2 projectToSfm(vec3 bearing) {
|
||||
`;
|
||||
|
||||
export class SphericalCamera extends Camera {
|
||||
public readonly projectToSfmFunction: string = SPHERICAL_PROJECT_FUNCTION;
|
||||
|
||||
constructor() { super(SPHERICAL_CAMERA_TYPE); }
|
||||
constructor() {
|
||||
super(
|
||||
SPHERICAL_CAMERA_TYPE,
|
||||
SPHERICAL_PROJECT_FUNCTION);
|
||||
}
|
||||
|
||||
public bearingFromSfm(point: number[]): number[] {
|
||||
return bearing(point);
|
||||
|
||||
@ -1,6 +1,19 @@
|
||||
export type CameraParameters = { [key: string]: number; };
|
||||
|
||||
export type CameraUniforms = { [key: string]: boolean | number | number[]; };
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* @description Interface for cameras. This is a
|
||||
* specification for implementers to model: it is not
|
||||
* an exported method or class.
|
||||
*
|
||||
* Implmenting a custom camera allows the implementer to
|
||||
* render textures and camera frustums with proper undistortion.
|
||||
*
|
||||
* Custom cameras must have a unique type.
|
||||
*/
|
||||
export interface ICamera {
|
||||
readonly type: string;
|
||||
|
||||
@ -12,3 +25,7 @@ export interface ICamera {
|
||||
bearingFromSfm(point: number[]): number[];
|
||||
projectToSfm(bearing: number[]): number[];
|
||||
}
|
||||
|
||||
export interface CameraConstructor {
|
||||
new(parameters: number[]): ICamera;
|
||||
};
|
||||
|
||||
@ -10,13 +10,14 @@ import {
|
||||
SphericalCamera,
|
||||
SPHERICAL_CAMERA_TYPE,
|
||||
} from "../geometry/camera/SphericalCamera";
|
||||
import { ICamera } from "../geometry/interfaces/ICamera";
|
||||
import {
|
||||
CameraConstructor,
|
||||
ICamera,
|
||||
} from "../geometry/interfaces/ICamera";
|
||||
import { ICameraFactory } from "../geometry/interfaces/ICameraFactory";
|
||||
|
||||
export type CameraCtor = { new(parameters: number[]): ICamera; };
|
||||
|
||||
export class ProjectionService implements ICameraFactory {
|
||||
private readonly _cameraFactory: { [type: string]: CameraCtor; } = {};
|
||||
private readonly _cameraFactory: { [type: string]: CameraConstructor; } = {};
|
||||
|
||||
constructor() {
|
||||
this.registerCamera(
|
||||
@ -30,7 +31,7 @@ export class ProjectionService implements ICameraFactory {
|
||||
SphericalCamera);
|
||||
}
|
||||
|
||||
public registerCamera(type: string, ctor: CameraCtor): void {
|
||||
public registerCamera(type: string, ctor: CameraConstructor): void {
|
||||
this._cameraFactory[type] = ctor;
|
||||
}
|
||||
|
||||
@ -38,6 +39,7 @@ export class ProjectionService implements ICameraFactory {
|
||||
if (!(type in this._cameraFactory)) {
|
||||
return new PerspectiveCamera([0.85, 0, 0]);
|
||||
}
|
||||
|
||||
return new this._cameraFactory[type](parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ import { cameraControlsToState } from "./Modes";
|
||||
import { ViewerReferenceEvent } from "./events/ViewerReferenceEvent";
|
||||
import { IDataProvider } from "../external/api";
|
||||
import { ViewerResetEvent } from "./events/ViewerResetEvent";
|
||||
import { ICamera } from "../geometry/interfaces/ICamera";
|
||||
import { CameraConstructor } from "../geometry/interfaces/ICamera";
|
||||
|
||||
/**
|
||||
* @class Viewer
|
||||
@ -1486,7 +1486,7 @@ export class Viewer extends EventEmitter implements IViewer {
|
||||
*/
|
||||
public registerCamera(
|
||||
type: string,
|
||||
ctor: { new(parameters: number[]): ICamera; }): void {
|
||||
ctor: CameraConstructor): void {
|
||||
this._navigator.projectionService.registerCamera(type, ctor);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user