ST_MaterialFromText

更新时间:
复制 MD 格式

Constructs a material object from its text representation.

Syntax

material ST_MaterialFromText(text text);

Parameters

ParameterDescription
textThe material object in text representation, as returned by ST_AsText. Example: '{"type":"raw", "attributes": {"ambient":"#ffddeeaa"}}'

Description

ST_MaterialFromText is the inverse of ST_AsText: it takes the JSON string that ST_AsText produces and reconstructs the original material object. For details on material object structure, see ST_MakeMaterial.

Examples

The following example passes a JSON literal directly to show the expected input format:

SELECT ST_MaterialFromText('{"type":"raw", "attributes": {"ambient":"#ffddeeaa"}}');

The following example demonstrates a full round-trip: serialize a material object to text with ST_AsText, then reconstruct it with ST_MaterialFromText:

-- Serialize then deserialize
SELECT ST_AsText(
  ST_MaterialFromText(
    ST_AsText(ST_MakeMaterial(ambient => '#FFDDEEAA'))
  )
);

Output:

{"type":"raw", "attributes": {"ambient":"#ffddeeaa"}}

See also

  • ST_AsText — serializes a material object to its text representation

  • ST_MakeMaterial — constructs a material object from individual attributes