sceneview-android
sceneview-android copied to clipboard
Programmatic control of rendering
I'd like to be able to control the render cycle for the SceneView model.
Actually my requirement is to selectively enable/disable animation, and avoid render work for power savings when it's disabled.
Currently the render cycle is driven directly by Lifecycle, coming from LocalLifecycleOwner.current.lifecycle. This works for navigation or backgrounding.
But I'd like to use a Scene Composable mixed with other content. My test is currently using the damaged_helment mode with a rotation for testing. But it seems like it still spends as much power if I disable the rotation. Render is called on every frame, which the lifecycle is resumed.
I'd like to be selectively control when the model should be animated to save power. This might be only when the item is focused, and paused other wise.
Alternatively, is there something wrong with my code? Should the model avoid the cost of render per frame, if nothing is animated?
I have a POC that passes in a dummy lifecycle, and then drives the render myself.
val lifecycle = object : Lifecycle() {
override val currentState: State = State.CREATED
override fun addObserver(observer: LifecycleObserver) {
}
override fun removeObserver(observer: LifecycleObserver) {
}
}
LaunchedEffect(Unit) {
val method = Class.forName("io.github.sceneview.SceneView").getDeclaredMethod("onFrame", java.lang.Long.TYPE).apply {
isAccessible = true
}
while (isActive) {
delay(1000)
println(view)
method.invoke(sceneView, System.nanoTime())
}
}
This appears to work, but obviously isn't an API and maybe not the best way to solve the problem.
You should take a look at the ModelNode class, in it you have functions like playAnimation and setCulling that I think can help you with what you are looking for.
I don't know how you have your scene configured but you can preload the models and render them whenever you want by adding them as children of the scene with the sceneView.addChildNode(myModelNode) function.
Thanks, I'll take a look. To be cleared I'm hoping for my model to be visible just static and not pay for per frame rendering.
Thanks