如何将对象从锚点移动到锚点?

时间:2018-07-14 10:19:19

标签: android arcore sceneform

我的用例是:

  1. 点击屏幕,然后将“点”保存为起始锚点
  2. 第二次点击屏幕并将“点”保存为结束锚点
  3. 按下将对象从锚点开始移动到末端的按钮

我已经建立了自己的节点,该节点正在使用ObjectAnimator,类似于太阳系示例。我唯一的问题是我不知道如何确定评估者的起点和终点。我的第一个想法是从起始和结束锚位

中提取x,y,z
Vector3 start = new Vector3(startAnchor.getPose().tx(), startAnchor.getPose().ty(), startAnchor.getPose().tz());
Vector3 end = new Vector3(endAnchor.getPose().tx(), endAnchor.getPose().ty(), endAnchor.getPose().tz());

...

movingAnimation.setObjectValues(startingPoint, endPoint);
movingAnimation.setPropertyName("localPosition");
movingAnimation.setEvaluator(new Vector3Evaluator());

但是当我这样做时,动画是在完全不同的地方完成的。

我没有t found any reference to inbuild tools for such operation. I使用场景形式

问题是。如何制作从锚点A到锚点B的流畅动画(一张简单的幻灯片就足够了)

2 个答案:

答案 0 :(得分:9)

我在HelloSceneform示例中做到了。我创建了第一个AnchorNode并将“ andy”节点添加为子节点。下一步,我创建了endPosition AnchorNode并开始将动画移到该位置。

要记住的事情是,如果您要使用具有不同父对象的对象的位置,则要使用 worldPosition 与localPosition。

  private void onPlaneTap(HitResult hitResult, Plane plane, MotionEvent motionEvent) {
      if (andyRenderable == null) {
        return;
      }
      // Create the Anchor.
      Anchor anchor = hitResult.createAnchor();

      // Create the starting position.
      if (startNode == null) {
        startNode = new AnchorNode(anchor);
        startNode.setParent(arFragment.getArSceneView().getScene());

        // Create the transformable andy and add it to the anchor.
        andy = new Node();
        andy.setParent(startNode);
        andy.setRenderable(andyRenderable);
      } else {
        // Create the end position and start the animation.
        endNode = new AnchorNode(anchor);
        endNode.setParent(arFragment.getArSceneView().getScene());
        startWalking();
      }
  }

  private void startWalking() {
    objectAnimation = new ObjectAnimator();
    objectAnimation.setAutoCancel(true);
    objectAnimation.setTarget(andy);

    // All the positions should be world positions
    // The first position is the start, and the second is the end.
    objectAnimation.setObjectValues(andy.getWorldPosition(), endNode.getWorldPosition());

    // Use setWorldPosition to position andy.
    objectAnimation.setPropertyName("worldPosition");

    // The Vector3Evaluator is used to evaluator 2 vector3 and return the next
    // vector3.  The default is to use lerp. 
    objectAnimation.setEvaluator(new Vector3Evaluator());
    // This makes the animation linear (smooth and uniform).
    objectAnimation.setInterpolator(new LinearInterpolator());
    // Duration in ms of the animation.
    objectAnimation.setDuration(500);
    objectAnimation.start();
  }

答案 1 :(得分:0)

<p:panel header="This is my header text"
         toggleable="true"
         toggleableHeader="true">
  The content of the panel.
</p:panel>