Skip to content

Custom Character Animations

Davis Cook edited this page Mar 2, 2018 · 17 revisions

To make custom character animations you need Blender and fbx-conv:

In Blender you should just create a bunch of textured quads with your character art on them. Look up some tutorial for 2d animation to see how to do this and make animations. You need these animations: (TODO list required animations for StS).

You have to make your character quads in the xy-plane with the textures facing in the negative Z direction. Turn on Backface Culling in Blender so you can tell if your texture has its normals facing properly.

When exporting to fbx from Blender, you should be able to leave things at default but here are the requirements:

  • scale should be 1.0
  • Y-up
  • forward: -Z

Then when using fbx-conv to convert the fbx into either a g3db or g3dj file you need to use the -f flag for flipping textures because otherwise everything will be upside down.

Here's an example of how to load a g3dj file:

		// Model loader needs a binary json reader to decode
		JsonReader jsonReader = new JsonReader();
		
		// Create a model loader passing in our json reader
		G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
		
		// Now load the model by name
		myModel = modelLoader.loadModel(Gdx.files.internal("data/seeker.g3dj"));
 		for (Material mat : myModel.materials) {
 			mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
 		}
		
		// Now create an instance. Instance holds the positioning data, etc
		// of an instance of your model
		myInstance = new ModelInstance(myModel, 0, 0, 10.0f);

		// fbx-conv is supposed to perform this rotation for you... it
		// doesnt seem to
		myInstance.transform.rotate(1, 0, 0, -90);

		// You use an AnimationController to um, control animations. Each
		// control is tied to the model instance
		controller = new AnimationController(myInstance);
		// Pick the current animation by name
		controller.setAnimation("bottom|idle", 1, new AnimationListener() {

			@Override
			public void onEnd(AnimationDesc animation) {
				// this will be called when the current animation is done.
				// queue up another animation called "Jump".
				// Passing a negative to loop count loops forever. 1f for
				// speed is normal speed.
				controller.queue("bottom|idle", -1, 1f, null, 0f);
			}

			@Override
			public void onLoop(AnimationDesc animation) {
				// TODO Auto-generated method stub

			}

		});
Clone this wiki locally