【问题标题】:Play animation when image anchor detected检测到图像锚点时播放动画
【发布时间】:2021-12-07 16:09:27
【问题描述】:

在 RealityKit 中,我有一个图像锚。当检测到图像锚时,我想显示一个对象并播放它具有的动画。我在 Reality Composer 中创建了一个动画。这是一个简单的“Ease Out”动画,内置了 Reality Composer。

目前,我的代码如下所示:

struct ARViewContainer: UIViewRepresentable {

func makeUIView(context: Context) -> ARView {
    
    let arView = CustomARView(frame: .zero)

    // generate image anchor
    let anchor = AnchorEntity(.image(group: "AR Resources", name: "imageAnchor"))

    // load 3D model from Experience.rcproject file
    let box = try! Experience.loadBox()
    
    // add 3D model to anchor
    anchor.addChild(box)
    
    // add anchor to scene
    arView.scene.addAnchor(anchor)
    
    return arView
    
}

func updateUIView(_ uiView: ARView, context: Context) {}

}

【问题讨论】:

标签: swift arkit realitykit reality-composer


【解决方案1】:

解决方法很简单。选择 Reality Composer 的 image anchor(提供相应的 .jpg.png 图像)。然后为您的模型分配一个Custom Behavior。作为触发器使用Scene Start。然后应用任何所需的操作。


您的代码将非常简单:

struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        let scene = try! Experience.loadCylinder()
        arView.scene.addAnchor(scene)
        return arView
    }

    func updateUIView(_ uiView: ARView, context: Context) { }
}

动作将自动播放(在图像锚出现后立即)。

【讨论】:

    猜你喜欢
    • 2015-08-17
    • 1970-01-01
    • 2019-03-15
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多