Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created June 24, 2022 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilemuller/cb738b6ddb730cee94589563432a03b3 to your computer and use it in GitHub Desktop.
Save cecilemuller/cb738b6ddb730cee94589563432a03b3 to your computer and use it in GitHub Desktop.
Swift: generate a TextureResource from UIImage
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