我正在尝试创建一个按钮,该按钮将在选定场景后将其从场景中删除。
我知道删除3d对象的方法是使用anchor.detach()。我可以使用node.select()选择单个模型。但是,我不确定选择节点后如何访问锚点。
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
deleteObject(//I'm not sure how to get the anchor from the selected node//);
}
});
private void deleteObject(Anchor anchor){
anchor.detach();
}
答案 0 :(得分:0)
如果您想删除特定的Renderable,并且您已经知道Anchronode,这就是我认为您遇到的情况,那么下面的代码将删除Renderable和Anchornode:
private void removeAnchorNode(AnchorNode nodeToremove) {
//Remove an anchor node
if (nodeToremove != null) {
arFragment.getArSceneView().getScene().removeChild(nodeToremove);
nodeToremove.getAnchor().detach();
nodeToremove.setParent(null);
nodeToremove = null;
Toast.makeText(LineViewMainActivity.this, "Test Delete - anchorNode removed", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(LineViewMainActivity.this, "Test Delete - markAnchorNode was null", Toast.LENGTH_SHORT).show();
}
}
吐司只是为了帮助测试,因此可以随意移除或保留。
答案 1 :(得分:0)
我有一个类似的问题要发给作者,但我不知道该如何选择必须添加到此函数的AnchorNode:
private void removeAnchorNode(AnchorNode nodeToremove) {
//Remove an anchor node
if (nodeToremove != null) {
arFragment.getArSceneView().getScene().removeChild(nodeToremove);
nodeToremove.getAnchor().detach();
nodeToremove.setParent(null);
nodeToremove = null;
Toast.makeText(LineViewMainActivity.this, "Test Delete - anchorNode removed", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(LineViewMainActivity.this, "Test Delete - markAnchorNode was null", Toast.LENGTH_SHORT).show();
}
}