Created
September 28, 2019 18:31
-
-
Save pythonpaul/07b335c14e284edd60f78d662efd313b to your computer and use it in GitHub Desktop.
replace the "R.raw.andy" default Android code with Uri.parse( )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (!checkIsSupportedDeviceOrFinish(this)) { | |
return; | |
} | |
setContentView(R.layout.activity_ux); | |
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment); | |
// When you build a Renderable, Sceneform loads its resources in the background while returning | |
// a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get(). | |
ModelRenderable.builder() | |
.setSource(this, Uri.parse("taka.sfb")) //(this, R.raw.andy) | |
.build() | |
.thenAccept(renderable -> andyRenderable = renderable) | |
.exceptionally( | |
throwable -> { | |
Toast toast = | |
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
return null; | |
}); | |
arFragment.setOnTapArPlaneListener( | |
(HitResult hitResult, Plane plane, MotionEvent motionEvent) -> { | |
if (andyRenderable == null) { | |
return; | |
} | |
// Create the Anchor. | |
Anchor anchor = hitResult.createAnchor(); | |
AnchorNode anchorNode = new AnchorNode(anchor); | |
anchorNode.setParent(arFragment.getArSceneView().getScene()); | |
// Create the transformable andy and add it to the anchor. | |
TransformableNode andy = new TransformableNode(arFragment.getTransformationSystem()); | |
andy.setParent(anchorNode); | |
andy.setRenderable(andyRenderable); | |
andy.select(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment