gpt4 book ai didi

android - 如何在 ARCore 的 Sceneform 中的两个 anchor 之间画线?

转载 作者:行者123 更新时间:2023-12-05 00:09:12 24 4
gpt4 key购买 nike

我想在 ArFragment 的 Sceneform 上用一些可见的线连接两个 TransformableNode,但不使用 OpenGL 函数。是否可以在 Android 中的 ARCore Java 中的 Sceneform 中的两个 anchor (或节点)之间画一条线?如果可能的话,我该怎么做?

最佳答案

是的,有一种方法可以做到这一点:

private void addLineBetweenHits(HitResult hitResult, Plane plane, MotionEvent motionEvent) {

int val = motionEvent.getActionMasked();
float axisVal = motionEvent.getAxisValue(MotionEvent.AXIS_X, motionEvent.getPointerId(motionEvent.getPointerCount() - 1));
Log.e("Values:", String.valueOf(val) + String.valueOf(axisVal));
Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);


if (lastAnchorNode != null) {
anchorNode.setParent(arFragment.getArSceneView().getScene());
Vector3 point1, point2;
point1 = lastAnchorNode.getWorldPosition();
point2 = anchorNode.getWorldPosition();

/*
First, find the vector extending between the two points and define a look rotation
in terms of this Vector.
*/
final Vector3 difference = Vector3.subtract(point1, point2);
final Vector3 directionFromTopToBottom = difference.normalized();
final Quaternion rotationFromAToB =
Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
MaterialFactory.makeOpaqueWithColor(getApplicationContext(), new Color(0, 255, 244))
.thenAccept(
material -> {
/* Then, create a rectangular prism, using ShapeFactory.makeCube() and use the difference vector
to extend to the necessary length. */
ModelRenderable model = ShapeFactory.makeCube(
new Vector3(.01f, .01f, difference.length()),
Vector3.zero(), material);
/* Last, set the world rotation of the node to the rotation calculated earlier and set the world position to
the midpoint between the given points . */
Node node = new Node();
node.setParent(anchorNode);
node.setRenderable(model);
node.setWorldPosition(Vector3.add(point1, point2).scaled(.5f));
node.setWorldRotation(rotationFromAToB);
}
);
lastAnchorNode = anchorNode;
}
}

关于android - 如何在 ARCore 的 Sceneform 中的两个 anchor 之间画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51951704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com