Created
December 9, 2020 11:14
-
-
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
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
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