I would like to animate the drawing of a continuous line.
I managed to create a loop that draws the line segment by segment, but I should somehow bind it to the time, so that the animation doesn't just run through as fast as possible. The animation should also be triggered by key input.
Should I use a controller or what? I didn't find any tutorial for this one.
Please, I want to animate a person who was loading a file. XML with the good. I sweated to import the 3D object, but there is a problem of the animated character with the good .
public class JmeXMLImporter extends SimpleGame {
private XMLImporter xmlImporter = XMLImporter.getInstance();
private Node t;
private static final Logger logger = Logger.getLogger(JmeXMLImporter.class.getName());
AnimationController ac;
boolean boneOn = false;
public static void main(String[] args) {
JmeXMLImporter app = new JmeXMLImporter();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleUpdate() {
if( KeyBindingManager.getKeyBindingManager().isValidCommand( “bones”, true ) ) {
boneOn = !boneOn;
}
ac.update(Timer.getTimer().getTimePerFrame());
}
protected void simpleRender() {
//If we want to display the skeleton use the BoneDebugger.
if(boneOn) {
BoneDebugger.drawBones(rootNode, display.getRenderer(), true);
}
}
protected void simpleInitGame() {
String XMLFileName = “elMensajeroDePekin/xurri-jme.xml”;
URL modelURL = JmeXMLImporter.class.getClassLoader().getResource(XMLFileName);
System.out.println("Carrego el model: "+modelURL);
KeyBindingManager.getKeyBindingManager().set( “bones”, KeyInput.KEY_SPACE );
KeyBindingManager.getKeyBindingManager().set(“canviarAnimacio”, KeyInput.KEY_9);
try {
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(JmeXMLImporter.class
.getClassLoader().getResource(
“elMensajeroDePekin/”)));
} catch (URISyntaxException e1) {
logger.warning("Unable to add texture directory to RLT: "
- e1.toString());
}
try {
System.out.println(“Estic dintre del try”);
Object o = xmlImporter.load(modelURL);
System.out.println("Objecte o: "+o);
if (!(o instanceof Spatial)){
throw new IOException("File contains non-spatial root: " + o.getClass().getName());
} else {
Spatial loadedSpatial = (Spatial) o;
t = (Node) loadedSpatial;
t.setName(“ASuperBone”);
t.setLocalTranslation(new Vector3f(0f,0f,0f));
System.out.println("LoadBlenderModel: "+ XMLFileName + “.xml loaded.”);
}
} catch (IOException e) { // Just in case anything happens
System.out.print(“Severe Error: " + e);
System.exit(0);
}
t.setModelBound(new BoundingBox());
rootNode.attachChild(t);
t.updateModelBound();
ac = getAnimationController();
System.out.println(“Available animations:”);
for (BoneAnimation anim : ac.getAnimations())
System.out.println(” " + anim.getName());
ac.setActiveAnimation(1);
System.err.println(“Executing animation '”
- ac.getActiveAnimation().getName() + “’”);
// The default update loop will update world bounding volumes.
rootNode.updateRenderState();
}
public AnimationController getAnimationController() {
//System.out.println(“descendantMatches”+rootNode.descendantMatches(Bone.class));
List armatures =
rootNode.descendantMatches(Bone.class, “.+SuperBone”);
if (armatures.size() < 1)
throw new IllegalStateException("Sorry. Program assumes "
- “you have a node named with suffix ‘SuperBone’”);
if (armatures.get(0).getControllerCount() != 1)
throw new IllegalStateException(
"Armature should have 1 controller, but has "
- armatures.get(0).getControllerCount());
Controller controller = armatures.get(0).getController(0);
if (!(controller instanceof AnimationController))
throw new IllegalStateException(
"Controller is of unexpected type: "
- controller.getClass().getName());
return (AnimationController) controller;
}
}