@Override
    public void simpleUpdate(float tpf) {
        // Each frame, determine the distance to each sphere/box from the camera.
        // If the object is > 25 units away, switch in the Box.  If it's nearer, switch in the Sphere.
        // Normally we wouldn't do this every frame, only when player has moved a sufficient distance, etc.

        boolean modified = false;
        for (int i = 0; i < 10; i++) {
            Vector3f location = locations[i];
            float distance = location.distance(cam.getLocation());

            if(distance > 25.0f && boxes[i].getParent() == null) {
                modified = true;
                instancedNode.attachChild(boxes[i]);
                instancedNode.detachChild(spheres[i]);
            } else if(distance <= 25.0f && spheres[i].getParent() == null) {
                modified = true;
                instancedNode.attachChild(spheres[i]);
                instancedNode.detachChild(boxes[i]);
            }
        }

        if(modified) {
            instancedNode.instance();
        }
    }
A test case for using instancing with shadow filter.

Based on distance from camera, swap in/out more/less detailed geometry to/from an InstancedNode.

@author duncanj
jme3-examples/src/main/java/jme3test/scene/instancing/TestInstancedNodeAttachDetachWithShadowFilter.java