在 RealityKit 中,我有一个图像锚点。当检测到图像锚点时,我想在 ARView 上围绕该图像的真实对象播放一些动画。我不想在它周围放置任何 3D 对象并在该对象上播放动画。我可以使用 Reality Composer 做到这一点。
我想在 ARView 上检测到图像锚点时在锚点上播放一些动画。
struct ContentView : View {
var body: some View {
ARViewContainer().edgesIgnoringSafeArea(.all)
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
context.coordinator.view = arView
context.coordinator.setupUI()
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
func makeCoordinator() -> Coordinator {
Coordinator()
}
}
class Coordinator: NSObject {
weak var view: ARView?
var cancellable: AnyCancellable?
func setupUI() {
guard let arView = self.view else { return }
guard let imageAnchor = try? Experience.loadMasalaEarth() else {
fatalError("Unable to load my image anchor scene")
}
// Here, I want to play animation on the actual object, when image anchor is detected.
arView.scene.addAnchor(imageAnchor)
}
}
有没有办法在真实物体上播放动画,或者我们只能在我们放置在检测到的锚点上的 3d 物体上播放动画?