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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
initialize
(AppStateManager stateManager, Application app) Called byAppStateManager
when transitioning thisAppState
from initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)
was called.void
registerBinding
(Trigger trigger, Filter filter) Will reload the filter's materials whenever the trigger is fired.void
registerBinding
(Trigger trigger, Spatial spat) Will reload the spatial's materials whenever the trigger is firedvoid
registerBinding
(String shaderName, Filter filter) Will reload the filter's materials whenever the shader file is changed on the hard drivevoid
registerBinding
(String shaderName, Spatial spat) Will reload the spatial's materials whenever the shader file is changed on the hard drivereloadMaterial
(Material mat) void
update
(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:AppState
Called byAppStateManager
when transitioning thisAppState
from initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.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 interfaceAppState
- Overrides:
initialize
in 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:AppState
Called to update theAppState
. This method will be called every render pass if theAppState
is both attached and enabled.- Specified by:
update
in interfaceAppState
- Overrides:
update
in classAbstractAppState
- Parameters:
tpf
- Time since the last call to update(), in seconds.
-