Target meshes on SkeletonControl are bad just after loading a .blend

Right after importing a .blend the target meshes in it skeleton control are some unknown meshes (maybe it has something to do with it internal cloning on import, which I don’t really know if it is being done or not). However, when the model is put on the scene, this meshes are updated and set to the correct ones.

This problem is only there for runtime loaded .blend (when generating a .j3o, this is just right) and it is easily patched (remove->add the control from the generated spatial).

The next code shows that problem for a given model:

public class TestPlayerSkeleton extends SimpleApplication {

    public static void main(String[] args) {
        TestPlayerSkeleton app = new TestPlayerSkeleton();

    Material mat;
    Spatial player;
    public void simpleInitApp() {
        rootNode.addLight(new AmbientLight());
        player = assetManager.loadModel("Models/player.blend");
    public static boolean checkSkeletonControls(Spatial spatial) {
        List<Geometry> list = new ArrayList<>();
        GeometryBatchFactory.gatherGeoms(spatial, list);
        Map<Mesh, Geometry> meshAssocMap = new HashMap<>();

        for(Geometry geom : list) {
            meshAssocMap.put(geom.getMesh(), geom);
//            System.out.println("MESH for: " + geom + ":" + geom.getMesh());

        final List<SkeletonControl> skControls = new ArrayList<>();
        spatial.depthFirstTraversal(new SceneGraphVisitor() {
            public void visit(Spatial spatial) {
                SkeletonControl sk = spatial.getControl(SkeletonControl.class);
                if(sk != null) {
                    // --- PATCH THAT FIX THE ISSUE ---
//                    spatial.removeControl(sk);
//                    spatial.addControl(sk);
                    // --------------------------------

        boolean success = true;

        if(skControls != null) {
            for (SkeletonControl skeletonControl : skControls) {
                Mesh[] targets = skeletonControl.getTargets();
                if(targets != null) {
                    for(Mesh target : targets) {
                        if(!meshAssocMap.containsKey(target)) {
                            success = false;

                            List<Geometry> skeletonGeoms = new ArrayList<>();
                            GeometryBatchFactory.gatherGeoms(skeletonControl.getSpatial(), skeletonGeoms);

                            boolean containsGeoms = true;

                            if(skeletonGeoms != null) {
                                for (Geometry geometry : skeletonGeoms) {
                                    if(!meshAssocMap.containsValue(geometry)) {
                                        containsGeoms = false;

                            System.out.println("SkeletonControl for: " + skeletonControl.getSpatial() + ", has a mesh: " + target + ", that isn't in it container spatial: " + spatial + ". However, it skeletonControls subGeoms are fine?:" + containsGeoms);

        return success;

What version of JME are you using?

The last one in jcenter (or it should be): 3.1.0-beta2

IMO that’s a blend loader issue… the meshes are gathered automatically on every update, and that’s why attaching the model fixes the issue.
Anyway… I don’t see why it’s an issue. For what do you need them valid before attaching them to the scene graph?

Some skeleton cloning related changes exist on the 3.1.x branch that haven’t been released yet. They may or may not be relevant here.

The fact that attaching it to the scene fixes it means probably not. It’s likely just something that’s dirty until the first update is called. It could be that the saved j3o just had an update run before being saved.

That’s the easy part xD, where I can’t do anything is just in the blender loader side.

Because I use an intermediate app where I load multiple blends and I merge all their skeleton together (where I got that problem with the meshes). The patch I use is just enough for my purpose but it doesn’t means it is not an issue in the loader :wink:

It could mean that, I don’t really know, I was just guessing but I think that yes, there is something dirty inside and since I just stuck with it for a while thinking it was a problem elsewhere until I found the issue I though it wasn’t a bad idea to inform about it.

It probably isn’t and won’t be a problem for the 99.9% of the people using jme3 though…

1 Like

Try other means of importing Animations. If those work its the blender loader if not it’s the controls or their cloning or something like that