我最近开始在 iOS 中学习 AR。我的第一次尝试是将一个眼镜模型从一个usdz
文件导入现实作曲家,并将它们锚定到一张脸上。那工作得很好。然后我尝试使用相同的文件以编程方式执行此操作,但没有任何反应。
由于它第一次工作,并且当我以编程方式加载文件时,我能够打印模型的描述(见下文),我认为问题不在文件中。
这是代码
import UIKit
import ARKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
// this one does not show
var glassesEntity: Entity {
guard let fileUrl = Bundle.main.url(forResource: "glasses", withExtension: "usdz"),
let entity = try? Entity.loadModel(contentsOf: fileUrl) else {
fatalError("could not load entity")
}
entity.name = "glasses"
print(entity)
return entity
}
// this one works perfectly fine
var boxEntity: Entity {
let box = MeshResource.generateBox(size: 0.3)
return ModelEntity(mesh: box)
}
override func viewDidLoad() {
super.viewDidLoad()
let arConfiguration = ARFaceTrackingConfiguration()
arView.session.run(arConfiguration, options: [])
let faceAnchor = AnchorEntity(AnchoringComponent.Target.face)
arView.scene.addAnchor(faceAnchor)
faceAnchor.addChild(glassesEntity)
// If I uncomments this line, I see the box on my face
// faceAnchor.addChild(boxEntity)
}
}
这是终端输出。无论如何都会出现前 3 行,即使我不尝试加载眼镜模型。
2021-04-05 10:52:39.589170+0300 FaceTracking[27470:2201299] Metal GPU Frame Capture Enabled
2021-04-05 10:52:39.589627+0300 FaceTracking[27470:2201299] Metal API Validation Enabled
Json Parse Error line 22: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping.
Warning: in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'preliminary:anchoring:type' to a prim path (/)
Warning: in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'triggers' to a prim path (/)
▿ 'glasses' : ModelEntity
⟐ ModelComponent
⟐ SynchronizationComponent
⟐ Transform
2021-04-05 10:52:40.549771+0300 FaceTracking[27470:2201340] [Graphics] Failed to find reflection for buffer clusterIndexTable