Play With Animation
Now that you've learnt how to load 3D model, we are going to learn how to play with animation in VR
Create a GearVR Framework project by copying the template project
Perform the following steps to make sure your project runs correctly
- (if developing for Gear VR) Copy your Oculus signature file to
- Change the
build.gradleto a unique name to avoid naming conflict when you test the app later
- Change the
res/values/strings.xmlto avoid confusion when you debug the app.
Before we start, we have to obtain a 3D model file with animation.
Gear VR Framework supports following formats
And here is one animated 3D model that we are going to use for this tutorial
How to play animations¶
Make sure to copy both files into
You can load the animated model with following code
GVRModelSceneObject character = gvrContext.getAssetLoader().loadModel("astro_boy.dae"); character.getTransform().setRotationByAxis(45.0f, 0.0f, 1.0f, 0.0f); character.getTransform().setScale(6, 6, 6); character.getTransform().setPosition(0.0f, -0.5f, -1f); gvrContext.getMainScene().addSceneObject(character);
And play the animation with
GVRAnimator, here we make sure the animation in looping forever with the
setRepeatCount set to -1
GVRAnimator animator = (GVRAnimator)character.getComponent(GVRAnimator.getComponentType()); animator.setRepeatCount(-1); animator.setRepeatMode(GVRRepeatMode.REPEATED); animator.start();
Work with 3D modeling tools¶
Fbx is the recommended format for the GearVR framework. Currently, all major 3D modeling tools support exporting to FBX format.
Complete Source Code for this sample