Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globe - basic infrastructure, raster layer adaptation for globe #3783

Merged
merged 53 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
18765bb
Port changes from main globe branch - basics
kubapelc Feb 29, 2024
864fc05
Fix PI redefinitions
kubapelc Mar 1, 2024
9c443ac
Fix stencil shader
kubapelc Mar 1, 2024
d318ae0
Port adaptation of raster layer for globe from main globe branch
kubapelc Mar 1, 2024
9efa2df
Add globe.html example from pheonor's repo
kubapelc Mar 1, 2024
6062c88
Better map projection parameter doc comment, warn when using unknown …
kubapelc Mar 1, 2024
d03d9f8
Mercator projectionData handles negative zoom correctly
kubapelc Mar 4, 2024
6a4f6df
Comment clarification
kubapelc Mar 4, 2024
8e7b42e
Fix spelling of "granularity"
kubapelc Mar 4, 2024
b18607e
Merge tag 'v4.1.0' into kubapelc/globe-pr
kubapelc Mar 4, 2024
9d2d8f1
Add missing docs
kubapelc Mar 4, 2024
ba1798a
Convert ProjectionBase to an interface
kubapelc Mar 5, 2024
925eff6
Do not leak GL object in globe projection error measurement, add a de…
kubapelc Mar 5, 2024
e20c02f
Fix chrome performance warning, refactor error measurement
kubapelc Mar 5, 2024
cb30ec2
Fix granularity capitalization
kubapelc Mar 5, 2024
c3d6973
Fix capitalization
kubapelc Mar 5, 2024
6428456
Fix typo
kubapelc Mar 5, 2024
abf9dfb
Fix stencil mask triangle index order (this was causing failing rende…
kubapelc Mar 5, 2024
3cc71ca
Cleanup vertex shader projection interface
kubapelc Mar 6, 2024
cf797bc
Move projection creation function into its own file
kubapelc Mar 9, 2024
d4b861e
Remove getProjectionName
kubapelc Mar 9, 2024
532180d
Added comment for deduplicateWrapped
kubapelc Mar 9, 2024
cdb98ec
Remove unused vertex-buffer-related code from image source
kubapelc Mar 11, 2024
e36c1e9
Add globe raster layer render test
kubapelc Mar 12, 2024
3612661
More render tests - test transition to mercator
kubapelc Mar 12, 2024
667d654
Remove pointless test, add test descriptions
kubapelc Mar 12, 2024
01e84e3
Render test for rendering poles on globe
kubapelc Mar 12, 2024
7d6fdb0
SubdivisionGranularitySetting constructor takes an object
kubapelc Mar 13, 2024
89b568c
Remove "defines" parameter from useProgram
kubapelc Mar 13, 2024
1c9ebb1
Refactor useProgram and Program constructor
kubapelc Mar 13, 2024
23533e8
Properly format translatePosMatrix comment
kubapelc Mar 13, 2024
d1d4960
Refactor globe-specific code outside projection classes, remove stenc…
kubapelc Mar 13, 2024
ff58e89
Refactor granularity settings to be more readable
kubapelc Mar 13, 2024
5f0f31f
Minor refactor of ProjectionErrorMeasurement
kubapelc Mar 13, 2024
d6136a7
Refactor draw_raster.ts
kubapelc Mar 13, 2024
31edcdd
Move globe utility functions to utils.ts, use easeCubicInOut instead …
kubapelc Mar 13, 2024
d2048b4
Simplify imports in globe.ts
kubapelc Mar 13, 2024
a0d8e50
globe.ts refactor
kubapelc Mar 13, 2024
c798bc8
Move ProjectionErrorMeasurement to a separate file
kubapelc Mar 13, 2024
3b392fe
Refactor ProjectionErrorMeasurement
kubapelc Mar 14, 2024
f12d996
Refactor draw_raster.ts
kubapelc Mar 14, 2024
80b4dd3
Refactor globe projection error measurement to not use Painter
kubapelc Mar 14, 2024
fbc654e
Painter.clearStencil creates custom ProjectionData instead of calling…
kubapelc Mar 14, 2024
01e55b1
Remove "deduplicateWrapped" functionality from source_cache.ts
kubapelc Mar 14, 2024
20cdfee
Globe projection no longer requires a map instance
kubapelc Mar 14, 2024
7363ed1
Painter doesn't pass `this` to `updateGPUdependent`
kubapelc Mar 14, 2024
560dd34
isRenderingDirty is now a function
kubapelc Mar 14, 2024
7494c02
Rename ProjectionBase to Projection
kubapelc Mar 14, 2024
79bacd0
Replace globeView property with setGlobeViewAllowed
kubapelc Mar 14, 2024
5054de0
Add mercator and globe projection unit tests
kubapelc Mar 14, 2024
8915b67
Remove tests that test for exact clipping planes
kubapelc Mar 14, 2024
d98921d
Update build test with new bundle size
kubapelc Mar 14, 2024
4526c16
isRenderingDirty is now a function
kubapelc Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/load_geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function loadGeometry(feature: VectorTileFeature): Array<Array<Point>> {
for (let p = 0; p < ring.length; p++) {
const point = ring[p];
// round here because mapbox-gl-native uses integers to represent
// points and we need to do the same to avoid renering differences.
// points and we need to do the same to avoid rendering differences.
const x = Math.round(point.x * scale);
const y = Math.round(point.y * scale);

Expand Down
7 changes: 7 additions & 0 deletions src/geo/lng_lat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ export type LngLatLike = LngLat | {
* @see [Create a timeline animation](https://maplibre.org/maplibre-gl-js/docs/examples/timeline-animation/)
*/
export class LngLat {
/**
* Longitude, measured in degrees.
*/
lng: number;

/**
* Latitude, measured in degrees.
*/
lat: number;

/**
Expand Down
123 changes: 123 additions & 0 deletions src/geo/projection/globe.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import {mat4} from 'gl-matrix';
import {GlobeProjection} from './globe';
import {EXTENT} from '../../data/extent';
import {Transform} from '../transform';
import {expectToBeCloseToArray} from './mercator.test';

describe('GlobeProjection', () => {
describe('getProjectionData', () => {
const globe = new GlobeProjection();

test('fallback matrix is set', () => {
const mat = mat4.create();
mat[0] = 1234;
const projectionData = globe.getProjectionData({
x: 0,
y: 0,
z: 0
}, mat);
expect(projectionData.u_projection_fallback_matrix).toEqual(mat);
});
test('mercator tile extents are set', () => {
const mat = mat4.create();
const projectionData = globe.getProjectionData({
x: 1,
y: 0,
z: 1
}, mat);
expectToBeCloseToArray(projectionData.u_projection_tile_mercator_coords, [0.5, 0, 0.5 / EXTENT, 0.5 / EXTENT]);
});
});

describe('clipping plane', () => {
const globe = new GlobeProjection();

describe('general plane properties', () => {
const mat = mat4.create();
const transform = createMockTransform({
pitchDegrees: 0,
});
globe.updateProjection(transform);
const projectionData = globe.getProjectionData({
x: 0,
y: 0,
z: 0
}, mat);

test('plane vector length', () => {
const len = Math.sqrt(
projectionData.u_projection_clipping_plane[0] * projectionData.u_projection_clipping_plane[0] +
projectionData.u_projection_clipping_plane[1] * projectionData.u_projection_clipping_plane[1] +
projectionData.u_projection_clipping_plane[2] * projectionData.u_projection_clipping_plane[2]
);
expect(len).toBeCloseTo(0.25);
});

test('camera is in positive halfspace', () => {
expect(planeDistance((globe as any)._globeCameraPosition, projectionData.u_projection_clipping_plane)).toBeGreaterThan(0);
});

test('coordinates 0E,0N are in positive halfspace', () => {
expect(testPlaneAgainstLngLat(0, 0, projectionData.u_projection_clipping_plane)).toBeGreaterThan(0);
});

test('coordinates 40E,0N are in positive halfspace', () => {
expect(testPlaneAgainstLngLat(40, 0, projectionData.u_projection_clipping_plane)).toBeGreaterThan(0);
});

test('coordinates 0E,90N are in negative halfspace', () => {
expect(testPlaneAgainstLngLat(0, 90, projectionData.u_projection_clipping_plane)).toBeLessThan(0);
});

test('coordinates 90E,0N are in negative halfspace', () => {
expect(testPlaneAgainstLngLat(90, 0, projectionData.u_projection_clipping_plane)).toBeLessThan(0);
});

test('coordinates 180E,0N are in negative halfspace', () => {
expect(testPlaneAgainstLngLat(180, 0, projectionData.u_projection_clipping_plane)).toBeLessThan(0);
});
});
});
});

function testPlaneAgainstLngLat(lngDegrees: number, latDegrees: number, plane: Array<number>) {
const lat = latDegrees / 180.0 * Math.PI;
const lng = lngDegrees / 180.0 * Math.PI;
const len = Math.cos(lat);
const pointOnSphere = [
Math.sin(lng) * len,
Math.sin(lat),
Math.cos(lng) * len
];
return planeDistance(pointOnSphere, plane);
}

function planeDistance(point: Array<number>, plane: Array<number>) {
return point[0] * plane[0] + point[1] * plane[1] + point[2] * plane[2] + plane[3];
}

function createMockTransform(object: {
center?: {
latDegrees: number;
lngDegrees: number;
};
pitchDegrees?: number;
angleDegrees?: number;
}): Transform {
const pitchDegrees = object.pitchDegrees ? object.pitchDegrees : 0;
return {
center: {
lat: object.center ? (object.center.latDegrees / 180.0 * Math.PI) : 0,
lng: object.center ? (object.center.lngDegrees / 180.0 * Math.PI) : 0,
},
worldSize: 10.5 * 512,
_fov: Math.PI / 4.0,
width: 640,
height: 480,
cameraToCenterDistance: 759,
_pitch: pitchDegrees / 180.0 * Math.PI, // in radians
pitch: pitchDegrees, // in degrees
angle: object.angleDegrees ? (object.angleDegrees / 180.0 * Math.PI) : 0,
zoom: 0,
} as Transform;
}