如何从ARKit中的特定时间间隔播放DAE动画?

问题描述 投票:3回答:2

我的动画模型的总时间间隔为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
2个回答
2
投票

假设,这是播放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")

0
投票

似乎我的.dae文件包含许多动画(具有多个ID),应将它们分组为一个。将它们组合在一起后,我就可以控制动画并可以从我想要的任何帧中播放它们。

© www.soinside.com 2019 - 2024. All rights reserved.