Textures are rescaled on glb export

Hello guys :slight_smile:
I am currently experiencing some issues with the glb exporter (GLTF2Export.GLBAsync). When I export my scene to a .glb file then the UV Scaling of only my AO-Textures is reset to (1,1). I read about a similar problem here, but I could not find a real solution in this conversation. Sadly, I also can not provide a PG at the moment nor upload a scene example because the glb file is to big. Sry I can fully understand if this is to little information to go by… :frowning:

This is the texture before exporting

This is the texture after exporting…
image

Note that the base color texture file and the normal texture file perfectly keep their UV scaling on export. Only the AO Texture file gets its scaling reset.

I am currently exporting the scene like this (I have to filter out quite a lot of stuff, that’s why the recursion is needed)

export(): void {
    const options = {
      shouldExportNode: (node: TransformNode): boolean => {
        return nameInHierarchy(node);
      },
    };

    const nameInHierarchy = (node: TransformNode): boolean => {
      if (node.name === 'apartment' || node.name === 'foundation' || node.name === 'diffuse-light') {
        return true;
      }
      if (node.parent) {
        return nameInHierarchy(node.parent as TransformNode);
      }
      return false;
    };

    void GLTF2Export.GLBAsync(this.scene, 'Wohneinheit_Export', options).then(glb => {
      glb.downloadFiles();
    });

    this.scene.transformNodes.forEach(my_node => nameInHierarchy(my_node));
  }

Exporting via the inspector yields the same results btw.

Edit: When exporting the scene as a .babylon file via the inspector and then displaying it in the sandbox tool, the UV Ratios are all perfectly fine, as they should be. Here I sadly stumble into the Problem of the actual texture files not loading as described here or here (on Github I read that this issue should be fixed years ago?)

cc @bghgary, I don’t know if it’s a problem on our side or an unsupported feature on glTF side…

glTF supports this, but our exporters has holes in the implementation depending on what you are doing. What kind of material is pointing to this texture?

I am creating a StandardMaterial and assigning the textures via diffuseTexture, bumpTexture and ambientTexture.

This is my Code for creating them:

export function createMaterial(name: string, scene: Scene, scale = { uScale: 1, vScale: 1 }): StandardMaterial {
  const material = new StandardMaterial(`${name}-material`, scene);
  material.diffuseTexture = createTexture(name, TextureType.diffuse, scale, scene);
  material.bumpTexture = createTexture(name, TextureType.bump, scale, scene);
  material.ambientTexture = createTexture(name, TextureType.ambient, scale, scene);
  material.specularColor = Color3.Black();
  material.invertNormalMapX = true;
  material.invertNormalMapY = true;
  material.freeze();
  return material;
}

function createTexture(
  name: string,
  type: TextureType,
  { uScale, vScale }: { uScale: number; vScale: number },
  scene: Scene,
): Texture {
  const texture = new Texture(`assets/vr/textures/${name}/${name}.${type}.jpg`, scene);
  texture.updateSamplingMode(Constants.TEXTURE_NEAREST_SAMPLINGMODE);
  texture.uScale = uScale;
  texture.vScale = vScale;
  return texture;
}

Okay, that’s the issue. The exporter doesn’t currently export UVs for StandardMaterial. We can fix it possibly, but the best thing to do is to use PBR materials. glTF only supports PBR materials, so the standard material won’t export perfectly to PBR.

1 Like

Thank you for that solution. I’ll go right ahead and implement it :slight_smile:

1 Like