- Added the SphereMapped texture modification.
-- This feature is available in the "Filters" menu on the top left of the texture window. --- With the original texture opened, click on the Filters then SphereMapped. --- A new window will open containing the new modified version of the texture. --- You can save that new texture by right-clicking on the texture's window tab then clicking on Save. - Did some code formatting and cleaning on the original classes (unused imports). - Added tooltips to buttons. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7693 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
413f2b1e48
commit
1e9ba3c0b0
@ -9,7 +9,6 @@ import java.awt.event.MouseAdapter;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import javax.swing.JColorChooser;
|
import javax.swing.JColorChooser;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@ public interface EditorToolTarget {
|
|||||||
JComponent getImageCanvas();
|
JComponent getImageCanvas();
|
||||||
|
|
||||||
float getScaleX();
|
float getScaleX();
|
||||||
|
|
||||||
float getScaleY();
|
float getScaleY();
|
||||||
|
|
||||||
BufferedImage getCurrentImage();
|
BufferedImage getCurrentImage();
|
||||||
|
|
||||||
public void setForeground(Color picked);
|
public void setForeground(Color picked);
|
||||||
|
@ -39,6 +39,7 @@ import com.jme3.gde.textureeditor.filters.GrayscaleFilter;
|
|||||||
import com.jme3.gde.textureeditor.filters.MirrorFilter;
|
import com.jme3.gde.textureeditor.filters.MirrorFilter;
|
||||||
import com.jme3.gde.textureeditor.filters.ResizeFilter;
|
import com.jme3.gde.textureeditor.filters.ResizeFilter;
|
||||||
import com.jme3.gde.textureeditor.filters.RotateLeftFilter;
|
import com.jme3.gde.textureeditor.filters.RotateLeftFilter;
|
||||||
|
import com.jme3.gde.textureeditor.filters.SphereMappedFilter;
|
||||||
import com.jme3.gde.textureeditor.tools.ColorPicker;
|
import com.jme3.gde.textureeditor.tools.ColorPicker;
|
||||||
import com.jme3.gde.textureeditor.tools.CropTool;
|
import com.jme3.gde.textureeditor.tools.CropTool;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -169,6 +170,7 @@ public class ImageEditorComponent implements EditorToolTarget {
|
|||||||
scroller.setViewportView(imageContainer);
|
scroller.setViewportView(imageContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void createToolBar() {
|
private void createToolBar() {
|
||||||
final JButton zoomIn = new JButton(Icon("zoom-in-2.png"));
|
final JButton zoomIn = new JButton(Icon("zoom-in-2.png"));
|
||||||
final JButton zoomOut = new JButton(Icon("zoom-out-2.png"));
|
final JButton zoomOut = new JButton(Icon("zoom-out-2.png"));
|
||||||
@ -260,7 +262,7 @@ public class ImageEditorComponent implements EditorToolTarget {
|
|||||||
builder.addFileFilter(FileFilters.PNG);
|
builder.addFileFilter(FileFilters.PNG);
|
||||||
|
|
||||||
JFileChooser fc = builder.createFileChooser();
|
JFileChooser fc = builder.createFileChooser();
|
||||||
fc.setFileSelectionMode(fc.SAVE_DIALOG);
|
fc.setFileSelectionMode(JFileChooser.SAVE_DIALOG);
|
||||||
fc.setAcceptAllFileFilterUsed(false);
|
fc.setAcceptAllFileFilterUsed(false);
|
||||||
|
|
||||||
int a = fc.showOpenDialog(COMPONENT);
|
int a = fc.showOpenDialog(COMPONENT);
|
||||||
@ -351,6 +353,7 @@ public class ImageEditorComponent implements EditorToolTarget {
|
|||||||
|
|
||||||
final JMenuItem gray = filters.add("Grayscale");
|
final JMenuItem gray = filters.add("Grayscale");
|
||||||
final JMenuItem bright = filters.add("Brightness");
|
final JMenuItem bright = filters.add("Brightness");
|
||||||
|
final JMenuItem spheremap = filters.add("SphereMapped");
|
||||||
|
|
||||||
ActionListener al = new ActionListener() {
|
ActionListener al = new ActionListener() {
|
||||||
|
|
||||||
@ -366,11 +369,13 @@ public class ImageEditorComponent implements EditorToolTarget {
|
|||||||
spawnEditor(GrayscaleFilter.create().filter(editedImage));
|
spawnEditor(GrayscaleFilter.create().filter(editedImage));
|
||||||
} else if (source == bright) {
|
} else if (source == bright) {
|
||||||
spawnEditor(BrightFilter.create().filter(editedImage, ImageEditorComponent.this));
|
spawnEditor(BrightFilter.create().filter(editedImage, ImageEditorComponent.this));
|
||||||
|
} else if (source == spheremap) {
|
||||||
|
spawnEditor(SphereMappedFilter.create().filter(editedImage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (AbstractButton b : Arrays.asList(bumpSoft, bumpMedium, bumpStrong, gray, bright)) {
|
for (AbstractButton b : Arrays.asList(bumpSoft, bumpMedium, bumpStrong, gray, bright, spheremap)) {
|
||||||
b.addActionListener(al);
|
b.addActionListener(al);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import org.openide.loaders.DataNode;
|
|||||||
import org.openide.loaders.DataObjectExistsException;
|
import org.openide.loaders.DataObjectExistsException;
|
||||||
import org.openide.loaders.MultiDataObject;
|
import org.openide.loaders.MultiDataObject;
|
||||||
import org.openide.loaders.MultiFileLoader;
|
import org.openide.loaders.MultiFileLoader;
|
||||||
import org.openide.nodes.CookieSet;
|
|
||||||
import org.openide.nodes.Node;
|
import org.openide.nodes.Node;
|
||||||
import org.openide.nodes.Children;
|
import org.openide.nodes.Children;
|
||||||
import org.openide.util.Lookup;
|
import org.openide.util.Lookup;
|
||||||
|
@ -20,7 +20,6 @@ public class BrightFilter implements BufferedImageFilter {
|
|||||||
public static BrightFilter create() {
|
public static BrightFilter create() {
|
||||||
return new BrightFilter();
|
return new BrightFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int[] lookup;
|
private final int[] lookup;
|
||||||
|
|
||||||
protected BrightFilter() {
|
protected BrightFilter() {
|
||||||
@ -49,7 +48,8 @@ public class BrightFilter implements BufferedImageFilter {
|
|||||||
sliderContainer.setBorder(BorderFactory.createTitledBorder("Brightness value"));
|
sliderContainer.setBorder(BorderFactory.createTitledBorder("Brightness value"));
|
||||||
sliderContainer.add(slider);
|
sliderContainer.add(slider);
|
||||||
JPanel labelContainer = new JPanel(new GridBagLayout());
|
JPanel labelContainer = new JPanel(new GridBagLayout());
|
||||||
GridBagConstraints lim = new GridBagConstraints(); lim.gridx = lim.gridy = 0;
|
GridBagConstraints lim = new GridBagConstraints();
|
||||||
|
lim.gridx = lim.gridy = 0;
|
||||||
labelContainer.add(label, lim);
|
labelContainer.add(label, lim);
|
||||||
labelContainer.setBorder(BorderFactory.createTitledBorder("Preview"));
|
labelContainer.setBorder(BorderFactory.createTitledBorder("Preview"));
|
||||||
JPanel container = new JPanel(new BorderLayout());
|
JPanel container = new JPanel(new BorderLayout());
|
||||||
|
@ -3,10 +3,11 @@ package com.jme3.gde.textureeditor.filters;
|
|||||||
import java.awt.color.ColorSpace;
|
import java.awt.color.ColorSpace;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.ColorConvertOp;
|
import java.awt.image.ColorConvertOp;
|
||||||
import com.jme3.gde.textureeditor.ImageEditorComponent;
|
|
||||||
|
|
||||||
public class BumpMapFilter implements BufferedImageFilter {
|
public class BumpMapFilter implements BufferedImageFilter {
|
||||||
|
|
||||||
private static class Vec3f {
|
private static class Vec3f {
|
||||||
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
void divideLocal(float d) {
|
void divideLocal(float d) {
|
||||||
@ -41,7 +42,7 @@ public class BumpMapFilter implements BufferedImageFilter {
|
|||||||
Vec3f S = new Vec3f();
|
Vec3f S = new Vec3f();
|
||||||
Vec3f T = new Vec3f();
|
Vec3f T = new Vec3f();
|
||||||
Vec3f N = new Vec3f();
|
Vec3f N = new Vec3f();
|
||||||
Vec3f ST = new Vec3f();
|
|
||||||
S.x = 1;
|
S.x = 1;
|
||||||
S.y = 0;
|
S.y = 0;
|
||||||
S.z = a * getHeight(image, x + 1, y) - a * getHeight(image, x - 1, y);
|
S.z = a * getHeight(image, x + 1, y) - a * getHeight(image, x - 1, y);
|
||||||
|
@ -5,6 +5,7 @@ import java.awt.image.AffineTransformOp;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class MirrorFilter implements BufferedImageFilter {
|
public class MirrorFilter implements BufferedImageFilter {
|
||||||
|
|
||||||
public static final Integer X = 0;
|
public static final Integer X = 0;
|
||||||
public static final Integer Y = 1;
|
public static final Integer Y = 1;
|
||||||
|
|
||||||
@ -12,7 +13,8 @@ public class MirrorFilter implements BufferedImageFilter {
|
|||||||
return new MirrorFilter();
|
return new MirrorFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MirrorFilter() {}
|
protected MirrorFilter() {
|
||||||
|
}
|
||||||
|
|
||||||
public BufferedImage filter(BufferedImage source, Object... args) {
|
public BufferedImage filter(BufferedImage source, Object... args) {
|
||||||
if (args[0] == Y) {
|
if (args[0] == Y) {
|
||||||
|
@ -9,7 +9,8 @@ public class ResizeFilter implements BufferedImageFilter {
|
|||||||
return new ResizeFilter();
|
return new ResizeFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ResizeFilter() {}
|
protected ResizeFilter() {
|
||||||
|
}
|
||||||
|
|
||||||
public BufferedImage filter(BufferedImage source, Object... args) {
|
public BufferedImage filter(BufferedImage source, Object... args) {
|
||||||
int newWidth = (Integer) args[0];
|
int newWidth = (Integer) args[0];
|
||||||
|
@ -11,7 +11,8 @@ public class RotateLeftFilter implements BufferedImageFilter {
|
|||||||
return new RotateLeftFilter();
|
return new RotateLeftFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RotateLeftFilter() {}
|
protected RotateLeftFilter() {
|
||||||
|
}
|
||||||
|
|
||||||
public BufferedImage filter(BufferedImage source, Object... args) {
|
public BufferedImage filter(BufferedImage source, Object... args) {
|
||||||
int type = source.getType();
|
int type = source.getType();
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.jme3.gde.textureeditor.filters;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture Mapper
|
||||||
|
*
|
||||||
|
* This class will take a texture and will map it to a spherical
|
||||||
|
* adaptation so no, at least no visible, distortion is apparent.
|
||||||
|
*
|
||||||
|
* @author MadJack
|
||||||
|
* @created 06/18/2011
|
||||||
|
*/
|
||||||
|
public class SphereMappedFilter implements BufferedImageFilter {
|
||||||
|
|
||||||
|
public static SphereMappedFilter create() {
|
||||||
|
return new SphereMappedFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SphereMappedFilter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following algorithm is heavily based on
|
||||||
|
* Paul Bourke's pseudo code available at:
|
||||||
|
* http://paulbourke.net/texture_colour/texturemap/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BufferedImage filter(BufferedImage sourceImg, Object... args) {
|
||||||
|
|
||||||
|
BufferedImage imageOut = new BufferedImage(sourceImg.getWidth(), sourceImg.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
double theta, phi, phi2;
|
||||||
|
int i, i2, j;
|
||||||
|
|
||||||
|
for (j = 0; j < sourceImg.getHeight(); j++) {
|
||||||
|
theta = Math.PI * (j - (sourceImg.getHeight() - 1) / 2.0f) / (sourceImg.getHeight() - 1);
|
||||||
|
for (i = 0; i < sourceImg.getWidth(); i++) {
|
||||||
|
phi = Math.PI * 2 * (i - sourceImg.getWidth() / 2.0f) / sourceImg.getWidth();
|
||||||
|
phi2 = phi * Math.cos(theta);
|
||||||
|
i2 = (int) Math.round(phi2 * sourceImg.getWidth() / (Math.PI * 2) + sourceImg.getWidth() / 2);
|
||||||
|
|
||||||
|
int newpixel = 0;
|
||||||
|
if (i2 < 0 || i2 > sourceImg.getWidth() - 1) {
|
||||||
|
/* Should not happen, make that a red pixel */
|
||||||
|
newpixel = 100;
|
||||||
|
} else {
|
||||||
|
newpixel = sourceImg.getRGB(i2, j);
|
||||||
|
}
|
||||||
|
imageOut.setRGB(i, j, newpixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return imageOut;
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,8 @@ public class ColorPicker extends MouseAdapter implements EditorTool {
|
|||||||
}
|
}
|
||||||
private EditorToolTarget target;
|
private EditorToolTarget target;
|
||||||
|
|
||||||
protected ColorPicker() {}
|
protected ColorPicker() {
|
||||||
|
}
|
||||||
|
|
||||||
public void install(EditorToolTarget t) {
|
public void install(EditorToolTarget t) {
|
||||||
target = t;
|
target = t;
|
||||||
|
@ -22,7 +22,8 @@ public class CropTool extends MouseInputAdapter implements EditorTool {
|
|||||||
private Rectangle track;
|
private Rectangle track;
|
||||||
private Point last;
|
private Point last;
|
||||||
|
|
||||||
protected CropTool() {}
|
protected CropTool() {
|
||||||
|
}
|
||||||
|
|
||||||
public void install(EditorToolTarget t) {
|
public void install(EditorToolTarget t) {
|
||||||
target = t;
|
target = t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user