I want to show image from gallery. i am loading the image using imagePicker.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image = info[.originalImage] as? UIImage else { return }
if let imgUrl = info[UIImagePickerController.InfoKey.imageURL] as? URL{
self.photoEntity = createPhotoEntity(fileUrl: imgUrl, fileName: imgName)
}
dismiss(animated: true)
}
and then i have created a modelEntity like this.
private func createPhotoEntity(fileUrl: URL, fileName: String) -> ModelEntity? {
// Create a TextureResource by loading the contents of the file URL.
do {
let texture = try TextureResource.load(contentsOf: fileUrl)
let planeMesh = MeshResource.generatePlane(width: 0.5, depth: 0.5)
var material = UnlitMaterial()
material.color = .init(tint: .red.withAlphaComponent(0.999), texture: .init(texture))
let entity = ModelEntity(mesh: planeMesh, materials: [material])
entity.generateCollisionShapes(recursive: true)
ARView.installGestures([.scale, .translation], for: entity)
return entity
} catch(let error) {
print("error loading. \(error.localizedDescription)")
}
return nil
}
But the fact is, image is being shown with a color and this is legit.
But Is there any way to show only image without any color?