【问题标题】:How to rotate animate the rotation of a Node in ARCore Sceneform如何在 ARCore Sceneform 中为节点的旋转设置动画
【发布时间】:2019-02-22 19:55:06
【问题描述】:

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

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

【问题讨论】:

    标签: android arcore sceneform


    【解决方案1】:

    最简单的方法是使用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();
    

    【讨论】:

    猜你喜欢
    • 2019-03-22
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    相关资源
    最近更新 更多