android: allow modelviewer to reset (#9813)

- Add reset functionality to ModelViewer
 - We use this reset in render-validation to not have to reload
   the scene in runs that use the same model.
 - Fix a bug where the camera manipulator is disabling setting
   the camera via view config.
This commit is contained in:
Powei Feng
2026-03-19 11:11:46 -07:00
committed by GitHub
parent 0d2ecb5436
commit 5007b4e428
3 changed files with 41 additions and 1 deletions

View File

@@ -266,6 +266,35 @@ class ModelViewer(
}
}
/**
* Resets the model's transform, animation, and camera state to defaults.
* Call this when reusing the same model across multiple tests.
*/
fun resetToDefaultState() {
// 1. Reset Camera parameters
cameraFocalLength = 28f
cameraNear = kNearPlane
cameraFar = kFarPlane
updateCameraProjection()
// 2. Reset the manipulator's look-at vectors to initial state
cameraManipulator?.let { cm ->
cm.jumpToBookmark(cm.homeBookmark)
}
// 3. Reset Animations
animator?.let {
if (it.animationCount > 0) {
it.applyAnimation(0, 0.0f)
}
it.updateBoneMatrices()
}
// 4. Re-apply the unit cube transform to clear custom scaling/translation
clearRootTransform()
transformToUnitCube()
}
/**
* Frees all entities associated with the most recently-loaded model.
*/

View File

@@ -175,7 +175,7 @@ class MainActivity : Activity(), ValidationRunner.Callback {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
choreographer = Choreographer.getInstance()
modelViewer = ModelViewer(surfaceView)
modelViewer = ModelViewer(surfaceView=surfaceView, manipulator=null)
inputManager = ValidationInputManager(this)
// Initialize IBL

View File

@@ -81,6 +81,17 @@ class ValidationRunner(
}
private fun startModel(modelName: String) {
if (currentModelName == modelName) {
Log.i("ValidationRunner", "Reusing model $modelName")
callback?.onStatusChanged("Reusing $modelName for ${currentTestConfig?.name}")
modelViewer.resetToDefaultState()
frameCounter = 0
currentState = State.WARMUP
return
}
currentModelName = modelName
val modelPath = config.models[modelName]
if (modelPath == null) {