Skip to content

docs: Add @typegpu/geometry docs with interactive previews - #2998

Open
reczkok wants to merge 22 commits into
feat/geometry-patchesfrom
docs/geometry
Open

reczkok wants to merge 22 commits into
feat/geometry-patchesfrom
docs/geometry

Conversation

@reczkok

@reczkok reczkok commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Adds a guide for @typegpu/geometry, covering mesh creation, composition and the different ways to evaluate and update geometry

  • primitives, parametric surfaces + custom geometry
  • transform, concat and custom vertex attributes
  • bake into buffers, evaluate in vertex shaders or update through compute
  • interactive previews for subdivisions, surface parameters, vertex colors and deformation
  • smooth, flat and wireframe shading to inspect the results

Stacks on #3014

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/eslint-plugin-typegpu@22b4ea421e804efab022f7afa193e40eaa207297
https://pkg.pr.new/software-mansion/TypeGPU/tinyest@22b4ea421e804efab022f7afa193e40eaa207297
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@22b4ea421e804efab022f7afa193e40eaa207297
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@22b4ea421e804efab022f7afa193e40eaa207297
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@22b4ea421e804efab022f7afa193e40eaa207297
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@22b4ea421e804efab022f7afa193e40eaa207297

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 360 0 0

No notable changes.

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.54, 1.05, 2.28, 3.07, 3.89, 7.04, 12.63, 16.46]
  line [0.42, 0.86, 1.95, 3.21, 3.97, 6.37, 13.93, 15.11]
  line [0.41, 0.85, 1.86, 3.42, 3.53, 6.33, 12.21, 12.93]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.13, 0.23, 0.38, 0.43, 0.61, 0.61, 0.75, 0.82]
  line [0.12, 0.22, 0.30, 0.36, 0.51, 0.50, 0.65, 0.72]
  line [0.09, 0.21, 0.26, 0.35, 0.50, 0.53, 0.61, 0.69]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.67, 1.36, 2.03, 3.61, 6.98, 15.09, 30.69, 66.59]
  line [0.63, 1.41, 1.92, 3.59, 7.03, 15.35, 30.64, 63.00]
  line [0.61, 1.12, 2.00, 3.65, 6.04, 13.35, 29.89, 57.89]
Loading

@reczkok
reczkok removed this pull request from stack #2999 September 9, 2026 14:49
@reczkok
reczkok changed the base branch from feat/geometry-meshes to feat/geometry-patches September 9, 2026 14:50
@reczkok
reczkok added this pull request to stack #3015 September 9, 2026 14:50
@reczkok
reczkok force-pushed the docs/geometry branch 2 times, most recently from 211795a to 86df052 Compare October 22, 2026 11:58
@reczkok
reczkok marked this pull request as ready for review October 22, 2026 13:00
Copilot AI balanced review requested due to automatic review settings October 22, 2026 13:00

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

This run reviewed the full @typegpu/geometry docs PR against its stacked base feat/geometry-patches, including the interactive preview runtime and its regression test.

  • Docs guide (typegpu-geometry.mdx) — 558-line guide covering primitives, parametric surfaces, triangular patches, custom geometry, combinators, baking/updating and lines/joins/caps; prose claims spot-checked against packages/typegpu-geometry/src.
  • Preview viewer (viewer.ts, renderer.ts, shaders.ts, demos.ts) — shared-root WebGPU viewer with visibility/pause gating, per-schema pipeline caching, deferred resource cleanup and five demo scenes.
  • React shell (MeshPreview.tsx) — param/shading/pause controls plus loading and error states.
  • Docs nav (astro.config.mjs) — DEV-gated @typegpu/geometry sidebar entry with a dev badge.
  • Regression test (mesh-preview.test.ts) — pins that a bake in flight at disposal submits before its uniforms are destroyed.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The line-rendering example leaves its control points uninitialized, so it renders no visible line.

1 open issue
What changed in this PR

Adds an @typegpu/geometry guide with interactive mesh previews, extending the documentation to cover the triangular patches introduced in #3014.

Changes:

  • Documents primitives, composition, custom attributes, mesh evaluation and updates, and line rendering.
  • Adds configurable previews with smooth, flat, and wireframe shading.
  • Adds a disposal regression test and development-only sidebar navigation.
File Description
apps/​typegpu-docs/​tests/​individual-example-tests/​mesh-preview.test.ts Tests disposal while asynchronous baking is pending.
apps/​typegpu-docs/​src/​content/​docs/​ecosystem/​typegpu-geometry.mdx Adds the geometry guide and embedded previews.
apps/​typegpu-docs/​src/​components/​geometry/​viewer.ts Manages preview state, animation, baking, and cleanup.
apps/​typegpu-docs/​src/​components/​geometry/​shaders.ts Defines lighting and shading modes.
apps/​typegpu-docs/​src/​components/​geometry/​renderer.ts Handles render pipelines, camera updates, and depth textures.
apps/​typegpu-docs/​src/​components/​geometry/​MeshPreview.tsx Adds preview controls and visibility handling.
apps/​typegpu-docs/​src/​components/​geometry/​demos.ts Defines configurable geometry demonstrations.
apps/​typegpu-docs/​astro.config.mjs Adds the development-only geometry sidebar entry.

