Created
June 24, 2022 12:31
-
-
Save cecilemuller/cb738b6ddb730cee94589563432a03b3 to your computer and use it in GitHub Desktop.
Swift: generate a TextureResource from UIImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import RealityKit | |
extension TextureResource { | |
static func generate(from: UIImage, withName: String?) -> TextureResource? { | |
guard let cgImage = from.cgImage else { return nil } | |
let options = TextureResource.CreateOptions( | |
semantic: .color, | |
mipmapsMode: .allocateAndGenerateAll | |
) | |
return try? TextureResource.generate(from: cgImage, withName: withName, options: options) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment