What sdk version you running it on?
3.2
You need to slow down and look at what youâre doing.
- Load the model.
- Get AnimControl.class
- Check if the control is null
- Get AnimComposer.class
- Check if the control is null
If they are both null then the spatial you are attempting to get the control from does not contain the control. You MUST get the control from the spatial that contains the control. You cannot just call .getControl anywhere and expect the engine to find it for you. There may be MULTIPLE animation controls, therefore you MUST call getControl ON THE SPATIAL THAT CONTAINS THE CONTROL.
I donât really know how else I can put it.
can you write some easy example?
If you copy and paste that code and run it as is in the 3.2.4 sdk, what does tutorial not work mean?
If you are using 3.2.4, change this line from this,
player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
to
player = (Node) assetManager.loadModel("Models/Oto/OtoOldAnim.j3o");
and see if it works.
I am using 3.2.1-stable and I see no commits that say this file was changed, nor were any ogre files changed between 3.2.1 and 3.2.4.
I see these commits happening between 3.2.4 and 3.3.0 so this should work, without changes, on 3.2.4.
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
/** Sample 7 - how to load an OgreXML model and play an animation,
* using channels, a controller, and an AnimEventListener. */
public class Main extends SimpleApplication
implements AnimEventListener {
private AnimChannel channel;
private AnimControl control;
Node player;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.j3o");
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim("stand");
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
if (animName.equals("Walk")) {
channel.setAnim("stand", 0.50f);
channel.setLoopMode(LoopMode.DontLoop);
channel.setSpeed(1f);
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
// unused
}
/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
inputManager.addMapping("Walk", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, "Walk");
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Walk") && !keyPressed) {
if (!channel.getAnimationName().equals("Walk")) {
channel.setAnim("Walk", 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
}
Null poiner exception at line
control.addListener(this);
Controll get null at line:
control = player.getControl(AnimControl.class);
Use:
otto.mesh.j3o
Right click the j3o and select Edit in scene composer
Show us a picture like you did in the post you made above.
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
/** Sample 7 - how to load an OgreXML model and play an animation,
* using channels, a controller, and an AnimEventListener. */
public class Main extends SimpleApplication
implements AnimEventListener {
private AnimChannel channel;
private AnimControl control;
Node player;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.j3o");
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim("stand");
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
if (animName.equals("Walk")) {
channel.setAnim("stand", 0.50f);
channel.setLoopMode(LoopMode.DontLoop);
channel.setSpeed(1f);
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
// unused
}
/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
inputManager.addMapping("Walk", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, "Walk");
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Walk") && !keyPressed) {
if (!channel.getAnimationName().equals("Walk")) {
channel.setAnim("Walk", 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
}
You said you were using 3.2 sdk. Thats 3.3 sdk.
It looks like you just converted that model without the texture and the skeleton. You need to read the tutorials for one. You are not learning anything like this.
If you read that link I sent, number 1 says.
Confirm that you exported the model into the
assets/Textures
directory (or subdirectories) together with all its textures.
Thats the first sentence.
You have to move ALL the files, Oto.material, Oto.mesh.xml, Oto.skeleton.xml, Oto.jpg into the assets/Textures
folder. Then convert to j3o by clicking the Oto.mesh.xml file, then drag the j3o into the models folder in the 3.2.4 SDK.
If you expect to use that model like that in the 3.3 SDK, the texture folder has to be in the 3.3 SDK exactly like it is in the 3.2.4 sdk.
You cannot move the j3o around after converting unless you have the textures exactly where they were when you converted the model. This only works in the SDK. It tracks things for you when you move them.
AFTER converting it in the 3.2.4 sdk, and moving the j3o, copy and paste the model and ALL its files to the EXACT SAME FOLDERS in the 3.3 sdk and try to run it.
Edit: Its also possible you just copied and pasted that .j3o into the 3.3 SDK.
Okay.
Thankâs
I try.
I understand:
- mesh texture armature bones move to texture catalog (ogre exportet blender model).
- And make j3o and move to models folder.
I convert all ogre files in texture folder and move j3o file to models folder
i have composer - not controlâŚ
and null pointer exception
So you did this in 3.3, after being told in dozens of posts YOU CANNOT DO THIS AND GET AN ANIMCONTROL.
YOU CANNOT DO THIS AND GET AN ANIMCONTROL.
I move that this thread be closed as this guy has to be a troll.
Im not troll.
Because documentation hello animation not work.
I canât run animation on character in my game.
Maybe you write work âHellow animationâ for latest versions?
Maybe you listen and convert the thing using 3.2.4 and move it to 3.3 if you want AnimControl?
yes
You converted the j3o in 3.2.4 and pasted that into 3.3, including textures and you say you get AnimComposer?
Yes
In screeshots.
Show me a screen shot of 3.2.4.