Review effort: Balanced

@reczkok
reczkok force-pushed the docs/geometry branch 2 times, most recently from 286afb9 to ffef34c Compare October 28, 2026 23:29

@aleksanderkatan aleksanderkatan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice and extensive docs with really cool visuals! I like the wireframe view

I leave some small suggestions, and potential tweaks to the geomery API.
I only skimmed the geometry component files.

Comment on lines +532 to +553

## Available utilities

Line utilities are exported from the package root:

| Group | Exports |
| --- | --- |
| Drawing | `polylineVariableWidth`, `lineVariableWidth`, `LineControlPoint`, `LineSegmentOutput` |
| Indices | `lineSegmentIndices`, `lineSegmentWireframeIndices`, `lineSegmentLeftIndices` |
| Joins and caps | `joins`, `caps`, `joinSlot`, `startCapSlot`, `endCapSlot`, `miterJoinLimitSlot`, `arrowCapParamsSlot`, `JoinInput` |

Mesh utilities live under the `meshes` namespace:

| Group | Exports |
| --- | --- |
| Primitives | `sphere`, `plane`, `box`, `cylinder`, `torus`, `icosphere`, `capsule`, `roundedBox` |
| Surfaces | `parametric`, `surfaces`, `patches.icosphere`, `patches.capsule`, `patches.roundedBox` |
| Tessellation | `tessellate`, `triangleBarycentrics`, `triangleIndexAt`, `triangleIndices`, `triangleVertexCount`, `triangleIndexCount` |
| Spherical interpolation | `patches.linear`, `patches.uniformArea` |
| Combinators | `transform`, `map`, `attach`, `concat`, `unindexed` |
| Buffers | `bake`, `bakeAsync`, `bakeIndices`, `bakeIndicesAsync`, `UpdateOptions`, `RecordOptions` |
| Schema and type guard | `Surface`, `isIndexed` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I don't think this table is too useful, and I think it will become outdated quickly.
I may be good to include this in a geometry skill if we ever make one

Suggested change
## Available utilities
Line utilities are exported from the package root:
| Group | Exports |
| --- | --- |
| Drawing | `polylineVariableWidth`, `lineVariableWidth`, `LineControlPoint`, `LineSegmentOutput` |
| Indices | `lineSegmentIndices`, `lineSegmentWireframeIndices`, `lineSegmentLeftIndices` |
| Joins and caps | `joins`, `caps`, `joinSlot`, `startCapSlot`, `endCapSlot`, `miterJoinLimitSlot`, `arrowCapParamsSlot`, `JoinInput` |
Mesh utilities live under the `meshes` namespace:
| Group | Exports |
| --- | --- |
| Primitives | `sphere`, `plane`, `box`, `cylinder`, `torus`, `icosphere`, `capsule`, `roundedBox` |
| Surfaces | `parametric`, `surfaces`, `patches.icosphere`, `patches.capsule`, `patches.roundedBox` |
| Tessellation | `tessellate`, `triangleBarycentrics`, `triangleIndexAt`, `triangleIndices`, `triangleVertexCount`, `triangleIndexCount` |
| Spherical interpolation | `patches.linear`, `patches.uniformArea` |
| Combinators | `transform`, `map`, `attach`, `concat`, `unindexed` |
| Buffers | `bake`, `bakeAsync`, `bakeIndices`, `bakeIndicesAsync`, `UpdateOptions`, `RecordOptions` |
| Schema and type guard | `Surface`, `isIndexed` |


