Package com.jme3.util
Class MaterialDebugAppState
java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.util.MaterialDebugAppState
- All Implemented Interfaces:
AppState
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
-
Field Summary
Fields inherited from class com.jme3.app.state.AbstractAppState
initialized -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinitialize(AppStateManager stateManager, Application app) Called byAppStateManagerwhen transitioning thisAppStatefrom initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)was called.voidregisterBinding(Trigger trigger, Filter filter) Will reload the filter's materials whenever the trigger is fired.voidregisterBinding(Trigger trigger, Spatial spat) Will reload the spatial's materials whenever the trigger is firedvoidregisterBinding(String shaderName, Filter filter) Will reload the filter's materials whenever the shader file is changed on the hard drivevoidregisterBinding(String shaderName, Spatial spat) Will reload the spatial's materials whenever the shader file is changed on the hard drivereloadMaterial(Material mat) voidupdate(float tpf) Called to update theAppState.Methods inherited from class com.jme3.app.state.AbstractAppState
cleanup, getId, isEnabled, isInitialized, postRender, render, setEnabled, setId, stateAttached, stateDetached
-
Constructor Details
-
MaterialDebugAppState
public MaterialDebugAppState()
-
-
Method Details
-
initialize
Description copied from interface:AppStateCalled byAppStateManagerwhen transitioning thisAppStatefrom initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)was called.AppStateManagerwill 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:
initializein interfaceAppState- Overrides:
initializein classAbstractAppState- Parameters:
stateManager- The state managerapp- The application
-
registerBinding
Will reload the spatial's materials whenever the trigger is fired- Parameters:
trigger- the triggerspat- the spatial to reload
-
registerBinding
Will reload the filter's materials whenever the trigger is fired.- Parameters:
trigger- the triggerfilter- the filter to reload
-
registerBinding
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
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
-
update
public void update(float tpf) Description copied from interface:AppStateCalled to update theAppState. This method will be called every render pass if theAppStateis both attached and enabled.- Specified by:
updatein interfaceAppState- Overrides:
updatein classAbstractAppState- Parameters:
tpf- Time since the last call to update(), in seconds.
-