【问题标题】:How can I play DAE animation from a specific time interval in ARKit?如何在 ARKit 中播放特定时间间隔的 DAE 动画?
【发布时间】:2019-11-16 15:37:12
【问题描述】:

我的动画模型的总时间间隔为 45 秒。我点击模型,应该不是从一开始就可以播放它,而是从第 15 秒开始播放。

如果您认为这是可能的,任何人都可以帮助我吗?

编辑:

只要我加载动画模型,SceneKit 就会播放动画。现在,有了钥匙,我在遇到的自定义方法的帮助下裁剪了动画。

通过点击模型,我枚举所有父/子节点以停止或从场景中删除动画。到目前为止,一切都很好。

当我尝试将裁剪后的动画添加回场景时出现问题。什么都没有发生,因为场景保持空闲,没有任何动作。

我在这里做错了吗?

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    let touchLocation = touches.first!.location(in: sceneView)

    // Let's test if a 3D Object was touch
    var hitTestOptions = [SCNHitTestOption: Any]()
    hitTestOptions[SCNHitTestOption.boundingBoxOnly] = true

    let hitResults: [SCNHitTestResult] = sceneView.hitTest(touchLocation, options: hitTestOptions)

    let animation = animScene?.entryWithIdentifier("myKey", withClass: CAAnimation.self)
    print(" duration is...", animation!.duration)

    let animationNew = subAnimation(of:(animation)!, startFrame: 10, endFrame: 360)
    print("New duration is...", animationNew.duration)

    sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in
        node.removeAllAnimations()
    }
    sceneView.scene.rootNode.enumerateChildNodes { (node, _) in
        node.addAnimation(animationNew, forKey: "myKey")
    }        
}

【问题讨论】:

    标签: swift scenekit augmented-reality arkit realitykit


    【解决方案1】:

    假设,这是播放包含在Collada 文件中的动画的最可靠方法:

    import SceneKit
    
    func myAnimation(path: String) -> SCNAnimation? {
    
        let scene = SCNScene(named: path)
        var animation: SCNAnimationPlayer?
    
        scene?.rootNode.enumerateChildNodes( { (child, stop) in
            if let animationKey = child.animationKeys.first {
    
                animation = child.animationPlayer(forKey: animationKey)
    
                // variable pointee: ObjCBool { get nonmutating set }
                stop.pointee = true
            }
        })
        return animation?.animation
    }
    
    let node = SCNNode()
    let animation = myAnimation(path: "animation.dae")
    node.addAnimation(animation!, forKey: "FirstAnimationSet")
    

    【讨论】:

      【解决方案2】:

      似乎我的 .dae 文件有许多动画(具有多个 id),它们应该被归为一个。一旦我将它们组合在一起,我就可以控制动画并且可以从我想要的任何帧播放它们。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-23
        • 1970-01-01
        • 2021-09-25
        • 2020-03-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多