ARTICLE AD BOX
I successfully exported my 3D model from Blender (a .glb file) and opened it in a T-pose within a scene view in Android Studio. Framing and rotation are fine.
However, when I try to load a pose, the 3D model remains in a T-pose, and the camera sticks to the ground and becomes uncontrollable.
My imported .glb file in Android Studio does contain three poses: "pose1", "pose2", and "pose3" (these are animations with a single frame 1). I verified their presence and functionality in the online viewers https://gltf-viewer.donmccurdy.com/ and https://sandbox.babylonjs.com/. Therefore, the problem doesn't seem to be with the .glb file itself.
I started with my code, which correctly displayed the 3D model in a T-pose:
Created a FilamentInstance, Added entities to this instance, Positioned the camera, Replaced the cameraManipulator with a new one to remember the camera position during rotations.But nothing works anymore as soon as I try to load a pose.
I tried again using the modelnode (which, according to my research, encapsulates the filament instance, so it's safer and recommended). But I'm still no better: the pose doesn't load, and the camera is stuck to the ground.
What I see on the screen when displaying the sceneview (the character is in a T-pose)
Can you help? I'm discouraged.
Here is the reference for the sceneview I use:
implementation "io.github.sceneview:sceneview:2.3.3"Here is the Kotlin code I'm using to try and display one pose (animationName) from the glb (assetPath):
package com.MyAndroidStudioProject import android.util.Log import com.google.android.filament.gltfio.FilamentInstance import io.github.sceneview.SceneView import io.github.sceneview.math.Position import io.github.sceneview.math.toFloat3 object ModelLoaderHelper { @JvmStatic fun displaySinglePose( sceneView: SceneView, assetPath: String, animationName: String ): io.github.sceneview.node.ModelNode { // 1️⃣ Charger l'instance GLB val instance = sceneView.modelLoader.createModelInstance(assetPath) // 2️⃣ Créer le ModelNode val modelNode = io.github.sceneview.node.ModelNode(instance) // 3️⃣ Ajouter à la scène sceneView.addChildNode(modelNode) // 4️⃣ Post pour attendre que le node soit attaché sceneView.post { val animator = instance.animator if (animator != null) { // Cherche l'index de l'animation par son nom var animIndex = -1 for (i in 0 until animator.animationCount) { if (animator.getAnimationName(i) == animationName) { animIndex = i break } } if (animIndex != -1) { // Applique la première frame animator.applyAnimation(animIndex, 0f) animator.updateBoneMatrices() } else { Log.e("SceneViewPose", "Animation '$animationName' introuvable") } } else { Log.e("SceneViewPose", "Animator non disponible sur cette instance") } // 5️⃣ Caméra centrée et reculée val box = modelNode.boundingBox val center = box.center val half = box.halfExtent val centerX = center[0] val centerY = center[1] val centerZ = center[2] val maxHalf = maxOf(half[0], half[1], half[2]) val distance = maxHalf * 2.5f sceneView.cameraNode.position = dev.romainguy.kotlin.math.Float3( centerX, centerY + maxHalf, centerZ + distance ) sceneView.cameraNode.lookAt( targetWorldPosition = dev.romainguy.kotlin.math.Float3(centerX, centerY, centerZ), upDirection = dev.romainguy.kotlin.math.Float3(0f, 1f, 0f), smooth = false, smoothSpeed = 0f ) } return modelNode } }And here is the Java code for my activity that calls the Kotlin function for the "pose1" pose of the glb "model3D.glb":
try { String animationNameToLoad = "pose1"; String assetPathToLoad = "models/model3D.glb"; io.github.sceneview.node.ModelNode modelNode = ModelLoaderHelper.displaySinglePose( sceneView, assetPathToLoad, animationNameToLoad ); } catch (Exception e) { e.printStackTrace(); } finally { progress.setVisibility(View.GONE); }Could someone please tell me how to display a pose using Scene View? And how to position and stabilize the camera?
Thank you in advance for your help!
