Skip to content

Instantly share code, notes, and snippets.

@iambaljeet
Created May 12, 2020 20:56
Show Gist options
  • Save iambaljeet/78e83dfc759c0d8b1a3450b4d140cd8d to your computer and use it in GitHub Desktop.
Save iambaljeet/78e83dfc759c0d8b1a3450b4d140cd8d to your computer and use it in GitHub Desktop.
/**
* Used to load model and set it on ArScene where a user Taps
*/
private fun setModelOnUi(hitResult: HitResult) {
loadModel(R.raw.model) { modelRenderable ->
//Used to get anchor point on scene where user tapped
val anchor = hitResult.createAnchor()
//Created an anchor node to attach the anchor with its parent
val anchorNode = AnchorNode(anchor)
//Added arSceneView as parent to the anchorNode. So our anchors will bind to arSceneView.
anchorNode.setParent(arFragment.arSceneView.scene)
//TransformableNode for out model. So that it can be rotated, scaled etc using gestures
val transformableNode = TransformableNode(arFragment.transformationSystem)
//Assigned anchorNode as parent so that our model stays at the position where user taps
transformableNode.setParent(anchorNode)
//Assigned the resulted model received from loadModel method to transformableNode
transformableNode.renderable = modelRenderable
//Sets this node as selected node by default
transformableNode.select()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment