ST_SceneFromGLB

更新时间:
复制 MD 格式

Constructs a scene object from a GLB binary input, optionally assigning a spatial reference identifier (SRID), a level of detail (LOD), and an affine transformation.

Syntax

scene ST_SceneFromGlb(bytea glb,
                      integer srid DEFAULT 0,
                      integer lod DEFAULT 0);

scene ST_SceneFromGlb(bytea glb,
                      integer srid,
                      integer lod,
                      float8[] affine);

Use the first overload when no affine transformation is needed. Use the second overload to apply a spatial transformation to every coordinate in the scene.

Parameters

ParameterTypeDefaultDescription
glbbyteaThe GLB object in binary representation.
sridinteger0The SRID. Use 0 when no coordinate reference system is assigned.
lodinteger0The LOD level.
affinefloat8[]An array of affine transformation coefficients. Must contain 12 or 16 elements. If 16 elements are provided, the last four are ignored.

Return value

Returns a scene object. When serialized with ST_AsText, the result is a JSON string with the following structure:

{"type": "gltf", "srid": <srid>, "lod": <lod>, "affine": [...], "content": {...}}

The srid, lod, and affine keys appear only when the corresponding parameters are supplied with non-default values.

Affine transformation

The 12-element affine array maps to a 3×4 transformation matrix as follows:

affine index:  [1]    [2]    [3]    [4]
               [5]    [6]    [7]    [8]
               [9]    [10]   [11]   [12]

Each coordinate (x, y, z) is transformed to (x', y', z') by:

x' = affine[1]*x  + affine[2]*y  + affine[3]*z  + affine[4]
y' = affine[5]*x  + affine[6]*y  + affine[7]*z  + affine[8]
z' = affine[9]*x  + affine[10]*y + affine[11]*z + affine[12]

The first three columns form the rotation/scale matrix. The fourth column (affine[4], affine[8], affine[12]) is the translation vector.

Examples

Construct a scene with no coordinate reference system

SELECT ST_AsText(ST_SceneFromGlb('\x676c544602...'::bytea));

Output:

{"type": "gltf", "content": {"accessors": ...}}

Assign a coordinate reference system

Pass an SRID to locate the scene geometry in a specific coordinate reference system, such as WGS 84 (SRID 4326).

SELECT ST_AsText(ST_SceneFromGlb('\x676c54460...'::bytea, 4326));

Output:

{"type": "gltf", "srid": 4326, "content": {"accessors": ...}}

Set a LOD level

Specify a LOD level to indicate the detail level of the scene geometry.

SELECT ST_AsText(ST_SceneFromGlb('\x676c544602...'::bytea, 4326, 1));

Output:

{"type": "gltf", "srid": 4326, "lod": 1, "content": {"accessors": ...}}

Apply an affine transformation

Apply a uniform scale of 0.5 on the X, Y, and Z axes with a translation of (1, 1, 1):

SELECT ST_AsText(
    ST_SceneFromGlb(
        '\x676c544602...'::bytea,
        4326,
        1,
        ARRAY[0.5, 0, 0, 1,
              0, 0.5, 0, 1,
              0, 0,   0.5, 1]::float8[]
    )
);

Output:

{"type": "gltf", "srid": 4326, "lod": 1, "affine": [0.5,0,0,1,0,0.5,0,1,0,0,0.5,1,0,0,0,1], "content": {"accessors": ...}}

A 12-element array is stored as 16 elements in the output. The last four elements (0,0,0,1) are appended automatically to complete the 4×4 homogeneous matrix.

Related functions

  • ST_AsText — Serialize a scene object to text.