Hey - I am confused as to how to properly animated a model in game,
the model is from here : PSIONIC GAMES & RETRO VANDAL ART
It correctly loads and skins the model and cycles through all the animations so its working - but how in this case do i set it to , "walk" "attack" "die" etc like it states it can in the readme - or even how do i set the specific frame cycles.
Thanks
Andy
Can nobody help me out with this question!?
Tadaaa.
Things i noticed:
- MilkToJme.findController(ant); does not work, because it tries to look for a Controller that is attached to the 1. child. But the controller is attached to the base node in this example.
You can just use JointController controller = (JointController)ant.getController(0); to get hold of the controller.
package models;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jmex.model.animation.JointController;
import com.jmex.model.converters.MilkToJme;
public class TestMs3dAnt extends SimpleGame {
private JointController controller;
@Override
protected void simpleInitGame() {
try {
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(TestMs3dAnt.class.getResource("/data/ant/")));
} catch (URISyntaxException e) {
e.printStackTrace();
}
try {
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_MODEL,
new SimpleResourceLocator(TestMs3dAnt.class.getResource("/data/ant/")));
} catch (URISyntaxException e) {
e.printStackTrace();
}
MilkToJme converter = new MilkToJme();
ByteArrayOutputStream out = new ByteArrayOutputStream();
URL modelUrl = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "ant01.ms3d");
Node ant = null;
try {
converter.convert(modelUrl.openStream(), out);
ant = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(out.toByteArray()));
ant.setModelBound(new BoundingBox());
ant.updateModelBound();
} catch (Exception e) {
e.printStackTrace();
}
rootNode.attachChild(ant);
// controller = MilkToJme.findController(ant);
controller = (JointController)ant.getController(0);
controller.setRepeatType(Controller.RT_CLAMP);
controller.setSpeed(0.5f);
controller.setActive(false);
KeyBindingManager.getKeyBindingManager().add("idle", KeyInput.KEY_1);
KeyBindingManager.getKeyBindingManager().add("walk", KeyInput.KEY_2);
KeyBindingManager.getKeyBindingManager().add("attack", KeyInput.KEY_3);
KeyBindingManager.getKeyBindingManager().add("stun", KeyInput.KEY_4);
KeyBindingManager.getKeyBindingManager().add("explode", KeyInput.KEY_5);
}
@Override
protected void simpleUpdate() {
if (KeyBindingManager.getKeyBindingManager().isValidCommand("idle")) {
controller.setTimes(47, 65);
controller.setActive(true);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("walk")) {
System.out.println("playing walk");
controller.setTimes(1, 9);
controller.setActive(true);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("attack")) {
controller.setTimes(10, 19);
controller.setActive(true);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("stun")) {
controller.setTimes(20, 29);
controller.setActive(true);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("explode")) {
controller.setTimes(31, 45);
controller.setActive(true);
}
}
public static void main(String[] args) {
TestMs3dAnt game = new TestMs3dAnt();
game.setConfigShowMode(ConfigShowMode.AlwaysShow);
game.start();
}
}
Core-dump you are a god…why is animating not consistent - for instance such an example doesnt work with my other md2 models - it is a true pest because you end up having to mess around with tons of different attempts to find out what works with each type of model!