filament入门挺难的,主要是因为受干扰的信息太多了,有arCore的干扰,也有scenceform的干扰。这里通过制作3D模型查看器的方式,理清他们之间的关系。
有用的信息来源主要有3个:
1,https://medium.com/@philiprideout/getting-started-with-filament-on-android-d10b16f0ec67
Android上的Filament入门
2,https://github.com/thomasgorisse/sceneform-android-sdk
适用于Android的Sceneform SDK-维护
3,https://github.com/Sergiioh/android-model-viewer
适用于Android的GLB和GLTF模型查看器
整体表现为:1实现了页面查看3D模型,2实现了ar查看3D模型,3提供了将1和2集成到你应用的一种思路。依照他们说的一步步来做,就可以实现这样的效果。
球状元素周期表
为了防止页面走丢,这里把他们的内容复制进来。
class gltfActivity : Activity()
companion object {
init {
Utils.init()
}
}
private lateinit var surfaceView: SurfaceView
private lateinit var choreographer: Choreographer
private lateinit var modelViewer: ModelViewer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
surfaceView = SurfaceView(this).apply { setContentView(this) }
choreographer = Choreographer.getInstance()
modelViewer = ModelViewer(surfaceView)
surfaceView.setOnTouchListener(modelViewer)
loadGltf("BoomBox")
loadEnvironment("courtyard_8k")
}
private fun loadGltf(name: String) {
val buffer = readAsset("models/BoomBox/${name}.gltf")
modelViewer.loadModelGltf(buffer) { uri -> readAsset("models/BoomBox/$uri") }
modelViewer.transformToUnitCube()
}
private fun readAsset(assetName: String): ByteBuffer {
val input = assets.open(assetName)
val bytes = ByteArray(input.available())
input.read(bytes)
return ByteBuffer.wrap(bytes)
}
private val frameCallback = object : Choreographer.FrameCallback