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 an SXR 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.
The SXR SDK 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
SXRModelNode character = sxrContext.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); sxrContext.getMainScene().addNode(character);
And play the animation with
SXRAnimator, here we make sure the animation in looping forever with the
setRepeatCount set to -1
SXRAnimator animator = (SXRAnimator)character.getComponent(SXRAnimator.getComponentType()); animator.setRepeatCount(-1); animator.setRepeatMode(SXRRepeatMode.REPEATED); animator.start();
Work with 3D modeling tools
Fbx is the recommended format for the SXR SDK. Currently, all major 3D modeling tools support exporting to FBX format.
Complete Source Code for this sample