Converts an sfmesh object to GLB, the binary format of GL Transmission Format (glTF) 2.0. Returns NULL if the conversion fails.
Syntax
bytea ST_AsGlb(sfmesh sfmeshObject);
bytea ST_AsGlb(sfmesh sfmeshObject, json options);Parameters
| Parameter | Type | Description |
|---|---|---|
sfmeshObject | sfmesh | The sfmesh object to convert. |
options | JSON | glTF export options. See Options for details. |
Options
Pass options as a JSON object. All fields are optional.
| Field | Type | Default | Description |
|---|---|---|---|
draco_compress | boolean | false | Applies Draco compression to the output. Use this to reduce file size when the client supports Draco-encoded GLB. |
with_geometry | boolean | true | Includes the child meshgeom object in the output. Set to false to omit geometry data. |
with_submesh | boolean | true | Includes child sfmesh objects in the output. Set to false to flatten the hierarchy. |
enable_tile_option | boolean | false | Applies the tile option to child objects. Configure tile behavior using ST_SetTileOption before conversion. |
Examples
Basic conversion
Convert an sfmesh object to GLB with default settings.
SELECT ST_AsGlb(
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:
\x676c54460200000028040000a40300004a534f4e7b226163636573736f7273223a5 ......With Draco compression
Apply Draco compression to reduce output size. The client must support Draco-encoded GLB.
SELECT ST_AsGlb(
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}]}'
),
'{"draco_compress": true, "with_geometry": true}'
);Result:
\x676c544602000000840300000c0300004a534f4e7b226173736574223a7b2276657273696f6e223a22322e3 ...See also
ST_MeshFromText — Creates an sfmesh object from a text representation
ST_SetTileOption — Configures the tile option used with
enable_tile_option