Skip to main content

Module material

Module material 

Source
Expand description

Material decoder: .kmat RON bytes → Box<dyn Material>.

A .kmat file is RON of the shape (type_name: "StandardMaterial", material: ( ...fields... )) — the same { type_name, material } split [material_to_json] produces, but RON-encoded. The type_name selects the matching MaterialRegistration from the open type-tag registry (re-exported from khora-data); that registration’s deserialize_json decodes the material sub-value into the concrete material type. Any material type that registers itself (including plugin types) is therefore loadable from a .kmat with no decoder change.

Decoding goes through serde_json::Value: RON is self-describing, so ron::de::from_bytes::<serde_json::Value> yields a serde value tree from which type_name (a string) and material (a sub-tree) are pulled, and the sub-tree is handed straight to deserialize_json. This reuses the existing serialize_json/deserialize_json machinery the editor inspector already relies on — no second, RON-specific code path on MaterialRegistration.

Auto-registered via inventory::submit! under the canonical "material" slot (the extension mapping kmat|mat → "material" lives in the index builder). No fallback material: a missing type_name, an unknown type, or a decode failure is returned as an error and the caller skips the asset.

Structs§

MaterialDecoder
Decodes a .kmat RON document into a type-erased [Material] via the MaterialRegistration type-tag dispatch.

Functions§

decode_material
Decodes .kmat RON bytes into a [Material] without the runtime AssetService, returning None on any failure.