From 022899c1993dbd1c0815ace2576febd38d24e871 Mon Sep 17 00:00:00 2001 From: Nehon Date: Fri, 20 Nov 2015 16:27:47 +0100 Subject: [PATCH] Changed the way texture previews are done in the SDK. All texture loading is now done on JME's thread and not on the awt thread anymore to avoid to stall the UI when loading big textures. --- .../gde/core/properties/TextureBrowser.form | 1 + .../gde/core/properties/TextureBrowser.java | 43 ++--- .../properties/TexturePropertyEditor.java | 7 + .../core/properties/preview/DDSPreview.java | 140 -------------- .../properties/preview/TexturePreview.java | 179 ++++++++++++++++++ .../core/properties/preview/tex3DThumb.frag | 9 +- .../core/properties/preview/tex3DThumb.vert | 4 +- .../multiview/widgets/TexturePanel.java | 25 +-- .../TerrainEditorTopComponent.java | 62 +++--- .../terraineditor/TerrainToolController.java | 3 +- .../terraineditor/sky/SkyboxVisualPanel2.java | 134 +++---------- 11 files changed, 274 insertions(+), 333 deletions(-) delete mode 100644 sdk/jme3-core/src/com/jme3/gde/core/properties/preview/DDSPreview.java create mode 100644 sdk/jme3-core/src/com/jme3/gde/core/properties/preview/TexturePreview.java diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.form b/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.form index 424078412..a5ad10fe2 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.form +++ b/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.form @@ -9,6 +9,7 @@ + diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.java b/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.java index c199fe39a..285ada07c 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/properties/TextureBrowser.java @@ -31,9 +31,8 @@ */ package com.jme3.gde.core.properties; -import com.jme3.asset.TextureKey; import com.jme3.gde.core.assets.ProjectAssetManager; -import com.jme3.gde.core.properties.preview.DDSPreview; +import com.jme3.gde.core.properties.preview.TexturePreview; import com.jme3.gde.core.util.TreeUtil; import com.jme3.texture.Texture; import java.awt.event.MouseEvent; @@ -42,6 +41,7 @@ import java.awt.event.WindowListener; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; import javax.swing.DefaultListSelectionModel; @@ -52,8 +52,6 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; -import jme3tools.converters.ImageToAwt; -import org.openide.util.ImageUtilities; /** * Displays all textures in the ProjectAssetManager, @@ -68,7 +66,7 @@ public class TextureBrowser extends javax.swing.JDialog implements TreeSelection private ProjectAssetManager assetManager; private TexturePropertyEditor editor; - private DDSPreview ddsPreview; + private TexturePreview texPreview; private Preferences prefs; private static final String PREF_LAST_SELECTED = "lastSelectedTexture"; @@ -234,8 +232,8 @@ private void noTexturebuttonActionPerformed(java.awt.event.ActionEvent evt) {//G if (node != null && node.isLeaf()) { String selected = TreeUtil.getPath(node.getUserObjectPath()); selected = selected.substring(0, selected.lastIndexOf("/")); - Texture tex = assetManager.loadTexture(selected); - editor.setValue(tex); +// Texture tex = assetManager.loadTexture(selected); +// editor.setValue(tex); editor.setAsText(selected); return true; } @@ -270,7 +268,7 @@ private void noTexturebuttonActionPerformed(java.awt.event.ActionEvent evt) {//G private void setSelectedTexture(Texture texture) { if (texture != null) { - Logger.getLogger(TextureBrowser.class.getName()).finer("Looking for Texture: " + texture.getName()); + Logger.getLogger(TextureBrowser.class.getName()).log(Level.FINER, "Looking for Texture: {0}", texture.getName()); String[] path = ("/" + texture.getName()).split("/"); TreePath parent = new TreePath((TreeNode) jTree1.getModel().getRoot()); TreePath selectedTreePath = TreeUtil.buildTreePath(jTree1, parent, path, 0, true); @@ -287,6 +285,7 @@ private void noTexturebuttonActionPerformed(java.awt.event.ActionEvent evt) {//G } } + @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent(); @@ -295,25 +294,14 @@ private void noTexturebuttonActionPerformed(java.awt.event.ActionEvent evt) {//G return; } - //Object nodeInfo = node.getUserObject(); if (node.isLeaf()) { String selected = TreeUtil.getPath(node.getUserObjectPath()); selected = selected.substring(0, selected.lastIndexOf("/")); Icon newicon = null; - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview(assetManager); - } - ddsPreview.requestPreview(selected, (String) node.getUserObject(), 450, 450, imagePreviewLabel, infoLabel); - - } else { - Texture tex = assetManager.loadTexture(selected); - newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - assetManager.deleteFromCache(new TextureKey(selected)); - imagePreviewLabel.setIcon(newicon); - infoLabel.setText(" " + node.getUserObject() + " w : " + newicon.getIconWidth() + " h : " + newicon.getIconHeight()); + if (texPreview == null) { + texPreview = new TexturePreview(assetManager); } - + texPreview.requestPreview(selected, (String) node.getUserObject(), 450, 450, imagePreviewLabel, infoLabel); prefs.put(PREF_LAST_SELECTED, selected); } else { imagePreviewLabel.setIcon(null); @@ -323,27 +311,34 @@ private void noTexturebuttonActionPerformed(java.awt.event.ActionEvent evt) {//G } + @Override public void windowOpened(WindowEvent e) { } + @Override public void windowClosing(WindowEvent e) { - if (ddsPreview != null) { - ddsPreview.cleanUp(); + if (texPreview != null) { + texPreview.cleanUp(); } } + @Override public void windowClosed(WindowEvent e) { } + @Override public void windowIconified(WindowEvent e) { } + @Override public void windowDeiconified(WindowEvent e) { } + @Override public void windowActivated(WindowEvent e) { } + @Override public void windowDeactivated(WindowEvent e) { } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/TexturePropertyEditor.java b/sdk/jme3-core/src/com/jme3/gde/core/properties/TexturePropertyEditor.java index 9f4658e02..555fc5160 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/properties/TexturePropertyEditor.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/properties/TexturePropertyEditor.java @@ -80,7 +80,14 @@ public class TexturePropertyEditor implements PropertyEditor { } } + @Override public Object getValue() { + if(texture == null && assetKey != null){ + if (manager == null){ + manager = SceneApplication.getApplication().getAssetManager(); + } + texture = manager.loadTexture(assetKey); + } return texture; } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/DDSPreview.java b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/DDSPreview.java deleted file mode 100644 index c6597ff6a..000000000 --- a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/DDSPreview.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2009-2010 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * 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.core.properties.preview; - -import com.jme3.asset.TextureKey; -import com.jme3.gde.core.assets.ProjectAssetManager; -import com.jme3.gde.core.scene.PreviewRequest; -import com.jme3.gde.core.scene.SceneApplication; -import com.jme3.gde.core.scene.SceneListener; -import com.jme3.gde.core.scene.SceneRequest; -import com.jme3.material.Material; -import com.jme3.math.Vector2f; -import com.jme3.math.Vector3f; -import com.jme3.scene.Geometry; -import com.jme3.scene.Spatial; -import com.jme3.scene.shape.Quad; -import com.jme3.texture.Texture; -import com.jme3.util.SkyFactory; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; - -/** - * - * @author Nehon - */ -public class DDSPreview implements SceneListener { - - private final ProjectAssetManager assetManager; - private JComponent picPreview; - private final Geometry quad; - private final Geometry quad3D; - private final Material material; - private final Material material3D; - - public DDSPreview(ProjectAssetManager assetManager) { - this.assetManager = assetManager; - - Quad quadMesh = new Quad(4.5f, 4.5f); - Quad quadMesh3D = new Quad(4.5f, 4.5f); - quadMesh3D.scaleTextureCoordinates(new Vector2f(4, 4)); - quad = new Geometry("previewQuad", quadMesh); - quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0)); - quad3D = new Geometry("previewQuad", quadMesh3D); - quad3D.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0)); - material3D = new Material(assetManager, "com/jme3/gde/core/properties/preview/tex3DThumb.j3md"); - material3D.setFloat("InvDepth", 1f / 16f); - material3D.setInt("Rows", 4); - material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - SceneApplication.getApplication().addSceneListener(this); - } - - public void requestPreview(String textureName, String displayName, int width, int height, JComponent picLabel, JLabel infoLabel) { - TextureKey key = new TextureKey(textureName); - picPreview = picLabel; - assetManager.deleteFromCache(key); - Texture t = assetManager.loadTexture(key); - Spatial geom = quad; - if (key.getTextureTypeHint() == Texture.Type.TwoDimensional) { - material.setTexture("ColorMap", t); - geom.setMaterial(material); - if (infoLabel != null) { - infoLabel.setText(" " + displayName + " w : " + t.getImage().getWidth() + " h : " + t.getImage().getHeight()); - } - } else if (key.getTextureTypeHint() == Texture.Type.ThreeDimensional) { - geom = quad3D; - assetManager.deleteFromCache(key); - key.setTextureTypeHint(Texture.Type.ThreeDimensional); - t = assetManager.loadTexture(key); - material3D.setTexture("Texture", t); - geom.setMaterial(material3D); - if (infoLabel != null) { - infoLabel.setText(" " + displayName + " (Texture3D) w : " + t.getImage().getWidth() + " h : " + t.getImage().getHeight() + " d : " + t.getImage().getDepth()); - } - } else if (key.getTextureTypeHint() == Texture.Type.CubeMap) { - assetManager.deleteFromCache(key); - geom = SkyFactory.createSky(assetManager, textureName, SkyFactory.EnvMapType.CubeMap); - if (infoLabel != null) { - infoLabel.setText(" " + displayName + " (CubeMap) w : " + t.getImage().getWidth() + " h : " + t.getImage().getHeight()); - } - } - - PreviewRequest request = new PreviewRequest(this, geom, width, height); - request.getCameraRequest().setLocation(new Vector3f(0, 0, 5.3f)); - request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y.mult(-1)); - SceneApplication.getApplication().createPreview(request); - } - - public void cleanUp() { - SceneApplication.getApplication().removeSceneListener(this); - } - - public void sceneOpened(SceneRequest request) { - } - - public void sceneClosed(SceneRequest request) { - } - - public void previewCreated(PreviewRequest request) { - if (request.getRequester() == this) { - final ImageIcon icon = new ImageIcon(request.getImage()); - if (picPreview instanceof JLabel) { - ((JLabel) picPreview).setIcon(icon); - } - if (picPreview instanceof JButton) { - ((JButton) picPreview).setIcon(icon); - } - } - } -} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/TexturePreview.java b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/TexturePreview.java new file mode 100644 index 000000000..337e3a34c --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/TexturePreview.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * 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.core.properties.preview; + +import com.jme3.asset.TextureKey; +import com.jme3.gde.core.assets.ProjectAssetManager; +import com.jme3.gde.core.scene.PreviewRequest; +import com.jme3.gde.core.scene.SceneApplication; +import com.jme3.gde.core.scene.SceneListener; +import com.jme3.gde.core.scene.SceneRequest; +import com.jme3.material.Material; +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.Spatial; +import com.jme3.scene.shape.Quad; +import com.jme3.texture.Texture; +import com.jme3.util.SkyFactory; +import java.util.concurrent.Callable; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; + +/** + * + * @author Nehon + */ +public class TexturePreview implements SceneListener { + + private final ProjectAssetManager assetManager; + private JComponent picPreview; + private final Geometry quad; + private final Geometry quad3D; + private final Material material; + private final Material material3D; + + public TexturePreview(ProjectAssetManager assetManager) { + this.assetManager = assetManager; + + Quad quadMesh = new Quad(4.5f, 4.5f); + Quad quadMesh3D = new Quad(4.5f, 4.5f); + quadMesh3D.scaleTextureCoordinates(new Vector2f(4, 4)); + quad = new Geometry("previewQuad", quadMesh); + quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0)); + quad3D = new Geometry("previewQuad", quadMesh3D); + quad3D.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0)); + material3D = new Material(assetManager, "com/jme3/gde/core/properties/preview/tex3DThumb.j3md"); + material3D.setFloat("InvDepth", 1f / 16f); + material3D.setInt("Rows", 4); + material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + SceneApplication.getApplication().addSceneListener(this); + } + + public void requestPreview(final String textureName, final String displayName, final int width, final int height, final JComponent picLabel, final JLabel infoLabel) { + + picPreview = picLabel; + clearPreview(); + if (infoLabel != null) { + infoLabel.setText(" Creating preview..."); + } + + SceneApplication.getApplication().enqueue(new Callable() { + + @Override + public Void call() throws Exception { + TextureKey key = new TextureKey(textureName); + Texture t = assetManager.loadTexture(key); + Spatial geom = quad; + if (key.getTextureTypeHint() == Texture.Type.TwoDimensional) { + material.setTexture("ColorMap", t); + geom.setMaterial(material); + setLabel(infoLabel, displayName, t.getImage().getWidth(), t.getImage().getHeight(), -1); + } else if (key.getTextureTypeHint() == Texture.Type.ThreeDimensional) { + geom = quad3D; + material3D.setTexture("Texture", t); + geom.setMaterial(material3D); + setLabel(infoLabel, displayName + " (Texture3D)", t.getImage().getWidth(), t.getImage().getHeight(), t.getImage().getDepth()); + + } else if (key.getTextureTypeHint() == Texture.Type.CubeMap) { + geom = SkyFactory.createSky(assetManager, textureName, SkyFactory.EnvMapType.CubeMap); + setLabel(infoLabel, displayName + " (CubeMap)", t.getImage().getWidth(), t.getImage().getHeight(), -1); + } + + PreviewRequest request = new PreviewRequest(TexturePreview.this, geom, width, height); + request.getCameraRequest().setLocation(new Vector3f(0, 0, 5.3f)); + request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y.mult(-1)); + SceneApplication.getApplication().createPreview(request); + + return null; + } + + }); + } + + public void cleanUp() { + SceneApplication.getApplication().removeSceneListener(this); + } + + @Override + public void sceneOpened(SceneRequest request) { + } + + @Override + public void sceneClosed(SceneRequest request) { + } + + private void setLabel(final JLabel label, final String text, final int width, final int height, final int depth) { + + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + if (label != null) { + String labText = " " + text + " w : " + width + " h : " + height; + if (depth > 0) { + labText += " d : " + depth; + } + label.setText(labText); + } + } + }); + } + + private void clearPreview() { + if (picPreview instanceof JLabel) { + ((JLabel) picPreview).setIcon(null); + } + if (picPreview instanceof JButton) { + ((JButton) picPreview).setIcon(null); + } + } + + @Override + public void previewCreated(final PreviewRequest request) { + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + if (request.getRequester() == TexturePreview.this) { + final ImageIcon icon = new ImageIcon(request.getImage()); + if (picPreview instanceof JLabel) { + ((JLabel) picPreview).setIcon(icon); + } + if (picPreview instanceof JButton) { + ((JButton) picPreview).setIcon(icon); + } + } + } + }); + } +} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.frag b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.frag index f6eb25a3b..4ae52bd3f 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.frag +++ b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.frag @@ -5,10 +5,9 @@ uniform float m_InvDepth; varying vec2 texCoord; void main(){ -float depthx=floor(texCoord.x); - float depthy=(m_Rows-1.0) - floor(texCoord.y); - //vec3 texC=vec3(texCoord.x,texCoord.y ,0.7);// + float depthx = floor(texCoord.x); + float depthy = (float(m_Rows) - 1.0) - floor(texCoord.y); - vec3 texC=vec3(fract(texCoord.x),fract(texCoord.y),(depthy*m_Rows+depthx)*m_InvDepth);// - gl_FragColor= texture3D(m_Texture,texC); + vec3 texC = vec3(fract(texCoord.x), fract(texCoord.y), (depthy * float(m_Rows) + depthx) * m_InvDepth);// + gl_FragColor = texture3D(m_Texture, texC); } \ No newline at end of file diff --git a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.vert b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.vert index 6d27bc030..fd940682b 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.vert +++ b/sdk/jme3-core/src/com/jme3/gde/core/properties/preview/tex3DThumb.vert @@ -6,6 +6,6 @@ attribute vec3 inPosition; varying vec2 texCoord; void main(){ - gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition,1.0); - texCoord=inTexCoord; + gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0); + texCoord = inTexCoord; } \ No newline at end of file diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java index 0129535e4..1e5856fd1 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java @@ -13,7 +13,7 @@ package com.jme3.gde.materials.multiview.widgets; import com.jme3.asset.AssetNotFoundException; import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.properties.TexturePropertyEditor; -import com.jme3.gde.core.properties.preview.DDSPreview; +import com.jme3.gde.core.properties.preview.TexturePreview; import com.jme3.gde.materials.MaterialProperty; import com.jme3.gde.materials.multiview.MaterialEditorTopComponent; import com.jme3.texture.Texture; @@ -39,7 +39,7 @@ public class TexturePanel extends MaterialPropertyWidget { private boolean flip = false; private boolean repeat = false; private String textureName = null; - private DDSPreview ddsPreview; + private TexturePreview texPreview; private final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); /** Creates new form SelectionPanel */ @@ -53,22 +53,13 @@ public class TexturePanel extends MaterialPropertyWidget { if (!"".equals(textureName)) { exec.execute(new Runnable() { + @Override public void run() { try{ - Texture tex = manager.loadTexture(textureName); - if (textureName.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview(manager); + if (texPreview == null) { + texPreview = new TexturePreview(manager); } - ddsPreview.requestPreview(textureName, "", 80, 80, texturePreview, null); - } else { - final Icon newicon = ImageUtilities.image2Icon(resizeImage(ImageToAwt.convert(tex.getImage(), false, true, 0))); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - texturePreview.setIcon(newicon); - } - }); - } + texPreview.requestPreview(textureName, "", 80, 25, texturePreview, null); } catch (AssetNotFoundException a) { Logger.getLogger(MaterialEditorTopComponent.class.getName()).log(Level.WARNING, "Could not load texture {0}", textureName); } @@ -318,8 +309,8 @@ public class TexturePanel extends MaterialPropertyWidget { @Override public void cleanUp() { - if (ddsPreview != null) { - ddsPreview.cleanUp(); + if (texPreview != null) { + texPreview.cleanUp(); } exec.shutdownNow(); } diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java index 9e12371ea..b99a24274 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java @@ -34,7 +34,7 @@ package com.jme3.gde.terraineditor; import com.jme3.gde.core.assets.AssetDataObject; import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.properties.TexturePropertyEditor; -import com.jme3.gde.core.properties.preview.DDSPreview; +import com.jme3.gde.core.properties.preview.TexturePreview; import com.jme3.gde.core.scene.PreviewRequest; import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.SceneListener; @@ -122,7 +122,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce //private TerrainNodeListener terrainDeletedNodeListener; private boolean availableNormalTextures; private HelpCtx ctx = new HelpCtx("sdk.terrain_editor"); - private DDSPreview ddsPreview; + private TexturePreview texPreview; private Map buttons = new HashMap(); private JPanel insideToolSettings; @@ -153,35 +153,29 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce private float max = 0; private final Object lock = new Object(); + @Override public void incrementProgress(float f) { progress += f; progressHandle.progress((int) progress); } + @Override public void setMonitorMax(float f) { max = f; -// java.awt.EventQueue.invokeLater(new Runnable() { -// public void run() { -// synchronized(lock){ if (progressHandle == null) { progressHandle = ProgressHandleFactory.createHandle("Calculating terrain entropies..."); progressHandle.start((int) max); } -// } -// } -// }); } + @Override public float getMonitorMax() { return max; } + @Override public void progressComplete() { -// SwingUtilities.invokeLater(new Runnable() { -// public void run() { progressHandle.finish(); -// } -// }); } } @@ -1631,6 +1625,13 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce protected abstract Texture getTextureFromModel(int index); protected abstract boolean supportsNullTexture(); + + private TexturePreview getTexturePreview(){ + if (texPreview == null) { + texPreview = new TexturePreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); + } + return texPreview; + } private JButton getButton(Object value, final int row, final int column) { @@ -1656,21 +1657,9 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce } Texture tex = getTextureFromModel(index); // delegate to sub-class - - //Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture((String)value); if (tex != null) { String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, lbl, null); - - } else { - Icon icon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - lbl.setIcon(icon); - } + getTexturePreview().requestPreview(selected, "", 80, 80, lbl, null); } } @@ -1694,24 +1683,17 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce TexturePropertyEditor editor = new TexturePropertyEditor(selectedTex); Component view = editor.getCustomEditor(); view.setVisible(true); - Texture tex = (Texture) editor.getValue(); - if (editor.getValue() != null) { - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, lbl, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - lbl.setIcon(newicon); - } + + if (editor.getAsText() != null) { + + String selected = editor.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, lbl, null); + Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(selected); + setTextureInModel(row, tex); } else if (supportsNullTexture()) { lbl.setIcon(null); } - setTextureInModel(row, tex); + } finally { alreadyChoosing = false; } diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java index e89175b76..d0072d06a 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java @@ -260,8 +260,7 @@ public class TerrainToolController extends SceneToolController { * The action on the tool has ended (mouse button up), record the Undo (for painting only now) */ void doTerrainEditToolActionEnded() { - if (terrainTool != null) { - System.out.println("undo tagged"); + if (terrainTool != null) { terrainTool.actionEnded(jmeRootNode, editorController.getCurrentDataObject()); } } diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/sky/SkyboxVisualPanel2.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/sky/SkyboxVisualPanel2.java index 754f5e933..9e3cd0396 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/sky/SkyboxVisualPanel2.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/sky/SkyboxVisualPanel2.java @@ -33,16 +33,14 @@ package com.jme3.gde.terraineditor.sky; import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.properties.TexturePropertyEditor; -import com.jme3.gde.core.properties.preview.DDSPreview; +import com.jme3.gde.core.properties.preview.TexturePreview; import com.jme3.gde.core.scene.SceneApplication; import com.jme3.texture.Texture; import com.jme3.util.SkyFactory; import java.awt.Component; -import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.Icon; import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JTextField; import jme3tools.converters.ImageToAwt; @@ -50,7 +48,7 @@ import org.openide.util.ImageUtilities; public final class SkyboxVisualPanel2 extends JPanel { - private DDSPreview ddsPreview; + private TexturePreview texPreview; /** Creates new form SkyboxVisualPanel2 */ public SkyboxVisualPanel2() { @@ -111,6 +109,14 @@ public final class SkyboxVisualPanel2 extends JPanel { return editorWest; } + + private TexturePreview getTexturePreview(){ + if (texPreview == null) { + texPreview = new TexturePreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); + } + return texPreview; + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is @@ -450,141 +456,63 @@ public final class SkyboxVisualPanel2 extends JPanel { private void multipleTexSouthLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexSouthLoadButtonActionPerformed Component view = editorSouth.getCustomEditor(); view.setVisible(true); - if (editorSouth.getValue() != null) { - Texture tex = (Texture) editorSouth.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, southPic, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - southPic.setIcon(newicon); - } + if (editorSouth.getAsText()!= null) { + String selected = editorSouth.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, southPic, null); } }//GEN-LAST:event_multipleTexSouthLoadButtonActionPerformed private void multipleTexNorthLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexNorthLoadButtonActionPerformed Component view = editorNorth.getCustomEditor(); view.setVisible(true); - if (editorNorth.getValue() != null) { - Texture tex = (Texture) editorNorth.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, northPic, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - northPic.setIcon(newicon); - } + if (editorNorth.getAsText() != null) { + String selected = editorNorth.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, northPic, null); } }//GEN-LAST:event_multipleTexNorthLoadButtonActionPerformed private void multipleTexEastLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexEastLoadButtonActionPerformed Component view = editorEast.getCustomEditor(); view.setVisible(true); - if (editorEast.getValue() != null) { - Texture tex = (Texture) editorEast.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, eastPic, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - eastPic.setIcon(newicon); - } + if (editorEast.getAsText() != null) { + String selected = editorEast.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, eastPic, null); } }//GEN-LAST:event_multipleTexEastLoadButtonActionPerformed private void multipleTexWestLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexWestLoadButtonActionPerformed Component view = editorWest.getCustomEditor(); view.setVisible(true); - if (editorWest.getValue() != null) { - Texture tex = (Texture) editorWest.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, westPic, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - westPic.setIcon(newicon); - } + if (editorWest.getAsText() != null) { + String selected = editorWest.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, westPic, null); } }//GEN-LAST:event_multipleTexWestLoadButtonActionPerformed private void multipleTexTopLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexTopLoadButtonActionPerformed Component view = editorTop.getCustomEditor(); view.setVisible(true); - if (editorTop.getValue() != null) { - Texture tex = (Texture) editorTop.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, topPic, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - topPic.setIcon(newicon); - } + if (editorTop.getAsText() != null) { + String selected = editorTop.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, topPic, null); } }//GEN-LAST:event_multipleTexTopLoadButtonActionPerformed private void multipleTexBottomLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexBottomLoadButtonActionPerformed Component view = editorBottom.getCustomEditor(); view.setVisible(true); - if (editorBottom.getValue() != null) { - Texture tex = (Texture) editorBottom.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, bottomPic, null); - - } else { - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - bottomPic.setIcon(newicon); - } + if (editorBottom.getAsText() != null) { + String selected = editorBottom.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, bottomPic, null); } }//GEN-LAST:event_multipleTexBottomLoadButtonActionPerformed private void singleTexLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleTexLoadButtonActionPerformed Component view = editorSingle.getCustomEditor(); view.setVisible(true); - if (editorSingle.getValue() != null) { - Texture tex = (Texture) editorSingle.getValue(); - String selected = tex.getKey().getName(); - - if (selected.toLowerCase().endsWith(".dds")) { - if (ddsPreview == null) { - ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); - } - ddsPreview.requestPreview(selected, "", 80, 80, singlePic, null); - - } else { - - Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); - singlePic.setIcon(newicon); - } + if (editorSingle.getAsText()!= null) { + String selected = editorSingle.getAsText(); + getTexturePreview().requestPreview(selected, "", 80, 80, singlePic, null); } }//GEN-LAST:event_singleTexLoadButtonActionPerformed