如何在RealityKit中为转换设置动画 [英] How to animate a transform in RealityKit

查看:204
本文介绍了如何在RealityKit中为转换设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的>上一个问题中我已经找到了如何仅在对象上的一个轴上进行旋转变换,现在我希望将其动画化。

In my previous question I already found how to put a rotation transform over only one axis on an object, now I want this to be animated.

有没有办法做到这一点?

Is there a way to do this in RealityKit?

推荐答案

动画旋转:



Rotation with animation:


复制框的当前变换

copy the box's current transform



var rotationTransform = boxAnchor.steelBox?.transform




将框设置为在z轴上旋转90度

set the box to rotate 90 degrees over z-axis



rotationTransform?.rotation = simd_quatf(angle: .pi/2, axis: [0,0,1])




将框移动到10秒钟以内的新转换

move the box to the new transform over 10s



boxAnchor.steelBox?.move(to: rotationTransform!, relativeTo: boxAnchor.steelBox?.parent, duration: 10, timingFunction: .easeInOut)






带有动画的翻译




Translation with animation:

var translationTransform = boxAnchor.steelBox?.transform

translationTransform?.translation = SIMD3<Float>(x: 5, y: 0, z: 0)

boxAnchor.steelBox?.move(to: translationTransform!, relativeTo: boxAnchor.steelBox?.parent, duration: 10, timingFunction: .easeInOut)






带有动画的缩放比例:




Scale with animation:

var scaleTransform = boxAnchor.steelBox?.transform

scaleTransform?.scale = SIMD3<Float>(x: 1, y: 1, z: 1)

boxAnchor.steelBox?.move(to: scaleTransform!, relativeTo: boxAnchor.steelBox?.parent, duration: 10, timingFunction: .easeInOut)

这篇关于如何在RealityKit中为转换设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