Adding animation to 3D models in ARKit

萝らか妹 提交于 2020-08-22 06:58:39

问题


In this video an object is given an animation to hover around the room when placed and then when tapped it gets dropped down with another animation. How can I add this kind of animations in my project? Is adding an already animated object the only way?

Thank you

https://youtu.be/OS_kScr0XkQ


回答1:


I think the hovering up and down is most likely an animation sequence. The following animation sequence for a hovering effect will work inside the first drop down selection function.

        let moveDown = SCNAction.move(by: SCNVector3(0, -0.1, 0), duration: 1)
        let moveUp = SCNAction.move(by: SCNVector3(0,0.1,0), duration: 1)
        let waitAction = SCNAction.wait(duration: 0.25)
        let hoverSequence = SCNAction.sequence([moveUp,waitAction,moveDown])
        let loopSequence = SCNAction.repeatForever(hoverSequence)
        node2Animate.runAction(loopSequence)

        self.sceneView.scene.rootNode.addChildNode(node2Animate)

The second part to stop the animation when you tap the node put this inside the tap gesture function.

node2animate.removeAllActions()

The last part dropping to the floor, the node2animate might be a physicsBody and before the tap the gravity attribute

node2animate.physicsBody?.isAffectedByGravity = false

after the tap you set it to true

node2animate.physicsBody?.isAffectedByGravity = true

There is other stuff going on as well, collision with the floor have also been set etc.



来源:https://stackoverflow.com/questions/48597130/adding-animation-to-3d-models-in-arkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!