如何在ARCore Sceneform中旋转节点的旋转动画

问题描述 投票:1回答:1

我知道ARCore尚不支持3D动画,例如步行,但我如何设置节点的旋转动画?

我知道我可以设置LocalRotation或WorldRotation但是如何以流畅的方式连续制作动画呢?

android arcore sceneform
1个回答
8
投票

最简单的方法是使用Android Property Animation。这样做的一个例子是Sceneform示例“Solar System”。看看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();
© www.soinside.com 2019 - 2024. All rights reserved.