Skip to content

feat(core): add position preprojection support - #10740

Merged
Pessimistress merged 10 commits into
masterfrom
x/alt-proj-core-plumbing
Oct 6, 2026
Merged

Pessimistress merged 10 commits into
masterfrom
x/alt-proj-core-plumbing

Conversation

@Pessimistress

@Pessimistress Pessimistress commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

For #10739 (PR 1 of 6)

Add the core infrastructure for application-defined coordinate projections.

Changed list

  • Add viewport preprojection hooks and projection-change detection.
  • Transform position attributes and invalidate them when projections change.
  • Integrate preprojection with CPU projection, picking, and shader uniforms.
  • Extend Tesselator position transforms, including binary geometry.
  • Normalize Viewport.distanceScales for consistent behavior (unitsPerDegree -> unitsPerWorldUnit, aligned with shader module uniform names)
  • Add unit coverage for projection and tessellation branches.

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[High risk] Refactors viewport projection and coordinate transformation system.

The PR is not yet safe to merge into its stack because higher PRs still use the removed projection mode.

Findings

  1. P1 Stacked callers use removed mode ▶

Summary

The PR adds core position-preprojection plumbing, projection-aware attribute invalidation, CPU and shader projection handling, tessellation transforms, normalized viewport distance scales, and tests.

  • The changes since the previous review that overlap this PR primarily adjust math.gl imports.
  • No new actionable issue was established.

Reviews (12) · Last reviewed commit: "address comments"

Comment thread modules/core/src/utils/tesselator.ts Resolved
Comment thread modules/core/src/lib/layer.ts Resolved
@greptile-apps

This comment has been minimized.

@coveralls

coveralls commented Sep 24, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 82.729% (+0.1%) from 82.583% — x/alt-proj-core-plumbing into master

Comment thread docs/api-reference/core/layer.md Resolved
Comment thread modules/core/src/utils/tesselator.ts Resolved
@Pessimistress
Pessimistress force-pushed the x/alt-proj-core-plumbing branch from 9796020 to 652227d Compare September 24, 2026 21:44
Comment thread modules/core/src/viewports/viewport.ts Resolved
@Pessimistress
Pessimistress force-pushed the x/alt-proj-core-plumbing branch from fce7860 to 27230f7 Compare September 29, 2026 00:34

@ibgreen ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some notes from a linear readthrough, in case they are helpful

Comment thread docs/upgrade-guide.md Resolved
Comment thread modules/core/src/lib/constants.ts Resolved
Comment thread modules/core/src/lib/layer.ts Outdated
const position: [number, number, number] = [input[0], input[1], input[2] ?? 0];
if (this.props.modelMatrix) {
// Transform the local copy in place without allocating a matrix for each vertex.
vec3.transformMat4(position, position, this.props.modelMatrix);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ideal but perhaps unavoidable to do modelMatrix mults on CPU...

}

if (viewport.projectionMode === PROJECTION_MODE.EXTERNAL) {
if (coordinateSystem === 'cartesian') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing to me. I would naively have expected that coordinateSystem would specify something like external rather than requiring users to match several constants.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use case is not specified by the user. Each layer is exposed to two world coordinate systems on CPU:

  1. world space (fromCrs, used by layer.props.data)
  2. preprojected world space (toCrs, packed into attributes, input to project shader module)

When a composite layer (aggregation layer, tiled layer) passes processed coordinates into sublayers, it needs a way to mark it as already preprojected, to skip another transform. catesian was used here because that's what MVTLayer uses to signal preprojected web-mercator coordinates (note: not common space).

type TesselatorOptions<GeometryT, ExtraOptionsT> = ExtraOptionsT & {
attributes?: Record<string, any>;
getGeometry?: AccessorFunction<any, GeometryT>;
/** Transforms each position after input-space subdivision, before tessellation. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have optimized tesselation in math.gl, a faster version of earcut. Perhaps coordinate support could be included there.

GLOBE: 2,

/** CPU-preprojected XY in common space; Z uses the viewport's distance scale. */
CUSTOM_GEOSPATIAL: 3,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Stacked callers use removed mode When PR #10741 adds CustomProjectionViewport, its projectionMode still returns PROJECTION_MODE.EXTERNAL. This rename removes that member, so the viewport returns undefined instead of the custom projection mode. Contour handling in PR #10743 and scale handling in PR #10745 also compare against the removed member, leaving those projection paths unable to recognize the custom mode. Update those stacked callers along with this rename.

@Pessimistress
Pessimistress force-pushed the x/alt-proj-core-plumbing branch from c939175 to 17b6ac0 Compare October 5, 2026 21:36
@Pessimistress
Pessimistress force-pushed the x/alt-proj-core-plumbing branch from 17b6ac0 to 5c4198f Compare October 5, 2026 22:19
@Pessimistress
Pessimistress merged commit fb72b26 into master Oct 6, 2026
7 checks passed
@Pessimistress
Pessimistress deleted the x/alt-proj-core-plumbing branch October 6, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants