I cant load my own model T.T

I’ve made an Animated model in blender for import it with “import model”
But i can’t understand what’s wrong, because jme can’t load correctly the model…

this is the error logout:
[java]
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@6c4bc190
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@61910c7b
Created constraint: Limit Distance with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionDistLimit@79ca9147
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@62080ac8
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@7dfc02bf
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@2c188a37
Created constraint: Limit Distance with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionDistLimit@7f1a377e
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@12317263
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@6c4ccae9
Created constraint: Limit Distance with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionDistLimit@259dbe8b
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@1748aaf8
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@23d08bb9
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Stop offview panel
Clearing asset List
Clearing asset List
Start offview panel
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@1a8e8c61
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@4a241e6
Created constraint: Limit Distance with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionDistLimit@3894656a
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@168e2f2b
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@50babb9e
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@1373ab7a
Created constraint: Limit Distance with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionDistLimit@efee090
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@7f4915a0
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@172afca9
Created constraint: Limit Distance with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionDistLimit@731c721
Created constraint: Copy Location with definition: com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinitionLocLike@55084b37
Created constraint: Locked Track with definition: com.jme3.scene.plugins.blender.constraints.definitions.UnsupportedConstraintDefinition@1382337e
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!
Removing invalid constraints.
Stop offview panel
[/java]

and this is the model (untitled3.blend) with Uv’s :

https://mega.co.nz/#!DkwGARQK!gur81jsqcjzDxonFi-IyxBYQhoBLq8efskW_ZzgfK5w

The problem is somehow tied to your armature/skeleton, I started by deleting that to test, and your model alone loads perfectly.

I’ll mess around with the armature settings to see if I can get something that complies, although you probably know more about your own armature and might find a solution faster than I can.

I managed to run your model with animation. Here is the image of it with your animation jumping up and down in jme.

When modeling make sure to give “Apply Rotation & Scale” in blender other wise the model will look all messed up when you export it. Sometimes “Apply Location” is also need which was in your model case. Anyway your model seem to work when I ogre export it from blender and then converting it to .j3o but when I try to convert it directly from .blend file to .j3o in jme then I also do get that problem:
“Constraint named: ‘Locked Track’ of type ‘Lock track’ is not implemented and will NOT be applied!”.

There may be something wrong with the model. Maybe someone with more knowledge can explain to you, as I can only explain this much. :slight_smile:

Ok found it, in pose mode seems the importer is not happy with those constraints you left, just as it says. So i just deleted them in each bone that had one and it works.

Seems there is recurring lesson to be learned: if you can ogre, you should ogre.

Ok, i tried to remove the constrain on every bone and it’s seems to be ok, import the model with the “import model…” ok,it looks like the model is kinda ok BUT when i tried to create the channels for animation…NULLPOINTER EXCEPTION
this is the error log:

[java]
feb 21, 2014 12:11:05 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.0.4
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Lwjgl 2.9.0 context running on thread LWJGL Renderer Thread
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: igdumd64
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: 9.17.10.2867
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: NVIDIA Corporation
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 4.3.0
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: GeForce GT 740M/PCIe/SSE2
feb 21, 2014 12:11:07 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 4.30 NVIDIA via Cg compiler
feb 21, 2014 12:11:07 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Device: OpenAL Soft
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Vendor: OpenAL Community
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Renderer: OpenAL Soft
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Version: 1.1 ALSOFT 1.15.1
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio effect extension version: 1.0
feb 21, 2014 12:11:07 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio max auxilary sends: 4
feb 21, 2014 12:11:16 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Golem.spawnEnemy(Golem.java:504)
at mygame.Golem$1.onAction(Golem.java:302)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onKeyEventQueued(InputManager.java:455)
at com.jme3.input.InputManager.processQueue(InputManager.java:831)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)
[/java]

:facepalm:

So i tried to use OgreXML but convertion is not so succesful beacuse when i’m trying to do this i’ve got something like this:

http://imageshack.com/a/img812/7508/27nr.png

EVEN UNITY3D READ THOSE ANIMATION DAMN

The NPE is in your own code…

Oh look, its the exact same errors I had to work around.

Keep Calm, if you think you can stomach it, follow my solution at:

http://hub.jmonkeyengine.org/forum/topic/stuck-at-animations-phase-blender-2-69/

Apparently, those of us who cannot do ogre conversion, which is a blender 2.69 problem, and blender26ogre only going as high as 2.66 as stated here:

https://bitbucket.org/MindCalamity/blender2ogre

Well we’re stuck importing directly from the .blend and seems most of us who do, have to useSpatial getChild() to plug in the correct node which AnimControl is on.

If you really want to use ogre, the only workaround I found, was to downgrade to Blender 2.66 and use the latest blender26ogre. Which has worked for me, as I was able to export ogre meshes after that.

1 Like

I was a bit mad, so i make a new model (Step by step)
(downgrading blender) (i didn’t use ogre btw, i don’t know,but everytime something goes wrong…)
At fist i had the same error but i made this change on the code (thanks to @cardboardman):

[java]
enemies = (Node)assetManager.loadModel(“Models/robot/robot.j3o”);
rootNode.attachChild(enemies);
cont_en = enemies.getChild(0).getControl(AnimControl.class);
chan_en = cont_en.createChannel();
chan_en.setAnim(“Walk”);
[/java]

So JME in fact finds the Animation but the model is still in the game and, this is strange, when i see the model in the scene explorer the animation in fact is visible:
http://imageshack.com/a/img23/1564/9fqe.png

here is the new model i’ve done:
https://mega.co.nz/#!C54FxQqS!7kuT-zvgNyf0oNA0gpc8Y-1Mvmmqxu2ptcy_O_CcMJ8

I’m going to lose my mind trying to solve this :explode:

(why JME is so buggy in models? Unity3d doesn’t have this kind of problem…)

/facepalm …you are the one who has the problems, you code crashes all the time… If you cause nullpointers then any game engine crashes…

If you make a model and its animations according to the documentation we provide it imports just fine. Just make a new blender file template for animation in the SDK and check out how it works.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

@normen said: /facepalm ...you are the one who has the problems, you code crashes all the time... If you cause nullpointers then any game engine crashes..

If you make a model and its animations according to the documentation we provide it imports just fine. Just make a new blender file template for animation in the SDK and check out how it works.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

I’m sorry sir, but my code worked pretty good while been using test models, you offend me
And when i created the second model, i followed all the rules for import/export

finally, if the model loads fine and the animation didn’t appear but i see there is an animation in the list of the animations, it means that i’ve done all fine. Don’t you think?

@TheWayIsNotSimple said: I'm sorry sir, but my code worked pretty good while been using test models, you offend me And when i created the second model, i followed all the rules for import/export

finally, if the model loads fine and the animation didn’t appear but i see there is an animation in the list of the animations, it means that i’ve done all fine. Don’t you think?

No, obviously not if it works in the SDK viewer, it also just uses engine code, but correctly.

@normen said: No, obviously not if it works in the SDK viewer, it also just uses engine code, but correctly.

Ok, but i think we’re missing the point of the discussion: i’ve done all i could for solving the problem, and i didn’t resolve anything
But if some of Senior Developers could help me and correct me it would be great… :frowning:

We never saw any code, we just know what you think you are doing.

Ok…but the code isn’t so long, i mean there are only 3 lines that are really important, but if you say, here’s the code:

[java]
public void spawnEnemy(Vector3f pos) {
enemies = (Node)assetManager.loadModel(“Models/robot/robot.j3o”);
enemies.setLocalTranslation(pos);
enemies.setLocalScale(0.1f);
enemies.setName(“ninja_en”);
rootNode.attachChild(enemies);
//
cont_en = enemies.getChild(0).getControl(AnimControl.class); //getChild(0) because for now enemy are all the same
chan_en = cont_en.createChannel();
chan_en.setAnim(“Walk”);

    bct_en = new BetterCharacterControl(0.5f, 2, 1);
    enemies.addControl(bct_en);
    bas.getPhysicsSpace().add(bct_en);
    enemies.getChild(0).setUserData("healt", 100);

}
[/java]

So now a screenshot of the completely unfolded model and info on which line in the code your posted the exception appears.

@normen said: So now a screenshot of the completely unfolded model and info on which line in the code your posted the exception appears.

Here’s the model with Uv’s and textures:
https://mega.co.nz/#!C54FxQqS!7kuT-zvgNyf0oNA0gpc8Y-1Mvmmqxu2ptcy_O_CcMJ8

and if i write:

cont_en = enemies.getChild(0).getControl(AnimControl.class);

the enemy is spawned correctly (only the animation doesn’t run but “there is”)

if i write:

cont_en = enemies.getControl(AnimControl.class);

i get this:

[java]
run:
feb 21, 2014 2:20:09 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.0.4
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Lwjgl 2.9.0 context running on thread LWJGL Renderer Thread
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: igdumd64
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: 9.17.10.2867
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: NVIDIA Corporation
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 4.3.0
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: GeForce GT 740M/PCIe/SSE2
feb 21, 2014 2:20:10 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 4.30 NVIDIA via Cg compiler
feb 21, 2014 2:20:11 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Device: OpenAL Soft
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Vendor: OpenAL Community
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Renderer: OpenAL Soft
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Version: 1.1 ALSOFT 1.15.1
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio effect extension version: 1.0
feb 21, 2014 2:20:11 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio max auxilary sends: 4
feb 21, 2014 2:20:17 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Golem.spawnEnemy(Golem.java:492)
at mygame.Golem$1.onAction(Golem.java:303)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onKeyEventQueued(InputManager.java:455)
at com.jme3.input.InputManager.processQueue(InputManager.java:831)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)
[/java]

Screenshot:
http://imageshack.com/a/img546/2742/7shr.jpg

A screenshot of the unfolded model in the SDK and the line number in the code you posted, please.

HELLO AGAIN!

I think you might have gone overboard as I did when I tested out the child codes, I can’t quite put my finger on it yet, but I THINK it has to do with these lines:

chan_en = cont_en.createChannel();
chan_en.setAnim(“Walk”);

It is only my assumption so far, but when I am able to, I’ll fully check it.

There appears to be 0 things wrong with your model.

Ok, something like this?
http://imageshack.com/a/img593/1286/faf0.png

ok,and here’s the whole code,so you can see

[java]
package mygame;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.animation.SkeletonControl;
import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingVolume;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.BetterCharacterControl;
import com.jme3.bullet.control.KinematicRagdollControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.collision.CollisionResult;
import com.jme3.collision.CollisionResults;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.material.*;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Line;
import com.jme3.math.Quaternion;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.post.filters.FogFilter;
import com.jme3.post.filters.LightScatteringFilter;
import com.jme3.post.ssao.SSAOFilter;
import com.jme3.renderer.Caps;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.debug.Arrow;
import com.jme3.scene.debug.SkeletonDebugger;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.BasicShadowRenderer;
import com.jme3.shadow.DirectionalLightShadowFilter;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.shadow.PssmShadowRenderer;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.texture.Texture;
import com.jme3.util.SkyFactory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Timer;
import jme3test.input.combomoves.ComboMoveExecution;
import net.java.games.input.Mouse;

public class Golem extends SimpleApplication implements ActionListener, AnalogListener, AnimEventListener {

Node hero = new Node();
Node terra = new Node();
Node act_element = new Node();
Node others = new Node();
Node enemies = new Node();
Node boneNode = new Node();
BulletAppState bas = new BulletAppState();
private AnimChannel chan, chan_en, chan_sword;
private AnimControl cont, cont_en;
private float time = 0;
private ComboMove doublejump;
private ComboMoveExecution doublejumpexec;
HashSet<String> pressedMappings = new HashSet<String>();
private ComboMove currentMove = null;
private float currentMoveCastTime = 0;
TerrainQuad terrain;
BetterCharacterControl bct_personaggio, bct_en;
boolean debug = false, isEnemy = false, moving_forward, moving_backward, moving_left, moving_right, moving;
int mov_flag, up_, down_, left_, right_, action;
DirectionalLight sun;
String moves[] = new String[]{"Kick", "Spin", "Attack1", "Attack3", "Attack2", "SideKick"};
String sel_action = "Kick";
int c_act = 0;
int id_bone = 12;
Geometry health;

public static void main(String[] args) {
    Golem app = new Golem();
    app.start();
}

@Override
public void simpleInitApp() {
    moving = moving_forward = moving_backward = moving_left = moving_right = false;
    mov_flag = up_ = down_ = left_ = right_ = action = 0;

    flyCam.setMoveSpeed(flyCam.getMoveSpeed() * 100);
    cam.setLocation(new Vector3f(0f, 0f, -100f));

    stateManager.attach(bas);
    rootNode.attachChild(hero);
    rootNode.attachChild(terra);
    rootNode.attachChild(act_element);
    rootNode.attachChild(others);
    rootNode.attachChild(enemies);
    rootNode.attachChild(boneNode);

    crea_personaggio();
    setupFilters();
    initLightNShadow();

// initFog();
initWorld();
initCam();
initKeys();
initActionEl();

    //debugSkeleton();
    cont.setEnabled(true);
}

@Override
public void simpleUpdate(float tpf) {
    time += tpf;
    doublejumpexec.updateExpiration(time); 
    
    if (currentMove != null){
        currentMoveCastTime -= tpf;
        if (currentMoveCastTime <= 0){

// chan.setAnim(“Backflip”);
// chan.setSpeed(2);
// chan.setLoopMode(LoopMode.DontLoop);
bct_personaggio.jump();
currentMoveCastTime = 0;
currentMove = null;
}
}
mov_flag = up_ + down_ + left_ + right_ + action;
bct_personaggio.setViewDirection(cam.getDirection().negate());
Vector3f dir = cam.getDirection();
Vector3f left = cam.getLeft();
if (moving) {
if (moving_forward) {
bct_personaggio.setWalkDirection(new Vector3f(dir.x, 0, dir.z).mult(5));
}
if (moving_backward) {
bct_personaggio.setWalkDirection(new Vector3f(dir.x, 0, dir.z).mult(5).negate());
}
if (moving_left) {
bct_personaggio.setWalkDirection(left.mult(8));
}
if (moving_right) {
bct_personaggio.setWalkDirection(left.mult(8).negate());
}
}
if (mov_flag == 0) {
chan.setAnim(“Idle3”, 0.50f);
bct_personaggio.setWalkDirection(new Vector3f(0, 0, 0));
}
if (bct_personaggio.getVelocity().equals(new Vector3f(0, 0, 0))) {
bct_personaggio.setWalkDirection(Vector3f.ZERO);
}
if (isEnemy) {
health.setLocalRotation(cam.getRotation());
}
Quaternion ROLL180 = new Quaternion().fromAngleAxis(FastMath.PI, new Vector3f(0, 0, 3));
cont.getSkeleton().getBone(id_bone).setUserControl(true);
cont.getSkeleton().getBone(id_bone).setUserTransformsWorld(Vector3f.ZERO, ROLL180);
//System.out.println(id_bone);//12 spada
}

@Override
public void simpleRender(RenderManager rm) {
}

public void crea_personaggio() {
    hero = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    hero.getChild(hero.getQuantity() - 1).setName("hero");
    cont = hero.getControl(AnimControl.class);
    cont.addListener(this);
    chan = cont.createChannel();
    chan_sword = cont.createChannel();
    //[Walk, Kick, JumpNoHeight, Jump, Spin, Attack1, Idle1, Attack3, Idle2, Idle3, Attack2, Stealth, Death2, Death1, HighJump, SideKick, Backflip, Block, Climb, Crouch]
    hero.setLocalTranslation(0, 0, 0);
    hero.setLocalTranslation(cam.getLocation());
    hero.setLocalScale(0.01f);
    //makeToonish(hero.getChild("hero"));
    rootNode.attachChild(hero);
    hero.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);

    bct_personaggio = new BetterCharacterControl(0.5f, 2, 1);
    hero.addControl(bct_personaggio);
    bas.getPhysicsSpace().add(bct_personaggio);
    bct_personaggio.setGravity(new Vector3f(0, -10.81f, 0));
}

public void onAction(String name, boolean isPressed, float tpf) {
}

public void onAnalog(String name, float value, float tpf) {
}

public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
    if (animName.equals(sel_action) || animName.equals("Jump") || animName.equals("Backflip") || animName.equals("JumpNoHeight")) {
        action = 0;
    }
}

public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
    if (animName.equals("Walk")) {
        action = 0;
    }
}

public void initCam() {
    cam.setLocation(new Vector3f(hero.getWorldTranslation().x + 5, hero.getWorldTranslation().y + 5, hero.getWorldTranslation().z + 5));
    ChaseCamera ccam = new ChaseCamera(cam, hero, inputManager);
    ccam.setSmoothMotion(false);
    ccam.setDefaultDistance(8);
    ccam.setMaxDistance(100);
    ccam.setDragToRotate(false);

}

public void initKeys() {
    inputManager.addMapping("Avanti", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Dietro", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Destra", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Sinistra", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Salta", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("Spara", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("+", new KeyTrigger(KeyInput.KEY_ADD));
    inputManager.addMapping("-", new KeyTrigger(KeyInput.KEY_SUBTRACT));
    inputManager.addMapping("spwn_killer", new KeyTrigger(KeyInput.KEY_N));


    inputManager.addMapping("MWheel_up", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    inputManager.addMapping("MWheel_down", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    inputManager.addMapping("Debug", new KeyTrigger(KeyInput.KEY_B));
    inputManager.addListener(actionListener, new String[]{"Avanti", "spwn_killer", "-", "+", "Dietro", "MWheel_up", "Debug", "MWheel_down", "Destra", "Sinistra", "Salta", "Spara"});

    doublejump = new ComboMove("DoubleJump");
    doublejump.press("Salta").done();
    doublejump.press("Salta").done();
    doublejump.useFinalState();
    doublejumpexec=new ComboMoveExecution(doublejump);

}

private ActionListener actionListener = new ActionListener() {
    public void onAction(String name, boolean pressed, float tpf) {
        if (pressed) {
            pressedMappings.add(name);
        } else {
            pressedMappings.remove(name);
        }

        List<ComboMove> invokedMoves = new ArrayList<ComboMove>();
        if (doublejumpexec.updateState(pressedMappings, time)) {
            invokedMoves.add(doublejump);
        }

        if (invokedMoves.size() > 0) {
            // identify the move with highest priority
            float priority = 0;
            ComboMove toExec = null;
            for (ComboMove move : invokedMoves) {
                if (move.getPriority() > priority) {
                    priority = move.getPriority();
                    toExec = move;
                }
            }
            if (currentMove != null && currentMove.getPriority() > toExec.getPriority()) {
                return; // skip lower-priority moves
            }

            // If a ComboMove has been identified, store it in currentMove
            currentMove = toExec;
            currentMoveCastTime = currentMove.getCastTime();
        }

        if (name.equals("+")) {
            if (id_bone < 26) {
                id_bone++;
            }
        }
        if (name.equals("-")) {
            if (id_bone > 0) {
                id_bone--;
            }
        }

        if (name.equals("spwn_killer") && pressed) {
            spawnEnemy(new Vector3f(hero.getWorldTranslation().x + 5, hero.getWorldTranslation().y + 3,  hero.getWorldTranslation().z + 5)); //FIRST LINE ERROR
        }

        if (name.equals("Avanti") && pressed) {
            moving = true;
            moving_forward = true;
            up_ = 1;
            if (bct_personaggio.isOnGround()) {

                chan.setAnim("Walk");
                chan.setSpeed(1.5f);
                chan.setLoopMode(LoopMode.Cycle);
            }
        }
        if (name.equals("Avanti") && !pressed) {
            moving_forward = false;
            up_ = 0;
        }
        if (name.equals("Dietro") && pressed) {
            moving = true;
            moving_backward = true;
            down_ = 1;
            chan.setAnim("Walk");
            chan.setLoopMode(LoopMode.Cycle);
        }

        if (name.equals("Dietro") && !pressed) {
            moving_backward = false;
            down_ = 0;
        }
        if (name.equals("Destra") && pressed) {
            moving = true;
            moving_right = true;
            right_ = 1;
            chan.setAnim("Walk");
            chan.setLoopMode(LoopMode.Cycle);
        }
        if (name.equals("Destra") && !pressed) {
            moving_right = false;
            right_ = 0;
        }
        if (name.equals("Sinistra") && pressed) {
            moving = true;
            moving_left = true;
            left_ = 1;
            chan.setAnim("Walk");
            chan.setLoopMode(LoopMode.Cycle);
        }
        if (name.equals("Sinistra") && !pressed) {
            moving_left = false;
            left_ = 0;
        }

        if (name.equals("Salta") && pressed) {
            if (bct_personaggio.isOnGround()) {
                chan.setAnim("JumpNoHeight");
                chan.setLoopMode(LoopMode.DontLoop);
                bct_personaggio.jump();
                action = 1;
            }
        }
        if (name.equals("Spara") && pressed) {
            action = 1;
            chan.setAnim(sel_action);
            chan.setSpeed(2);
            chan.setLoopMode(LoopMode.DontLoop);
            CollisionResults cs = new CollisionResults();
            BoundingVolume bv = hero.getWorldBound();
            enemies.collideWith(bv, cs);
            if (cs.size() > 0) {
                int healt = enemies.getChild(0).getUserData("healt");
                System.out.println(healt);
                healt -= Math.random() * 10;
                enemies.getChild(0).setUserData("healt", healt);
                System.out.println("Collided");
                if (healt == 0) {
                    chan_en.setAnim("Death1");
                    bct_en.setEnabled(false);
                    enemies.getChild(0).removeControl(bct_en);
                    enemies.detachAllChildren();
                    if (chan_en.getAnimMaxTime() == 0) {
                    }
                }
            }
        }
        if (name.equals("MWheel_up")) {
            if (c_act < moves.length - 1) {
                c_act++;
            } else {
                c_act = 0;
            }
            sel_action = moves[c_act];
        }
    }
};
private AnalogListener analogListener = new AnalogListener() {
    public void onAnalog(String name, float value, float tpf) {
    }
};

public void initActionEl() {
    Spatial straight = assetManager.loadModel("Models/pipe/pipe.j3o");
    straight.setName("climb_straight");
    straight.setLocalScale(0.5f);

    Ray r_tmp = new Ray(cam.getLocation(), new Vector3f(0, -1, 0));
    CollisionResults css_tmp = new CollisionResults();
    terra.collideWith(r_tmp, css_tmp);
    if (css_tmp.size() > 0) {
        CollisionResult cs_cp_tmp = css_tmp.getClosestCollision();
        straight.setLocalTranslation(cs_cp_tmp.getContactPoint().x, cs_cp_tmp.getContactPoint().y + 1, cs_cp_tmp.getContactPoint().z);
    }

    act_element.attachChild(straight);

    RigidBodyControl rgb_tmp = new RigidBodyControl(0);
    straight.addControl(rgb_tmp);
    bas.getPhysicsSpace().add(rgb_tmp);

    straight.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);

    Material defaultMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    defaultMat.setTexture("DiffuseMap", assetManager.loadTexture("Models/pipe/pipe_2.jpg"));
    straight.setMaterial(defaultMat);
}

public void initLightNShadow() {
    sun = new DirectionalLight();
    sun.setDirection((new Vector3f(0.08630039f, -0.8564289f, 0.50900066f)).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
    viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 3f));

    AmbientLight ambient = new AmbientLight();
    ambient.setColor(ColorRGBA.White);
    rootNode.addLight(ambient);
}

public void initWorld() {
    Material mat_terrain = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    mat_terrain.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));

    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass2.png");
    grass.setWrap(Texture.WrapMode.Repeat);
    mat_terrain.setTexture("Tex1", grass);
    mat_terrain.setFloat("Tex1Scale", 64f);

    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt3.png");
    dirt.setWrap(Texture.WrapMode.Repeat);
    mat_terrain.setTexture("Tex2", dirt);
    mat_terrain.setFloat("Tex2Scale", 32f);

    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road_indirect.png");
    rock.setWrap(Texture.WrapMode.Repeat);
    mat_terrain.setTexture("Tex3", rock);
    mat_terrain.setFloat("Tex3Scale", 128f);

    AbstractHeightMap heightmap = null;
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
    heightmap.load();

    int patchSize = 65;
    TerrainQuad terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());
    terrain.setMaterial(mat_terrain);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(2F, 1f, 2F);

    terrain.setShadowMode(RenderQueue.ShadowMode.Receive);
    terra.attachChild(terrain);

    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    terrain.addControl(control);
    terrain.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);

    RigidBodyControl rgb = new RigidBodyControl(0);
    terrain.addControl(rgb);
    bas.getPhysicsSpace().add(rgb);
}

