Imports an OBJ file from an Object Storage Service (OSS) bucket or binary stream into a database.
Syntax
boolean ST_ImportObj(text table_name, text url, text id, text options default '{}');
boolean ST_ImportObj(text table_name, bytea content, text id, text options default '{}');Return values
| Return value | Description |
|---|---|
| true | The file was imported successfully. |
| false | The file failed to import. |
Parameters
| Parameter | Type | Description |
|---|---|---|
| table_name | text | The name of the OBJ table and the prefix of the corresponding sharded table. |
| url | text | The path of the OBJ file in an OSS bucket. |
| content | bytea | The OBJ file as a binary stream. |
| id | text | The ID of the OBJ file. |
| options | text | Import options as a JSON string. Defaults to {}. See Import options for valid keys. |
Limitations
Only diffusetexture type textures are supported. Texture files of other types are ignored during import.
Import options
Pass options as a JSON string to the options parameter.
| Option | Type | Default | Description | Example |
|---|---|---|---|---|
| schema | string | public | The schema of the target table. | postgres |
| search_path | string | Parent path of the OBJ file URL; empty if content is used. | The search path for material and texture files. | OSS://foo/bar |
| ignore_missing | Boolean | true | Specifies whether to ignore errors when material or texture files are not found. | false |
| force_triangulate | Boolean | true | Specifies whether to force triangulation of non-triangular faces. | false |
| metallic_roughness | Boolean | true | Specifies whether to parse materials as metallic_roughness type. Set to false to parse as specular_glossiness type. | true |
| obj_data_column | string | obj_data | The data field name in the primary table. | my_data |
| obj_id_column | string | obj_id | The ID field name in the primary table. | my_id |
Table schemas
ST_ImportObj creates three tables on import: a primary table, a component table, and a texture table.
Primary table
| Field | Type | Description |
|---|---|---|
| id | serial | The primary key. |
| [obj_id_column] | text | The ID of the data record. Field name is configurable via obj_id_column; defaults to obj_id. |
| [obj_data_column] | sfmesh | The mesh data. Field name is configurable via obj_data_column; defaults to obj_data. |
Component table
| Field | Type | Description |
|---|---|---|
| id | serial | The primary key. |
| obj_id | text | The ID of the data record. Fixed field name. |
| component_id | text | The sequence number of the component in the original OBJ file. |
| name | text | The group or object name of the OBJ file. If multiple names exist, the first is used. Defaults to Mesh_[object sequence number]. |
| tags | jsonb | The tags of the OBJ file. |
| component | sfmesh | The component name. |
Texture table
| Field | Type | Description |
|---|---|---|
| id | serial | The primary key. |
| obj_id | text | The ID of the data record. Fixed field name. |
| texture_id | text | The sequence number of the texture in the original OBJ file. |
| name | text | The file name of the texture. |
| texture | texture | The texture name. |
Examples
Import an OBJ file from OSS
SELECT ST_ImportObj('test_obj', 'OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/path_to_obj.obj');Returns:
---------
tImport with forced triangulation disabled
SELECT ST_ImportObj('test_obj', 'OSS://<ak>:<ak_secret>@oss-cn-beijing-internal.aliyuncs.com/mybucket/path_to_obj.obj', '{"force_triangulate": false}');Returns:
---------
t