Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3.  
  4. if (!checkIsSupportedDeviceOrFinish(this)) {
  5. return;
  6. }
  7.  
  8. setContentView(R.layout.activity_ux);
  9. arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
  10.  
  11. // When you build a Renderable, Sceneform loads its resources in the background while returning
  12. // a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
  13. ModelRenderable.builder()
  14. .setSource(this, Uri.parse("taka.sfb")) //(this, R.raw.andy)
  15. .build()
  16. .thenAccept(renderable -> andyRenderable = renderable)
  17. .exceptionally(
  18. throwable -> {
  19. Toast toast =
  20. Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
  21. toast.setGravity(Gravity.CENTER, 0, 0);
  22. toast.show();
  23. return null;
  24. });
  25.  
  26. arFragment.setOnTapArPlaneListener(
  27. (HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {
  28. if (andyRenderable == null) {
  29. return;
  30. }
  31.  
  32. // Create the Anchor.
  33. Anchor anchor = hitResult.createAnchor();
  34. AnchorNode anchorNode = new AnchorNode(anchor);
  35. anchorNode.setParent(arFragment.getArSceneView().getScene());
  36.  
  37. // Create the transformable andy and add it to the anchor.
  38. TransformableNode andy = new TransformableNode(arFragment.getTransformationSystem());
  39. andy.setParent(anchorNode);
  40. andy.setRenderable(andyRenderable);
  41. andy.select();
  42. });
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement