Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

685
Vistas
Android: How to load a GLTF or GLB file from remote URL in filament

I'm trying to load a remote asset (.glb or .gltf) into the ModelViewer in filament. The Google Filament sample-gltf-viewer shows a RemoteServer object but I'm not seeing how I can load a remote asset from a URL (e.g. https://github.com/kelvinwatson/glb-files/raw/main/DamagedHelmet.glb)

I've tried the below but I get "Unable to parse glb file".

The code for RemoteServer doesn't indicate where we can pass a URL.

val glbUrl = "<URL TO YOUR GLB ASSET>"

private fun loadGlbRemote() {
    lifecycleScope.launch {
        withContext(Dispatchers.IO) {
        val url = URL(glbUrl)
        val connection = url.openConnection()
        connection.connect()
        val inputStream: InputStream = BufferedInputStream(url.openStream())
        val len = connection.contentLength
        val byteArray = ByteArray(len)
        inputStream.read(byteArray, 0, byteArray.size)
        val byteBuffer = ByteBuffer.wrap(byteArray)
        modelViewer.loadModelGlb(byteBuffer)
        inputStream.close()
    }
implementation 'com.google.android.filament:filament-android:1.7.0'
implementation 'com.google.android.filament:filament-utils-android:1.7.0'
implementation 'com.google.android.filament:gltfio-android:1.7.0'`

Any help would be appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Issue has been resolved. The issue was that I wasn't fully downloading the file, and that the modelViewer.loadModelGlb needed to be called on the main thread.

Here is the working code:

val glbUrl = "<URL TO YOUR GLB ASSET>"
URL(glbUrl).openStream().use { inputStream: InputStream ->
    val inputStream = BufferedInputStream(inputStream)
    ByteArrayOutputStream().use {  output->
        inputStream.copyTo(output)
        val byteArr = output.toByteArray()
        val byteBuffer = ByteBuffer.wrap(byteArr)
        val rewound = byteBuffer.rewind()
        withContext(Dispatchers.Main) {
            modelViewer.destroyModel()
            modelViewer.loadModelGlb(rewound)
            modelViewer.transformToUnitCube()

Solution has been included in the filed issue: https://github.com/google/filament/issues/5255

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda