Fix*_*xus 1 android arcore sceneform
我的用例是:
我已经构建了自己的节点,使用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());
Run Code Online (Sandbox Code Playgroud)
...
movingAnimation.setObjectValues(startingPoint, endPoint);
movingAnimation.setPropertyName("localPosition");
movingAnimation.setEvaluator(new Vector3Evaluator());
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,动画是从完全不同的地方完成的.
我没有t found any reference to inbuild tools for such operation.
I使用sceneform
所以问题是.如何从锚A到锚B制作流畅的动画(简单的幻灯片就足够了)
我是在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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1481 次 |
| 最近记录: |