- 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
3.0
dan..om 14 years ago
parent 413f2b1e48
commit 1e9ba3c0b0
  1. 17
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ColorController.java
  2. 2
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/EditorToolTarget.java
  3. 2
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/IOModule.java
  4. 13
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ImageEditorComponent.java
  5. 1
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/JmeTextureDataObject.java
  6. 8
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BrightFilter.java
  7. 2
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BufferedImageFilter.java
  8. 17
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BumpMapFilter.java
  9. 8
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/MirrorFilter.java
  10. 3
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/ResizeFilter.java
  11. 5
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/RotateLeftFilter.java
  12. 56
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/SphereMappedFilter.java
  13. 7
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/ColorPicker.java
  14. 17
      sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/CropTool.java

@ -9,7 +9,6 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
@ -31,13 +30,13 @@ public class ColorController {
int w3 = getWidth() / 3;
int h3 = getHeight() / 3;
g.setColor(ColorController.this.getBackground());
g.fillRect(w3, h3, 2*w3, 2*h3);
g.fillRect(w3, h3, 2 * w3, 2 * h3);
g.setColor(Color.BLACK);
g.drawRect(w3, h3, 2*w3, 2*h3);
g.drawRect(w3, h3, 2 * w3, 2 * h3);
g.setColor(ColorController.this.getForeground());
g.fillRect(0, 0, 2*w3, 2*h3);
g.fillRect(0, 0, 2 * w3, 2 * h3);
g.setColor(Color.BLACK);
g.drawRect(0, 0, 2*w3, 2*h3);
g.drawRect(0, 0, 2 * w3, 2 * h3);
}
};
display.addMouseListener(new MouseAdapter() {
@ -46,9 +45,9 @@ public class ColorController {
public void mouseReleased(MouseEvent e) {
int w3 = display.getWidth() / 3;
int h3 = display.getHeight() / 3;
if(new Rectangle(0, 0, 2*w3, 2*h3).contains(e.getPoint())) {
if (new Rectangle(0, 0, 2 * w3, 2 * h3).contains(e.getPoint())) {
chooseColor(foreground);
} else if(new Rectangle(w3, h3, 2*w3, 2*h3).contains(e.getPoint())) {
} else if (new Rectangle(w3, h3, 2 * w3, 2 * h3).contains(e.getPoint())) {
chooseColor(background);
}
}
@ -87,8 +86,8 @@ public class ColorController {
String title = source == foreground ? "Foreground Color" : "Background Color";
Frame parent = JOptionPane.getFrameForComponent(COMPONENT);
Color choice = JColorChooser.showDialog(parent, title, initial);
if(choice != null) {
if(source == foreground) {
if (choice != null) {
if (source == foreground) {
setForeground(choice);
} else {
setBackground(choice);

@ -9,7 +9,9 @@ public interface EditorToolTarget {
JComponent getImageCanvas();
float getScaleX();
float getScaleY();
BufferedImage getCurrentImage();
public void setForeground(Color picked);

@ -35,7 +35,7 @@ public class IOModule {
}
public BufferedImage load(FileObject file) throws IOException, URISyntaxException {
if(file.getExt().equalsIgnoreCase("tga")) {
if (file.getExt().equalsIgnoreCase("tga")) {
ImageInputStream in = new FileImageInputStream(new File(file.getURL().toURI()));
TGAImageReaderSpi spi = new TGAImageReaderSpi();
TGAImageReader rea = new TGAImageReader(spi);

@ -39,6 +39,7 @@ import com.jme3.gde.textureeditor.filters.GrayscaleFilter;
import com.jme3.gde.textureeditor.filters.MirrorFilter;
import com.jme3.gde.textureeditor.filters.ResizeFilter;
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.CropTool;
import java.io.IOException;
@ -169,6 +170,7 @@ public class ImageEditorComponent implements EditorToolTarget {
scroller.setViewportView(imageContainer);
}
@SuppressWarnings("unchecked")
private void createToolBar() {
final JButton zoomIn = new JButton(Icon("zoom-in-2.png"));
final JButton zoomOut = new JButton(Icon("zoom-out-2.png"));
@ -259,8 +261,8 @@ public class ImageEditorComponent implements EditorToolTarget {
builder.addFileFilter(FileFilters.TGA);
builder.addFileFilter(FileFilters.PNG);
JFileChooser fc= builder.createFileChooser();
fc.setFileSelectionMode(fc.SAVE_DIALOG);
JFileChooser fc = builder.createFileChooser();
fc.setFileSelectionMode(JFileChooser.SAVE_DIALOG);
fc.setAcceptAllFileFilterUsed(false);
int a = fc.showOpenDialog(COMPONENT);
@ -275,7 +277,7 @@ public class ImageEditorComponent implements EditorToolTarget {
} else if (name.endsWith(".bmp")) {
type = "bmp";
} else if (name.endsWith(".tga")) {
type ="tga";
type = "tga";
} else {
ExtensionFileFilter filter = (ExtensionFileFilter) fc.getFileFilter();
file = new File(file.getParentFile(), file.getName() + filter.getExtension());
@ -351,6 +353,7 @@ public class ImageEditorComponent implements EditorToolTarget {
final JMenuItem gray = filters.add("Grayscale");
final JMenuItem bright = filters.add("Brightness");
final JMenuItem spheremap = filters.add("SphereMapped");
ActionListener al = new ActionListener() {
@ -366,11 +369,13 @@ public class ImageEditorComponent implements EditorToolTarget {
spawnEditor(GrayscaleFilter.create().filter(editedImage));
} else if (source == bright) {
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);
}
}

@ -10,7 +10,6 @@ import org.openide.loaders.DataNode;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.loaders.MultiFileLoader;
import org.openide.nodes.CookieSet;
import org.openide.nodes.Node;
import org.openide.nodes.Children;
import org.openide.util.Lookup;

@ -20,7 +20,6 @@ public class BrightFilter implements BufferedImageFilter {
public static BrightFilter create() {
return new BrightFilter();
}
private final int[] lookup;
protected BrightFilter() {
@ -39,7 +38,7 @@ public class BrightFilter implements BufferedImageFilter {
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if(!slider.getValueIsAdjusting()) {
if (!slider.getValueIsAdjusting()) {
label.setIcon(new ImageIcon(doFilter(sourceIcon, slider.getValue() / 100f)));
}
}
@ -49,7 +48,8 @@ public class BrightFilter implements BufferedImageFilter {
sliderContainer.setBorder(BorderFactory.createTitledBorder("Brightness value"));
sliderContainer.add(slider);
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.setBorder(BorderFactory.createTitledBorder("Preview"));
JPanel container = new JPanel(new BorderLayout());
@ -57,7 +57,7 @@ public class BrightFilter implements BufferedImageFilter {
container.add(sliderContainer, BorderLayout.SOUTH);
int choice = JOptionPane.showConfirmDialog(parent.getComponent(), container, "Brightness Filter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);
if(choice == JOptionPane.OK_OPTION) {
if (choice == JOptionPane.OK_OPTION) {
return doFilter(source, slider.getValue() / 100f);
} else {
return null;

@ -4,5 +4,5 @@ import java.awt.image.BufferedImage;
public interface BufferedImageFilter {
BufferedImage filter(BufferedImage source, Object...args);
BufferedImage filter(BufferedImage source, Object... args);
}

@ -3,10 +3,11 @@ package com.jme3.gde.textureeditor.filters;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import com.jme3.gde.textureeditor.ImageEditorComponent;
public class BumpMapFilter implements BufferedImageFilter {
private static class Vec3f {
float x, y, z;
void divideLocal(float d) {
@ -29,8 +30,8 @@ public class BumpMapFilter implements BufferedImageFilter {
BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
gscale.filter(sourceImage, heightMap);
for(int x = 0; x < bumpMap.getWidth(); x++) {
for(int y = 0; y < bumpMap.getHeight(); y++) {
for (int x = 0; x < bumpMap.getWidth(); x++) {
for (int y = 0; y < bumpMap.getHeight(); y++) {
bumpMap.setRGB(x, y, generateBumpPixel(heightMap, x, y, a));
}
}
@ -41,7 +42,7 @@ public class BumpMapFilter implements BufferedImageFilter {
Vec3f S = new Vec3f();
Vec3f T = new Vec3f();
Vec3f N = new Vec3f();
Vec3f ST = new Vec3f();
S.x = 1;
S.y = 0;
S.z = a * getHeight(image, x + 1, y) - a * getHeight(image, x - 1, y);
@ -58,14 +59,14 @@ public class BumpMapFilter implements BufferedImageFilter {
}
private float getHeight(BufferedImage image, int x, int y) {
if(x < 0) {
if (x < 0) {
x = 0;
} else if(x >= image.getWidth()) {
} else if (x >= image.getWidth()) {
x = image.getWidth() - 1;
}
if(y < 0) {
if (y < 0) {
y = 0;
} else if(y >= image.getHeight()) {
} else if (y >= image.getHeight()) {
y = image.getHeight() - 1;
}
return image.getRGB(x, y) & 0xff;

@ -5,6 +5,7 @@ import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
public class MirrorFilter implements BufferedImageFilter {
public static final Integer X = 0;
public static final Integer Y = 1;
@ -12,14 +13,15 @@ public class MirrorFilter implements BufferedImageFilter {
return new MirrorFilter();
}
protected MirrorFilter() {}
protected MirrorFilter() {
}
public BufferedImage filter(BufferedImage source, Object... args) {
if(args[0] == Y) {
if (args[0] == Y) {
AffineTransform op = AffineTransform.getScaleInstance(1, -1);
op.translate(0, -source.getHeight(null));
return new AffineTransformOp(op, null).filter(source, null);
} else if(args[0] == X) {
} else if (args[0] == X) {
AffineTransform op = AffineTransform.getScaleInstance(-1, 1);
op.translate(-source.getWidth(null), 0);
return new AffineTransformOp(op, null).filter(source, null);

@ -9,7 +9,8 @@ public class ResizeFilter implements BufferedImageFilter {
return new ResizeFilter();
}
protected ResizeFilter() {}
protected ResizeFilter() {
}
public BufferedImage filter(BufferedImage source, Object... args) {
int newWidth = (Integer) args[0];

@ -11,11 +11,12 @@ public class RotateLeftFilter implements BufferedImageFilter {
return new RotateLeftFilter();
}
protected RotateLeftFilter() {}
protected RotateLeftFilter() {
}
public BufferedImage filter(BufferedImage source, Object... args) {
int type = source.getType();
if(type == BufferedImage.TYPE_CUSTOM) {
if (type == BufferedImage.TYPE_CUSTOM) {
type = BufferedImage.TYPE_INT_ARGB;
}
// BufferedImage dest = new BufferedImage(source.getHeight(), source.getWidth(), type);

@ -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;
protected ColorPicker() {}
protected ColorPicker() {
}
public void install(EditorToolTarget t) {
target = t;
@ -36,9 +37,9 @@ public class ColorPicker extends MouseAdapter implements EditorTool {
p.x /= target.getScaleX();
p.y /= target.getScaleY();
Color picked = new Color(target.getCurrentImage().getRGB(p.x, p.y));
if(SwingUtilities.isLeftMouseButton(e)) {
if (SwingUtilities.isLeftMouseButton(e)) {
target.setForeground(picked);
} else if(SwingUtilities.isRightMouseButton(e)) {
} else if (SwingUtilities.isRightMouseButton(e)) {
target.setBackground(picked);
}
}

@ -18,11 +18,12 @@ public class CropTool extends MouseInputAdapter implements EditorTool {
return new CropTool();
}
private EditorToolTarget target;
private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[] { 4, 4 }, 0);
private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[]{4, 4}, 0);
private Rectangle track;
private Point last;
protected CropTool() {}
protected CropTool() {
}
public void install(EditorToolTarget t) {
target = t;
@ -44,13 +45,13 @@ public class CropTool extends MouseInputAdapter implements EditorTool {
@Override
public void mouseReleased(MouseEvent e) {
int x = (int)(track.x / target.getScaleX());
int y = (int)(track.y / target.getScaleY());
int w = (int)(track.width / target.getScaleX());
int h = (int)(track.height / target.getScaleY());
int x = (int) (track.x / target.getScaleX());
int y = (int) (track.y / target.getScaleY());
int w = (int) (track.width / target.getScaleX());
int h = (int) (track.height / target.getScaleY());
BufferedImage source = target.getCurrentImage();
int type = source.getType();
if(type == BufferedImage.TYPE_CUSTOM) {
if (type == BufferedImage.TYPE_CUSTOM) {
type = BufferedImage.TYPE_INT_ARGB;
}
BufferedImage dest = new BufferedImage(w, h, type);
@ -73,7 +74,7 @@ public class CropTool extends MouseInputAdapter implements EditorTool {
}
public void drawTrack(Graphics2D g, int width, int height, float scaleX, float scaleY) {
if(track != null) {
if (track != null) {
g.setPaint(Color.GREEN);
g.setStroke(stroke);
g.draw(track);

Loading…
Cancel
Save