Ejemplo n.º 1
0
  /**
   * Walks through the scenegraph beneath the supplied {@link Spatial} and indicates to any attached
   * textures that the data should be stored internally rather than in the file. Original image file
   * locations are saved and returned.
   *
   * @param s The object to perform this action on
   * @param textureFiles - used for recursion; pass in null
   * @return The locations of all located textures
   */
  public static List<URL> setupTextureStorage(Spatial s, List<URL> textureFiles) {
    if (textureFiles == null) {
      textureFiles = new ArrayList<URL>();
    }

    if (s instanceof Node) {
      // a Node shouldn't have a texture state attached to it, but in case it does:
      if (s.getRenderState(StateType.Texture) != null) {
        TextureState ts = (TextureState) s.getRenderState(StateType.Texture);
        for (int i = 0; i < ts.getNumberOfSetTextures(); i++) {
          Texture tex = ts.getTexture(i);
          if (tex != null) {
            try {
              textureFiles.add(new URL(tex.getImageLocation()));
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
            tex.setStoreTexture(true);
          }
        }
      }

      if (((Node) s).getChildren() != null) {
        Iterator<Spatial> it = ((Node) s).getChildren().iterator();
        while (it.hasNext()) {
          setupTextureStorage(it.next(), textureFiles);
        }
      }
    } else {
      if (s.getRenderState(StateType.Texture) != null) {
        TextureState ts = (TextureState) s.getRenderState(StateType.Texture);
        for (int i = 0; i < ts.getNumberOfSetTextures(); i++) {
          Texture tex = ts.getTexture(i);
          if (tex != null) {
            try {
              textureFiles.add(new URL(tex.getImageLocation()));
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
            tex.setStoreTexture(true);
          }
        }
      }
    }

    return textureFiles;
  }
 public TextureAnimationController(TextureState ts) {
   textures = new Texture[ts.getNumberOfSetTextures()];
   for (int i = 0, count = 0; i < TextureState.getNumberOfTotalUnits(); i++) {
     Texture t = ts.getTexture(i);
     if (t != null) {
       textures[count++] = t;
     }
   }
   initializeValues();
 }