Skip to content

Commit 5007b4e

Browse files
authored
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.
1 parent 0d2ecb5 commit 5007b4e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

android/filament-utils-android/src/main/java/com/google/android/filament/utils/ModelViewer.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,35 @@ class ModelViewer(
266266
}
267267
}
268268

269+
/**
270+
* Resets the model's transform, animation, and camera state to defaults.
271+
* Call this when reusing the same model across multiple tests.
272+
*/
273+
fun resetToDefaultState() {
274+
// 1. Reset Camera parameters
275+
cameraFocalLength = 28f
276+
cameraNear = kNearPlane
277+
cameraFar = kFarPlane
278+
updateCameraProjection()
279+
280+
// 2. Reset the manipulator's look-at vectors to initial state
281+
cameraManipulator?.let { cm ->
282+
cm.jumpToBookmark(cm.homeBookmark)
283+
}
284+
285+
// 3. Reset Animations
286+
animator?.let {
287+
if (it.animationCount > 0) {
288+
it.applyAnimation(0, 0.0f)
289+
}
290+
it.updateBoneMatrices()
291+
}
292+
293+
// 4. Re-apply the unit cube transform to clear custom scaling/translation
294+
clearRootTransform()
295+
transformToUnitCube()
296+
}
297+
269298
/**
270299
* Frees all entities associated with the most recently-loaded model.
271300
*/

android/samples/sample-render-validation/src/main/java/com/google/android/filament/validation/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class MainActivity : Activity(), ValidationRunner.Callback {
175175
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
176176

177177
choreographer = Choreographer.getInstance()
178-
modelViewer = ModelViewer(surfaceView)
178+
modelViewer = ModelViewer(surfaceView=surfaceView, manipulator=null)
179179
inputManager = ValidationInputManager(this)
180180

181181
// Initialize IBL

android/samples/sample-render-validation/src/main/java/com/google/android/filament/validation/ValidationRunner.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ class ValidationRunner(
8181
}
8282

8383
private fun startModel(modelName: String) {
84+
if (currentModelName == modelName) {
85+
Log.i("ValidationRunner", "Reusing model $modelName")
86+
callback?.onStatusChanged("Reusing $modelName for ${currentTestConfig?.name}")
87+
88+
modelViewer.resetToDefaultState()
89+
90+
frameCounter = 0
91+
currentState = State.WARMUP
92+
return
93+
}
94+
8495
currentModelName = modelName
8596
val modelPath = config.models[modelName]
8697
if (modelPath == null) {

0 commit comments

Comments
 (0)