From 91fda76dc8c3d20e26b0d0ba82ac1d3c5c822a86 Mon Sep 17 00:00:00 2001 From: brentowens Date: Tue, 28 Jun 2011 00:11:59 +0000 Subject: [PATCH] * support for new terrain texture limit * better threading git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7760 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../gde/terraineditor/TerrainEditorController.java | 92 ++++++++---- .../terraineditor/TerrainEditorTopComponent.java | 58 ++++---- sdk/nbproject/build-impl.xml | 98 ++++++------- sdk/nbproject/genfiles.properties | 16 +- sdk/nbproject/platform.properties | 161 ++++++++++----------- 5 files changed, 227 insertions(+), 198 deletions(-) diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java index 9f9c81f5d..a17253556 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java @@ -83,14 +83,15 @@ public class TerrainEditorController { private Node terrainNode; private Node rootNode; private AssetDataObject currentFileObject; + private TerrainEditorTopComponent topComponent; // texture settings public static final String DEFAULT_TERRAIN_TEXTURE = "com/jme3/gde/terraineditor/dirt.jpg"; public static final float DEFAULT_TEXTURE_SCALE = 16.0625f; public static final int NUM_ALPHA_TEXTURES = 3; - private final int BASE_TEXTURE_COUNT = NUM_ALPHA_TEXTURES; // add any others here, like a global specular map - protected final int MAX_TEXTURE_LAYERS = 7-BASE_TEXTURE_COUNT; // 16 max, minus the ones we are reserving - + 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 SaveCookie terrainSaveCookie = new SaveCookie() { @@ -113,6 +114,7 @@ public class TerrainEditorController { rootNode = this.jmeRootNode.getLookup().lookup(Node.class); this.currentFileObject = currentFileObject; this.currentFileObject.setSaveCookie(terrainSaveCookie); + this.topComponent = topComponent; } public void setToolController(TerrainToolController toolController) { @@ -398,30 +400,6 @@ public class TerrainEditorController { return tex; } - /** - * Get the diffuse texture at the specified layer. - * Run this on the GL thread! - */ - private Texture doGetAlphaTextureFromDiffuse(Terrain terrain, int diffuseLayer) { - int alphaIdx = diffuseLayer/4; // 4 = rgba = 4 textures - - return doGetAlphaTexture(terrain, alphaIdx); - /* Terrain terrain = (Terrain) getTerrain(null); - MatParam matParam = null; - //TODO: add when supported -// if (alphaIdx == 0) - matParam = terrain.getMaterial().getParam("AlphaMap"); -// else -// matParam = terrain.getMaterial().getParam("AlphaMap_"+alphaIdx); - - if (matParam == null || matParam.getValue() == null) { - return null; - } - Texture tex = (Texture) matParam.getValue(); - return tex; - */ - } - /** * Set the diffuse texture at the specified layer. @@ -736,10 +714,10 @@ public class TerrainEditorController { Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false)); if (i == 0) mat.setTexture("AlphaMap", tex); - /*else if (i == 1) // add these in when they are supported + else if (i == 1) // add these in when they are supported mat.setTexture("AlphaMap_1", tex); else if (i == 2) - mat.setTexture("AlphaMap_2", tex);*/ + mat.setTexture("AlphaMap_2", tex); } // give the first layer default texture @@ -936,7 +914,61 @@ public class TerrainEditorController { return false; } + /** + * Enable/disable the add and remove texture buttons based + * on how many textures are currently being used. + */ + protected void enableTextureButtons() { + final int numAvailable = MAX_TEXTURES-doGetNumUsedTextures(); + final boolean add = doGetNumDiffuseTextures() < MAX_DIFFUSE && numAvailable > 0; + final boolean remove = doGetNumDiffuseTextures() > 1; + + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + topComponent.enableAddTextureButton(add); + topComponent.enableRemoveTextureButton(remove); + topComponent.updateTextureCountLabel(numAvailable); + topComponent.setAddNormalTextureEnabled(numAvailable>0); + } + }); + } + + /** + * How many diffuse textures are being used. + * Blocking call on GL thread + */ + protected int getNumDiffuseTextures() { + try { + Integer count = + SceneApplication.getApplication().enqueue(new Callable() { + 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); + if (terrain == null) + return 0; + int count = 0; + + for (int i=0; i= editorController.MAX_TEXTURE_LAYERS) - addTextureButton.setEnabled(false); - if (currentTextureCount > 0) - removeTextureButton.setEnabled(true); - remainingTexturesLabel.setText(""+(editorController.MAX_TEXTURE_LAYERS-currentTextureCount)); + editorController.enableTextureButtons(); }//GEN-LAST:event_addTextureButtonActionPerformed + protected void enableAddTextureButton(boolean enabled) { + addTextureButton.setEnabled(enabled); + } + + protected void enableRemoveTextureButton(boolean enabled) { + removeTextureButton.setEnabled(enabled); + } + + protected void updateTextureCountLabel(int count) { + remainingTexturesLabel.setText(""+count); + } + + protected void setAddNormalTextureEnabled(boolean enabled) { + availableNormalTextures = enabled; + } + private void removeTextureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTextureButtonActionPerformed if (editorController == null || editorController.getTerrain(null) == null) return; @@ -642,11 +653,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce return; int index = getTableModel().getRowCount() - 1; // get the last row removeTextureLayer(index); - if (currentTextureCount == 0) - removeTextureButton.setEnabled(false); - if (currentTextureCount < editorController.MAX_TEXTURE_LAYERS) - addTextureButton.setEnabled(true); - remainingTexturesLabel.setText(""+(editorController.MAX_TEXTURE_LAYERS-currentTextureCount)); + editorController.enableTextureButtons(); }//GEN-LAST:event_removeTextureButtonActionPerformed private void eraseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eraseButtonActionPerformed @@ -813,12 +820,9 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce addSaveNode(selectedSpat); - // editorController.getAlphaSaveDataObject(this); - editorController.setNeedsSave(true); - currentTextureCount = editorController.getNumUsedTextures(); - remainingTexturesLabel.setText(""+(editorController.MAX_TEXTURE_LAYERS-currentTextureCount)); + editorController.enableTextureButtons(); reinitTextureTable(); // update the UI @@ -1003,7 +1007,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce addSaveNode(jmeNode); - SceneUndoRedoManager m = Lookup.getDefault().lookup(SceneUndoRedoManager.class);//TODO remove this line + //SceneUndoRedoManager m = Lookup.getDefault().lookup(SceneUndoRedoManager.class);//TODO remove this line Logger.getLogger(TerrainEditorTopComponent.class.getName()).finer("Terrain openScene "+file.getName()); @@ -1017,6 +1021,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce SceneApplication.getApplication().requestScene(request); terrainDeletedNodeListener = new TerrainNodeListener(); + editorController.enableTextureButtons(); } // run on GL thread @@ -1177,8 +1182,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce else toolController.setSelectedTextureIndex(-1); - currentTextureCount = editorController.getNumUsedTextures(); - remainingTexturesLabel.setText(""+(editorController.MAX_TEXTURE_LAYERS-currentTextureCount)); + editorController.enableTextureButtons(); triPlanarCheckBox.setSelected(editorController.isTriPlanarEnabled()); } @@ -1230,7 +1234,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce removeRow(0); // fill the table with the proper data - for (int i=0; i - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/nbproject/genfiles.properties b/sdk/nbproject/genfiles.properties index 95f4ba30b..7c5821921 100644 --- a/sdk/nbproject/genfiles.properties +++ b/sdk/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=cbef27ca -build.xml.script.CRC32=7efad5da -build.xml.stylesheet.CRC32=531c622b@1.31.1.7 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=cbef27ca -nbproject/build-impl.xml.script.CRC32=ce1d717c -nbproject/build-impl.xml.stylesheet.CRC32=183e6ef3@1.42.1 +build.xml.data.CRC32=cbef27ca +build.xml.script.CRC32=7efad5da +build.xml.stylesheet.CRC32=531c622b@1.31.1.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=cbef27ca +nbproject/build-impl.xml.script.CRC32=ce1d717c +nbproject/build-impl.xml.stylesheet.CRC32=183e6ef3@1.42.2 diff --git a/sdk/nbproject/platform.properties b/sdk/nbproject/platform.properties index c2f6adec0..a2a03d7c8 100644 --- a/sdk/nbproject/platform.properties +++ b/sdk/nbproject/platform.properties @@ -1,83 +1,78 @@ -cluster.path=\ - ${nbplatform.active.dir}/extra:\ - ${nbplatform.active.dir}/harness:\ - ${nbplatform.active.dir}/ide:\ - ${nbplatform.active.dir}/java:\ - ${nbplatform.active.dir}/platform -disabled.modules=\ - org.netbeans.libs.bugtracking,\ - org.netbeans.libs.bugzilla,\ - org.netbeans.libs.jsr223,\ - org.netbeans.libs.smack,\ - org.netbeans.libs.springframework,\ - org.netbeans.libs.swingx,\ - org.netbeans.modules.apisupport.apidocs,\ - org.netbeans.modules.bugtracking,\ - org.netbeans.modules.bugtracking.bridge,\ - org.netbeans.modules.bugzilla,\ - org.netbeans.modules.db,\ - org.netbeans.modules.db.core,\ - org.netbeans.modules.db.dataview,\ - org.netbeans.modules.db.drivers,\ - org.netbeans.modules.db.kit,\ - org.netbeans.modules.db.metadata.model,\ - org.netbeans.modules.db.mysql,\ - org.netbeans.modules.db.sql.editor,\ - org.netbeans.modules.db.sql.visualeditor,\ - org.netbeans.modules.dbapi,\ - org.netbeans.modules.dbschema,\ - org.netbeans.modules.derby,\ - org.netbeans.modules.form,\ - org.netbeans.modules.form.j2ee,\ - org.netbeans.modules.form.kit,\ - org.netbeans.modules.glassfish.common,\ - org.netbeans.modules.hibernate,\ - org.netbeans.modules.hibernatelib,\ - org.netbeans.modules.hudson,\ - org.netbeans.modules.hudson.ant,\ - org.netbeans.modules.hudson.maven,\ - org.netbeans.modules.hudson.mercurial,\ - org.netbeans.modules.hudson.subversion,\ - org.netbeans.modules.i18n.form,\ - org.netbeans.modules.j2ee.core.utilities,\ - org.netbeans.modules.j2ee.jpa.refactoring,\ - org.netbeans.modules.j2ee.jpa.verification,\ - org.netbeans.modules.j2ee.persistence,\ - org.netbeans.modules.j2ee.persistence.kit,\ - org.netbeans.modules.j2ee.toplinklib,\ - org.netbeans.modules.jellytools,\ - org.netbeans.modules.jellytools.ide,\ - org.netbeans.modules.jellytools.java,\ - org.netbeans.modules.jellytools.platform,\ - org.netbeans.modules.jemmy,\ - org.netbeans.modules.languages,\ - org.netbeans.modules.maven,\ - org.netbeans.modules.maven.embedder,\ - org.netbeans.modules.maven.grammar,\ - org.netbeans.modules.maven.graph,\ - org.netbeans.modules.maven.hints,\ - org.netbeans.modules.maven.indexer,\ - org.netbeans.modules.maven.junit,\ - org.netbeans.modules.maven.kit,\ - org.netbeans.modules.maven.model,\ - org.netbeans.modules.maven.osgi,\ - org.netbeans.modules.maven.persistence,\ - org.netbeans.modules.maven.repository,\ - org.netbeans.modules.maven.search,\ - org.netbeans.modules.maven.spring,\ - org.netbeans.modules.server,\ - org.netbeans.modules.spellchecker,\ - org.netbeans.modules.spellchecker.bindings.htmlxml,\ - org.netbeans.modules.spellchecker.bindings.properties,\ - org.netbeans.modules.spellchecker.dictionary_en,\ - org.netbeans.modules.spellchecker.kit,\ - org.netbeans.modules.spring.beans,\ - org.netbeans.modules.swing.validation,\ - org.netbeans.modules.swingapp,\ - org.netbeans.modules.websvc.saas.codegen.java,\ - org.netbeans.modules.xml.wsdl.model,\ - org.openide.compat,\ - org.openide.options,\ - org.openide.util.enumerations -nbjdk.active=default -nbplatform.active=default +cluster.path=\ + ${nbplatform.active.dir}/extra:\ + ${nbplatform.active.dir}/harness:\ + ${nbplatform.active.dir}/ide:\ + ${nbplatform.active.dir}/java:\ + ${nbplatform.active.dir}/platform +disabled.modules=\ + org.netbeans.libs.bugtracking,\ + org.netbeans.libs.bugzilla,\ + org.netbeans.libs.jsr223,\ + org.netbeans.libs.smack,\ + org.netbeans.libs.springframework,\ + org.netbeans.libs.swingx,\ + org.netbeans.modules.apisupport.apidocs,\ + org.netbeans.modules.bugtracking,\ + org.netbeans.modules.bugtracking.bridge,\ + org.netbeans.modules.bugzilla,\ + org.netbeans.modules.db,\ + org.netbeans.modules.db.core,\ + org.netbeans.modules.db.dataview,\ + org.netbeans.modules.db.drivers,\ + org.netbeans.modules.db.kit,\ + org.netbeans.modules.db.metadata.model,\ + org.netbeans.modules.db.mysql,\ + org.netbeans.modules.db.sql.editor,\ + org.netbeans.modules.db.sql.visualeditor,\ + org.netbeans.modules.dbapi,\ + org.netbeans.modules.dbschema,\ + org.netbeans.modules.derby,\ + org.netbeans.modules.form,\ + org.netbeans.modules.form.j2ee,\ + org.netbeans.modules.form.kit,\ + org.netbeans.modules.glassfish.common,\ + org.netbeans.modules.hibernate,\ + org.netbeans.modules.hibernatelib,\ + org.netbeans.modules.hudson,\ + org.netbeans.modules.hudson.ant,\ + org.netbeans.modules.hudson.maven,\ + org.netbeans.modules.hudson.mercurial,\ + org.netbeans.modules.hudson.subversion,\ + org.netbeans.modules.i18n.form,\ + org.netbeans.modules.j2ee.core.utilities,\ + org.netbeans.modules.j2ee.jpa.refactoring,\ + org.netbeans.modules.j2ee.jpa.verification,\ + org.netbeans.modules.j2ee.persistence,\ + org.netbeans.modules.j2ee.persistence.kit,\ + org.netbeans.modules.j2ee.toplinklib,\ + org.netbeans.modules.jellytools,\ + org.netbeans.modules.jellytools.ide,\ + org.netbeans.modules.jellytools.java,\ + org.netbeans.modules.jellytools.platform,\ + org.netbeans.modules.jemmy,\ + org.netbeans.modules.languages,\ + org.netbeans.modules.maven.grammar,\ + org.netbeans.modules.maven.graph,\ + org.netbeans.modules.maven.hints,\ + org.netbeans.modules.maven.junit,\ + org.netbeans.modules.maven.kit,\ + org.netbeans.modules.maven.osgi,\ + org.netbeans.modules.maven.persistence,\ + org.netbeans.modules.maven.repository,\ + org.netbeans.modules.maven.search,\ + org.netbeans.modules.maven.spring,\ + org.netbeans.modules.server,\ + org.netbeans.modules.spellchecker,\ + org.netbeans.modules.spellchecker.bindings.htmlxml,\ + org.netbeans.modules.spellchecker.bindings.properties,\ + org.netbeans.modules.spellchecker.dictionary_en,\ + org.netbeans.modules.spellchecker.kit,\ + org.netbeans.modules.spring.beans,\ + org.netbeans.modules.swingapp,\ + org.netbeans.modules.websvc.saas.codegen.java,\ + org.netbeans.modules.xml.wsdl.model,\ + org.openide.compat,\ + org.openide.options,\ + org.openide.util.enumerations +nbjdk.active=default +nbplatform.active=default -- 2.11.0