Skip to content

feat: Load font assets only through featureFontAssets - #10229

Merged
mvaligursky merged 3 commits into
main-v3from
mv-font-assets-feature
Dec 4, 2026
Merged

mvaligursky merged 3 commits into
main-v3from
mv-font-assets-feature

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Font assets now load through a feature, featureFontAssets, rather than by listing FontHandler in AppOptions#resourceHandlers. The feature also brings the shader chunks of multi-channel signed distance field (MSDF) text, which the core shader chunks no longer include. Part of #10055, following featureTextureAssets (#10228).

Changes:

  • Added featureFontAssets, which registers the font handler, unless the application registered its own, and adds the MSDF text shader chunks. It requires featureTextureAssets, which loads the texture pages of the fonts.
  • Moved the msdfPS and msdfVS chunks out of the core GLSL and WGSL chunk collections into the font assets feature, the same way area lights, shadows and particles bring their chunks.
  • The playcanvas/webgl and playcanvas/webgpu entry points bind featureFontAssets to their device, so an application built from one does not bundle the MSDF chunks of the other shader language.
  • Loading a font asset without the feature reports, in debug builds, that featureFontAssets is needed.
  • An application that loads no font assets, including one with text elements using a CanvasFont, no longer bundles the font handler, Font or the MSDF chunks.

API Changes:

  • New: featureFontAssets.
  • FontHandler is still exported, for its type, but it is registered by featureFontAssets rather than listed in AppOptions#resourceHandlers.
// before
options.resourceHandlers = [TextureHandler, FontHandler];

// after
options.features = [featureTextureAssets, featureFontAssets];

Examples:

  • All 55 examples that listed FontHandler now list featureFontAssets in their features instead.

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 font-assets exemption needs clarification because manually constructed MSDF fonts still require the feature’s shader chunks, while CanvasFont does not.

1 open issue
What changed in this PR

Moves font loading and MSDF shader chunks into featureFontAssets, continuing the engine’s tree-shakable feature migration.

Changes:

  • Adds font registration with a texture-feature dependency and device-specific shader chunks.
  • Updates exports, diagnostics, documentation, and 55 examples.
  • Adds feature, export, and tree-shaking tests.
File Description
test/​framework/​features/​feature-font-assets.test.mjs Tests font feature installation and diagnostics.
test/​bundles/​treeshake.test.mjs Checks font code and shader tree-shaking.
test/​bundles/​exports.test.mjs Checks device-specific feature exports.
test/​app.mjs Uses the font feature in test setup.
src/​scene/​shader-lib/​wgsl/​collections/​shader-chunks-wgsl.js Removes MSDF chunks from core WGSL.
src/​scene/​shader-lib/​wgsl/​collections/​msdf-chunks-wgsl.js Adds the WGSL MSDF collection.
src/​scene/​shader-lib/​glsl/​collections/​shader-chunks-glsl.js Removes MSDF chunks from core GLSL.
src/​scene/​shader-lib/​glsl/​collections/​msdf-chunks-glsl.js Adds the GLSL MSDF collection.
src/​index.js Exports featureFontAssets.
src/​index-webgpu.js Exports the WebGPU variant.
src/​index-webgl.js Exports the WebGL variant.
src/​framework/​handlers/​loader.js Adds missing-font-feature guidance.
src/​framework/​handlers/​font.js Documents feature-based registration.
src/​framework/​features/​feature-font-assets.js Defines font registration and shader dependencies.
src/​framework/​features/​constants.js Adds the font feature identifier.
examples/​src/​examples/​xr/​xr-ui/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​xr/​xr-menu/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​xr/​vr-test-bed/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​xr/​ar-plane-detection/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​xr/​ar-mesh-detection/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​world-ui/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​world-to-screen/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text-typewriter/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text-markup/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text-localization/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text-justify/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text-emojis/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​text-auto-font-size/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​scroll-view/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​screen-scaling/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​render-to-image/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​particle-system/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​panel/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​masking/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​layout-group/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​input-events/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​image-fit/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​drag-and-drop/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​custom-shader/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​common-widgets/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​buttons/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​user-interface/​anchors/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​text-markup/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​render-target-orientation/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​opacity/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​material-instance-overrides/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​lightmap-sources/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​environment-sources/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​element-states/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​element-colors/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​test/​alpha-to-coverage/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​render-targets/​multi-render-targets/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​physics/​raycast/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​physics/​falling-shapes/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​physics/​compound-collision/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​misc/​multi-app/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​materials/​material-transparency/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​materials/​material-translucent-specular/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​materials/​material-physical/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​materials/​material-anisotropic/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​loaders/​compressed-meshes/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​graphics/​asset-viewer/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​gaussian-splatting/​vr-lod/​example.mjs Uses the feature for HUD fonts.
examples/​src/​examples/​demos/​splash-one/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​demos/​catapult/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​camera-frame/​post-processing/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​camera-frame/​hdr/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​camera-frame/​ambient-occlusion/​example.mjs Migrates font registration to the feature.
examples/​src/​examples/​animation/​tween/​example.mjs Migrates font registration to the feature.

Review effort: Balanced

Comment on lines +56 to +57
* to load font assets. Fonts created in code, such as a {@link CanvasFont}, do not need it. It
* brings {@link featureTextureAssets}, which loads the texture pages of the fonts.
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Public API report

This PR changes the public API surface (+1 / −0), per the docs' rules (@ignore / @Private / undocumented are excluded).

Show API diff
+const featureFontAssets: Feature

Informational only — this never fails the build.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip
playcanvas.min.js +603 B (+0.02%) +111 B (+0.01%)
playcanvas.min.mjs +581 B (+0.02%) +173 B (+0.02%)

Measured on a min build with identifier mangling off. In the shipped build esbuild renames identifiers by use count across the whole bundle, so any change reshuffles names file-wide and moves gzip/brotli by hundreds of bytes regardless of the actual change.

Shipped bundle sizes with this PR
Bundle Minified Gzip Brotli
playcanvas.min.js 2948.3 KB 801.6 KB 628.2 KB
playcanvas.min.mjs 2945.1 KB 800.6 KB 627.8 KB

@mvaligursky
mvaligursky merged commit b37f60a into main-v3 Dec 4, 2026
9 checks passed
@mvaligursky
mvaligursky deleted the mv-font-assets-feature branch December 4, 2026 18:41
@mvaligursky mvaligursky mentioned this pull request Dec 4, 2026
9 of 43 tasks

This branch was successfully deployed

2 active deployments
Preview – engine — fd29339e Deployed Dec 4, 2026 by vercel[bot]
Preview – engine-api-docs — fd29339e Deployed Dec 4, 2026 by vercel[bot]
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.

2 participants