cleaned up threading in TerrainEditorController

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8639 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent fda1ee37ca
commit a2975b70a0
  1. 791
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java

@ -39,7 +39,6 @@ import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode; import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial; import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
import com.jme3.gde.core.sceneexplorer.nodes.JmeTerrainQuad;
import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
import com.jme3.gde.core.undoredo.SceneUndoRedoManager; import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
import com.jme3.gde.core.util.TerrainUtils; import com.jme3.gde.core.util.TerrainUtils;
@ -309,116 +308,121 @@ public class TerrainEditorController implements NodeListener {
* pre-calculate the terrain's entropy values * pre-calculate the terrain's entropy values
*/ */
public void generateEntropies(final ProgressMonitor progressMonitor) { public void generateEntropies(final ProgressMonitor progressMonitor) {
SceneApplication.getApplication().enqueue(new Callable<Object>() { if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null);
public Object call() throws Exception { if (terrain == null)
doGenerateEntropies(progressMonitor); return;
return null;
}
});
}
private void doGenerateEntropies(ProgressMonitor progressMonitor) {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
terrain.generateEntropy(progressMonitor);
}
// blocks on scale get
public Float getTextureScale(final int layer) {
try {
Float scale =
SceneApplication.getApplication().enqueue(new Callable<Float>() {
public Float call() throws Exception {
return doGetTextureScale(layer);
}
}).get();
return scale;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
protected Float doGetTextureScale(int layer) {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return 1f;
MatParam matParam = null;
matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer+"_scale");
if (matParam == null)
return -1f;
return (Float) matParam.getValue();
}
terrain.generateEntropy(progressMonitor);
} else {
SceneApplication.getApplication().enqueue(new Callable<Object>() {
// blocks on scale set
public void setTextureScale(final int layer, final float scale) {
try {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
doSetTextureScale(layer, scale); generateEntropies(progressMonitor);
return null; return null;
} }
}).get(); });
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
} }
} }
private void doSetTextureScale(int layer, float scale) { /**
Terrain terrain = (Terrain) getTerrain(null); * Get the scale of the texture at the specified layer.
if (terrain == null) * Blocks on the OGL thread
return; */
terrain.getMaterial().setFloat("DiffuseMap_"+layer+"_scale", scale); public Float getTextureScale(final int layer) {
setNeedsSave(true); if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return 1f;
MatParam matParam = null;
matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer+"_scale");
if (matParam == null)
return -1f;
return (Float) matParam.getValue();
} else {
try {
Float scale =
SceneApplication.getApplication().enqueue(new Callable<Float>() {
public Float call() throws Exception {
return getTextureScale(layer);
}
}).get();
return scale;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
} }
// blocks on texture get /**
public Texture getDiffuseTexture(final int layer) { * Set the scale of a texture at the specified layer
try { * Blocks on the OGL thread
Texture tex = */
SceneApplication.getApplication().enqueue(new Callable<Texture>() { public void setTextureScale(final int layer, final float scale) {
public Texture call() throws Exception { if (SceneApplication.getApplication().isOgl()) {
return doGetDiffuseTexture(layer); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
terrain.getMaterial().setFloat("DiffuseMap_"+layer+"_scale", scale);
setNeedsSave(true);
} else {
try {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception {
setTextureScale(layer, scale);
return null;
} }
}).get(); }).get();
return tex; } catch (InterruptedException ex) {
} catch (InterruptedException ex) { Exceptions.printStackTrace(ex);
Exceptions.printStackTrace(ex); } catch (ExecutionException ex) {
} catch (ExecutionException ex) { Exceptions.printStackTrace(ex);
Exceptions.printStackTrace(ex); }
} }
return null;
} }
/** /**
* Get the diffuse texture at the specified layer. * Get the diffuse texture at the specified layer.
* Run this on the GL thread! * Blocks on the GL thread!
*/ */
private Texture doGetDiffuseTexture(int layer) { public Texture getDiffuseTexture(final int layer) {
Terrain terrain = (Terrain) getTerrain(null); if (SceneApplication.getApplication().isOgl()) {
if (terrain == null) Terrain terrain = (Terrain) getTerrain(null);
return null; if (terrain == null)
MatParam matParam = null; return null;
if (layer == 0) MatParam matParam = null;
matParam = terrain.getMaterial().getParam("DiffuseMap"); if (layer == 0)
else matParam = terrain.getMaterial().getParam("DiffuseMap");
matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer); else
matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer);
if (matParam == null || matParam.getValue() == null) { if (matParam == null || matParam.getValue() == null) {
return null;
}
Texture tex = (Texture) matParam.getValue();
return tex;
} else {
try {
Texture tex =
SceneApplication.getApplication().enqueue(new Callable<Texture>() {
public Texture call() throws Exception {
return getDiffuseTexture(layer);
}
}).get();
return tex;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return null; return null;
} }
Texture tex = (Texture) matParam.getValue();
return tex;
} }
private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) { private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) {
@ -447,63 +451,44 @@ public class TerrainEditorController implements NodeListener {
* @param texturePath if null, the default texture will be used * @param texturePath if null, the default texture will be used
*/ */
public void setDiffuseTexture(final int layer, final String texturePath) { public void setDiffuseTexture(final int layer, final String texturePath) {
try { String path = texturePath;
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception {
doSetDiffuseTexture(layer, texturePath);
return null;
}
}).get();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}
private void doSetDiffuseTexture(int layer, String texturePath) {
if (texturePath == null || texturePath.equals("")) if (texturePath == null || texturePath.equals(""))
texturePath = DEFAULT_TERRAIN_TEXTURE; path = DEFAULT_TERRAIN_TEXTURE;
Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath);
tex.setWrap(WrapMode.Repeat);
Terrain terrain = (Terrain) getTerrain(null);
if (layer == 0) Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(path);
terrain.getMaterial().setTexture("DiffuseMap", tex); setDiffuseTexture(layer, tex);
else
terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex);
doSetTextureScale(layer, DEFAULT_TEXTURE_SCALE);
setNeedsSave(true);
} }
private void doSetDiffuseTexture(int layer, Texture tex) { /**
tex.setWrap(WrapMode.Repeat); * Set the diffuse texture at the specified layer.
Terrain terrain = (Terrain) getTerrain(null); * Blocks on the GL thread
if (terrain == null) * @param layer number to set the texture
return; */
if (layer == 0) public void setDiffuseTexture(final int layer, final Texture texture) {
terrain.getMaterial().setTexture("DiffuseMap", tex); if (SceneApplication.getApplication().isOgl()) {
else texture.setWrap(WrapMode.Repeat);
terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
setNeedsSave(true); return;
} if (layer == 0)
terrain.getMaterial().setTexture("DiffuseMap", texture);
else
terrain.getMaterial().setTexture("DiffuseMap_"+layer, texture);
public void setDiffuseTexture(final int layer, final Texture texture) { setNeedsSave(true);
try { } else {
SceneApplication.getApplication().enqueue(new Callable() { try {
public Object call() throws Exception { SceneApplication.getApplication().enqueue(new Callable() {
doSetDiffuseTexture(layer, texture); public Object call() throws Exception {
return null; setDiffuseTexture(layer, texture);
} return null;
}).get(); }
} catch (InterruptedException ex) { }).get();
Exceptions.printStackTrace(ex); } catch (InterruptedException ex) {
} catch (ExecutionException ex) { Exceptions.printStackTrace(ex);
Exceptions.printStackTrace(ex); } catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
} }
} }
@ -513,18 +498,22 @@ public class TerrainEditorController implements NodeListener {
* @param texturePath * @param texturePath
*/ */
public void removeTextureLayer(final int layer) { public void removeTextureLayer(final int layer) {
try { if (SceneApplication.getApplication().isOgl()) {
SceneApplication.getApplication().enqueue(new Callable() { doRemoveDiffuseTexture(layer);
public Object call() throws Exception { doRemoveNormalMap(layer);
doRemoveDiffuseTexture(layer); } else {
doRemoveNormalMap(layer); try {
return null; SceneApplication.getApplication().enqueue(new Callable() {
} public Object call() throws Exception {
}).get(); removeTextureLayer(layer);
} catch (InterruptedException ex) { return null;
Exceptions.printStackTrace(ex); }
} catch (ExecutionException ex) { }).get();
Exceptions.printStackTrace(ex); } catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
} }
} }
@ -553,43 +542,42 @@ public class TerrainEditorController implements NodeListener {
setNeedsSave(true); setNeedsSave(true);
} }
// blocks on normal map get
public Texture getNormalMap(final int layer) {
try {
Texture tex =
SceneApplication.getApplication().enqueue(new Callable<Texture>() {
public Texture call() throws Exception {
return doGetNormalMap(layer);
}
}).get();
return tex;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
/** /**
* Get the normal map texture at the specified layer. * Get the normal map texture at the specified layer.
* Run this on the GL thread! * Run this on the GL thread!
*/ */
private Texture doGetNormalMap(int layer) { public Texture getNormalMap(final int layer) {
Terrain terrain = (Terrain) getTerrain(null); if (SceneApplication.getApplication().isOgl()) {
if (terrain == null) Terrain terrain = (Terrain) getTerrain(null);
return null; if (terrain == null)
MatParam matParam = null; return null;
if (layer == 0) MatParam matParam = null;
matParam = terrain.getMaterial().getParam("NormalMap"); if (layer == 0)
else matParam = terrain.getMaterial().getParam("NormalMap");
matParam = terrain.getMaterial().getParam("NormalMap_"+layer); else
matParam = terrain.getMaterial().getParam("NormalMap_"+layer);
if (matParam == null || matParam.getValue() == null) { if (matParam == null || matParam.getValue() == null) {
return null; return null;
}
Texture tex = (Texture) matParam.getValue();
return tex;
} else {
try {
Texture tex =
SceneApplication.getApplication().enqueue(new Callable<Texture>() {
public Texture call() throws Exception {
return getNormalMap(layer);
}
}).get();
return tex;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
} }
Texture tex = (Texture) matParam.getValue(); return null;
return tex;
} }
/** /**
@ -597,7 +585,13 @@ public class TerrainEditorController implements NodeListener {
* Blocks on the GL thread * Blocks on the GL thread
*/ */
public void setNormalMap(final int layer, final String texturePath) { public void setNormalMap(final int layer, final String texturePath) {
try { if (texturePath != null) {
Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath);
setNormalMap(layer, tex);
} else {
setNormalMap(layer, (Texture)null);
}
/*try {
SceneApplication.getApplication().enqueue(new Callable() { SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
doSetNormalMap(layer, texturePath); doSetNormalMap(layer, texturePath);
@ -608,69 +602,48 @@ public class TerrainEditorController implements NodeListener {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) { } catch (ExecutionException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} }*/
} }
private void doSetNormalMap(int layer, String texturePath) { /**
Terrain terrain = (Terrain) getTerrain(null); * Set the normal map texture at the specified layer
if (terrain == null) */
return; public void setNormalMap(final int layer, final Texture texture) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
if (texture == null) {
// remove the texture if it is null
if (layer == 0)
terrain.getMaterial().clearParam("NormalMap");
else
terrain.getMaterial().clearParam("NormalMap_"+layer);
return;
}
if (texturePath == null) { texture.setWrap(WrapMode.Repeat);
// remove the texture if it is null
if (layer == 0)
terrain.getMaterial().clearParam("NormalMap");
else
terrain.getMaterial().clearParam("NormalMap_"+layer);
} else {
Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath);
tex.setWrap(WrapMode.Repeat);
if (layer == 0) if (layer == 0)
terrain.getMaterial().setTexture("NormalMap", tex); terrain.getMaterial().setTexture("NormalMap", texture);
else else
terrain.getMaterial().setTexture("NormalMap_"+layer, tex); terrain.getMaterial().setTexture("NormalMap_"+layer, texture);
}
enableTextureButtons();
setNeedsSave(true);
}
public void setNormalMap(final int layer, final Texture texture) { setNeedsSave(true);
try { } else {
SceneApplication.getApplication().enqueue(new Callable() { try {
public Object call() throws Exception { SceneApplication.getApplication().enqueue(new Callable() {
doSetNormalMap(layer, texture); public Object call() throws Exception {
return null; setNormalMap(layer, texture);
} return null;
}).get(); }
} catch (InterruptedException ex) { }).get();
Exceptions.printStackTrace(ex); } catch (InterruptedException ex) {
} catch (ExecutionException ex) { Exceptions.printStackTrace(ex);
Exceptions.printStackTrace(ex); } catch (ExecutionException ex) {
} Exceptions.printStackTrace(ex);
} }
private void doSetNormalMap(int layer, Texture tex) {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
if (tex == null) {
// remove the texture if it is null
if (layer == 0)
terrain.getMaterial().clearParam("NormalMap");
else
terrain.getMaterial().clearParam("NormalMap_"+layer);
return;
} }
tex.setWrap(WrapMode.Repeat);
if (layer == 0)
terrain.getMaterial().setTexture("NormalMap", tex);
else
terrain.getMaterial().setTexture("NormalMap_"+layer, tex);
setNeedsSave(true);
} }
// blocks on GL thread until terrain is created // blocks on GL thread until terrain is created
@ -701,72 +674,6 @@ public class TerrainEditorController implements NodeListener {
return null; // if failed return null; // if failed
} }
/*private Terrain doCreateTerrain(Node parent,
int totalSize,
int patchSize,
int alphaTextureSize,
float[] heightmapData,
String sceneName,
JmeSpatial jmeNodeParent) throws IOException
{
AssetManager manager = SceneApplication.getApplication().getAssetManager();
Terrain terrain = new TerrainQuad("terrain-"+sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations
com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
String assetFolder = "";
if (manager != null && manager instanceof ProjectAssetManager)
assetFolder = ((ProjectAssetManager)manager).getAssetFolderName();
// write out 3 alpha blend images
for (int i=0; i<NUM_ALPHA_TEXTURES; i++) {
BufferedImage alphaBlend = new BufferedImage(alphaTextureSize, alphaTextureSize, BufferedImage.TYPE_INT_ARGB);
if (i == 0) {
// the first alpha level should be opaque so we see the first texture over the whole terrain
for (int h=0; h<alphaTextureSize; h++)
for (int w=0; w<alphaTextureSize; w++)
alphaBlend.setRGB(w, h, 0x00FF0000);//argb
}
File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/");
if (!alphaFolder.exists())
alphaFolder.mkdir();
String alphaBlendFileName = "/Textures/terrain-alpha/"+sceneName+"-"+((Node)terrain).getName()+"-alphablend"+i+".png";
File alphaImageFile = new File(assetFolder+alphaBlendFileName);
ImageIO.write(alphaBlend, "png", alphaImageFile);
Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
if (i == 0)
mat.setTexture("AlphaMap", tex);
else if (i == 1)
mat.setTexture("AlphaMap_1", tex);
else if (i == 2)
mat.setTexture("AlphaMap_2", tex);
}
// give the first layer default texture
Texture defaultTexture = manager.loadTexture(DEFAULT_TERRAIN_TEXTURE);
defaultTexture.setWrap(WrapMode.Repeat);
mat.setTexture("DiffuseMap", defaultTexture);
mat.setFloat("DiffuseMap_0_scale", DEFAULT_TEXTURE_SCALE);
mat.setBoolean("WardIso", true);
((Node)terrain).setMaterial(mat);
((Node)terrain).setModelBound(new BoundingBox());
((Node)terrain).updateModelBound();
((Node)terrain).setLocalTranslation(0, 0, 0);
((Node)terrain).setLocalScale(4f, 1f, 4f);
// add the lod control
TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
((Node)terrain).addControl(control);
parent.attachChild((Node)terrain);
setNeedsSave(true);
addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
return terrain;
}*/
private void addSpatialUndo(final Node undoParent, final Spatial undoSpatial, final AbstractSceneExplorerNode parentNode) { private void addSpatialUndo(final Node undoParent, final Spatial undoSpatial, final AbstractSceneExplorerNode parentNode) {
//add undo //add undo
@ -919,22 +826,30 @@ public class TerrainEditorController implements NodeListener {
return sky; return sky;
} }
/**
* Is there a texture at the specified layer?
* Blocks on ogl thread
*/
public boolean hasTextureAt(final int i) { public boolean hasTextureAt(final int i) {
try { if (SceneApplication.getApplication().isOgl()) {
Boolean result = Texture tex = getDiffuseTexture(i);
SceneApplication.getApplication().enqueue(new Callable<Boolean>() { return tex != null;
public Boolean call() throws Exception { } else {
Texture tex = doGetDiffuseTexture(i); try {
return tex != null; Boolean result =
} SceneApplication.getApplication().enqueue(new Callable<Boolean>() {
}).get(); public Boolean call() throws Exception {
return result; return hasTextureAt(i);
} catch (InterruptedException ex) { }
Exceptions.printStackTrace(ex); }).get();
} catch (ExecutionException ex) { return result;
Exceptions.printStackTrace(ex); } catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return false;
} }
return false;
} }
/** /**
@ -942,11 +857,11 @@ public class TerrainEditorController implements NodeListener {
* on how many textures are currently being used. * on how many textures are currently being used.
*/ */
protected void enableTextureButtons() { protected void enableTextureButtons() {
SceneApplication.getApplication().enqueue(new Callable<Object>() { //SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception { // public Object call() throws Exception {
final int numAvailable = MAX_TEXTURES-doGetNumUsedTextures(); final int numAvailable = MAX_TEXTURES-getNumUsedTextures();
final boolean add = doGetNumDiffuseTextures() < MAX_DIFFUSE && numAvailable > 0; final boolean add = getNumDiffuseTextures() < MAX_DIFFUSE && numAvailable > 0;
final boolean remove = doGetNumDiffuseTextures() > 1; final boolean remove = getNumDiffuseTextures() > 1;
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
@ -956,9 +871,9 @@ public class TerrainEditorController implements NodeListener {
topComponent.setAddNormalTextureEnabled(numAvailable>0); topComponent.setAddNormalTextureEnabled(numAvailable>0);
} }
}); });
return null; // return null;
} // }
}); //});
} }
@ -967,35 +882,35 @@ public class TerrainEditorController implements NodeListener {
* Blocking call on GL thread * Blocking call on GL thread
*/ */
protected int getNumDiffuseTextures() { protected int getNumDiffuseTextures() {
try { if (SceneApplication.getApplication().isOgl()) {
Integer count = Terrain terrain = (Terrain) getTerrain(null);
SceneApplication.getApplication().enqueue(new Callable<Integer>() { if (terrain == null)
public Integer call() throws Exception { return 0;
return doGetNumDiffuseTextures();
}
}).get();
return count;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return -1;
}
private int doGetNumDiffuseTextures() {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return 0;
int count = 0; int count = 0;
for (int i=0; i<MAX_TEXTURES; i++) { for (int i=0; i<MAX_TEXTURES; i++) {
Texture tex = doGetDiffuseTexture(i); Texture tex = getDiffuseTexture(i);
if (tex != null) if (tex != null)
count++; count++;
}
return count;
} else {
try {
Integer count =
SceneApplication.getApplication().enqueue(new Callable<Integer>() {
public Integer call() throws Exception {
return getNumDiffuseTextures();
}
}).get();
return count;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return -1;
} }
return count;
} }
/** /**
@ -1003,80 +918,65 @@ public class TerrainEditorController implements NodeListener {
* Blocking call on GL thread * Blocking call on GL thread
*/ */
protected int getNumUsedTextures() { protected int getNumUsedTextures() {
try { if (SceneApplication.getApplication().isOgl()) {
Integer count = Terrain terrain = (Terrain) getTerrain(null);
SceneApplication.getApplication().enqueue(new Callable<Integer>() { if (terrain == null)
public Integer call() throws Exception { return 0;
return doGetNumUsedTextures();
} int count = 0;
}).get();
for (int i=0; i<MAX_TEXTURES; i++) {
Texture tex = getDiffuseTexture(i);
if (tex != null)
count++;
tex = getNormalMap(i);
if (tex != null)
count++;
}
return count; return count;
} catch (InterruptedException ex) { } else {
Exceptions.printStackTrace(ex); try {
} catch (ExecutionException ex) { Integer count =
Exceptions.printStackTrace(ex); SceneApplication.getApplication().enqueue(new Callable<Integer>() {
} public Integer call() throws Exception {
return -1; return getNumUsedTextures();
} }
}).get();
protected int doGetNumUsedTextures() { return count;
Terrain terrain = (Terrain) getTerrain(null); } catch (InterruptedException ex) {
if (terrain == null) Exceptions.printStackTrace(ex);
return 0; } catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
int count = 0; }
return -1;
for (int i=0; i<MAX_TEXTURES; i++) {
Texture tex = doGetDiffuseTexture(i);
if (tex != null)
count++;
tex = doGetNormalMap(i);
if (tex != null)
count++;
} }
return count;
} }
public boolean isTriPlanarEnabled() { public boolean isTriPlanarEnabled() {
try { if (SceneApplication.getApplication().isOgl()) {
Boolean isEnabled = Terrain terrain = (Terrain) getTerrain(null);
SceneApplication.getApplication().enqueue(new Callable<Boolean>() { if (terrain == null)
public Boolean call() throws Exception { return false;
return doIsTriPlanarEnabled(); MatParam param = terrain.getMaterial().getParam("useTriPlanarMapping");
} if (param != null)
}).get(); return (Boolean)param.getValue();
return isEnabled;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
return false;
}
private boolean doIsTriPlanarEnabled() {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return false; return false;
MatParam param = terrain.getMaterial().getParam("useTriPlanarMapping"); } else {
if (param != null) try {
return (Boolean)param.getValue(); Boolean isEnabled =
SceneApplication.getApplication().enqueue(new Callable<Boolean>() {
return false; public Boolean call() throws Exception {
} return isTriPlanarEnabled();
}
public void setTriPlanarEnabled(final boolean selected) { }).get();
try { return isEnabled;
SceneApplication.getApplication().enqueue(new Callable() { } catch (InterruptedException ex) {
public Object call() throws Exception { Exceptions.printStackTrace(ex);
doSetTriPlanarEnabled(selected); } catch (ExecutionException ex) {
return null; Exceptions.printStackTrace(ex);
} }
}).get(); return false;
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
} }
} }
@ -1087,27 +987,42 @@ public class TerrainEditorController implements NodeListener {
* @param enabled * @param enabled
* @param terrainTotalSize * @param terrainTotalSize
*/ */
private void doSetTriPlanarEnabled(boolean enabled) { public void setTriPlanarEnabled(final boolean enabled) {
Terrain terrain = (Terrain) getTerrain(null); if (SceneApplication.getApplication().isOgl()) {
if (terrain == null) Terrain terrain = (Terrain) getTerrain(null);
return; if (terrain == null)
terrain.getMaterial().setBoolean("useTriPlanarMapping", enabled); return;
terrain.getMaterial().setBoolean("useTriPlanarMapping", enabled);
float texCoordSize = 1/terrain.getTextureCoordinateScale();
float texCoordSize = 1/terrain.getTextureCoordinateScale();
if (enabled) {
for (int i=0; i<doGetNumUsedTextures(); i++) { if (enabled) {
float scale = 1f/(float)(texCoordSize/doGetTextureScale(i)); for (int i=0; i<getNumUsedTextures(); i++) {
doSetTextureScale(i, scale); float scale = 1f/(float)(texCoordSize/getTextureScale(i));
setTextureScale(i, scale);
}
} else {
for (int i=0; i<getNumUsedTextures(); i++) {
float scale = (float)(texCoordSize*getTextureScale(i));
setTextureScale(i, scale);
}
} }
setNeedsSave(true);
} else { } else {
for (int i=0; i<doGetNumUsedTextures(); i++) { try {
float scale = (float)(texCoordSize*doGetTextureScale(i)); SceneApplication.getApplication().enqueue(new Callable() {
doSetTextureScale(i, scale); public Object call() throws Exception {
setTriPlanarEnabled(enabled);
return null;
}
}).get();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
} }
} }
setNeedsSave(true);
} }
public void propertyChange(PropertyChangeEvent ev) { public void propertyChange(PropertyChangeEvent ev) {

Loading…
Cancel
Save