Problem linking the mesh and the armature with HottBJ

Hi forum,



First of all, I want to thanks Blaine, and all people who works in that, for this tool and its tutorials, for me was a great surprise when I see that in the wiki.



And now my problem… when I create a armature with a mesh linked to a armature, if I play in blender's pose mode (for example with the sheep-duck) it seems that the mesh move when I move a bone correctly, and I can create animations, but when I export it and load with the modeler or in my jme xml loader example, it seems that the bones don't have a link with the mesh. Any idea?



I use the HottBJ 0.3e and Blender 2.48a.



Thanks for all,

Peter.

PeterPunkZ said:

Hi forum,

First of all, I want to thanks Blaine, and all people who works in that, for this tool and its tutorials, for me was a great surprise when I see that in the wiki.

And now my problem... when I create a armature with a mesh linked to a armature, if I play in blender's pose mode (for example with the sheep-duck) it seems that the mesh move when I move a bone correctly, and I can create animations, but when I export it and load with the modeler or in my jme xml loader example, it seems that the bones don't have a link with the mesh. Any idea?

I use the HottBJ 0.3e and Blender 2.48a.

Thanks for all,
Peter.


If you are able to load your model using Modeler, do so and investigate using the Tree widget to see if everything you expect is there with correct parenting.  Right click and turn on the bone debugger to verify that bones animate.

If you don't figure it out, make the model available somewhere, with referenced resources, and post the URL here.

With Modeler I can move the bones manually and load animations, and it works fine, but the mesh don’t move. In the Tree window it looks like in the blender outline window.



I upload the *-jme.xml file here: http://www.mediafire.com/file/qjmjmm1fwqv/xurri-jme.xml.



Thanks again.

PeterPunkZ said:

With Modeler I can move the bones manually and load animations, and it works fine, but the mesh don't move. In the Tree window it looks like in the blender outline window.

I upload the *-jme.xml file here: http://www.mediafire.com/file/qjmjmm1fwqv/xurri-jme.xml.

Thanks again.


Your skin mesh was not exported as a skin mesh and has no association to the armature.  Associate as documented in the exporter docs and tutorials, and watch Blender stdout for indications of why the skin is not recognized as such.

I follow the steps of the tutorial to link the mesh, and I was revising that in my model and I think that is correct, but looking in the tutorial images I see that Armature and Body in the Outliner was in the same level of the tree, and I remove the "Par:" in the Transform Properties window of the body. Now, in the Modeler the mesh moves with the bones, but some vertex don't and it make a strange effect. In my jme example it still don't move.



Furthermore, looking in the stdout of blender, it seems that all talk about the bones structure, and bones animation, except the line "357 verts out of 369 weighted for skin 'Body'" what I suppose that talk about how mesh link with bones, and I do and redo the "Apply Bone Heat

Could you post your blender and java-file so we could have a look there as well?

The blender file: http://www.mediafire.com/file/tummzlwdb25/female.blend



And the code of the java file:


import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.logging.Logger;

import com.jme.animation.AnimationController;
import com.jme.animation.Bone;
import com.jme.animation.BoneAnimation;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.util.BoneDebugger;
import com.jme.util.Timer;
import com.jme.util.export.xml.XMLImporter;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;

public class JmeXMLImporter extends SimpleGame {
   private XMLImporter xmlImporter = XMLImporter.getInstance();
   private Node t;
   
    private static final Logger logger = Logger
            .getLogger(JmeXMLImporter.class.getName());
   
    AnimationController ac;
    boolean boneOn = false;
   
    public static void main(String[] args) {
       JmeXMLImporter app = new JmeXMLImporter();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }
   
    protected void simpleUpdate() {
       /*if(KeyBindingManager.getKeyBindingManager().isValidCommand( "canviarAnimacio", true ))
       {
          ac.setActiveAnimation(1);
          
       }
       else
          ac.setActiveAnimation(0);*/
       if( KeyBindingManager.getKeyBindingManager().isValidCommand( "bones", false ) ) {
            boneOn = !boneOn;
        }
       ac.update(Timer.getTimer().getTimePerFrame());
    }

    protected void simpleRender() {
        //If we want to display the skeleton use the BoneDebugger.
        if(boneOn) {
            BoneDebugger.drawBones(rootNode, display.getRenderer(), true);
        }
    }

    protected void simpleInitGame() {
       String XMLFileName = "elMensajeroDePekin/xurri-jme.xml";
       URL modelURL = JmeXMLImporter.class.getClassLoader().getResource(XMLFileName);
       System.out.println("Carrego el model: "+modelURL);
       
       KeyBindingManager.getKeyBindingManager().set( "bones", KeyInput.KEY_SPACE );
       KeyBindingManager.getKeyBindingManager().set("canviarAnimacio", KeyInput.KEY_9);
       
       
       try {
            ResourceLocatorTool.addResourceLocator(
                    ResourceLocatorTool.TYPE_TEXTURE,
                    new SimpleResourceLocator(JmeXMLImporter.class
                            .getClassLoader().getResource(
                                    "elMensajeroDePekin/")));
        } catch (URISyntaxException e1) {
            logger.warning("Unable to add texture directory to RLT: "
                    + e1.toString());
        }
       
       
        try {
           System.out.println("Estic dintre del try");
           Object o = xmlImporter.load(modelURL);
           System.out.println("Objecte o: "+o);
           if (!(o instanceof Spatial)){
              throw new IOException("File contains non-spatial root: " + o.getClass().getName());
           } else {
                  Spatial loadedSpatial = (Spatial) o;
                  t = (Node) loadedSpatial;
                  t.setName("ASuperBone");
                  t.setLocalTranslation(new Vector3f(0f,0f,0f));
                    System.out.println("LoadBlenderModel: "+ XMLFileName + ".xml loaded.");
               }   
      } catch (IOException e) {   // Just in case anything happens
            System.out.print("Severe Error: " + e);
            System.exit(0);
      }
        t.setModelBound(new BoundingBox());

        rootNode.attachChild(t);
        t.updateModelBound();
        ac = getAnimationController();
        System.out.println("Available animations:");
        for (BoneAnimation anim : ac.getAnimations())
            System.out.println("    " + anim.getName());
        ac.setActiveAnimation(1);
        System.err.println("Executing animation '"
                + ac.getActiveAnimation().getName() + "'");

        // The default update loop will update world bounding volumes.
        rootNode.updateRenderState();
    }
   
