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.
This commit is contained in:
parent
33222e33be
commit
851af2f7bc
@ -24,6 +24,7 @@ import com.jme3.scene.shape.Sphere;
|
|||||||
import com.jme3.util.MaterialDebugAppState;
|
import com.jme3.util.MaterialDebugAppState;
|
||||||
import com.jme3.util.TangentBinormalGenerator;
|
import com.jme3.util.TangentBinormalGenerator;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
@ -42,6 +43,7 @@ public class MaterialPreviewRenderer implements SceneListener {
|
|||||||
private Material currentMaterial;
|
private Material currentMaterial;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
private final JLabel label;
|
private final JLabel label;
|
||||||
|
private final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(5);
|
||||||
|
|
||||||
public enum DisplayType {
|
public enum DisplayType {
|
||||||
|
|
||||||
@ -79,16 +81,22 @@ public class MaterialPreviewRenderer implements SceneListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void showMaterial(ProjectAssetManager assetManager, String materialFileName) {
|
public void showMaterial(final ProjectAssetManager assetManager,final String materialFileName) {
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
|
||||||
|
public void run() {
|
||||||
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
|
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
|
||||||
assetManager.deleteFromCache(key);
|
assetManager.deleteFromCache(key);
|
||||||
Material mat = (Material) assetManager.loadAsset(key);
|
Material mat = (Material) assetManager.loadAsset(key);
|
||||||
if (mat != null) {
|
if (mat != null) {
|
||||||
showMaterial(mat);
|
showMaterial(mat);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,5 +237,6 @@ public class MaterialPreviewRenderer implements SceneListener {
|
|||||||
|
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
SceneApplication.getApplication().removeSceneListener(this);
|
SceneApplication.getApplication().removeSceneListener(this);
|
||||||
|
exec.shutdownNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user