Every option has a default, so `meshes.box()` is a unit cube and `meshes.torus()` a ring that fits the same space.
Options ending in `Segments` count the subdivisions along one direction: `radialSegments` around the vertical axis of a sphere or cylinder, `heightSegments` from top to bottom. The `segments` option of `icosphere`, `capsule` and `roundedBox` subdivides each edge of their [triangular patches](#triangular-patches).
Switch the previews to **Wireframe** to inspect their triangles. **Pause animation** freezes both rotation and deformation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I don't see any deformation in this preview, can we move this note to previews below?

<MeshPreview client:visible demo="primitives" />

Primitives use the `Surface` schema: `position: d.vec3f`, `normal: d.vec3f` and `uv: d.vec2f`. Normals point outwards. UVs follow each surface's parametrization.
`capsule.height` is the length of its straight section, excluding the caps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: This sentence seems misplaced to me
I think it belongs in JSDoc

Suggested change
`capsule.height` is the length of its straight section, excluding the caps.


<MeshPreview client:visible demo="primitives" />

Primitives use the `Surface` schema: `position: d.vec3f`, `normal: d.vec3f` and `uv: d.vec2f`. Normals point outwards. UVs follow each surface's parametrization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we already mention UVs, how about we add a UV view?

image

Normals view would also be interesting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good idea, leaving it for a follow-up

const ball = meshes.sphere();
const pole = ball.vertexAt(0);

console.log(pole.position, pole.normal, pole.uv);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
console.log(pole.position, pole.normal, pole.uv);
console.log(`${pole.position} ${pole.normal} ${pole.uv}`);
// vec3f(0, 0.5, 0) vec3f(0, 1, 0) vec2f(0, 0)

Vertex updates leave indices unchanged. They reuse the pipeline and bindings prepared by `bake`, including on the first update.
Counts and schemas are fixed at bake time. To change the number of subdivisions, create and bake a new geometry.

Without options, an update submits its own compute work. Use `{ encoder }` to record it as one compute pass alongside draws before submitting, or `{ pass }` for an open compute pass. Pass one or the other, not both. Updates leave the encoder or pass open. `bake` and `bakeIndices` accept these options for the initial fill too, as `@typegpu/sort` does for its `run()`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sort is not yet published, we should make sure to wait with this doc until it is published, or publish sort soon after

Vertex updates leave indices unchanged. They reuse the pipeline and bindings prepared by `bake`, including on the first update.
Counts and schemas are fixed at bake time. To change the number of subdivisions, create and bake a new geometry.

Without options, an update submits its own compute work. Use `{ encoder }` to record it as one compute pass alongside draws before submitting, or `{ pass }` for an open compute pass. Pass one or the other, not both. Updates leave the encoder or pass open. `bake` and `bakeIndices` accept these options for the initial fill too, as `@typegpu/sort` does for its `run()`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: types already forbid that

Suggested change
Without options, an update submits its own compute work. Use `{ encoder }` to record it as one compute pass alongside draws before submitting, or `{ pass }` for an open compute pass. Pass one or the other, not both. Updates leave the encoder or pass open. `bake` and `bakeIndices` accept these options for the initial fill too, as `@typegpu/sort` does for its `run()`.
Without options, an update submits its own compute work. Use `{ encoder }` to record it as one compute pass alongside draws before submitting, or `{ pass }` for an open compute pass. Updates leave the encoder or pass open. `bake` and `bakeIndices` accept these options for the initial fill too, as `@typegpu/sort` does for its `run()`.


If the source accesses resources through a [bind group layout](/TypeGPU/apis/bind-groups/), pass the bind groups to `bake` through `{ bindGroups }`.
Updates keep using them, and `{ bindGroups }` on an update swaps them for that one call.
For [slots](/TypeGPU/apis/slots/) and [accessors](/TypeGPU/apis/accessors/), pass a configured pipeline builder, for example `{ with: root.with(heightAccess, heightUniform) }`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we could use config?: (cfg: Configurable) => Configurable instead of with in this API?

setPaused(window.matchMedia('(prefers-reduced-motion: reduce)').matches);

createMeshViewer(canvas, (value) => {
if (!disposed) setState(value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I keep seeing braceless ifs across different PRs, do we really want to keep the convention of no braceless ifs?
If so, we can enforce it easily via one line in oxlint config. We'll also be able to add missing blocks to all ifs via nr fix.
Otherwise, I think that we could clean up a lot of existing code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, braced these, a repo-wide curly rule fits better in its own PR

A miter longer than `miterJoinLimitSlot` times the radius, 2 by default, bends back towards a bevel. `arrowCapParamsSlot` sets the arrow's length, width and slant, relative to the radius.
A custom join or cap is a `'use gpu'` function with the same signature, `(join: JoinInput, joinVertexIndex: number, maxJoinCount: number) => d.v2f`. For index 0 it returns the segment's own corner, `join.v`. Indices 1 to `maxJoinCount` fan out from that corner around the control point `join.C`.

The [Lines Combinations](/TypeGPU/examples#example=geometry--lines-combinations) example shows every join and cap.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we link to a dev example in docs?

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound — the new commits are review-driven docs and preview polish, and the only behavior change is an integer twist step that removes the UV seam.

Reviewed changes

This run re-reviewed the delta since the prior pullfrog review: the author's response to the human review, synced with the base package's uvSphere rename and new config bake option.

  • uvSphere rename — the guide and previews now call meshes.uvSphere, matching the base package; meshes.surfaces.sphere is still a valid export and remains correctly referenced.
  • config bake option — the slot/accessor guidance now uses { config: (cfg) => cfg.with(...) }, which BakeOptions provides in the base package.
  • Seam-safe twist slider — the stripes preview steps twist by whole turns, so the torus UV seam stays continuous.
  • Review-driven prose cleanup — the utilities tables, the @typegpu/sort comparison, the "pass one or the other" note and the lines-combinations link are gone; the pause note now sits under the deformation preview; patch primitives are described as examples rather than an exhaustive list.
  • Brace cleanup — every single-statement if in the preview components is braced; oxlint --type-aware and oxfmt --check pass on the changed files.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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