Hi can anyone post a little example on how to play an animation from a 3d model?

I usually use blender for modelling to m3g into mobile phones… and is really easy to play an animation(walking person for example) just load a SkinnedMesh and play the animation like obj.animate(time).

Is that easy using jmonkey?

can anyone post a simple example on loading a model that has an animation and play it? which extension is good for animation that blender can export?



MD5 would be the format you would likely want to use.

Look here:

Look at HelloModelLoading in the tests, this is some code from the User-Code section which can help you load any model format that's listed in the if-statements (3ds, obj, md2, md3, or ms3d).

private Node loadModel(String fileName) {
   Spatial model = null;

   try {
      String format = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());

      File binary = new File(fileName.substring(0, fileName.lastIndexOf(".") + 1) + "jme");
      if (!binary.exists()) {
         FormatConverter formatConverter = null;

         if (format.equalsIgnoreCase("ase")) {
            formatConverter = new AseToJme();
         } else if (format.equalsIgnoreCase("3ds")) {
            formatConverter = new MaxToJme();
         } else if (format.equalsIgnoreCase("md2")) {
            formatConverter = new Md2ToJme();
         } else if (format.equalsIgnoreCase("md3")) {
            formatConverter = new Md3ToJme();
         } else if (format.equalsIgnoreCase("ms3d")) {
            formatConverter = new MilkToJme();
         } else if (format.equalsIgnoreCase("obj")) {
            formatConverter = new ObjToJme();
         } else if (format.equalsIgnoreCase("x3d")) {
            formatConverter = new X3dToJme();

         File file = new File(fileName);
         formatConverter.setProperty("texurl", file.getParentFile().toURI().toURL());
         formatConverter.setProperty("mtllib", file.toURI().toURL());

         ByteArrayOutputStream output = new ByteArrayOutputStream();

         formatConverter.convert(file.toURI().toURL().openStream(), output);
         BinaryImporter importer = BinaryImporter.getInstance();
         model = (Spatial) importer.load(new ByteArrayInputStream(output.toByteArray()));

         // BinaryExporter.getInstance().save((Savable) model, binary);
      } else {
         model = (Spatial) BinaryImporter.getInstance().load(binary.toURI().toURL());
   } catch (Exception exception) {
      model = new Box("box", new Vector3f(), 15, 15, 15);

   Node node = new Node("model");

   return node;

When you load a model, all animation ranges will play. You fix that by doing something like this:

JointController cntrl = (JointController)(myModel.getController(0));
cntrl.setTimes(1, 50);

That would play frames 1 - 50 and repeat.