如何在ARCore的Sceneform中的两个锚点之间画线?

时间:2018-08-21 15:08:32

标签: android arcore

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

2 个答案:

答案 0 :(得分:1)

是的,有一种方法可以实现:

def buildJob(jobName){
    echo "${jobName} will be built."
}

node {

    map = [:]
    projects = ['project1-dev', 'project2-dev', 'project1-qa', 'project2-qa', 'project1-pp', 'project2-pp']

    stage ('Build') {
        for (project in projects) {
            map[project] = { buildJob("'${project}'") }
        }

        parallel map
    } 
}

答案 1 :(得分:0)

通过圆柱体画线的其他方法。

private void addLineBetweenPoints(Scene scene, Vector3 from, Vector3 to) {
        // prepare an anchor position
        Quaternion camQ = scene.getCamera().getWorldRotation();
        float[] f1 = new float[]{to.x, to.y, to.z};
        float[] f2 = new float[]{camQ.x, camQ.y, camQ.z, camQ.w};
        Pose anchorPose = new Pose(f1, f2);

        // make an ARCore Anchor
        Anchor anchor = mCallback.getSession().createAnchor(anchorPose);
        // Node that is automatically positioned in world space based on the ARCore Anchor.
        AnchorNode anchorNode = new AnchorNode(anchor);
        anchorNode.setParent(scene);

        // Compute a line's length
        float lineLength = Vector3.subtract(from, to).length();

        // Prepare a color
        Color colorOrange = new Color(android.graphics.Color.parseColor("#ffa71c"));

        // 1. make a material by the color
        MaterialFactory.makeOpaqueWithColor(getContext(), colorOrange)
                .thenAccept(material -> {
                    // 2. make a model by the material
                    ModelRenderable model = ShapeFactory.makeCylinder(0.0025f, lineLength,
                            new Vector3(0f, lineLength / 2, 0f), material);
                    model.setShadowReceiver(false);
                    model.setShadowCaster(false);

                    // 3. make node
                    Node node = new Node();
                    node.setRenderable(model);
                    node.setParent(anchorNode);

                    // 4. set rotation
                    final Vector3 difference = Vector3.subtract(to, from);
                    final Vector3 directionFromTopToBottom = difference.normalized();
                    final Quaternion rotationFromAToB =
                            Quaternion.lookRotation(directionFromTopToBottom, Vector3.up());
                    node.setWorldRotation(Quaternion.multiply(rotationFromAToB,
                            Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), 90)));
                });
    }