Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

684
Views
Android: cómo cargar un archivo GLTF o GLB desde una URL remota en filamento

Estoy tratando de cargar un activo remoto (.glb o .gltf) en ModelViewer en filamento. Google Filament sample-gltf-viewer muestra un objeto RemoteServer , pero no veo cómo puedo cargar un activo remoto desde una URL (por ejemplo, https://github.com/kelvinwatson/glb-files/raw/main/DamagedHelmet. glb )

Intenté lo siguiente, pero aparece "No se puede analizar el archivo glb".

El código para RemoteServer no indica dónde podemos pasar una 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'`

Cualquier ayuda sería apreciada.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cuestión ha sido resuelta. El problema era que no estaba descargando completamente el archivo y que era necesario llamar a modelViewer.loadModelGlb en el hilo principal.

Aquí está el código de trabajo:

 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()

La solución se ha incluido en el problema archivado: https://github.com/google/filament/issues/5255

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!