Changing the size of a node

problem:

i want to take an arbitrary spatial and make the largest side of its bounding box be p_newSize long. this is the code:

 public static Spatial resizeNode(final Spatial p_view, final float p_newSize) {
    if (!(p_view.getWorldBound() instanceof BoundingBox)) {
      p_view.setModelBound(new BoundingBox());
      p_view.updateModelBound();
    }
    if (p_view.getWorldBound() == null) {
      Utils.updateWorldBounds(p_view);
    }
    final BoundingVolume l_volume = p_view.getWorldBound();
    final BoundingBox l_box = (BoundingBox) l_volume;
    final float l_xExtent = l_box.xExtent;
    final float l_yExtent = l_box.yExtent;
    final float l_zExtent = l_box.zExtent;
    final Float l_factor = HsUtils.biggest(l_xExtent, l_yExtent, l_zExtent);
    p_view.getLocalScale().set(p_view.getLocalScale().x / l_factor * p_newSize, p_view.getLocalScale().y / l_factor * p_newSize,
       p_view.getLocalScale().z / l_factor * p_newSize);
    p_view.updateGeometricState(0.0F, false);
    p_view.updateModelBound();
    Utils.updateWorldBounds(p_view);

//    assert p_view.getWorldBound() != null;
//    assert ((BoundingBox) p_view.getWorldBound()).getExtent(null).x <= p_newSize;
//    assert ((BoundingBox) p_view.getWorldBound()).getExtent(null).y <= p_newSize;
//    assert ((BoundingBox) p_view.getWorldBound()).getExtent(null).z <= p_newSize;

    return p_view;
  }

  public static void updateWorldBounds(final Spatial p_view) {
    if (p_view instanceof Node) {
      final Node l_node = (Node) p_view;
      updateWorldBounds(l_node);
    } else {
      p_view.updateWorldBound();
    }
  }

  public static void updateWorldBounds(final Node p_node) {
    final ArrayList<Spatial> l_children = p_node.getChildren();
    for (int i = 0; l_children != null && i < l_children.size(); i++) {
      final Spatial l_spatial = l_children.get(i);
    if (l_spatial instanceof Node) {
        final Node l_node = (Node) l_spatial;
        Utils.updateWorldBounds(l_node);
        l_node.updateWorldBound();
      } else {
        l_spatial.updateWorldBound();
      }
    }
    p_node.updateWorldBound();

  }



it doesn't work. the resulting nodes are sometimes too big, somestimes too small. the result even changes if i call the method twice in a row. any ideas?

It works only if local scale is (1;1;1) at the beginning. Throw out that use of the old local scale.

i believe that would be even more wrong. if the current local scale is 1000, and therefore, the objects size is 1000, and i divide the old local scale by 1000, i get 1. correct. if i ignore the old local scale, i'd get a size of 0.001, which is wrong.

oh, right :), nvm

it gets even more puzzling:

resizing the node to 1, then wrapping it and setting the local scale of the wrapping node -> works

resizing any freshly created or loaded (byte[]) node to any size -> works

resizing a resized node to any size -> broken