如何在 ARCore Sceneform 中旋转动画节点的旋转 [英] How to rotate animate the rotation of a Node in ARCore Sceneform

查看:44
本文介绍了如何在 ARCore Sceneform 中旋转动画节点的旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 ARCore 尚不支持步行等 3D 动画,但如何为节点的旋转设置动画?

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

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

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

推荐答案

最简单的方法是使用 Android 属性动画.这样做的一个例子是在 Sceneform 示例太阳系"中.看看 RotatingNode.这会围绕其轴旋转节点.

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.

首先,它创建了一个 ObjectAnimator,它使用 LinearInterpolation 来设置4 点绕一圈.

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

接下来,它开始动画:

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

这篇关于如何在 ARCore Sceneform 中旋转动画节点的旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