Can not adjust the transform of a spatial after it was added to a bone

I imported my models from Blender in JME3 (character, sword and shield).

Right now, I want to attach the shield in the left hand and the sword in the right hand of the character.
Blender

I followed the instructions from TestOgreAnim.java but the transform of the objects relative to the character is wrong. What can be wrong?

Kingdom of the dead warlock 2025-04-25 15-18-26 (online-video-cutter.com)

Maybe were the bones created wrong in Blender? Or I should mirror the position of the spatial (sword and shield) relative to the character-node inside the JME? I cannot see the source model of the Ogre, used in JME3-examples to determine the best practices.

Code to load the character:

private void loadPlayer() {
        String path = WrapperPathsCreationUtil.getPath(false, false, "Models", "Player", "Player.j3o");
        var player = (Node) assetManager.loadModel(path);
        ((Node) rootNode.getChild(0)).attachChild(player);
        enableAnimation(player);
        loadWeaponAndShield(player);
    }

code to load and attach the sword:

private void loadWeaponAndShield(Node person) {
        String shieldName = "Shield";
        String path = WrapperPathsCreationUtil.getPath(false, false, "Models",shieldName , shieldName  + ".j3o");
        this.shield = assetManager.loadModel(path);    
        
        String swordName = "Sword";
        path = WrapperPathsCreationUtil.getPath(false, false, "Models",swordName , swordName  + ".j3o");
        this.sword = assetManager.loadModel(path);
        this.sword.rotate(FastMath.PI, 0, 0);    //I have played already with the angles but can not determine the dependency
        
        SkinningControl skinningControl = person.getControl(SkinningControl.class);
        Node n = skinningControl.getAttachmentsNode(SHIELD_BONE_NAME);
        n.attachChild(this.shield);
        Node n1 = skinningControl.getAttachmentsNode(SWORD_BONE_NAME);
        n1.attachChild(this.sword);
    }

Well, for starters at least you should switch to GLTF and not use the Ogre XML. That is deprecated pretty much. That might even already solve the problem.

I use GLTF. I talked not about the file format but about the code from the example. I have also tried to add the simple red box from the JME-example. And it appears also in same place as the sword. This is the example code:

        Box b = new Box(.25f, 3f, .25f);
        Geometry item = new Geometry("Item", b);
        item.move(0, 1.5f, 0);
        item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        Node n = skinningControl.getAttachmentsNode("hand.right");
        n.attachChild(item);

And this is the red box.

The ogre from the examples holds the box right, but I can not see the source orge armature.

Maybe I should set some checkBox by Blender-export? Or should I make the anchor-bones for the weapon and shield using an another method?

1 Like

I’m watching this video and it seems the sword makes the rotation right, but the translation must be from the left to the right (on the picture), but the sword makes the translation from backward to forward.

Attachment nodes “just work” for me… so I wonder if there is something wrong with your armature somehow.

Where can I see your armature, which “just works”? Maybe some screenshot?

Do you any non-uniform scaling in your bones or anything like that? All transforms applied, and so on. No weird scaling of the model itself?

I have nothing strange in the code, but I have tried to edit the character model in the SceneComposer and highlighted the low level mesh in the SceneExplorer. And it shows me something strange:

All the code is bellow:

@Override
    public void simpleInitApp() {
        GlobalVariables.initEngine(this);
        loadScene();
        loadPlayer();
        setCameraParams();
    }

    private void setCameraParams() {
        flyCam.setMoveSpeed(flyCam.getMoveSpeed() * 25);
        var cameraPos = getCamera().getLocation();
        cameraPos.y += 15;
        cameraPos.z += 15;
        cameraPos.x += -10;
        getCamera().setLocation(cameraPos);
    }

    private void loadWeaponAndShield(Node person) {
        String shieldName = "Shield";
        String path = WrapperPathsCreationUtil.getPath(false, false, "Models",shieldName , shieldName  + ".j3o");
        this.shield = assetManager.loadModel(path);

        String swordName = "Sword";
        path = WrapperPathsCreationUtil.getPath(false, false, "Models",swordName , swordName  + ".j3o");
        this.sword = assetManager.loadModel(path);

        SkinningControl skinningControl = person.getControl(SkinningControl.class);
        Node n = skinningControl.getAttachmentsNode(SHIELD_BONE_NAME);
        n.attachChild(this.shield);
        Node n1 = skinningControl.getAttachmentsNode(SWORD_BONE_NAME);
        n1.attachChild(this.sword);
    }

    private void loadPlayer() {
        String path = WrapperPathsCreationUtil.getPath(false, false, "Models", "Player", "Player.j3o");
        var player = (Node) assetManager.loadModel(path);
        ((Node) rootNode.getChild(0)).attachChild(player);
        enableAnimation(player);
        loadWeaponAndShield(player);
    }

    private void enableAnimation(Node player) {
        var composer = player.getControl(AnimComposer.class);
        composer.setCurrentAction("ATTACK_1");
        composer.getCurrentAction().setSpeed(composer.getCurrentAction().getSpeed()*0.3f);
    }

    private void loadScene() {
        String path = WrapperPathsCreationUtil.getPath(false, false,  "Scenes", "Level_-1_test.j3o");
        var scene = (Node) assetManager.loadModel(path);
        rootNode.attachChild(scene);
    }

    @Override
    public void update() {
        super.update();
    }

When exporting the GLTF file from Blender, did you click the “y up” checkbox?

Edit: also make sure you “apply transforms” on your model. Hint: so far all of my model-related suggestions have been “things to fix in Blender”.

I also think it is the export problem, but I can not determine how to fix it. I have played with this check-box. It rotates the model but the blue mesh is also rotated relative to the visible model. The modifiers are applied. It could be intuitive right if I could rotate the low level mesh around 180 grad and the parent node around -90, but it is not successfully in the SceneComposer window.

I didn’t found any adequate method to set right export parameters and used the next export pipeline:

  1. Export to .GLTF
  2. Import in Blender again
  3. Rotate the mesh
  4. Export to .GLTF again
  5. Import in JME3

And I receive the next model. I think, something should be changed in my original .BLEND model to avoid the unnecessary imports.

These all seem like “forgot to apply transforms” problems to me.