Ejemplo n.º 1
0
 private static RenderState doRemoveRenderState(Spatial s, StateType state) {
   if (s.getRenderState(state) != null) {
     RenderState rs = s.getRenderState(state);
     s.clearRenderState(state);
     return rs;
   }
   return null;
 }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
 public static void lookForRenderState(Spatial s, StateType stateType) {
   if (s.getRenderState(stateType) != null) {
     System.out.println(s.getName() + " has " + stateType.toString());
   } else {
     System.out.println(s.getName() + " lacks " + stateType.toString());
   }
   if (s instanceof Node && ((Node) s).getChildren() != null) {
     for (int i = 0; i < ((Node) s).getChildren().size(); i++) {
       lookForRenderState(((Node) s).getChildren().get(i), stateType);
     }
   }
 }
Ejemplo n.º 4
0
 public static boolean checkForRenderState(Spatial s, StateType stateType) {
   if (s.getRenderState(stateType) != null) {
     return true;
   } else {
     if (s instanceof Node && ((Node) s).getChildren() != null) {
       for (int i = 0; i < ((Node) s).getChildren().size(); i++) {
         if (checkForRenderState(((Node) s).getChildren().get(i), stateType)) {
           return true;
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 5
0
  /**
   * Sets the MaterialFaces for a given object. By using the applyToFront and applyToBack
   * parameters, each desired combination of face settings can be produced (None, Front, Back,
   * Both).
   *
   * @param spatial The spatial for which to set the MaterialFace
   * @param applyToFront True if the front face should have the material applied
   * @param applyToBack True if the back face should have the material applied
   * @see MaterialFace
   */
  public static void setMaterialFaceApplication(
      Spatial spatial, boolean applyToFront, boolean applyToBack) {
    if (applyToFront && applyToBack) {
      if (spatial.getRenderState(StateType.Material) != null)
        ((MaterialState) spatial.getRenderState(StateType.Material))
            .setMaterialFace(MaterialFace.FrontAndBack);
    } else if (applyToFront) {
      if (spatial.getRenderState(StateType.Material) != null)
        ((MaterialState) spatial.getRenderState(StateType.Material))
            .setMaterialFace(MaterialFace.Front);
    } else if (applyToBack) {
      if (spatial.getRenderState(StateType.Material) != null)
        ((MaterialState) spatial.getRenderState(StateType.Material))
            .setMaterialFace(MaterialFace.Back);
    }

    if (spatial instanceof Node) {
      if (((Node) spatial).getChildren() != null) {
        for (Spatial child : ((Node) spatial).getChildren()) {
          setMaterialFaceApplication(child, applyToFront, applyToBack);
        }
      }
    }
  }
Ejemplo n.º 6
0
 public static boolean checkForRenderState(Spatial s, RenderState rs) {
   if (s.getRenderState(rs.getStateType()) != null) {
     return s.getRenderState(rs.getStateType()).equals(rs);
   } else return false;
 }
Ejemplo n.º 7
0
 private static void doWireframeApplication(Spatial s, boolean apply, WireframeState ws) {
   if (apply) s.setRenderState(ws);
   else if (s.getRenderState(StateType.Wireframe) != null) {
     s.clearRenderState(StateType.Wireframe);
   }
 }