diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometry.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometry.java index 3cd610a5d..725cdf97e 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometry.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometry.java @@ -35,22 +35,80 @@ import com.jme3.asset.AssetManager; import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; -import com.jme3.gde.core.sceneexplorer.nodes.actions.AbstractToolAction; +import com.jme3.gde.core.sceneexplorer.nodes.actions.AbstractToolWizardAction; import com.jme3.gde.core.sceneexplorer.nodes.actions.ToolAction; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.Spatial; +import java.awt.Component; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import javax.swing.JComponent; import jme3tools.optimize.TextureAtlas; +import org.openide.DialogDisplayer; +import org.openide.WizardDescriptor; /** * * @author normenhansen */ @org.openide.util.lookup.ServiceProvider(service = ToolAction.class) -public class AtlasBatchGeometry extends AbstractToolAction { +public class AtlasBatchGeometry extends AbstractToolWizardAction { + + public static enum AtlasResolution { + + RES_256x256("256x256", 256, 256), + RES_512x512("512x512", 512, 512), + RES_1024x1024("1024x1024", 1024, 1024), + RES_2048x2048("2048x2048", 2048, 2048), + RES_4096x4096("4096x4096", 4096, 4096), + RES_8192x8192("8192x8192", 8192, 8192), + RES_16384x16384("16384x16384", 16384, 16384); + private final String name; + private final int resX; + private final int resY; + + public String getName() { + return name; + } + + public int getResX() { + return resX; + } + + public int getResY() { + return resY; + } + + public static AtlasResolution getNumber(int id) { + switch (id) { + case 1: + return RES_256x256; + case 2: + return RES_512x512; + case 3: + return RES_1024x1024; + case 4: + return RES_2048x2048; + case 5: + return RES_4096x4096; + case 6: + return RES_8192x8192; + case 7: + return RES_16384x16384; + default: + return RES_2048x2048; + } + } + + private AtlasResolution(String name, int resX, int resY) { + this.name = name; + this.resX = resX; + this.resY = resY; + } + } private class OldNew { @@ -62,18 +120,52 @@ public class AtlasBatchGeometry extends AbstractToolAction { List oldChildren; } + @Override + protected Object showWizard(org.openide.nodes.Node node) { + List> panels = new ArrayList>(); + panels.add(new AtlasBatchGeometryWizardPanel1()); + String[] steps = new String[panels.size()]; + for (int i = 0; i < panels.size(); i++) { + Component c = panels.get(i).getComponent(); + // Default step name to component name of panel. + steps[i] = c.getName(); + if (c instanceof JComponent) { // assume Swing components + JComponent jc = (JComponent) c; + jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); + jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); + jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); + jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); + jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); + } + } + WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator(panels)); + // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() + wiz.setTitleFormat(new MessageFormat("{0}")); + wiz.setTitle("...dialog title..."); + if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { + // do something + return wiz; + } + return null; + } + public AtlasBatchGeometry() { - name = "Batch Geometry with TextureAtlas"; + name = "Batch Geometry with TextureAtlas.."; } @Override - protected Object doApplyTool(AbstractSceneExplorerNode rootNode) { + protected Object doApplyTool(AbstractSceneExplorerNode rootNode, Object settings) { + if (settings == null) { + return null; + } + WizardDescriptor wiz = (WizardDescriptor)settings; + AtlasResolution res = (AtlasResolution)wiz.getProperty("size"); Node parent = rootNode.getLookup().lookup(Node.class); AssetManager mgr = rootNode.getLookup().lookup(ProjectAssetManager.class); if (parent == null || mgr == null) { return null; } - Geometry batch = TextureAtlas.makeAtlasBatch(parent, mgr, 4096); + Geometry batch = TextureAtlas.makeAtlasBatch(parent, mgr, res.resX); batch.setName(parent.getName() + " - batched"); List currentChildren = new ArrayList(); if (parent != null && batch != null) { @@ -86,6 +178,9 @@ public class AtlasBatchGeometry extends AbstractToolAction { @Override protected void doUndoTool(AbstractSceneExplorerNode rootNode, Object undoObject) { + if (undoObject == null) { + return; + } Node parent = rootNode.getLookup().lookup(Node.class); OldNew undo = (OldNew) undoObject; if (parent == null || undo == null) { diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryVisualPanel1.form b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryVisualPanel1.form new file mode 100644 index 000000000..c11ab2928 --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryVisualPanel1.form @@ -0,0 +1,90 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryVisualPanel1.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryVisualPanel1.java new file mode 100644 index 000000000..c0a021319 --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryVisualPanel1.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2003-2012 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.sceneexplorer.nodes.actions.impl; + +import com.jme3.gde.core.sceneexplorer.nodes.actions.impl.AtlasBatchGeometry.AtlasResolution; +import javax.swing.JPanel; + +public final class AtlasBatchGeometryVisualPanel1 extends JPanel { + + private AtlasResolution res = AtlasResolution.RES_2048x2048; + + /** + * Creates new form AtlasBatchGeometryVisualPanel1 + */ + public AtlasBatchGeometryVisualPanel1() { + initComponents(); + } + + @Override + public String getName() { + return "Set Atlas Size"; + } + + public AtlasResolution getAtlasSize() { + return res; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jSlider1 = new javax.swing.JSlider(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jLabel2 = new javax.swing.JLabel(); + + jSlider1.setMajorTickSpacing(1); + jSlider1.setMaximum(7); + jSlider1.setMinimum(1); + jSlider1.setPaintTicks(true); + jSlider1.setSnapToTicks(true); + jSlider1.setValue(4); + jSlider1.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + updateResolution(evt); + } + }); + + jTextArea1.setEditable(false); + jTextArea1.setColumns(20); + jTextArea1.setLineWrap(true); + jTextArea1.setRows(5); + jTextArea1.setText(org.openide.util.NbBundle.getMessage(AtlasBatchGeometryVisualPanel1.class, "AtlasBatchGeometryVisualPanel1.jTextArea1.text")); // NOI18N + jTextArea1.setWrapStyleWord(true); + jTextArea1.setDisabledTextColor(new java.awt.Color(0, 0, 0)); + jScrollPane1.setViewportView(jTextArea1); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, res.getName()); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void updateResolution(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_updateResolution + res = AtlasResolution.getNumber(jSlider1.getValue()); + jLabel2.setText(res.getName()); + }//GEN-LAST:event_updateResolution + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JSlider jSlider1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryWizardPanel1.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryWizardPanel1.java new file mode 100644 index 000000000..3cd25bc1d --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AtlasBatchGeometryWizardPanel1.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2003-2012 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.sceneexplorer.nodes.actions.impl; + +import javax.swing.event.ChangeListener; +import org.openide.WizardDescriptor; +import org.openide.util.HelpCtx; + +public class AtlasBatchGeometryWizardPanel1 implements WizardDescriptor.Panel { + + /** + * The visual component that displays this panel. If you need to access the + * component from this class, just use getComponent(). + */ + private AtlasBatchGeometryVisualPanel1 component; + + // Get the visual component for the panel. In this template, the component + // is kept separate. This can be more efficient: if the wizard is created + // but never displayed, or not all panels are displayed, it is better to + // create only those which really need to be visible. + @Override + public AtlasBatchGeometryVisualPanel1 getComponent() { + if (component == null) { + component = new AtlasBatchGeometryVisualPanel1(); + } + return component; + } + + @Override + public HelpCtx getHelp() { + // Show no Help button for this panel: + return HelpCtx.DEFAULT_HELP; + // If you have context help: + // return new HelpCtx("help.key.here"); + } + + @Override + public boolean isValid() { + // If it is always OK to press Next or Finish, then: + return true; + // If it depends on some condition (form filled out...) and + // this condition changes (last form field filled in...) then + // use ChangeSupport to implement add/removeChangeListener below. + // WizardDescriptor.ERROR/WARNING/INFORMATION_MESSAGE will also be useful. + } + + @Override + public void addChangeListener(ChangeListener l) { + } + + @Override + public void removeChangeListener(ChangeListener l) { + } + + @Override + public void readSettings(WizardDescriptor wiz) { + // use wiz.getProperty to retrieve previous panel state + } + + @Override + public void storeSettings(WizardDescriptor wiz) { + wiz.putProperty("size", component.getAtlasSize()); + // use wiz.putProperty to remember current panel state + } +} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties index 80b7ecc63..91985a894 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties @@ -1,2 +1,3 @@ NewCustomControlVisualPanel1.jTextField1.text=com.mycompany.mygame.MyControl NewCustomControlVisualPanel1.jLabel1.text=Class Name: +AtlasBatchGeometryVisualPanel1.jTextArea1.text=Note that all the textures of the batched geometry have to fit in the atlas texture, else not all will be added to the atlas. There is no scaling happening!\n\nAlso note that when batching geometry with normal maps you have to make sure the current normal map and color/diffuse map etc. match in size for each geometry. \nE.g. a model with a diffuse map of 256x256 has to use a normal map with 256x256 pixels as well.