【发布时间】:2022-01-16 03:55:02
【问题描述】:
我想显示图库中的图像。 我正在使用 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)
}
然后我创建了一个这样的模型实体。
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
}
但事实是,图像以颜色显示,这是合法的。
但是 有没有办法只显示没有颜色的图像?
【问题讨论】:
标签: ios swift augmented-reality arkit realitykit