I'm loading a model from a MD2 file and trying to calculate the Model height to place it over the ground …
I'm getting the triangles from the child meshes … but something is going wrong with the result …
any other easy way to do it ?
look ath the code !
public class NodeUtil {
public static float getHeight(Node node) {
float top = 0;
float bottom = 0;
Vector3f[] foo = new Vector3f[3];
Stack<Node> toInspect = new Stack<Node>();
toInspect.push(node);
while (!toInspect.isEmpty()) {
Node current = (Node) toInspect.pop();
Iterator iterator = current.getChildren().iterator();
while (iterator.hasNext()) {
Spatial element = (Spatial) iterator.next();
if (element instanceof Node) {
toInspect.push((Node) element);
} else {
if (element instanceof TriMesh) {
TriMesh mesh = (TriMesh) element;
for (int i = 0; i < mesh.getTotalTriangles(); i++) {
mesh.getTriangle(i, foo);
LoggingSystem.getLogger().info("foo[0].y=" + foo[0].y);
if (foo[0].y > top)
top = foo[0].y;
if (foo[1].y > top)
top = foo[1].y;
if (foo[2].y > top)
top = foo[2].y;
if (foo[0].y < bottom)
bottom = foo[0].y;
if (foo[1].y < bottom)
bottom = foo[1].y;
if (foo[2].y < bottom)
bottom = foo[2].y;
}
}
} // if node
}
}
float height = top - bottom;
LoggingSystem.getLogger().info("height = " + height);
return height;
}
}
and the character still is floating ... :D

here is the code that I use at the update() method
@Override
protected void update(float interpolation) {
// update the time to get the framerate
timer.update();
interpolation = timer.getTimePerFrame();
// update the keyboard input (move the player around)
input.update(interpolation);
// update the chase camera to handle the player moving around.
chaser.update(interpolation);
// if escape was pressed, we exit
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
finished = true;
}
// We don't want the chase camera to go below the world, so always keep
// it 2 units above the level.
if (cam.getLocation().y < (page.getHeight(cam.getLocation()) + 2)) {
cam.getLocation().y = page.getHeight(cam.getLocation()) + 2;
cam.update();
}
// player.getLocalTranslation().y = page.getHeight(player
// .getLocalTranslation().x, player.getLocalTranslation().z)
// + (player.getHeight() / 2);
float characterMinHeight = page.getHeight(player.getLocalTranslation())
+ (player.getHeight() / 2) + DISTANCE_FROM_THE_GROUND;
if (!Float.isInfinite(characterMinHeight)
&& !Float.isNaN(characterMinHeight)) {
player.getLocalTranslation().y = characterMinHeight;
}
// get the normal of the terrain at our current location. We then apply
// it to the up vector
// of the player.
page.getSurfaceNormal(player.getLocalTranslation(), normal);
if (normal != null) {
player.rotateUpTo(normal);
}
// Because we are changing the scene (moving the skybox and player) we
// need to update
// the graph.
scene.updateGeometricState(interpolation, true);
}