java - ARCORE:点击后不显示 View (信息卡)

标签 java android-studio arcore sceneform

我是 arcore 的新手,正在为一个项目使用 sceneform。具体来说,我正在使用太阳系示例,并尝试将其在 Planet.java 中的信息卡实现到我的项目中。我已经设置了信息卡(至少我认为我这样做了)但是,它们不会出现在水龙头上。我是否遗漏了什么或者我做错了什么?预先感谢您的帮助。

private void makeinfoCards(ArFragment arFragment, Anchor anchor, Context context) {
        if (infoCard == null) {
            AnchorNode anchorNode = new AnchorNode(anchor);
            infoCard = new Node();
            infoCard.setParent(anchorNode);
            infoCard.setEnabled(false);
            infoCard.setLocalPosition(new Vector3(0.0f, 2.90f * INFO_CARD_Y_POS_COEFF, 0.0f));
            //below would hide/bring up the info card on tap
            infoCard.setOnTapListener(  //anchorNode.setOnTapListener doesn't make info card appear either
                    (hitTestResult, motionEvent) -> {
                        infoCard.setEnabled(!infoCard.isEnabled());
                    }
            );
            ViewRenderable.builder()
                    .setView(arFragment.getContext(), R.layout.card_view) //putting context instead makes no difference
                    .build()
                    .thenAccept(
                            (renderable) -> {
                                infoCard.setRenderable(renderable);
                                TextView textView = (TextView) renderable.getView();
                                textView.setText("random");
                            })
                    .exceptionally(
                            (throwable) -> {
                                throw new AssertionError("Could not load plane card view.", throwable);
                            });
        }

}

最佳答案

您已在 infoCard 节点上设置了默认禁用的 onTapListener。您应该在包含要单击的 3D 模型的节点上使用 setOnTapListener,尝试将 3D 模型设置为可渲染的特定节点作为参数而不是 Anchor 传递给函数。如果您有节点,请说 modelNode 具有 3D 模型。

在您的 ARActivity 通话中

makeInfoCard(arFragment,modelNode,context);

并在函数中使用

private void makeInfoCard(ArFragment arFragment, Node modelNode, Context context){
//
    modelNode.setOnTapListener((hitTestResult, motionEvent) -> {
        infoCard.setEnabled(!infoCard.isEnabled());
    });
//
}

关于java - ARCORE:点击后不显示 View (信息卡),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59831335/

相关文章:

Android模拟器顶部无法点击

android - 当我在 Android native 项目(使用 ARCore)中使用 Unity 库(使用 ARCore)时,程序类型已经存在 : android. media.VisibleImage 错误

java - 循环中的 if 语句中的 i-- 做什么?

java - 如何从给定的 iso 语言代码中检索匹配的宏语言区域设置?

java - 关于eclipse中的null检查插件

macos - 我可以在 Android Studio 窗口内(或顶部)运行 Android 模拟器吗?

android - Windows 10 中的 Gradle 文件目录

java - Android:无法检测垂直平面

arcore - 如何使用 Sceneform 对每一帧进行处理?

java - 如何使用 Retrofit android 设置工具栏标题?