var url = "https://github.com/kelvinwatson/glb-files/raw/main/DamagedHelmet.glb"
runBlocking {
async {
customViewer!!.loadRemoteGlb(url)
}
}
suspend fun loadRemoteGlb(url: String) {
GlobalScope.launch(Dispatchers.IO) {
URL(url).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()
output.close()
inputStream.close()
}
}
}
}
}
Filament加载网络glb文件
最新推荐文章于 2024-04-18 14:29:02 发布