Как вращать анимацию вращения узла в ARCore Sceneform - PullRequest
0 голосов
/ 18 сентября 2018

Я понимаю, что 3D-анимации, такие как ходьба, еще не поддерживаются в ARCore, но как я могу анимировать вращение узла?

Я знаю, что могу установить LocalRotation или WorldRotation, но как мне сделать это анимированным?непрерывно плавно?

1 Ответ

0 голосов
/ 19 сентября 2018

Самый простой способ - использовать 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();
...