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

Swift 如何在ARKit中从特定时间间隔播放DAE动画?,swift,scenekit,augmented-reality,arkit,realitykit,Swift,Scenekit,Augmented Reality,Arkit,Realitykit,我的动画模型的总时间间隔为45秒。我点击了模型,应该能够播放它不是从一开始,而是从说,第15秒 如果你认为这是可能的,有人能帮我吗 编辑: 加载动画模型后,SceneKit将播放动画。现在,有了关键点,我在一个自定义方法的帮助下裁剪动画 通过点击模型,我枚举所有父/子节点以停止或从场景中删除动画。到目前为止还不错 当我尝试将剪切的动画添加回场景时,问题出现了。什么也没有发生,因为场景仍然闲置,没有任何动作 我做错什么了吗 override func touchesBegan(_ touches:

我的动画模型的总时间间隔为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")
    }        
}
override func touchsbegind(touch:Set,带有事件:UIEvent?){
让touchLocation=touchs.first!.location(在:sceneView中)
//让我们测试一个3D对象是否被触摸
var hitTestOptions=[scnhitestoption:Any]()
hitTestOptions[SCNHITESTOPTION.boundingBoxOnly]=真
让hitResults:[SCNHITESTRESULT]=sceneView.hitTest(触摸位置,选项:hitTestOptions)
让animation=animsecene?.entryWithIdentifier(“myKey”,withClass:CAAnimation.self)
打印(“持续时间为…”,动画!.duration)
让animationNew=子动画(of:(动画)!,开始帧:10,结束帧:360)
打印(“新的持续时间是…”,animationNew.duration)
sceneView.scene.rootNode.enumerateChildNodes{(节点,停止)位于
node.removeAllAnimations()
}
sceneView.scene.rootNode.enumerateChildNodes{(节点,_)在
node.addAnimation(animationNew,forKey:“myKey”)
}        
}

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

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