我正在关注有关在 Vision Pro 上跟踪 3D 空间中的图像的文档。 https://developer.apple.com/documentation/visionos/tracking-images-in-3d-space
预期结果是 3D 球体将平滑地跟踪移动的参考图像。但是,当我运行该应用程序时,3D 球体只会每秒更新两次左右的位置。没有太多用于故障排除的文档。我是否应该调用某种渲染函数来更快地渲染 RealityView?
import SwiftUI
import ARKit
import RealityKit
import RealityKitContent
struct ImmersiveView: View {
var arkitSession = ARKitSession()
@State var entityMap : [UUID: ModelEntity] = [:]
let imageInfo = ImageTrackingProvider(
referenceImages: ReferenceImage.loadReferenceImages(inGroupNamed: "ref")
)
var material = SimpleMaterial()
var rootEntity = Entity()
func updateImage(_ anchor: ImageAnchor) {
if entityMap[anchor.id] == nil {
// Add a new entity to represent this image.
let entity = ModelEntity(mesh: .generateSphere(radius: 0.05))
entityMap[anchor.id] = entity
rootEntity.addChild(entity)
}
if anchor.isTracked {
entityMap[anchor.id]?.transform = Transform(matrix: anchor.originFromAnchorTransform)
}
}
var body: some View {
RealityView { content in
// Add the initial RealityKit content
content.add(rootEntity)
Task {
try await arkitSession.run([imageInfo]);
for await update in imageInfo.anchorUpdates {
updateImage(update.anchor)
}
}
}
}
}
我在 Vision Pro 上与 Unity 合作,我也看到了这种行为。我找不到Apple关于这个问题的任何官方文档,但目前看来在visionOS上更新跟踪图像的位置不是很顺利。
来源:我询问 Unity 开发人员这是 Unity 还是 VisionOS 的问题。看来是后者。希望他们将来能改进这一点。