public void spawnEnemy(Vector3f pos) {
    //Spatial x = assetManager.loadModel("Models/robot/robot.j3o");
    enemies = (Node)assetManager.loadModel("Models/robot/robot.j3o");
    enemies.setLocalTranslation(pos);
    enemies.setLocalScale(0.1f);
    enemies.setName("ninja_en");
    rootNode.attachChild(enemies);

//
cont_en = enemies.getControl(AnimControl.class);
chan_en = cont_en.createChannel();//SECOND ERROR LINE
chan_en.setAnim(“Walk”);

    bct_en = new BetterCharacterControl(0.5f, 2, 1);
    enemies.addControl(bct_en);
    bas.getPhysicsSpace().add(bct_en);
    enemies.getChild(0).setUserData("healt", 100);

    Box box = new Box(1, 0.5f, -50);
    health = new Geometry("Health", box);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Red);
    health.setMaterial(mat);
    health.setLocalTranslation(new Vector3f(enemies.getWorldTranslation().x, enemies.getWorldTranslation().y + 200, enemies.getWorldTranslation().z + 80));
    enemies.attachChild(health);
    health.setLocalRotation(cam.getRotation());
    isEnemy = true;
}

public void setupFilters() {
     FilterPostProcessor fpp=new FilterPostProcessor(assetManager);

// nodeCARTOON
//
// if (renderer.getCaps().contains(Caps.GLSL100)){
// FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
// //fpp.setNumSamples(4);
// CartoonEdgeFilter toon=new CartoonEdgeFilter();
// toon.setEdgeColor(ColorRGBA.Black);
// toon.setEdgeWidth(0.5f);
// toon.setEdgeIntensity(10);
// //toon.setDepthThreshold(1);
// fpp.addFilter(toon);
// viewPort.addProcessor(fpp);
// }
//BLOOM

   // fpp.setNumSamples(4);
    BloomFilter bloom=new BloomFilter();
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    //BLUR

// FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
// fpp.setNumSamples(4);

    DepthOfFieldFilter dofFilter = new DepthOfFieldFilter();
    dofFilter.setFocusDistance(10);
    dofFilter.setFocusRange(50);
    dofFilter.setBlurScale(1.4f);
    fpp.addFilter(dofFilter);
    viewPort.addProcessor(fpp);

// FogFilter fog = new FogFilter();
// fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
// fog.setFogDistance(155);
// fog.setFogDensity(2.0f);
// fpp.addFilter(fog);
// viewPort.addProcessor(fpp);
}

}
[/java]

… double-click the model (the j3o file), unfold all nodes in the SceneExplorer, make a screenshot of the SceneExplorer.