-
-
Notifications
You must be signed in to change notification settings - Fork 158
Description
Hello, very new to android development and development in general. I'm following a tutorial on placing objects and hosting cloud anchors; I've got everything working but I'd like to modify things a bit. How can I place a single model in a scene (currently just using shapes from the ModelFactory) and then only host the anchor once the user has placed the object where and how they'd like it?
The onTapListener code I'm currently running:
MaterialFactory.makeOpaqueWithColor(this, new Color(android.graphics.Color.BLUE))
.thenAccept(material -> {
sphereRenderable = ShapeFactory.makeSphere(0.1f, new Vector3(0.0f,0.15f, 0.0f ),material);
});
arFragment = (CustomArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
assert arFragment != null;
arFragment.getArSceneView().getScene().addOnUpdateListener(this::onUpdateFrame);
assert arFragment != null;
arFragment.setOnTapArPlaneListener(
(HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {
if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING ||
appAnchorState != AppAnchorState.NONE) {
return;
}
Anchor anchor = arFragment.getArSceneView().getSession().hostCloudAnchor(hitResult.createAnchor());
setCloudAnchor(anchor);
appAnchorState = AppAnchorState.HOSTING;
Toast.makeText(this,"Now Hosting...", Toast.LENGTH_LONG).show();
snackbarHelper.showMessage(this, "Now hosting...");
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
TransformableNode sphere = new TransformableNode(arFragment.getTransformationSystem());
sphere.setParent(anchorNode);
sphere.setRenderable(sphereRenderable);
isPlaced = true;
sphere.select();
}
);I believe I would first have to set the initial anchor to hitResult.createAnchor(); but how would I allow the anchor to be hosted only after it is placed in a scene? This code begins hosting the anchor immediately. I planned to have a button revealed once the object is placed called "Finish" which would host the anchor. Thank you for any help.