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. 463
      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,42 +308,29 @@ 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()) {
public Object call() throws Exception {
doGenerateEntropies(progressMonitor);
return null;
}
});
}
private void doGenerateEntropies(ProgressMonitor progressMonitor) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return; return;
terrain.generateEntropy(progressMonitor); terrain.generateEntropy(progressMonitor);
} } else {
SceneApplication.getApplication().enqueue(new Callable<Object>() {
// blocks on scale get public Object call() throws Exception {
public Float getTextureScale(final int layer) { generateEntropies(progressMonitor);
try { return null;
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) { /**
* Get the scale of the texture at the specified layer.
* Blocks on the OGL thread
*/
public Float getTextureScale(final int layer) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return 1f; return 1f;
@ -353,57 +339,59 @@ public class TerrainEditorController implements NodeListener {
if (matParam == null) if (matParam == null)
return -1f; return -1f;
return (Float) matParam.getValue(); return (Float) matParam.getValue();
} } else {
// blocks on scale set
public void setTextureScale(final int layer, final float scale) {
try { try {
SceneApplication.getApplication().enqueue(new Callable() { Float scale =
public Object call() throws Exception { SceneApplication.getApplication().enqueue(new Callable<Float>() {
doSetTextureScale(layer, scale); public Float call() throws Exception {
return null; return getTextureScale(layer);
} }
}).get(); }).get();
return scale;
} 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;
}
private void doSetTextureScale(int layer, float scale) {
/**
* Set the scale of a texture at the specified layer
* Blocks on the OGL thread
*/
public void setTextureScale(final int layer, final float scale) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return; return;
terrain.getMaterial().setFloat("DiffuseMap_"+layer+"_scale", scale); terrain.getMaterial().setFloat("DiffuseMap_"+layer+"_scale", scale);
setNeedsSave(true); setNeedsSave(true);
} } else {
// blocks on texture get
public Texture getDiffuseTexture(final int layer) {
try { try {
Texture tex = SceneApplication.getApplication().enqueue(new Callable() {
SceneApplication.getApplication().enqueue(new Callable<Texture>() { public Object call() throws Exception {
public Texture call() throws Exception { setTextureScale(layer, scale);
return doGetDiffuseTexture(layer); 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) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return null; return null;
@ -419,6 +407,22 @@ public class TerrainEditorController implements NodeListener {
Texture tex = (Texture) matParam.getValue(); Texture tex = (Texture) matParam.getValue();
return tex; 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;
}
} }
private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) { private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) {
@ -447,56 +451,36 @@ 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)
terrain.getMaterial().setTexture("DiffuseMap", tex);
else
terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex);
doSetTextureScale(layer, DEFAULT_TEXTURE_SCALE); Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(path);
setDiffuseTexture(layer, tex);
setNeedsSave(true);
} }
private void doSetDiffuseTexture(int layer, Texture tex) { /**
tex.setWrap(WrapMode.Repeat); * Set the diffuse texture at the specified layer.
* Blocks on the GL thread
* @param layer number to set the texture
*/
public void setDiffuseTexture(final int layer, final Texture texture) {
if (SceneApplication.getApplication().isOgl()) {
texture.setWrap(WrapMode.Repeat);
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return; return;
if (layer == 0) if (layer == 0)
terrain.getMaterial().setTexture("DiffuseMap", tex); terrain.getMaterial().setTexture("DiffuseMap", texture);
else else
terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex); terrain.getMaterial().setTexture("DiffuseMap_"+layer, texture);
setNeedsSave(true); setNeedsSave(true);
} } else {
public void setDiffuseTexture(final int layer, final Texture texture) {
try { try {
SceneApplication.getApplication().enqueue(new Callable() { SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
doSetDiffuseTexture(layer, texture); setDiffuseTexture(layer, texture);
return null; return null;
} }
}).get(); }).get();
@ -506,6 +490,7 @@ public class TerrainEditorController implements NodeListener {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} }
} }
}
/** /**
* Remove a whole texture layer: diffuse and normal map * Remove a whole texture layer: diffuse and normal map
@ -513,11 +498,14 @@ public class TerrainEditorController implements NodeListener {
* @param texturePath * @param texturePath
*/ */
public void removeTextureLayer(final int layer) { public void removeTextureLayer(final int layer) {
if (SceneApplication.getApplication().isOgl()) {
doRemoveDiffuseTexture(layer);
doRemoveNormalMap(layer);
} else {
try { try {
SceneApplication.getApplication().enqueue(new Callable() { SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
doRemoveDiffuseTexture(layer); removeTextureLayer(layer);
doRemoveNormalMap(layer);
return null; return null;
} }
}).get(); }).get();
@ -527,6 +515,7 @@ public class TerrainEditorController implements NodeListener {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} }
} }
}
private void doRemoveDiffuseTexture(int layer) { private void doRemoveDiffuseTexture(int layer) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
@ -553,29 +542,12 @@ 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) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return null; return null;
@ -590,6 +562,22 @@ public class TerrainEditorController implements NodeListener {
} }
Texture tex = (Texture) matParam.getValue(); Texture tex = (Texture) matParam.getValue();
return tex; 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);
}
}
return null;
} }
/** /**
@ -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,38 +602,39 @@ 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) { /**
* Set the normal map texture at the specified layer
*/
public void setNormalMap(final int layer, final Texture texture) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return; return;
if (texture == null) {
if (texturePath == null) {
// remove the texture if it is null // remove the texture if it is null
if (layer == 0) if (layer == 0)
terrain.getMaterial().clearParam("NormalMap"); terrain.getMaterial().clearParam("NormalMap");
else else
terrain.getMaterial().clearParam("NormalMap_"+layer); terrain.getMaterial().clearParam("NormalMap_"+layer);
} else { return;
Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath); }
tex.setWrap(WrapMode.Repeat);
texture.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);
} else {
try { try {
SceneApplication.getApplication().enqueue(new Callable() { SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
doSetNormalMap(layer, texture); setNormalMap(layer, texture);
return null; return null;
} }
}).get(); }).get();
@ -649,28 +644,6 @@ public class TerrainEditorController implements NodeListener {
Exceptions.printStackTrace(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,13 +826,20 @@ 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) {
if (SceneApplication.getApplication().isOgl()) {
Texture tex = getDiffuseTexture(i);
return tex != null;
} else {
try { try {
Boolean result = Boolean result =
SceneApplication.getApplication().enqueue(new Callable<Boolean>() { SceneApplication.getApplication().enqueue(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
Texture tex = doGetDiffuseTexture(i); return hasTextureAt(i);
return tex != null;
} }
}).get(); }).get();
return result; return result;
@ -936,17 +850,18 @@ public class TerrainEditorController implements NodeListener {
} }
return false; return false;
} }
}
/** /**
* Enable/disable the add and remove texture buttons based * Enable/disable the add and remove texture buttons based
* 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,23 +882,7 @@ 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 =
SceneApplication.getApplication().enqueue(new Callable<Integer>() {
public Integer call() throws Exception {
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); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return 0; return 0;
@ -991,23 +890,17 @@ public class TerrainEditorController implements NodeListener {
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; return count;
} } else {
/**
* How many textures are currently being used.
* Blocking call on GL thread
*/
protected int getNumUsedTextures() {
try { try {
Integer count = Integer count =
SceneApplication.getApplication().enqueue(new Callable<Integer>() { SceneApplication.getApplication().enqueue(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
return doGetNumUsedTextures(); return getNumDiffuseTextures();
} }
}).get(); }).get();
return count; return count;
@ -1018,8 +911,14 @@ public class TerrainEditorController implements NodeListener {
} }
return -1; return -1;
} }
}
protected int doGetNumUsedTextures() { /**
* How many textures are currently being used.
* Blocking call on GL thread
*/
protected int getNumUsedTextures() {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return 0; return 0;
@ -1027,34 +926,34 @@ public class TerrainEditorController implements NodeListener {
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++;
tex = doGetNormalMap(i); tex = getNormalMap(i);
if (tex != null) if (tex != null)
count++; count++;
} }
return count; return count;
} } else {
public boolean isTriPlanarEnabled() {
try { try {
Boolean isEnabled = Integer count =
SceneApplication.getApplication().enqueue(new Callable<Boolean>() { SceneApplication.getApplication().enqueue(new Callable<Integer>() {
public Boolean call() throws Exception { public Integer call() throws Exception {
return doIsTriPlanarEnabled(); return getNumUsedTextures();
} }
}).get(); }).get();
return isEnabled; return count;
} 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 false; return -1;
}
} }
private boolean doIsTriPlanarEnabled() { public boolean isTriPlanarEnabled() {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return false; return false;
@ -1063,21 +962,22 @@ public class TerrainEditorController implements NodeListener {
return (Boolean)param.getValue(); return (Boolean)param.getValue();
return false; return false;
} } else {
public void setTriPlanarEnabled(final boolean selected) {
try { try {
SceneApplication.getApplication().enqueue(new Callable() { Boolean isEnabled =
public Object call() throws Exception { SceneApplication.getApplication().enqueue(new Callable<Boolean>() {
doSetTriPlanarEnabled(selected); public Boolean call() throws Exception {
return null; return isTriPlanarEnabled();
} }
}).get(); }).get();
return isEnabled;
} 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 false;
}
} }
/** /**
@ -1087,7 +987,8 @@ public class TerrainEditorController implements NodeListener {
* @param enabled * @param enabled
* @param terrainTotalSize * @param terrainTotalSize
*/ */
private void doSetTriPlanarEnabled(boolean enabled) { public void setTriPlanarEnabled(final boolean enabled) {
if (SceneApplication.getApplication().isOgl()) {
Terrain terrain = (Terrain) getTerrain(null); Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null) if (terrain == null)
return; return;
@ -1096,18 +997,32 @@ public class TerrainEditorController implements NodeListener {
float texCoordSize = 1/terrain.getTextureCoordinateScale(); float texCoordSize = 1/terrain.getTextureCoordinateScale();
if (enabled) { if (enabled) {
for (int i=0; i<doGetNumUsedTextures(); i++) { for (int i=0; i<getNumUsedTextures(); i++) {
float scale = 1f/(float)(texCoordSize/doGetTextureScale(i)); float scale = 1f/(float)(texCoordSize/getTextureScale(i));
doSetTextureScale(i, scale); setTextureScale(i, scale);
} }
} else { } else {
for (int i=0; i<doGetNumUsedTextures(); i++) { for (int i=0; i<getNumUsedTextures(); i++) {
float scale = (float)(texCoordSize*doGetTextureScale(i)); float scale = (float)(texCoordSize*getTextureScale(i));
doSetTextureScale(i, scale); setTextureScale(i, scale);
} }
} }
setNeedsSave(true); setNeedsSave(true);
} else {
try {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception {
setTriPlanarEnabled(enabled);
return null;
}
}).get();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}
} }
public void propertyChange(PropertyChangeEvent ev) { public void propertyChange(PropertyChangeEvent ev) {

Loading…
Cancel
Save