Search code examples
swiftvisionos

TextureResource.load issue (Image decoding failure)


I am attempting to apply a texture to MeshResource, using the following code:

let largeSphere = MeshResource.generateSphere(radius: 2)
var myMaterial = UnlitMaterial()

do {
    let texture = try TextureResource.load(named: "studio-mod")
    myMaterial.color = .init(texture: .init(texture))
} catch {
    print("Failed to create myMaterial with texture: \(error)")
    return nil
}

This failed, throwing this error:

Error Domain=MTKTextureLoaderErrorDomain Code=0 "Image decoding failed"
UserInfo={NSLocalizedDescription=Image decoding failed, MTKTextureLoaderErrorKey=Image decoding failed}

The resource "studio-mod" is a jpg image, included in the resources of the app bundle.

The textures I'm trying to apply are 360º panoramic images. I have been able to it with images stitched together from an iPhone, however when I try to use images created using the Insta360 x3 I get this error.

The Insta360 images appear to be openable and look as expected using every other 360º panoramic image viewer I have tried. I have successfully done this with other panoramic jpg images – and other regular jpg images.

The jpg images from the Insta360 appear to me to be the same (examining the metadata and opening them in other applications, etc.)

Can anyone think of a reason these particular jpg files might fail to be decoded properly in this operation?


Solution

  • Try resizing your image to 8192 pixels max per side, and see if you can load it. That's the Metal texture limit on visionOS.

    I don't, however, yet have a solution to your original objective, which is obviously to load the image so it can be viewed.