Odd vanishing of the head of my model

Hello,
I’ve got a model which has two animations; created in Blender and exported using Ogre3D. It is being loaded into my game and it plays the walk animation. When I shoot it (currently just a ray checking fo the hit), I load the AnimChannel of a map and play the die animation without a loop. Then the model is lyiing on the ground. Everything is working fine, but when I get too close to the model and look at it, the head suddenly disappears. It’s really odd and I double checked the model in blender but there’s no strange behaviour there… Here is a video because it’s quite difficult to describe: http://youtu.be/K6fNQZyBPm4
As you see, sometimes the whole model disappears (more obvious at the big one).

Here is the Code I use for the models and the animation:

[java]

private AnimChannel getChannel(Spatial s) {
Node n = (Node) s;
Node metarig = (Node) n.getChild(“metarig”);
Node pelvis = (Node) metarig.getChild(“Pelvis”);
Node polySurface1 = (Node) pelvis.getChild(“polySurface2.006-entity”);
Node polySurface2 = (Node) polySurface1.getChild(“polySurface2.006-ogremesh”);
AnimControl control = polySurface2.getControl(AnimControl.class);
AnimChannel channel = control.createChannel();
return channel;
}

private void initEnemies() {
enemies = new Node(“Enemies”);

    Spatial e1 = assetManager.loadModel("Models/skeleton.j3o");
    e1.scale(5);
    BetterCharacterControl e1Control = new BetterCharacterControl(2f, 10f, 170f);
    e1.addControl(e1Control);
    bulletAppState.getPhysicsSpace().add(e1Control);
    e1Control.warp(new Vector3f(100f, 0.2f, 0.0f));
    e1Control.setGravity(new Vector3f(0f, -50f, 0f));
    AnimChannel bigChannel = getChannel(e1);
    bigChannel.setAnim("Walk");
    bigEnemies.put(e1, bigChannel);
    enemies.attachChild(e1);

    Spatial t1 = assetManager.loadModel("Models/skeleton.j3o");
    BetterCharacterControl t1Control = new BetterCharacterControl(1f, 2f, 30f);
    t1.addControl(t1Control);
    bulletAppState.getPhysicsSpace().add(t1Control);
    t1Control.warp(new Vector3f(20f, 0.2f, 0.0f));
    t1Control.setGravity(new Vector3f(0f, -30f, 0f));

    AnimChannel channel = getChannel(t1);
    channel.setAnim("Walk");
    enemies.attachChild(t1);
    smallEnemies.put(t1, channel);

    rootNode.attachChild(enemies);
}

public void shoot(int damage) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
enemies.collideWith(ray, results);
if (results.size() > 0) {
CollisionResult closest = results.getClosestCollision();
Spatial result = closest.getGeometry().getParent().getParent().getParent().getParent().getParent();
for (Spatial s : enemies.getChildren()) {
if (result.equals(s)) {
AnimChannel channel;
if(bigEnemies.containsKey(s)) {
channel = bigEnemies.get(s);
} else {
channel = smallEnemies.get(s);
}
channel.setAnim(“Die”, 0.3f);
channel.setSpeed(0.8f);
channel.setLoopMode(LoopMode.DontLoop);
}
}
}
}[/java]

The strange thing is, that the model works perfectly fine if I run the walk animation / no animation. At the start of the die animation the head disappears (if I am too close and look down with the camera).Is something wrong with the blender model / animation? I really can’t find a solution…

Looks like a culling issue. If the “falling down” is an animation and the head is a separate geometry the head might move out of the original bounding volume, they are not updated during animations as this would be too taxing on the performance. I think @Momoko_Fan wanted to make it so that the when the bounding volume is generated it would play the whole animation once and make the bounding volume encompass the whole area of the animation. For now you could simply set a larger bounding box on the geometry manually or disable culling altogether.

Okay thank you very much! This already helped me a lot. The head issue is solved now with this line of code:
[java]spatial.setCullHint(Spatial.CullHint.Never);[/java]

But one problem remains as you see in the video ca at 0:40; when I move the camera, the whole model disappears at a certain angle. What could cause this?

Btw, never received such a fast anwser in a forum :smiley:

@mathiasj said: Okay thank you very much! This already helped me a lot. The head issue is solved now with this line of code: [java]spatial.setCullHint(Spatial.CullHint.Never);[/java]

But one problem remains as you see in the video ca at 0:40; when I move the camera, the whole model disappears at a certain angle. What could cause this?

Btw, never received such a fast anwser in a forum :smiley:

I guess its the same issue. You have to imagine your bounding box staying in the same location as the model in its initial pose. So if the animation moves the model out of this original bounding box and the box moves out of the view the model will be culled, no matter if its visible on the screen or not.

Yeah you’re right. I solve it by disabling culling for the rootNode once the model is shot, and when the dead model which is not used any more is removed, I enable CullHint again. But something like @Momoko_Fan wanted to do would be awesome!