diff --git a/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java b/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java index d63b9379f..d8d57b2ef 100644 --- a/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java +++ b/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2010 jMonkeyEngine + * Copyright (c) 2009-2025 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,18 +29,14 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package com.jme3.gde.terraineditor; import com.jme3.asset.AssetManager; import com.jme3.gde.core.assets.AssetDataObject; import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.scene.SceneApplication; -import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial; -import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; -import com.jme3.gde.core.undoredo.SceneUndoRedoManager; import com.jme3.gde.core.util.TerrainUtils; import com.jme3.gde.terraineditor.tools.PaintTerrainToolAction; import com.jme3.material.MatParam; @@ -63,13 +59,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import javax.imageio.ImageIO; import javax.imageio.stream.FileImageOutputStream; import javax.imageio.stream.ImageOutputStream; -import javax.swing.undo.CannotRedoException; -import javax.swing.undo.CannotUndoException; import jme3tools.converters.ImageToAwt; import org.openide.cookies.SaveCookie; import org.openide.filesystems.FileObject; @@ -79,7 +72,6 @@ import org.openide.nodes.NodeMemberEvent; import org.openide.nodes.NodeReorderEvent; import org.openide.util.Exceptions; -import org.openide.util.Lookup; /** * Modifies the actual terrain in the scene. @@ -101,42 +93,33 @@ public class TerrainEditorController implements NodeListener { public static final float DEFAULT_TEXTURE_SCALE = 16.0625f; public static final int NUM_ALPHA_TEXTURES = 3; protected final int MAX_DIFFUSE = 12; - protected final int MAX_TEXTURES = 16-NUM_ALPHA_TEXTURES; // 16 max (diffuse and normal), minus the ones we are reserving + protected final int MAX_TEXTURES = 16 - NUM_ALPHA_TEXTURES; // 16 max (diffuse and normal), minus the ones we are reserving private boolean alphaLayersChanged = false; - //private InstanceContent content; class TerrainSaveCookie implements SaveCookie { + JmeSpatial rootNode; @Override public void save() throws IOException { - if (alphaLayersChanged) { - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Object call() throws Exception { - //currentFileObject.saveAsset(); - //TerrainSaveCookie sc = currentFileObject.getCookie(TerrainSaveCookie.class); - //if (sc != null) { - //Node root = rootNode.getLookup().lookup(Node.class); - doSaveAlphaImages(); - //content.remove(TerrainSaveCookie.this); - //} - return null; - } - }); - alphaLayersChanged = false; - } + + SceneApplication.getApplication().enqueue(() -> { + if (alphaLayersChanged) { + doSaveAlphaImages(); + } + currentFileObject.saveAsset(); + return null; + }); + alphaLayersChanged = false; + } } private final TerrainSaveCookie terrainSaveCookie = new TerrainSaveCookie(); - public TerrainEditorController(JmeSpatial jmeRootNode, - AssetDataObject currentFileObject, - TerrainEditorTopComponent topComponent) - { + AssetDataObject currentFileObject, + TerrainEditorTopComponent topComponent) { this.jmeRootNode = jmeRootNode; rootNode = this.jmeRootNode.getLookup().lookup(Node.class); this.currentFileObject = currentFileObject; @@ -156,10 +139,7 @@ public DataObject getCurrentDataObject() { } public void setNeedsSave(boolean state) { - if (state && !currentFileObject.isModified()) - currentFileObject.setModified(state); - else if (!state && currentFileObject.isModified()) - currentFileObject.setModified(state); + currentFileObject.setModified(state); } protected void setSelectedSpat(JmeSpatial selectedSpat) { @@ -179,25 +159,27 @@ protected void setSelectedSpat(JmeSpatial selectedSpat) { } public Node getTerrain(Spatial root) { - if (terrainNode != null) + if (terrainNode != null) { return terrainNode; + } - if (root == null) + if (root == null) { root = rootNode; + } // is this the terrain? if (root instanceof Terrain && root instanceof Node) { - terrainNode = (Node)root; + terrainNode = (Node) root; return terrainNode; } - if (root instanceof Node) { - Node n = (Node) root; + if (root instanceof Node n) { for (Spatial c : n.getChildren()) { - if (c instanceof Node){ + if (c instanceof Node) { Node res = getTerrain(c); - if (res != null) + if (res != null) { return res; + } } } } @@ -206,8 +188,9 @@ public Node getTerrain(Spatial root) { } public JmeNode findJmeTerrain(JmeNode root) { - if (root == null) + if (root == null) { root = (JmeNode) jmeRootNode; + } Node node = root.getLookup().lookup(Node.class); if (node != null && node instanceof Terrain && node instanceof Node) { @@ -216,11 +199,12 @@ public JmeNode findJmeTerrain(JmeNode root) { if (node != null) { if (root.getChildren() != null) { - for (org.openide.nodes.Node child : root.getChildren().getNodes() ) { - if (child instanceof JmeNode) { - JmeNode res = findJmeTerrain((JmeNode)child); - if (res != null) + for (org.openide.nodes.Node child : root.getChildren().getNodes()) { + if (child instanceof JmeNode jmeNode) { + JmeNode res = findJmeTerrain(jmeNode); + if (res != null) { return res; + } } } } @@ -240,6 +224,7 @@ public void alphaLayersChanged() { /** * Perform the actual height modification on the terrain. + * * @param worldLoc the location in the world where the tool was activated * @param radius of the tool, terrain in this radius will be affected * @param heightFactor the amount to adjust the height by @@ -247,30 +232,31 @@ public void alphaLayersChanged() { public void doModifyTerrainHeight(Vector3f worldLoc, float radius, float heightFactor) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; + } setNeedsSave(true); - int radiusStepsX = (int) (radius / ((Node)terrain).getLocalScale().x); - int radiusStepsZ = (int) (radius / ((Node)terrain).getLocalScale().z); + int radiusStepsX = (int) (radius / ((Node) terrain).getLocalScale().x); + int radiusStepsZ = (int) (radius / ((Node) terrain).getLocalScale().z); - float xStepAmount = ((Node)terrain).getLocalScale().x; - float zStepAmount = ((Node)terrain).getLocalScale().z; + float xStepAmount = ((Node) terrain).getLocalScale().x; + float zStepAmount = ((Node) terrain).getLocalScale().z; List locs = new ArrayList<>(); List heights = new ArrayList<>(); - for (int z=-radiusStepsZ; z() { - - @Override - public Object call() throws Exception { - generateEntropies(progressMonitor); - return null; - } + SceneApplication.getApplication().enqueue(() -> { + generateEntropies(progressMonitor); + return null; }); } } /** - * Get the scale of the texture at the specified layer. - * Blocks on the OGL thread + * 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); - if (terrain == null) + if (terrain == null) { return 1f; - MatParam matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer+"_scale"); + } + MatParam 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() { - - @Override - public Float call() throws Exception { - return getTextureScale(layer); - } - - }).get(); - return scale; + Float scale + = SceneApplication.getApplication().enqueue(() -> getTextureScale(layer)).get(); + return scale; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } @@ -383,28 +362,23 @@ public Float call() throws Exception { return null; } - /** - * Set the scale of a texture at the specified layer - * Blocks on the OGL thread + * 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); - if (terrain == null) + if (terrain == null) { return; - terrain.getMaterial().setFloat("DiffuseMap_"+layer+"_scale", scale); + } + terrain.getMaterial().setFloat("DiffuseMap_" + layer + "_scale", scale); setNeedsSave(true); } else { try { - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Object call() throws Exception { - setTextureScale(layer, scale); - return null; - } - + SceneApplication.getApplication().enqueue(() -> { + setTextureScale(layer, scale); + return null; }).get(); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -412,21 +386,20 @@ public Object call() throws Exception { } } - /** - * Get the diffuse texture at the specified layer. - * Blocks on the GL thread! + * Get the diffuse texture at the specified layer. Blocks on the GL thread! */ public Texture getDiffuseTexture(final int layer) { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return null; + } MatParam matParam; if (layer == 0) { matParam = terrain.getMaterial().getParam("DiffuseMap"); } else { - matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer); + matParam = terrain.getMaterial().getParam("DiffuseMap_" + layer); } if (matParam == null || matParam.getValue() == null) { @@ -437,14 +410,9 @@ public Texture getDiffuseTexture(final int layer) { return tex; } else { try { - Texture tex = - SceneApplication.getApplication().enqueue(new Callable() { - @Override - public Texture call() throws Exception { - return getDiffuseTexture(layer); - } - }).get(); - return tex; + Texture tex + = SceneApplication.getApplication().enqueue(() -> getDiffuseTexture(layer)).get(); + return tex; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } @@ -460,16 +428,13 @@ private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) { MatParam matParam = null; switch (alphaLayer) { - case 0: + case 0 -> matParam = terrain.getMaterial().getParam("AlphaMap"); - break; - case 1: + case 1 -> matParam = terrain.getMaterial().getParam("AlphaMap_1"); - break; - case 2: + case 2 -> matParam = terrain.getMaterial().getParam("AlphaMap_2"); - break; - default: + default -> throw new IllegalArgumentException("Invalid AlphaLayer"); } @@ -480,47 +445,46 @@ private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) { return tex; } - /** - * Set the diffuse texture at the specified layer. - * Blocks on the GL thread + * Set the diffuse texture at the specified layer. Blocks on the GL thread + * * @param layer number to set the texture * @param texturePath if null, the default texture will be used */ public void setDiffuseTexture(final int layer, final String texturePath) { String path = texturePath; - if (texturePath == null || texturePath.equals("")) + if (texturePath == null || texturePath.equals("")) { path = DEFAULT_TERRAIN_TEXTURE; + } Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(path); setDiffuseTexture(layer, tex); } /** - * Set the diffuse texture at the specified layer. - * Blocks on the GL thread + * 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); - if (terrain == null) + if (terrain == null) { return; - if (layer == 0) + } + if (layer == 0) { terrain.getMaterial().setTexture("DiffuseMap", texture); - else - terrain.getMaterial().setTexture("DiffuseMap_"+layer, texture); + } else { + terrain.getMaterial().setTexture("DiffuseMap_" + layer, texture); + } setNeedsSave(true); } else { try { - SceneApplication.getApplication().enqueue(new Callable() { - @Override - public Object call() throws Exception { - setDiffuseTexture(layer, texture); - return null; - } + SceneApplication.getApplication().enqueue(() -> { + setDiffuseTexture(layer, texture); + return null; }).get(); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -530,6 +494,7 @@ public Object call() throws Exception { /** * Remove a whole texture layer: diffuse and normal map + * * @param layer * @param texturePath */ @@ -540,12 +505,9 @@ public void removeTextureLayer(final int layer) { doClearAlphaMap(layer); } else { try { - SceneApplication.getApplication().enqueue(new Callable() { - @Override - public Object call() throws Exception { - removeTextureLayer(layer); - return null; - } + SceneApplication.getApplication().enqueue(() -> { + removeTextureLayer(layer); + return null; }).get(); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -555,36 +517,40 @@ public Object call() throws Exception { private void doRemoveDiffuseTexture(int layer) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; - if (layer == 0) + } + if (layer == 0) { terrain.getMaterial().clearParam("DiffuseMap"); - else - terrain.getMaterial().clearParam("DiffuseMap_"+layer); + } else { + terrain.getMaterial().clearParam("DiffuseMap_" + layer); + } setNeedsSave(true); } - private void doRemoveNormalMap(int layer) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; - if (layer == 0) + } + if (layer == 0) { terrain.getMaterial().clearParam("NormalMap"); - else - terrain.getMaterial().clearParam("NormalMap_"+layer); + } else { + terrain.getMaterial().clearParam("NormalMap_" + layer); + } setNeedsSave(true); } private void doClearAlphaMap(int selectedTextureIndex) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; + } - int alphaIdx = selectedTextureIndex/4; // 4 = rgba = 4 textures - int texIndex = selectedTextureIndex - ((selectedTextureIndex/4)*4); // selectedTextureIndex/4 is an int floor + int alphaIdx = selectedTextureIndex / 4; // 4 = rgba = 4 textures + int texIndex = selectedTextureIndex - ((selectedTextureIndex / 4) * 4); // selectedTextureIndex/4 is an int floor //selectedTextureIndex - (alphaIdx * 4) Texture tex = doGetAlphaTexture(terrain, alphaIdx); Image image = tex.getImage(); @@ -592,19 +558,23 @@ private void doClearAlphaMap(int selectedTextureIndex) { PaintTerrainToolAction paint = new PaintTerrainToolAction(); ColorRGBA color = ColorRGBA.Black; - for (int y=0; y() { - - @Override - public Texture call() throws Exception { - return getNormalMap(layer); - } - - }).get(); - return tex; + Texture tex + = SceneApplication.getApplication().enqueue(() -> getNormalMap(layer)).get(); + return tex; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } @@ -659,15 +623,14 @@ public Texture call() throws Exception { } /** - * Set the normal map at the specified layer. - * Blocks on the GL thread + * Set the normal map at the specified layer. Blocks on the GL thread */ public void setNormalMap(final int layer, final String texturePath) { if (texturePath != null) { Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath); setNormalMap(layer, tex); } else { - setNormalMap(layer, (Texture)null); + setNormalMap(layer, (Texture) null); } /*try { SceneApplication.getApplication().enqueue(new Callable() { @@ -689,35 +652,33 @@ public Object call() throws Exception { public void setNormalMap(final int layer, final Texture texture) { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; + } if (texture == null) { // remove the texture if it is null - if (layer == 0) + if (layer == 0) { terrain.getMaterial().clearParam("NormalMap"); - else - terrain.getMaterial().clearParam("NormalMap_"+layer); + } else { + terrain.getMaterial().clearParam("NormalMap_" + layer); + } return; } texture.setWrap(WrapMode.Repeat); - if (layer == 0) + if (layer == 0) { terrain.getMaterial().setTexture("NormalMap", texture); - else - terrain.getMaterial().setTexture("NormalMap_"+layer, texture); + } else { + terrain.getMaterial().setTexture("NormalMap_" + layer, texture); + } setNeedsSave(true); } else { try { - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Object call() throws Exception { - setNormalMap(layer, texture); - return null; - } - + SceneApplication.getApplication().enqueue(() -> { + setNormalMap(layer, texture); + return null; }).get(); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -727,25 +688,19 @@ public Object call() throws Exception { // blocks on GL thread until terrain is created public Terrain createTerrain(final Node parent, - final int totalSize, - final int patchSize, - final int alphaTextureSize, - final float[] heightmapData, - final String sceneName, - final JmeSpatial jmeNodeParent) throws IOException - { + final int totalSize, + final int patchSize, + final int alphaTextureSize, + final float[] heightmapData, + final String sceneName, + final JmeSpatial jmeNodeParent) throws IOException { try { - Terrain terrain = - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Terrain call() throws Exception { - //return doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeNodeParent); - AddTerrainAction a = new AddTerrainAction(); - return (Terrain) a.doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeRootNode); - } - - }).get(); + Terrain terrain + = SceneApplication.getApplication().enqueue(() -> { + //return doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeNodeParent); + AddTerrainAction a = new AddTerrainAction(); + return (Terrain) a.doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeRootNode); + }).get(); return terrain; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -754,69 +709,36 @@ public Terrain call() throws Exception { return null; // if failed } - - private void addSpatialUndo(final Node undoParent, final Spatial undoSpatial, final AbstractSceneExplorerNode parentNode) { - //add undo - if (undoParent != null && undoSpatial != null) { - Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, new AbstractUndoableSceneEdit() { - - @Override - public void sceneUndo() throws CannotUndoException { - //undo stuff here - undoSpatial.removeFromParent(); - } - - @Override - public void sceneRedo() throws CannotRedoException { - //redo stuff here - undoParent.attachChild(undoSpatial); - } - - @Override - public void awtRedo() { - if (parentNode != null) { - parentNode.refresh(true); - } - } - - @Override - public void awtUndo() { - if (parentNode != null) { - parentNode.refresh(true); - } - } - }); - } - } - /** - * Save the terrain's alpha maps to disk, in the Textures/terrain-alpha/ directory + * Save the terrain's alpha maps to disk, in the Textures/terrain-alpha/ + * directory + * * @throws IOException */ private synchronized void doSaveAlphaImages() { terrainNode = null; // re-look it up - Terrain terrain = (Terrain)getTerrain(rootNode); - + Terrain terrain = (Terrain) getTerrain(rootNode); AssetManager manager = SceneApplication.getApplication().getAssetManager(); String assetFolder = null; - if (manager != null && manager instanceof ProjectAssetManager) - assetFolder = ((ProjectAssetManager)manager).getAssetFolderName(); - if (assetFolder == null) + if (manager != null && manager instanceof ProjectAssetManager) { + assetFolder = ((ProjectAssetManager) manager).getAssetFolderName(); + } + if (assetFolder == null) { throw new IllegalStateException("AssetManager was not a ProjectAssetManager. Could not locate image save directories."); - + } Texture alpha1 = doGetAlphaTexture(terrain, 0); BufferedImage bi1 = ImageToAwt.convert(alpha1.getImage(), false, true, 0); - File imageFile1 = new File(assetFolder+"/"+alpha1.getKey().getName()); + File imageFile1 = new File(assetFolder + "/" + alpha1.getKey().getName()); Texture alpha2 = doGetAlphaTexture(terrain, 1); BufferedImage bi2 = ImageToAwt.convert(alpha2.getImage(), false, true, 0); - File imageFile2 = new File(assetFolder+"/"+alpha2.getKey().getName()); + File imageFile2 = new File(assetFolder + "/" + alpha2.getKey().getName()); Texture alpha3 = doGetAlphaTexture(terrain, 2); BufferedImage bi3 = ImageToAwt.convert(alpha3.getImage(), false, true, 0); - File imageFile3 = new File(assetFolder+"/"+alpha3.getKey().getName()); + File imageFile3 = new File(assetFolder + "/" + alpha3.getKey().getName()); ImageOutputStream ios1 = null; ImageOutputStream ios2 = null; @@ -830,26 +752,29 @@ private synchronized void doSaveAlphaImages() { ImageIO.write(bi3, "png", imageFile3); } catch (IOException ex) { System.out.println("Failed saving alphamaps"); - System.out.println(" "+imageFile1); - System.out.println(" "+imageFile2); - System.out.println(" "+imageFile3); + System.out.println(" " + imageFile1); + System.out.println(" " + imageFile2); + System.out.println(" " + imageFile3); Exceptions.printStackTrace(ex); } finally { try { - if (ios1 != null) + if (ios1 != null) { ios1.close(); + } } catch (IOException ex) { Exceptions.printStackTrace(ex); } try { - if (ios2 != null) + if (ios2 != null) { ios2.close(); + } } catch (IOException ex) { Exceptions.printStackTrace(ex); } try { - if (ios3 != null) + if (ios3 != null) { ios3.close(); + } } catch (IOException ex) { Exceptions.printStackTrace(ex); } @@ -858,28 +783,19 @@ private synchronized void doSaveAlphaImages() { } /** - * Create a skybox with 6 textures. - * Blocking call. + * Create a skybox with 6 textures. Blocking call. */ protected Spatial createSky(final Node parent, - final Texture west, - final Texture east, - final Texture north, - final Texture south, - final Texture top, - final Texture bottom, - final Vector3f normalScale) - { + final Texture west, + final Texture east, + final Texture north, + final Texture south, + final Texture top, + final Texture bottom, + final Vector3f normalScale) { try { - Spatial sky = - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Spatial call() throws Exception { - return doCreateSky(parent, west, east, north, south, top, bottom, normalScale); - } - - }).get(); + Spatial sky + = SceneApplication.getApplication().enqueue(() -> doCreateSky(parent, west, east, north, south, top, bottom, normalScale)).get(); return sky; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -888,14 +804,13 @@ public Spatial call() throws Exception { } private Spatial doCreateSky(Node parent, - Texture west, - Texture east, - Texture north, - Texture south, - Texture top, - Texture bottom, - Vector3f normalScale) - { + Texture west, + Texture east, + Texture north, + Texture south, + Texture top, + Texture bottom, + Vector3f normalScale) { AssetManager manager = SceneApplication.getApplication().getAssetManager(); Spatial sky = SkyFactory.createSky(manager, west, east, north, south, top, bottom, normalScale); parent.attachChild(sky); @@ -903,24 +818,15 @@ private Spatial doCreateSky(Node parent, } /** - * Create a skybox with a single texture. - * Blocking call. + * Create a skybox with a single texture. Blocking call. */ protected Spatial createSky(final Node parent, - final Texture texture, - final boolean useSpheremap, - final Vector3f normalScale) - { + final Texture texture, + final boolean useSpheremap, + final Vector3f normalScale) { try { - Spatial sky = - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Spatial call() throws Exception { - return doCreateSky(parent, texture, useSpheremap, normalScale); - } - - }).get(); + Spatial sky + = SceneApplication.getApplication().enqueue(() -> doCreateSky(parent, texture, useSpheremap, normalScale)).get(); return sky; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -929,10 +835,9 @@ public Spatial call() throws Exception { } private Spatial doCreateSky(Node parent, - Texture texture, - boolean useSpheremap, - Vector3f normalScale) - { + Texture texture, + boolean useSpheremap, + Vector3f normalScale) { AssetManager manager = SceneApplication.getApplication().getAssetManager(); Spatial sky = SkyFactory.createSky(manager, texture, normalScale, useSpheremap ? EnvMapType.SphereMap : EnvMapType.CubeMap); parent.attachChild(sky); @@ -940,8 +845,7 @@ private Spatial doCreateSky(Node parent, } /** - * Is there a texture at the specified layer? - * Blocks on ogl thread + * Is there a texture at the specified layer? Blocks on ogl thread */ public boolean hasTextureAt(final int i) { if (SceneApplication.getApplication().isOgl()) { @@ -949,16 +853,9 @@ public boolean hasTextureAt(final int i) { return tex != null; } else { try { - Boolean result = - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Boolean call() throws Exception { - return hasTextureAt(i); - } - - }).get(); - return result; + Boolean result + = SceneApplication.getApplication().enqueue(() -> hasTextureAt(i)).get(); + return result; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } @@ -967,27 +864,22 @@ public Boolean call() throws Exception { } /** - * Enable/disable the add and remove texture buttons based - * on how many textures are currently being used. + * Enable/disable the add and remove texture buttons based on how many + * textures are currently being used. */ protected void enableTextureButtons() { //SceneApplication.getApplication().enqueue(new Callable() { // public Object call() throws Exception { - final int numAvailable = MAX_TEXTURES-getNumUsedTextures(); - final boolean add = getNumDiffuseTextures() < MAX_DIFFUSE && numAvailable > 0; - final boolean remove = getNumDiffuseTextures() > 1; - - java.awt.EventQueue.invokeLater(new Runnable() { - - @Override - public void run() { - topComponent.enableAddTextureButton(add); - topComponent.enableRemoveTextureButton(remove); - topComponent.updateTextureCountLabel(numAvailable); - topComponent.setAddNormalTextureEnabled(numAvailable>0); - } - - }); + final int numAvailable = MAX_TEXTURES - getNumUsedTextures(); + final boolean add = getNumDiffuseTextures() < MAX_DIFFUSE && numAvailable > 0; + final boolean remove = getNumDiffuseTextures() > 1; + + java.awt.EventQueue.invokeLater(() -> { + topComponent.enableAddTextureButton(add); + topComponent.enableRemoveTextureButton(remove); + topComponent.updateTextureCountLabel(numAvailable); + topComponent.setAddNormalTextureEnabled(numAvailable > 0); + }); // return null; // } //}); @@ -995,34 +887,28 @@ public void run() { } /** - * How many diffuse textures are being used. - * Blocking call on GL thread + * How many diffuse textures are being used. Blocking call on GL thread */ protected int getNumDiffuseTextures() { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return 0; + } int count = 0; - for (int i=0; i() { - - @Override - public Integer call() throws Exception { - return getNumDiffuseTextures(); - } - - }).get(); + Integer count + = SceneApplication.getApplication().enqueue(() -> getNumDiffuseTextures()).get(); return count; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1032,36 +918,32 @@ public Integer call() throws Exception { } /** - * How many textures are currently being used. - * Blocking call on GL thread + * How many textures are currently being used. Blocking call on GL thread */ protected int getNumUsedTextures() { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return 0; + } int count = 0; - for (int i=0; i() { - - @Override - public Integer call() throws Exception { - return getNumUsedTextures(); - } - }).get(); + Integer count + = SceneApplication.getApplication().enqueue(() -> getNumUsedTextures()).get(); return count; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1073,24 +955,19 @@ public Integer call() throws Exception { public boolean isTriPlanarEnabled() { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return false; + } MatParam param = terrain.getMaterial().getParam("useTriPlanarMapping"); - if (param != null) - return (Boolean)param.getValue(); + if (param != null) { + return (Boolean) param.getValue(); + } return false; } else { try { - Boolean isEnabled = - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Boolean call() throws Exception { - return isTriPlanarEnabled(); - } - - }).get(); + Boolean isEnabled + = SceneApplication.getApplication().enqueue(() -> isTriPlanarEnabled()).get(); return isEnabled; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1101,28 +978,31 @@ public Boolean call() throws Exception { /** * Also adjusts the scale. Normal texture scale uses texture coordinates, - * which are each 1/(total size of the terrain). But for tri planar it doesn't - * use texture coordinates, so we need to re-calculate it to be the same scale. + * which are each 1/(total size of the terrain). But for tri planar it + * doesn't use texture coordinates, so we need to re-calculate it to be the + * same scale. + * * @param enabled * @param terrainTotalSize */ public void setTriPlanarEnabled(final boolean enabled) { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; + } terrain.getMaterial().setBoolean("useTriPlanarMapping", enabled); float size = terrain.getTerrainSize(); if (enabled) { - for (int i=0; i { + setTriPlanarEnabled(enabled); + return null; }).get(); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1145,47 +1020,40 @@ public Object call() throws Exception { } } - protected void setShininess(final float shininess) { + protected void setShininess(final float shininess) { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; + } terrain.getMaterial().setFloat("Shininess", shininess); setNeedsSave(true); } else { - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Object call() throws Exception { - setShininess(shininess); - return null; - } + SceneApplication.getApplication().enqueue(() -> { + setShininess(shininess); + return null; }); } } - protected float getShininess() { + protected float getShininess() { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return 0; + } MatParam param = terrain.getMaterial().getParam("Shininess"); - if (param != null) - return (Float)param.getValue(); + if (param != null) { + return (Float) param.getValue(); + } return 0; } else { try { - Float shininess = SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Float call() throws Exception { - return getShininess(); - } - }).get(); + Float shininess = SceneApplication.getApplication().enqueue(() -> getShininess()).get(); return shininess; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1197,21 +1065,17 @@ public Float call() throws Exception { protected void setWardIsoEnabled(final boolean enabled) { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return; + } terrain.getMaterial().setBoolean("WardIso", enabled); setNeedsSave(true); } else { try { - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Object call() throws Exception { - setWardIsoEnabled(enabled); - return null; - } - + SceneApplication.getApplication().enqueue(() -> { + setWardIsoEnabled(enabled); + return null; }).get(); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1222,24 +1086,19 @@ public Object call() throws Exception { protected boolean isWardIsoEnabled() { if (SceneApplication.getApplication().isOgl()) { Terrain terrain = (Terrain) getTerrain(null); - if (terrain == null) + if (terrain == null) { return false; + } MatParam param = terrain.getMaterial().getParam("WardIso"); - if (param != null) - return (Boolean)param.getValue(); + if (param != null) { + return (Boolean) param.getValue(); + } return false; } else { try { - Boolean isEnabled = - SceneApplication.getApplication().enqueue(new Callable() { - - @Override - public Boolean call() throws Exception { - return isWardIsoEnabled(); - } - - }).get(); + Boolean isEnabled + = SceneApplication.getApplication().enqueue(() -> isWardIsoEnabled()).get(); return isEnabled; } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); @@ -1248,7 +1107,6 @@ public Boolean call() throws Exception { } } - @Override public void propertyChange(PropertyChangeEvent ev) { if (ev.getNewValue() == null && ev.getOldValue() != null) { @@ -1260,15 +1118,16 @@ public void propertyChange(PropertyChangeEvent ev) { @Override public void childrenAdded(NodeMemberEvent ev) { boolean isTerrain = false; - for(org.openide.nodes.Node n : ev.getSnapshot()) { + for (org.openide.nodes.Node n : ev.getSnapshot()) { Node node = n.getLookup().lookup(Node.class); if (node instanceof Terrain) { isTerrain = true; break; } } - if (isTerrain) + if (isTerrain) { topComponent.reinitTextureTable(); + } } @Override @@ -1286,9 +1145,8 @@ public void nodeDestroyed(NodeEvent ev) { } /** - * Re-attach the camera to the LOD control. - * Called when the scene is opened and will only - * update the control if there is already a terrain present in + * Re-attach the camera to the LOD control. Called when the scene is opened + * and will only update the control if there is already a terrain present in * the scene. */ protected void setTerrainLodCamera() { @@ -1297,6 +1155,4 @@ protected void setTerrainLodCamera() { TerrainUtils.enableLodControl(camera, root); } - - }