Group Group Group Group Group Group Group Group Group

Texture Sets in Xcode Asset Catalog

Hello,

I want to use texture sets as discussed in chapter 6. However, I would like to store several texture sets inside a folder in the Assets.xcassets folder. So I could have a folder called Swimming Pool Tiles and then just store an Albedo texture set and a Roughness texture set inside this folder.

However, I’m not sure of the correct way to then refer to each texture when loading.

I would have assumed that you could just do:

textureLoader.newTexture(name: “Swimming Pool Tiles/Albedo”, scaleFactor: 1.0, bundle: Bundle.main, options: nil)

However, this does not work…

Also, does anyone know why build times are so slow when using texture sets?

The asset name needs to be unique. I think (on macOS), from looking at the app package that this is necessary because assets are placed in an Assets.car file. That’s why the initial build time is so long too, because it has a lot of interpretation to do.

I just found an amazing blog post that tells you everything you need to know about Assets.car! https://blog.timac.org/2018/1018-reverse-engineering-the-car-file-format/

I prefix the file names, as for example in chapter 9 - racing-car-color and oilcan-color.

I have in the past used images with Folder References - that’s the blue folder group in Xcode rather than the yellow group. You can use the actual folder name when referencing files there.

Hi eoey - Could you let me know what’s happening when you run your code? Is the texture being returned nil?

I ask because there may be a bug with MTKTextureLoader when it interfaces with the asset catalog. I went in search of a solution on the Apple Developers Forum and at least one other person is having an issue where the texture loader always returns nil from images in the catalog.

I personally tried numerous variations of the code in Swift and Objective-C and with various naming conventions.

I’ll return to this at some point because I really like the asset catalog, but for now, I’m loading textures from a regular asset folder, which is working fine.