This topic describes the ST_MakeMaterial function. This function creates a material object.

Syntax

material ST_MakeMaterial(cstring ambient default NULL,
                         cstring diffuse default NULL,
                         cstring specular default NULL,
                         integer shininess default NULL,
                         integer transparency default NULL,
                         integer texture_index default NULL);
material ST_MakeMaterial(text table_name,
                         text column_name,
                         text key_value,
                         text schema_name default NULL);
material ST_MakeMaterial(cstring attributes,
                         texture[] textures default NULL);

Parameters

Parameter Description
ambient The ambient light color. The value is an RGBA color value, which is represented by using a hexadecimal string. Example: #FF88FF00.
diffuse The diffuse color. The value is an RGBA color value, which is represented by using a hexadecimal string. Example: #FF88FF00.
specular The specular color. The value is an RGBA color value, which is represented by using a hexadecimal string. Example: #FF88FF00.
shininess The glossiness. Valid values: 0 to 100.
transparency The transparency. Valid values: 0 to 100.
texture_index The index of the texture to which the material belongs. Valid values: 0 to 32767.
table_name The name of the table in which the existing material locates.
column_name The name of the column in which the existing material locates.
key_value The ID of the existing material. This parameter is used in the WHERE clause.
schema_name The name of the schema for the existing material. The default value is the schema of the table that is specified in the search path.
attributes The JSON-formatted description of the material. The value is in the form of PBR material description in GL Transmission Format (glTF).
textures The array of textures that are contained in the material.

Description

This function returns a material object.
  • Syntax 1 provides a description for the material based on Open Computing Language (OpenCL). This function eventually converts the OpenCL-type description to a JSON-formatted description.
  • Syntax 2 provides material information that is stored in another table, which can effectively reduce the amount of data mesh and facilitate modifications.
  • Syntax 3 provides a JSON-formatted description for the material.

Examples

  • Syntax 1
    -- form 1
    SELECT ST_AsText(ST_MakeMaterial('#FFDDEEAA', '#FFDDEEAA', '#FFDDEEAA', 30, 70, 2));
    
    --------------------------------------------------------------------------------
    {"type":"raw", "attributes": {"ambient":"#FFDDEEAA","diffuse":"#FFDDEEAA","specular":"#FFDDEEAA","shininess":30,"transparency":70,"texture":2}}
    
    
    -- form 1
    SELECT ST_AsText(ST_MakeMaterial(diffuse => '#FFDDEEAA'));
    
    -------------------------
     {"type":"raw", "attributes": {"diffuse":"#FFDDEEAA"}}
  • Syntax 2
    -- form 2, reference to other material object
     SELECT ST_AsText(ST_MakeMaterial('t_material'::text,
        'the_material'::text,
        'num=1'::text));
     -----------------------------
     {"type":"db", "attributes": {"schema":"public","table":"t_material","column":"the_material","key":"num=1"}}
  • Syntax 3
    -- form3, with PBR json string and textures
    SELECT ST_AsText(ST_MakeMaterial('{"pbrMetallicRoughness": {"baseColorFactor": [ 1.000, 0.766, 0.336, 1.0 ], "metallicFactor": 0.5,"roughnessFactor": 0.1}}',
                                     ARRAY(SELECT the_texture from t_texture)));
    -----------------------------
    {"type":"raw", "textures":[{"compressionType" : "None", "format" : "JPEG", "wrap" : "Wrap", "type" : "Raw", "depth" : 3, "width" : 256, "height" : 256, "size" : 6, "data" : "313233343536"}], "attributes": {"pbrMetallicRoughness":{"baseColorFactor":[1.0,0.766,0.336,1.0],"metallicFactor":0.5,"roughnessFactor":0.1}}}