0
0

AssetsからTextureResourceをLoadできない

Posted at

Vision OS用にRealityKitでこんな感じで画像からTexttureを生成しようとしたのですが、画像によっては何故かエラーが発生してしまいました。

画像は、Assetsに入れてあり、大きさも同じなのですが、1はOKでも、2は読めないみたいな事象が起きており、悩んでいたのですが、

guard
    let texture1 = try? TextureResource.load(named: "1"),
    let texture2 = try? TextureResource.load(named: "2")
else {
    // error
}

Assetsからの画像読み込みだと暗くなるという記事を見つけたので、もしやと思い、Bundleから読み込むようにしてみました。すると、

guard
    let url1 = Bundle.main.url(forResource: "1", withExtension: "png"),
    let texture1 = try? TextureResource.load(contentsOf:url1, withName:nil),
    let url2 = Bundle.main.url(forResource: "2", withExtension: "png"),
    let texture2 = try? TextureResource.load(contentsOf:url2, withName:nil),
else {
    // error
}

原因は不明ですが、うまく読み取れました。参考になれば。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0