sdk
sdk copied to clipboard
Update Material when MatDef changes on disk
From @grizeldi 's wishlist:
"The preview as it is, is rather useless for shader development, as it doesn’t have live refresh. If I change my shader file on disk, the preview should refresh, so I don’t need to reopen the material window every time I do a small shader tweak. Lack of this functionality sadly prevents me from undocking the material editor, putting it somewhere else in the UI and just start coding."
I see two ways of doing this:
- As the scenecomposer does it for materials, through a listener/provider on the Shader editor
- As the scenecomposer does it for models, listening for changes on the file itself.
The first creates a nice integration with the other editors, encouraging usage. It however requires using them, and I figure a lot of people will be editing text files. The second allows for external editing, but it's complicated a bit by being multiple files (at least 3, matdef, vertex and frag shaders)
Given that, the first one is probably easier to implement.
If this is going to work in other instances (ie the scenecomposer) using the listener pattern is probably best. Then we can use it wherever we want)
I just found out I had already made a listener while working on the Shader Editor, I presume :P https://github.com/jMonkeyEngine/sdk/blob/0435fddab8d3758c28e64ba35cc87544f4b78a41/jme3-materialeditor/src/com/jme3/gde/materialdefinition/MatStructChangeListener.java#L51 Edit: NM, it was for the structure of the MatDef. But it got me started!