How to rotate animate the rotation of a Node in ARCore Sceneform

不问归期 提交于 2019-12-08 05:36:01

问题


I understand that 3D animations such as walking are not yet supported in ARCore, but how can I animate the rotation of a Node?

I know I can set LocalRotation or WorldRotation but how do I make this animated continuously in a smooth fashion?


回答1:


The easiest way is to use the Android Property Animation. An example of doing this is in the Sceneform sample "Solar System". Take a look at RotatingNode. This rotates the node around its axis.

First, it creates an ObjectAnimator that uses LinearInterpolation to set the rotation between 4 points around a circle.

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;
  }

Next, it starts the animation:

  orbitAnimation = createAnimator();
  orbitAnimation.setTarget(this);
  orbitAnimation.setDuration(getAnimationDuration());
  orbitAnimation.start();


来源:https://stackoverflow.com/questions/52392333/how-to-rotate-animate-the-rotation-of-a-node-in-arcore-sceneform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!