|
|
|
@ -97,14 +97,14 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
showMaterial(m, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void showMaterial(final Material m,final String techniqueName) { |
|
|
|
|
public void showMaterial(final Material m, final String techniqueName) { |
|
|
|
|
if (!init) { |
|
|
|
|
init(); |
|
|
|
|
} |
|
|
|
|
SceneApplication.getApplication().enqueue(new Callable<Material>() { |
|
|
|
|
|
|
|
|
|
public Material call() throws Exception { |
|
|
|
|
if(techniqueName!= null){ |
|
|
|
|
if (techniqueName != null) { |
|
|
|
|
try { |
|
|
|
|
m.selectTechnique(techniqueName, SceneApplication.getApplication().getRenderManager()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
@ -142,9 +142,10 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private int lastErrorHash = 0; |
|
|
|
|
private void smartLog(String expText, String message){ |
|
|
|
|
|
|
|
|
|
private void smartLog(String expText, String message) { |
|
|
|
|
int hash = message.hashCode(); |
|
|
|
|
if(hash != lastErrorHash){ |
|
|
|
|
if (hash != lastErrorHash) { |
|
|
|
|
Logger.getLogger(MaterialPreviewRenderer.class.getName()).log(Level.SEVERE, expText, message); |
|
|
|
|
lastErrorHash = hash; |
|
|
|
|
} |
|
|
|
@ -152,7 +153,7 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
|
|
|
|
|
public Material reloadMaterial(Material mat) { |
|
|
|
|
|
|
|
|
|
((ProjectAssetManager)mat.getMaterialDef().getAssetManager()).clearCache(); |
|
|
|
|
((ProjectAssetManager) mat.getMaterialDef().getAssetManager()).clearCache(); |
|
|
|
|
|
|
|
|
|
//creating a dummy mat with the mat def of the mat to reload
|
|
|
|
|
Material dummy = new Material(mat.getMaterialDef()); |
|
|
|
@ -160,7 +161,9 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
for (MatParam matParam : mat.getParams()) { |
|
|
|
|
dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue()); |
|
|
|
|
} |
|
|
|
|
dummy.selectTechnique(mat.getActiveTechnique().getDef().getName(), SceneApplication.getApplication().getRenderManager()); |
|
|
|
|
if (mat.getActiveTechnique() != null) { |
|
|
|
|
dummy.selectTechnique(mat.getActiveTechnique().getDef().getName(), SceneApplication.getApplication().getRenderManager()); |
|
|
|
|
} |
|
|
|
|
dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState()); |
|
|
|
|
|
|
|
|
|
//creating a dummy geom and assigning the dummy material to it
|
|
|
|
@ -168,7 +171,7 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
dummyGeom.setMaterial(dummy); |
|
|
|
|
|
|
|
|
|
//preloading the dummyGeom, this call will compile the shader again
|
|
|
|
|
SceneApplication.getApplication().getRenderManager().preloadScene(dummyGeom); |
|
|
|
|
SceneApplication.getApplication().getRenderManager().preloadScene(dummyGeom); |
|
|
|
|
} catch (RendererException e) { |
|
|
|
|
//compilation error, the shader code will be output to the console
|
|
|
|
|
//the following code will output the error
|
|
|
|
@ -181,8 +184,10 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return null; |
|
|
|
|
} catch (NullPointerException npe){ |
|
|
|
|
} catch (NullPointerException npe) { |
|
|
|
|
//utterly bad, but for some reason I get random NPE here and can't figure out why so to avoid bigger issues, I just catch it.
|
|
|
|
|
//the printStackTrace is intended, it will show up in debug mode, but won't be displayed in standzrd mode
|
|
|
|
|
npe.printStackTrace(); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -191,7 +196,6 @@ public class MaterialPreviewRenderer implements SceneListener { |
|
|
|
|
return dummy; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void switchDisplay(DisplayType type) { |
|
|
|
|
switch (type) { |
|
|
|
|
case Box: |
|
|
|
|