    public AnimationController getAnimationController() {
       //System.out.println("descendantMatches"+rootNode.descendantMatches(Bone.class));
        List<Spatial> armatures =
           rootNode.descendantMatches(Bone.class, ".+SuperBone");
        if (armatures.size() < 1)
            throw new IllegalStateException("Sorry.  Program assumes "
                    + "you have a node named with suffix 'SuperBone'");
        if (armatures.get(0).getControllerCount() != 1)
            throw new IllegalStateException(
                    "Armature should have 1 controller, but has "
                    + armatures.get(0).getControllerCount());
        Controller controller = armatures.get(0).getController(0);
        if (!(controller instanceof AnimationController))
            throw new IllegalStateException(
                    "Controller is of unexpected type: "
                    + controller.getClass().getName());
        return (AnimationController) controller;
    }
}



Thanks.

Ok,…as you mentioned. You have to remove the parent from mesh (if using the armature-modifier).

With your code for me also only the bones move. With using this it works (with the vertex-faults):

package org.tomtro.sasa.gs;

import java.io.IOException;

import org.tomtro.sasa.utils.Utils;

import com.jme.animation.AnimationController;
import com.jme.app.SimpleGame;
import com.jme.scene.Node;
import com.jme.util.export.xml.XMLImporter;
import com.jmex.game.state.DebugGameState;
import com.jmex.model.ogrexml.anim.MeshAnimationController;

public class Game extends SimpleGame {
   
   public Game(String name)
   {

   }
   
    @Override
   protected void simpleInitGame() {
      Node sandro = Utils.getJMEXML("org/tomtro/sasa/res/default-jme.xml");
      Utils.setResourceLoader("org/tomtro/sasa/res/");
      AnimationController anim = (AnimationController)sandro.getChild("ArmatureSuperBone").getController(0);
      anim.setActiveAnimation("Walk");
      anim.setActive(true);
      sandro.updateRenderState();
      rootNode.attachChild(sandro);
   }

  public static Node getJMEXML(String resource)
    {
       try {
          XMLImporter importer = new XMLImporter();
         Node result = (Node)importer.load(Game.class.getClassLoader().getResource(resource));
         return result;
      } catch (IOException e) {
         e.printStackTrace();
         return null;
      }       
    }    
  
  public static void main(String[] args)
  {
     new Game("a").start();
  }
    
}



The vertex-problems seems to occur 'cause you did forget to add the hair to a bone. If you just assign the hair-verteces to the head-vertexgroup it is fine.

Hope that helped.


Ok, I go to try it and post the result.



Thanks again :slight_smile:

Hey ttrocha,



I changed the weight of the bones in every vertex and it finally works, thanks.



I changed a little your code 'cause I don't have your Utils library, but it works equally, now I will try to fix my code :).

PeterPunkZ said:

Hey ttrocha,

I changed the weight of the bones in every vertex and it finally works, thanks.

I changed a little your code 'cause I don't have your Utils library, but it works equally, now I will try to fix my code :).


Too late to help with the case-at-hand, but if you are using Bone Heat and you do something that requires it to be re-applied, you don't need to do it manually.  Select all bones in Arma Edit mode, switch to skin Weight Paint mode, "w", Apply Bone Heat.  I don't have time to verify now, but it's something very close to that.
blaine said:

Too late to help with the case-at-hand, but if you are using Bone Heat and you do something that requires it to be re-applied, you don't need to do it manually.  Select all bones in Arma Edit mode, switch to skin Weight Paint mode, "w", Apply Bone Heat.  I don't have time to verify now, but it's something very close to that.


I was trying that with the model but it seems that didn't work. Maybe the problem is that I don't know anything about blender (I started a couple of weeks ago with your tutorials of the wiki) and the model isn't mine (I use that only for testing bones animation), and the woman isn't prepared for this type of animation, I don't know.

If you are new to Blender, don't only rely on Blaine's excellent tutorials but do some of the Blender tuts as well.  Blender seems kind of complex and maybe backwards and unintuitive at first, but after a while it will all make sense and you'll know what needs to be done when working with HottBJ.



Here's a great intro tut to get you started:



http://wiki.blender.org/index.php/Doc:Tutorials/Animation/BSoD/Character_Animation/Setting_up_the_mesh



It will walk you through setting up a mesh, setting up an armature (more complex than necessary for HottBJ) and assigning the mesh/vert weights, and animation.  If you can get through the whole thing then you will be well on your way!