Android 没有 Sceneform 的 ARCore 渲染对象

Android ARCore render objects without Sceneform

我想像下图那样渲染附在锚点上的球体。

不幸的是,所有示例都基于我不想使用的 Sceneform。球体应在空气中自由移动,而不会束缚在平面上。

使用 Google 中的 Hello_AR 示例,我能够将 3D 球体渲染到 space 中并通过将其附加到锚点来修复它。

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            ...
            backgroundRenderer.createOnGlThread(this);

            virtualObject.createOnGlThread(this, "models/sphere.obj", "models/sphere.png");
            virtualObject.setMaterialProperties(0.0f, 0.0f, 0.0f, 0.0f);
            ...
    }
    @Override
    public void onDrawFrame(GL10 gl) {
            ...
            // Get projection matrix.
            float[] projmtx = new float[16];
            camera.getProjectionMatrix(projmtx, 0, 0.1f, 100.0f);

            // Get camera matrix and draw.
            float[] viewmtx = new float[16];
            camera.getViewMatrix(viewmtx, 0);

            // Compute lighting from average intensity of the image.
            // The first three components are color scaling factors.
            // The last one is the average pixel intensity in gamma space.
            final float[] colorCorrectionRgba = new float[] {255f, 0, 0, 255f};
            frame.getLightEstimate().getColorCorrection(colorCorrectionRgba, 0);

            // Visualize anchors created by touch.
            float scaleFactor = 1.0f;
            for (Anchor anchor : anchors) {
                if (anchor.getTrackingState() != TrackingState.TRACKING) {
                    continue;
                }
                anchor.getPose().toMatrix(anchorMatrix, 0);
                virtualObject.updateModelMatrix(anchorMatrix, scaleFactor);
                float[] objColor = new float[] { 255f, 255f, 255f, 0 };
                virtualObject.draw(viewmtx, projmtx, colorCorrectionRgba, objColor);
            }
    }

这样我就可以在距离相机1米的空中创建一个黑色球体了。

我的问题:

  1. 这是一个好的/正确的方法吗?

  2. 如何更改球体的颜色,因为颜色值对对象没有影响

  3. 如何让它透明?

非常感谢。

您需要将其附加到锚点。您不需要使用场景形式。 Sceneform 只是两种方法中的一种。 在颜色和透明度方面,它取决于您为对象服务的方式。在你的代码中我看到你正在使用 material 所以很难改变颜色。