Esc

gltf_set_extension

procedureextensionsince 0.36.1Source
  • macOS: gltf_set_extension works on macOS
  • Linux: gltf_set_extension works on Linux
  • Windows: gltf_set_extension works on Windows
  • Wasm: gltf_set_extension works on Wasm

Store a typed extension in the extensions of a document, node, material or texture reference, replacing the extension of that name: the write-back of gltf_extension. An extensions that is absent becomes an object. The value is encoded straight away, so it may be freed or changed afterwards. An extensions that is not an object gives an error and is left unchanged. Declare the extension with gltf_use_extension, or the written asset will not load.

Signature

gltf_set_extension :: (
    extensions: *Json_Value,
    name: string,
    value: $T
) -> Gltf_Error
Example↗
asset, error := gltf_load("{\"asset\":{\"version\":\"2.0\"},\"extensionsUsed\":[\"KHR_materials_ior\"],\"materials\":[{\"extensions\":{\"KHR_materials_ior\":{\"ior\":1.33}}}]}");
assert(error.kind == .NONE);
defer gltf_free(*asset);
extensions := *asset.document.materials[0].extensions;
ior, _, _ := gltf_extension(extensions, "KHR_materials_ior", Gltf_Ior);
ior.ior = 2.4;
set_error := gltf_set_extension(extensions, "KHR_materials_ior", ior);
assert(set_error.kind == .NONE);
again, _, _ := gltf_extension(extensions, "KHR_materials_ior", Gltf_Ior);
assert(again.ior == 2.4);

See also