MaterialPreviewRenderer now loads the material in a separate thread to avoid to stall the awt thread.

This and the previous change makes the material editor a lot faster to open when the loaded material has big textures.
experimental
Nehon 10 years ago
parent 33222e33be
commit 851af2f7bc
  1. 11
      sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.java

@ -24,6 +24,7 @@ import com.jme3.scene.shape.Sphere;
import com.jme3.util.MaterialDebugAppState;
import com.jme3.util.TangentBinormalGenerator;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
@ -42,6 +43,7 @@ public class MaterialPreviewRenderer implements SceneListener {
private Material currentMaterial;
private boolean init = false;
private final JLabel label;
private final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(5);
public enum DisplayType {
@ -79,16 +81,22 @@ public class MaterialPreviewRenderer implements SceneListener {
}
@SuppressWarnings("unchecked")
public void showMaterial(ProjectAssetManager assetManager, String materialFileName) {
public void showMaterial(final ProjectAssetManager assetManager,final String materialFileName) {
if (!init) {
init();
}
exec.execute(new Runnable() {
public void run() {
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
assetManager.deleteFromCache(key);
Material mat = (Material) assetManager.loadAsset(key);
if (mat != null) {
showMaterial(mat);
}
}
});
}
@ -229,5 +237,6 @@ public class MaterialPreviewRenderer implements SceneListener {
public void cleanUp() {
SceneApplication.getApplication().removeSceneListener(this);
exec.shutdownNow();
}
}

Loading…
Cancel
Save