Service APIs for creating virtual avatars
  • Welcome
    • Overview
    • About us
    • Glossary
  • What's New
    • Changelog
    • Subscribe for updates
  • EXAMPLES
    • 3D model from single photo
  • Getting started
    • Introduction
    • Getting a token
    • 3D Face Reconstruction
    • 3D Hair Reconstruction
    • GLB Constructor
      • Easy - Head Visualization
      • Advanced - Schema preparation
      • Advanced - Assembling
  • API Methods
    • 3D Face Reconstruction
      • Bad Case Examples
    • 3D Hair Reconstruction
    • GLB Constructor
  • Errors
    • 3D Face Reconstruction
    • 3D Hair Reconstruction
    • GLB Constructor
  • API Metrics
    • SLA
Powered by GitBook
On this page
  • 1. Getting a token
  • 2. Creating a schema
  • 4. Uploading GLB models
  1. Getting started
  2. GLB Constructor

Advanced - Schema preparation

PreviousEasy - Head VisualizationNextAdvanced - Assembling

Last updated 2 years ago

1. Getting a token

2. Creating a schema

You must describe all your types and model IDs in a JSON file. For example, you have 2 types of models - body and hair. The JSON structure will then look like this:

schema.json
{
	"hair" : [ # <- model type
		"hairM_01", "hairF_01" # <- model id
	],
	"body": [
		"body_01", "body_02", "body_03"
	]
}

In this example, 5 models are declared: 2 body IDs and 3 hairstyle IDs.

You can also leave the JSON empty, then when assembled, only the head will be generated.

schema.json
{
}

Note: You can't do nested model types. there are only 2 levels: types and IDs.

Sending your schema.

token="ENTER_YOUR_TOKEN"
schema_path="ENTER_SCHEMA_PATH"

curl -X 'PUT' \
  'https://api.metahumansdk.io/glb_const/schema' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F "token=$token" \
  -F "schema=@$schema_path;type=application/json"
import requests

schema_path = "ENTER_SCHEMA_PATH"
token = "ENTER_YOUR_TOKEN"

if __name__ == "__main__":
    service_url = "https://api.metahumansdk.io/glb_const"
    service_headers = {"accept": "application/json"}

    files = {
        "token": (None, token),
        "schema": ("schema.json", open(schema_path, 'r'), "application/json")
    }
    response = requests.put(service_url + "/schema", headers=service_headers, files=files)
    assert (response.status_code == 200)
    assert ('result' in response.json())
    print(response.json())

You should get:

{
  "result": {
    "status": "schema loaded successfully"
  }
}

4. Uploading GLB models

You must add all the models declared in the schema.

Sending your GLB file.

Note: To calculate the hash you can use the command sha256sum in the terminal.

Note: If you want the texture with the skin color to be automatically repainted in the color taken from the face, the name of this material should contain "skin". The "baseColorFactor" component of the material is repainted.

token="ENTER_YOUR_TOKEN"
glb_path="ENTER_GLB_PATH"
glb_hash="ENTER_GLB_HASH"
data_type="ENTER_DATA_TYPE"
data_id="ENTER_DATA_ID"

curl -X 'PUT' \
  'https://api.metahumansdk.io/glb_const/glb' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F "token=$token" \
  -F "data=@$glb_path" \
  -F "sha256=$glb_hash" \
  -F "data_type=$data_type" \
  -F "data_id=$data_id"
import requests

token="ENTER_YOUR_TOKEN"
glb_path="ENTER_GLB_PATH"
glb_hash="ENTER_GLB_HASH"
data_type="ENTER_DATA_TYPE"
data_id="ENTER_DATA_ID"

if __name__ == "__main__":
    service_url = "https://api.metahumansdk.io/glb_const"
    service_headers = {"accept": "application/json"}
    files = {
        "token": (None, token),
        "data": ("model", open(glb_path, "rb"), "model/gltf-binary"),
        "sha256": (None, glb_hash),
        "data_type": (None, data_type),
        "data_id": (None, data_id)
    }
    response = requests.put(service_url + "/glb", headers=service_headers, files=files)
    assert (response.status_code == 200)
    assert ('result' in response.json())
    print(response.json())

You should get:

{
  "result": {
    "status": "model loaded successfully"
  }
}

Getting a token