Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Created December 9, 2020 11:14
Show Gist options
  • Save Kashif-E/40c55644af37df92547a6b7d0422532f to your computer and use it in GitHub Desktop.
Save Kashif-E/40c55644af37df92547a6b7d0422532f to your computer and use it in GitHub Desktop.
this function builds and loads the model from firebase and saves it into a variable
private fun renderObject() {
ModelRenderable.builder()
.setSource(
requireContext(), builder().setSource(
requireContext(),
Uri.parse(link),
SourceType.GLB
)
.setRecenterMode(RecenterMode.ROOT)
.build()
)
.setRegistryId(link)
.build()
.thenAccept { modelRenderable: ModelRenderable ->
model= modelRenderable
onRenderableLoaded(model)
}
.exceptionally { throwable: Throwable? ->
val message: String = if (throwable is CompletionException) {
"Internet is not working"
} else {
"Can't load Model"
}
val mainHandler = Handler(Looper.getMainLooper())
val finalMessage: String = message
val myRunnable = Runnable {
AlertDialog.Builder(requireContext())
.setTitle("Error")
.setMessage(finalMessage + "")
.setPositiveButton("Retry") { dialogInterface: DialogInterface, _: Int ->
renderObject()
dialogInterface.dismiss()
}
.setNegativeButton("Cancel") { dialogInterface, _ -> dialogInterface.dismiss() }
.show()
}
mainHandler.post(myRunnable)
null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment