我了解 ARCore 尚不支持行走等 3D 动画,但如何为节点的旋转设置动画?
我知道我可以设置 LocalRotation 或 WorldRotation 但如何以流畅的方式连续制作动画?
最简单的方法是使用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();