Would this sort of code be useful to others, I think a method like spatial.getController(MeshAnimationController); would be nice for initialization code, especially for noobs. That way you don't have to know what order the Controllers were added.
Here's the diff for com.jme.scene.Spatial.java:
@@ -369,7 +369,30 @@
}
return geometricalControllers.get(i);
}
+
+ /**
+ * Returns the first controller hopefully only
+ * in this list of controllers with class c.
+ *
+ * @param c
+ * The class to get a controller from.
+ * @return The controller with Class c.
+ * @see com.jme.scene.Controller
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Controller> T getController(Class<T> c) {
+ if (geometricalControllers == null) {
+ geometricalControllers = new ArrayList<Controller>(1);
+ }
+ for (Controller controller : geometricalControllers) {
+ if (controller.getClassTag() == c) {
+ return (T)controller;
+ }
+ }
+ return null;
+ }
+
/**
* Returns the ArrayList that contains this spatial's Controllers.
*