我了解ARCore尚不支持步行等3D动画,但是如何为Node的旋转设置动画?
我知道我可以设置LocalRotation或WorldRotation,但是如何使这种动画以平滑的方式连续播放?
答案 0 :(得分:8)
最简单的方法是使用Android Property Animation。例如,在Sceneform示例“太阳能系统”中。看一下RotatingNode。这将使节点绕其轴旋转。
首先,它会创建一个ObjectAnimator,它使用LinearInterpolation设置围绕一个圆的4个点之间的旋转。
private static ObjectAnimator createAnimator() {
// Node's setLocalRotation method accepts Quaternions as parameters.
// First, set up orientations that will animate a circle.
Quaternion orientation1 = Quaternion.axisAngle(new Vector3(0.0f, 1.0f, 0.0f), 0);
Quaternion orientation2 = Quaternion.axisAngle(new Vector3(0.0f, 1.0f, 0.0f), 120);
Quaternion orientation3 = Quaternion.axisAngle(new Vector3(0.0f, 1.0f, 0.0f), 240);
Quaternion orientation4 = Quaternion.axisAngle(new Vector3(0.0f, 1.0f, 0.0f), 360);
ObjectAnimator orbitAnimation = new ObjectAnimator();
orbitAnimation.setObjectValues(orientation1, orientation2, orientation3, orientation4);
// Next, give it the localRotation property.
orbitAnimation.setPropertyName("localRotation");
// Use Sceneform's QuaternionEvaluator.
orbitAnimation.setEvaluator(new QuaternionEvaluator());
// Allow orbitAnimation to repeat forever
orbitAnimation.setRepeatCount(ObjectAnimator.INFINITE);
orbitAnimation.setRepeatMode(ObjectAnimator.RESTART);
orbitAnimation.setInterpolator(new LinearInterpolator());
orbitAnimation.setAutoCancel(true);
return orbitAnimation;
}
接下来,它开始动画:
orbitAnimation = createAnimator();
orbitAnimation.setTarget(this);
orbitAnimation.setDuration(getAnimationDuration());
orbitAnimation.start();