Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b94ae1a

Browse files
gchoqueuxpeppsac
authored andcommitted
feat(panorama): add projection type constant #677
Add explicit projection type constants instead of relying on the ratio to deduce the projection.
1 parent 7f86bf1 commit b94ae1a

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

examples/panorama.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
new itowns.Coordinates('EPSG:4326',
5858
panoramas[0]['coordinates'][0],
5959
panoramas[0]['coordinates'][1]).as('EPSG:4978'),
60-
panoramas[0]['ratio']);
60+
itowns.Panorama.SPHERICAL);
6161

6262
var index = 0;
6363
var layers = [];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
CYLINDRICAL: 1,
3+
SPHERICAL: 2,
4+
};

src/Core/Prefab/Panorama/PanoramaTileBuilder.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
import * as THREE from 'three';
22
import OBB from '../../../Renderer/ThreeExtended/OBB';
33
import Coordinates, { UNIT } from '../../Geographic/Coordinates';
4+
import ProjectionType from './Constants';
45
import Extent from '../../Geographic/Extent';
56

6-
function PanoramaTileBuilder(ratio) {
7+
function PanoramaTileBuilder(type, ratio) {
78
this.tmp = {
89
coords: new Coordinates('EPSG:4326', 0, 0),
910
position: new THREE.Vector3(),
1011
normal: new THREE.Vector3(0, 0, 1),
1112
};
1213

13-
if (!ratio) {
14-
throw new Error('ratio must be defined');
14+
if (type === undefined) {
15+
throw new Error('Projection type must be defined');
1516
}
16-
if (ratio === 2) {
17-
this.equirectangular = true;
17+
if (type === ProjectionType.SPHERICAL) {
1818
this.type = 's';
1919
this.radius = 100;
20-
} else {
21-
this.equirectangular = false; // cylindrical proj
20+
} else if (type === ProjectionType.CYLINDRICAL) {
21+
if (!ratio) {
22+
throw new Error('Image ratio must be defined when using cylindrical projection');
23+
}
2224
this.type = 'c';
2325
this.height = 200;
2426
this.radius = (ratio * this.height) / (2 * Math.PI);
27+
} else {
28+
throw new Error(`Unsupported panorama projection type ${type}`);
2529
}
30+
this.projectionType = type;
2631
}
2732

2833
PanoramaTileBuilder.prototype.constructor = PanoramaTileBuilder;
@@ -33,7 +38,7 @@ const axisX = new THREE.Vector3(0, 1, 0);
3338
PanoramaTileBuilder.prototype.Prepare = function Prepare(params) {
3439
const angle = (params.extent.north(UNIT.RADIAN) + params.extent.south(UNIT.RADIAN)) * 0.5;
3540

36-
if (this.equirectangular) {
41+
if (this.projectionType === ProjectionType.SPHERICAL) {
3742
params.quatNormalToZ = new THREE.Quaternion().setFromAxisAngle(axisX, (Math.PI * 0.5 - angle));
3843
params.projected = {
3944
theta: 0,
@@ -61,7 +66,7 @@ PanoramaTileBuilder.prototype.Center = function Center(extent) {
6166

6267
// get position 3D cartesian
6368
PanoramaTileBuilder.prototype.VertexPosition = function VertexPosition(params) {
64-
if (this.equirectangular) {
69+
if (this.projectionType === ProjectionType.SPHERICAL) {
6570
this.tmp.position.setFromSpherical(params.projected);
6671
} else {
6772
this.tmp.position.setFromCylindrical(params.projected);
@@ -88,7 +93,7 @@ PanoramaTileBuilder.prototype.uProjecte = function uProjecte(u, params) {
8893

8994
// coord v tile to projected
9095
PanoramaTileBuilder.prototype.vProjecte = function vProjecte(v, params) {
91-
if (this.equirectangular) {
96+
if (this.projectionType === ProjectionType.SPHERICAL) {
9297
params.projected.phi = Math.PI * 0.5 -
9398
THREE.Math.lerp(
9499
params.extent.north(UNIT.RADIAN),
@@ -122,7 +127,10 @@ PanoramaTileBuilder.prototype.computeSharableExtent = function fnComputeSharable
122127
// compute rotation to transform tile to position it
123128
// this transformation take into account the transformation of the parents
124129
const rotLon = extent.west(UNIT.RADIAN) - sharableExtent.west(UNIT.RADIAN);
125-
const rotLat = Math.PI * 0.5 - (!this.equirectangular ? 0 : (extent.north(UNIT.RADIAN) + extent.south(UNIT.RADIAN)) * 0.5);
130+
const rotLat = Math.PI * 0.5 -
131+
(this.projectionType === ProjectionType.CYLINDRICAL ?
132+
0 :
133+
(extent.north(UNIT.RADIAN) + extent.south(UNIT.RADIAN)) * 0.5);
126134
quatToAlignLongitude.setFromAxisAngle(axisZ, -rotLon);
127135
quatToAlignLatitude.setFromAxisAngle(axisY, -rotLat);
128136
quatToAlignLongitude.multiply(quatToAlignLatitude);

src/Core/Prefab/PanoramaView.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import { updateLayeredMaterialNodeImagery } from '../../Process/LayeredMaterialN
99
import { panoramaCulling, panoramaSubdivisionControl } from '../../Process/PanoramaTileProcessing';
1010
import PanoramaTileBuilder from './Panorama/PanoramaTileBuilder';
1111
import SubdivisionControl from '../../Process/SubdivisionControl';
12+
import ProjectionType from './Panorama/Constants';
1213

13-
export function createPanoramaLayer(id, coordinates, ratio, options = {}) {
14+
export function createPanoramaLayer(id, coordinates, type, options = {}) {
1415
const tileLayer = new GeometryLayer(id, options.object3d || new THREE.Group());
1516

1617
coordinates.xyz(tileLayer.object3d.position);
@@ -26,7 +27,7 @@ export function createPanoramaLayer(id, coordinates, ratio, options = {}) {
2627
south: -90,
2728
});
2829

29-
if (ratio == 2) {
30+
if (type === ProjectionType.SPHERICAL) {
3031
// equirectangular -> spherical geometry
3132
tileLayer.schemeTile = [
3233
new Extent('EPSG:4326', {
@@ -40,7 +41,7 @@ export function createPanoramaLayer(id, coordinates, ratio, options = {}) {
4041
north: 90,
4142
south: -90,
4243
})];
43-
} else {
44+
} else if (type === ProjectionType.CYLINDRICAL) {
4445
// cylindrical geometry
4546
tileLayer.schemeTile = [
4647
new Extent('EPSG:4326', {
@@ -64,6 +65,9 @@ export function createPanoramaLayer(id, coordinates, ratio, options = {}) {
6465
north: 90,
6566
south: -90,
6667
})];
68+
} else {
69+
throw new Error(`Unsupported panorama projection type ${type}.
70+
Only ProjectionType.SPHERICAL and ProjectionType.CYLINDRICAL are supported`);
6771
}
6872
tileLayer.disableSkirt = true;
6973

@@ -146,13 +150,13 @@ export function createPanoramaLayer(id, coordinates, ratio, options = {}) {
146150
function subdivision(context, layer, node) {
147151
if (SubdivisionControl.hasEnoughTexturesToSubdivide(context, layer, node)) {
148152
return panoramaSubdivisionControl(
149-
options.maxSubdivisionLevel || 10, new THREE.Vector2(512, 512 / ratio))(context, layer, node);
153+
options.maxSubdivisionLevel || 10, new THREE.Vector2(512, 256))(context, layer, node);
150154
}
151155
return false;
152156
}
153157

154158
tileLayer.update = processTiledGeometryNode(panoramaCulling, subdivision);
155-
tileLayer.builder = new PanoramaTileBuilder(ratio);
159+
tileLayer.builder = new PanoramaTileBuilder(type, options.ratio);
156160
tileLayer.onTileCreated = nodeInitFn;
157161
tileLayer.type = 'geometry';
158162
tileLayer.protocol = 'tile';
@@ -167,7 +171,7 @@ export function createPanoramaLayer(id, coordinates, ratio, options = {}) {
167171
return tileLayer;
168172
}
169173

170-
function PanoramaView(viewerDiv, coordinates, ratio, options = {}) {
174+
function PanoramaView(viewerDiv, coordinates, type, options = {}) {
171175
THREE.Object3D.DefaultUp.set(0, 0, 1);
172176

173177
// Setup View
@@ -184,10 +188,12 @@ function PanoramaView(viewerDiv, coordinates, ratio, options = {}) {
184188
// look at to the north
185189
camera.lookAt(new THREE.Vector3(0, 1, 0).add(camera.position));
186190

187-
camera.updateProjectionMatrix();
191+
if (camera.updateProjectionMatrix) {
192+
camera.updateProjectionMatrix();
193+
}
188194
camera.updateMatrixWorld();
189195

190-
const tileLayer = createPanoramaLayer('panorama', coordinates, ratio, options);
196+
const tileLayer = createPanoramaLayer('panorama', coordinates, type, options);
191197

192198
View.prototype.addLayer.call(this, tileLayer);
193199

src/Main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { default as GlobeView, GLOBE_VIEW_EVENTS, createGlobeLayer } from './Cor
66
export { default as GpxUtils } from './Core/Scheduler/Providers/GpxUtils';
77
export { default as PlanarView, createPlanarLayer } from './Core/Prefab/PlanarView';
88
export { default as PanoramaView, createPanoramaLayer } from './Core/Prefab/PanoramaView';
9+
export { default as Panorama } from './Core/Prefab/Panorama/Constants';
910
export { default as Fetcher } from './Core/Scheduler/Providers/Fetcher';
1011
export { MAIN_LOOP_EVENTS } from './Core/MainLoop';
1112
export { default as View } from './Core/View';

0 commit comments

Comments
 (0)