我是 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/