Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

README.md

SVG → Texture Importer

Bakes loose .svg writes into a first-class .texture asset.

What it does

When a .svg file is written loose into the VFS (not already inside a typed-asset folder), this importer:

  1. Rasterizes the SVG via the engine's generic rasterizer (__svg.rasterize → resvg/usvg/tiny-skia → straight-alpha RGBA → PNG), at the SVG's intrinsic viewBox size (clamped to 4096 px, aspect preserved).
  2. Creates a <name>.texture/ asset through asset.create, encoding the baked raster into data.ztex and stamping the texture's settings.yaml.
  3. Moves the original <name>.svg inside that .texture/ folder so the vector source is never lost and stays linked to its baked raster.
logo.svg
  ↓ (write)
logo.texture/
  data.ztex      ← baked raster, encoded
  settings.yaml  ← the texture's settings
  logo.svg       ← original source, moved in

Settings

The importer's settings.luau declares textureSettings — the texture type's settings, embedded — with a declared default of { filter = "nearest", textureType = "sprite" }, so a baked SVG is a crisp sprite (sRGB, with its fully transparent texels filled with their neighbours' colour so filtering never darkens its edges) unless the importer's settings say otherwise. Whatever the group holds is the importer layer of the baked texture's settings, and asset.settings(importerRef).textureSettings reports it.

The resulting .texture is usable anywhere a texture is accepted — bind it to a material slot, hand it to the material toolbox (material.fromTexture(logoTexture)), etc.

Claiming rules

  • Claims any path ending in .svg that is not already inside a .texture/ (so re-writes of the moved-in source don't re-bake).
  • Dispatch, origin-gating (only the originating client bakes in a multiplayer session), content-gating (unchanged bytes are a no-op), and re-entrancy all live in the importer type's shared.module — this importer only implements the format-specific canImport + import pair.

Re-baking

Like every importer, once the source is moved into its asset folder it is quiescent. To re-bake after editing the vector, re-write a loose copy of the .svg (or call the importer explicitly via its AssetRef:run(path)).

Related

  • texture.assetType — the .texture asset this produces.
  • material.toolbox — turn the baked texture into a material in one call.
  • __svg.rasterize — the underlying rasterization capability (Rust).