7

I try to load a scene that's in gltf format. It has metallic and roughness textures (not embedded). Now I want to load the model with the specified textures using Assimp. I retrieve the textures using GetTexture(), but aiTextureType doesn't have members for roughness / metallic.

So the question: How do I import them? Since Assimp supports gltf, it has to support physically based material maps as well somehow.

Thanks

DaOnlyOwner
  • 343
  • 3
  • 8

4 Answers4

7

There are generic PBR material properties since Assimp 5.1.0 that work even for non-glTF files:

// for some formats (like glTF) metallic and roughness may be the same file
aiString fileBaseColor, fileMetallic, fileRoughness;
material->GetTexture(AI_MATKEY_BASE_COLOR_TEXTURE, &fileBaseColor);
material->GetTexture(AI_MATKEY_METALLIC_TEXTURE, &fileMetallic);
material->GetTexture(AI_MATKEY_ROUGHNESS_TEXTURE, &fileRoughness);

Full list here: https://github.com/assimp/assimp/blob/v5.1.4/include/assimp/material.h#L972


Old answer: (deprecated since Assimp 5.1.0)

For GLTF PBR materials you can use the material keys defined in pbrmaterial.h

#include <assimp/pbrmaterial.h>

aiString fileBaseColor, fileMetallicRoughness;
material->GetTexture(AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_BASE_COLOR_TEXTURE, &fileBaseColor);
material->GetTexture(AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE, &fileMetallicRoughness);
pezcode
  • 5,490
  • 2
  • 24
  • 37
2

So if anyone has the same problem: GetTexture(aiTextureType_UNKNOWN) returns a path to the pbr texture.

DaOnlyOwner
  • 343
  • 3
  • 8
2

The combined roughness/metallic texture is aiTextureType_UNKNOWN.

You can see this here: https://github.com/assimp/assimp/blob/master/include/assimp/pbrmaterial.h#L57

The albedo texture (or base color) is aiTextureType_DIFFUSE

The normals is aiTextureType_NORMALS

etc...

(the non-pbr specific stuff seems to be the same naming)

Lord Nikon
  • 172
  • 8
0

So there's no better alternative than getting aiTextureType_UNKNOWN (or most likely AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE) since the mettalic and roughness textures are specified in the same material property metallicRoughnessTexture in the gltf? Like this:

  "images": [
    {
      "uri": "textures/DefaultMaterial_metallicRoughness.png"
    },
    {
      "uri": "textures/DefaultMaterial_baseColor.jpeg"
    },
    {
      "uri": "textures/DefaultMaterial_normal.png"
    }
  ],
  "materials": [
    {
      "doubleSided": true,
      "emissiveFactor": [
        0,
        0,
        0
      ],
      "name": "DefaultMaterial",
      "normalTexture": {
        "index": 2,
        "scale": 1,
        "texCoord": 0
      },
      "pbrMetallicRoughness": {
        "baseColorFactor": [
          1,
          1,
          1,
          1
        ],
        "baseColorTexture": {
          "index": 1,
          "texCoord": 0
        },
        "metallicFactor": 1,
        "metallicRoughnessTexture": {
          "index": 0,
          "texCoord": 0
        },
        "roughnessFactor": 0.86756859760000005
      }
    }
  ],

I tried:

material->GetTexture(AI_MATKEY_METALLIC_TEXTURE, &fileMetallic);
material->GetTexture(AI_MATKEY_ROUGHNESS_TEXTURE, &fileRoughness);

with assimp 5.2.2, but it fails with my glTF test file.

khelkun
  • 159
  • 1
  • 13