All Products
Search
Document Center

PolarDB:ST_AsGltf

Last Updated:Mar 28, 2026

Converts an sfmesh object to GL Transmission Format (glTF) 2.0 and returns the result as a text string. Returns NULL if the conversion fails.

Syntax

text ST_AsGltf(sfmesh sfmeshObject);
text ST_AsGltf(sfmesh mesh, cstring options);

The first form converts the object using all default options. The second form accepts a JSON string to control the output structure.

Parameters

ParameterDescription
sfmeshObjectThe sfmesh object to convert.
optionsA JSON string that controls the output. See Options for supported fields.

Options

Pass a JSON string to the options parameter to customize the glTF output. All fields are optional.

FieldDescriptionDefault
with_geometrySpecifies whether to include child meshgeom objects in the output.true
with_submeshSpecifies whether to include child sfmesh objects in the output.true
enable_tile_optionSpecifies whether to apply tile options to child objects. To configure per-object tile behavior, call ST_SetTileOption.false

Examples

Convert an sfmesh object to glTF using default options:

SELECT ST_AsGltf(
  ST_MeshFromText(
    '{"version" : 1, "root" : 0, "meshgeoms" : ["MESHGEOM(PATCH(INDEXSURFACE Z (VERTEX(0 0 2,0 10 3,10 10 1,10 0 1),INDEX((0,1,2),(1,2,3)))))"], "primitives" : [{"meshgeom" : 0}], "nodes" : [{"primitive" : 0}]}'
  )
);

Result (truncated):

{"accessors":[{"bufferView":0,"componentType":5121,"count":6,"max" ....

Convert with with_geometry set to false to exclude child meshgeom objects:

SELECT ST_AsGltf(
  ST_MeshFromText(
    '{"version" : 1, "root" : 0, "meshgeoms" : ["MESHGEOM(PATCH(INDEXSURFACE Z (VERTEX(0 0 2,0 10 3,10 10 1,10 0 1),INDEX((0,1,2),(1,2,3)))))"], "primitives" : [{"meshgeom" : 0}], "nodes" : [{"primitive" : 0}]}'
  ),
  '{"with_geometry":false}'
);

Result:

{"asset":{"generator":"ganos","version":"2.0"},"nodes":[{}]}