ST_Materials

更新时间:
复制 MD 格式

Returns the materials stored in an sfmesh object as an array.

Syntax

material[]  ST_Materials(sfmesh sfmesh);

Parameters

ParameterDescription
sfmeshThe sfmesh object from which to extract materials.

Description

ST_Materials extracts the materials array from an sfmesh object and returns it as a material[] array. Each element in the returned array corresponds to one material entry in the sfmesh JSON structure.

Access individual elements using standard PostgreSQL array indexing (1-based). For example, (ST_Materials(...))[1] returns the first material.

Examples

Return all materials

select ST_Materials('{"meshgeoms" : ["MESHGEOM(PATCH(TRIANGLESTRIP(0 0,0 10,10 10,10 0)))"],  "materials":[{"type":"db", "attributes": {"schema":"public","table":"t_material","column":"the_material","key":"num=1"}} ], "textures":[{"compressionType" : "None", "format" : "JPEG", "wrap" : "Wrap", "type" : "DB", "depth" : 3, "width" : 256, "height" : 256, "name" : "texture_name3", "size" : 72, "data" : {"schema":"public","table":"test","column":"the_texture","key":"num=1"}} ],"primitives" : [  {"meshgeom": 0, "material" : 0}],  "nodes" : [    {"primitive" : 0} ] }'::sfmesh);

Output:

 {010102FFDDEEAA}

Access a material by index

-- Array elements by index
select (ST_Materials('{"meshgeoms" : ["MESHGEOM(PATCH(TRIANGLESTRIP(0 0,0 10,10 10,10 0)))"],  "materials":[{"type":"db", "attributes": {"schema":"public","table":"t_material","column":"the_material","key":"num=1"}} ], "textures":[{"compressionType" : "None", "format" : "JPEG", "wrap" : "Wrap", "type" : "DB", "depth" : 3, "width" : 256, "height" : 256, "name" : "texture_name3", "size" : 72, "data" : {"schema":"public","table":"test","column":"the_texture","key":"num=1"}} ],"primitives" : [  {"meshgeom": 0, "material" : 0}],  "nodes" : [    {"primitive" : 0} ] }'::sfmesh))[1];

Output:

 010102FFDDEEAA