Package com.jme3.util

Class MaterialDebugAppState

java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.util.MaterialDebugAppState
All Implemented Interfaces:
AppState

public class MaterialDebugAppState extends AbstractAppState
This appState is for debug purpose only, and was made to provide an easy way to test shaders, with a live update capability. This class provides and easy way to reload a material and catches compilation errors when needed and displays the error in the console. If no error occur on compilation, the material is reloaded in the scene. You can either trigger the reload when pressing a key (or whatever input is supported by Triggers you can attach to the input manager), or trigger it when a specific file (the shader source) has been changed on the hard drive. Usage : MaterialDebugAppState matDebug = new MaterialDebugAppState(); stateManager.attach(matDebug); matDebug.registerBinding(new KeyTrigger(KeyInput.KEY_R), whateverGeometry); this will reload the material of whateverGeometry when pressing the R key. matDebug.registerBinding("Shaders/distort.frag", whateverGeometry); this will reload the material of whateverGeometry when the given file is changed on the hard drive. you can also register bindings to the appState with a post process Filter
  • Constructor Details

    • MaterialDebugAppState

      public MaterialDebugAppState()
  • Method Details

    • initialize

      public void initialize(AppStateManager stateManager, Application app)
      Description copied from interface: AppState
      Called by AppStateManager when transitioning this AppState from initializing to running.
      This will happen on the next iteration through the update loop after AppStateManager.attach(com.jme3.app.state.AppState) was called.

      AppStateManager will call this only from the update loop inside the rendering thread. This means is it safe to modify the scene graph from this method.

      Specified by:
      initialize in interface AppState
      Overrides:
      initialize in class AbstractAppState
      Parameters:
      stateManager - The state manager
      app - The application
    • registerBinding

      public void registerBinding(Trigger trigger, Spatial spat)
      Will reload the spatial's materials whenever the trigger is fired
      Parameters:
      trigger - the trigger
      spat - the spatial to reload
    • registerBinding

      public void registerBinding(Trigger trigger, Filter filter)
      Will reload the filter's materials whenever the trigger is fired.
      Parameters:
      trigger - the trigger
      filter - the filter to reload
    • registerBinding

      public void registerBinding(String shaderName, Filter filter)
      Will reload the filter's materials whenever the shader file is changed on the hard drive
      Parameters:
      shaderName - the shader name (relative path to the asset folder or to a registered asset path)
      filter - the filter to reload
    • registerBinding

      public void registerBinding(String shaderName, Spatial spat)
      Will reload the spatial's materials whenever the shader file is changed on the hard drive
      Parameters:
      shaderName - the shader name (relative path to the asset folder or to a registered asset path)
      spat - the spatial to reload
    • reloadMaterial

      public Material reloadMaterial(Material mat)
    • update

      public void update(float tpf)
      Description copied from interface: AppState
      Called to update the AppState. This method will be called every render pass if the AppState is both attached and enabled.
      Specified by:
      update in interface AppState
      Overrides:
      update in class AbstractAppState
      Parameters:
      tpf - Time since the last call to update(), in seconds.