- 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;
|
||||||
|
|
||||||
@ -31,13 +30,13 @@ public class ColorController {
|
|||||||
int w3 = getWidth() / 3;
|
int w3 = getWidth() / 3;
|
||||||
int h3 = getHeight() / 3;
|
int h3 = getHeight() / 3;
|
||||||
g.setColor(ColorController.this.getBackground());
|
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.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.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.setColor(Color.BLACK);
|
||||||
g.drawRect(0, 0, 2*w3, 2*h3);
|
g.drawRect(0, 0, 2 * w3, 2 * h3);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
display.addMouseListener(new MouseAdapter() {
|
display.addMouseListener(new MouseAdapter() {
|
||||||
@ -46,9 +45,9 @@ public class ColorController {
|
|||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
int w3 = display.getWidth() / 3;
|
int w3 = display.getWidth() / 3;
|
||||||
int h3 = display.getHeight() / 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);
|
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);
|
chooseColor(background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,8 +86,8 @@ public class ColorController {
|
|||||||
String title = source == foreground ? "Foreground Color" : "Background Color";
|
String title = source == foreground ? "Foreground Color" : "Background Color";
|
||||||
Frame parent = JOptionPane.getFrameForComponent(COMPONENT);
|
Frame parent = JOptionPane.getFrameForComponent(COMPONENT);
|
||||||
Color choice = JColorChooser.showDialog(parent, title, initial);
|
Color choice = JColorChooser.showDialog(parent, title, initial);
|
||||||
if(choice != null) {
|
if (choice != null) {
|
||||||
if(source == foreground) {
|
if (source == foreground) {
|
||||||
setForeground(choice);
|
setForeground(choice);
|
||||||
} else {
|
} else {
|
||||||
setBackground(choice);
|
setBackground(choice);
|
||||||
|
@ -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);
|
||||||
|
@ -35,7 +35,7 @@ public class IOModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage load(FileObject file) throws IOException, URISyntaxException {
|
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()));
|
ImageInputStream in = new FileImageInputStream(new File(file.getURL().toURI()));
|
||||||
TGAImageReaderSpi spi = new TGAImageReaderSpi();
|
TGAImageReaderSpi spi = new TGAImageReaderSpi();
|
||||||
TGAImageReader rea = new TGAImageReader(spi);
|
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.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"));
|
||||||
@ -259,8 +261,8 @@ public class ImageEditorComponent implements EditorToolTarget {
|
|||||||
builder.addFileFilter(FileFilters.TGA);
|
builder.addFileFilter(FileFilters.TGA);
|
||||||
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);
|
||||||
@ -275,7 +277,7 @@ public class ImageEditorComponent implements EditorToolTarget {
|
|||||||
} else if (name.endsWith(".bmp")) {
|
} else if (name.endsWith(".bmp")) {
|
||||||
type = "bmp";
|
type = "bmp";
|
||||||
} else if (name.endsWith(".tga")) {
|
} else if (name.endsWith(".tga")) {
|
||||||
type ="tga";
|
type = "tga";
|
||||||
} else {
|
} else {
|
||||||
ExtensionFileFilter filter = (ExtensionFileFilter) fc.getFileFilter();
|
ExtensionFileFilter filter = (ExtensionFileFilter) fc.getFileFilter();
|
||||||
file = new File(file.getParentFile(), file.getName() + filter.getExtension());
|
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 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() {
|
||||||
@ -39,7 +38,7 @@ public class BrightFilter implements BufferedImageFilter {
|
|||||||
slider.addChangeListener(new ChangeListener() {
|
slider.addChangeListener(new ChangeListener() {
|
||||||
|
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
if(!slider.getValueIsAdjusting()) {
|
if (!slider.getValueIsAdjusting()) {
|
||||||
label.setIcon(new ImageIcon(doFilter(sourceIcon, slider.getValue() / 100f)));
|
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.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());
|
||||||
@ -57,7 +57,7 @@ public class BrightFilter implements BufferedImageFilter {
|
|||||||
container.add(sliderContainer, BorderLayout.SOUTH);
|
container.add(sliderContainer, BorderLayout.SOUTH);
|
||||||
|
|
||||||
int choice = JOptionPane.showConfirmDialog(parent.getComponent(), container, "Brightness Filter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);
|
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);
|
return doFilter(source, slider.getValue() / 100f);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -4,5 +4,5 @@ import java.awt.image.BufferedImage;
|
|||||||
|
|
||||||
public interface BufferedImageFilter {
|
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.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) {
|
||||||
@ -29,8 +30,8 @@ public class BumpMapFilter implements BufferedImageFilter {
|
|||||||
BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
|
ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
|
||||||
gscale.filter(sourceImage, heightMap);
|
gscale.filter(sourceImage, heightMap);
|
||||||
for(int x = 0; x < bumpMap.getWidth(); x++) {
|
for (int x = 0; x < bumpMap.getWidth(); x++) {
|
||||||
for(int y = 0; y < bumpMap.getHeight(); y++) {
|
for (int y = 0; y < bumpMap.getHeight(); y++) {
|
||||||
bumpMap.setRGB(x, y, generateBumpPixel(heightMap, x, y, a));
|
bumpMap.setRGB(x, y, generateBumpPixel(heightMap, x, y, a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,13 +42,13 @@ 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);
|
||||||
T.x = 0;
|
T.x = 0;
|
||||||
T.y = 1;
|
T.y = 1;
|
||||||
T.z = a * getHeight(image, x, y + 1) - a * getHeight(image, x, y - 1);
|
T.z = a * getHeight(image, x, y + 1) - a * getHeight(image, x, y - 1);
|
||||||
|
|
||||||
float den = (float) Math.sqrt(S.z * S.z + T.z * T.z + 1);
|
float den = (float) Math.sqrt(S.z * S.z + T.z * T.z + 1);
|
||||||
N.x = -S.z;
|
N.x = -S.z;
|
||||||
@ -58,14 +59,14 @@ public class BumpMapFilter implements BufferedImageFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private float getHeight(BufferedImage image, int x, int y) {
|
private float getHeight(BufferedImage image, int x, int y) {
|
||||||
if(x < 0) {
|
if (x < 0) {
|
||||||
x = 0;
|
x = 0;
|
||||||
} else if(x >= image.getWidth()) {
|
} else if (x >= image.getWidth()) {
|
||||||
x = image.getWidth() - 1;
|
x = image.getWidth() - 1;
|
||||||
}
|
}
|
||||||
if(y < 0) {
|
if (y < 0) {
|
||||||
y = 0;
|
y = 0;
|
||||||
} else if(y >= image.getHeight()) {
|
} else if (y >= image.getHeight()) {
|
||||||
y = image.getHeight() - 1;
|
y = image.getHeight() - 1;
|
||||||
}
|
}
|
||||||
return image.getRGB(x, y) & 0xff;
|
return image.getRGB(x, y) & 0xff;
|
||||||
|
@ -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,14 +13,15 @@ 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) {
|
||||||
AffineTransform op = AffineTransform.getScaleInstance(1, -1);
|
AffineTransform op = AffineTransform.getScaleInstance(1, -1);
|
||||||
op.translate(0, -source.getHeight(null));
|
op.translate(0, -source.getHeight(null));
|
||||||
return new AffineTransformOp(op, null).filter(source, 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);
|
AffineTransform op = AffineTransform.getScaleInstance(-1, 1);
|
||||||
op.translate(-source.getWidth(null), 0);
|
op.translate(-source.getWidth(null), 0);
|
||||||
return new AffineTransformOp(op, null).filter(source, null);
|
return new AffineTransformOp(op, null).filter(source, null);
|
||||||
|
@ -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,17 +11,18 @@ 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();
|
||||||
if(type == BufferedImage.TYPE_CUSTOM) {
|
if (type == BufferedImage.TYPE_CUSTOM) {
|
||||||
type = BufferedImage.TYPE_INT_ARGB;
|
type = BufferedImage.TYPE_INT_ARGB;
|
||||||
}
|
}
|
||||||
// BufferedImage dest = new BufferedImage(source.getHeight(), source.getWidth(), type);
|
// BufferedImage dest = new BufferedImage(source.getHeight(), source.getWidth(), type);
|
||||||
AffineTransform rot = AffineTransform.getRotateInstance(
|
AffineTransform rot = AffineTransform.getRotateInstance(
|
||||||
Math.PI / 2, source.getWidth() / 2,
|
Math.PI / 2, source.getWidth() / 2,
|
||||||
source.getHeight() / 2);
|
source.getHeight() / 2);
|
||||||
Point2D p0 = new Point2D.Double();
|
Point2D p0 = new Point2D.Double();
|
||||||
Point2D p1 = rot.transform(p0, null);
|
Point2D p1 = rot.transform(p0, null);
|
||||||
double dy = p1.getY();
|
double dy = p1.getY();
|
||||||
|
@ -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;
|
||||||
@ -36,9 +37,9 @@ public class ColorPicker extends MouseAdapter implements EditorTool {
|
|||||||
p.x /= target.getScaleX();
|
p.x /= target.getScaleX();
|
||||||
p.y /= target.getScaleY();
|
p.y /= target.getScaleY();
|
||||||
Color picked = new Color(target.getCurrentImage().getRGB(p.x, p.y));
|
Color picked = new Color(target.getCurrentImage().getRGB(p.x, p.y));
|
||||||
if(SwingUtilities.isLeftMouseButton(e)) {
|
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||||
target.setForeground(picked);
|
target.setForeground(picked);
|
||||||
} else if(SwingUtilities.isRightMouseButton(e)) {
|
} else if (SwingUtilities.isRightMouseButton(e)) {
|
||||||
target.setBackground(picked);
|
target.setBackground(picked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,12 @@ public class CropTool extends MouseInputAdapter implements EditorTool {
|
|||||||
return new CropTool();
|
return new CropTool();
|
||||||
}
|
}
|
||||||
private EditorToolTarget target;
|
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 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;
|
||||||
@ -44,13 +45,13 @@ public class CropTool extends MouseInputAdapter implements EditorTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
int x = (int)(track.x / target.getScaleX());
|
int x = (int) (track.x / target.getScaleX());
|
||||||
int y = (int)(track.y / target.getScaleY());
|
int y = (int) (track.y / target.getScaleY());
|
||||||
int w = (int)(track.width / target.getScaleX());
|
int w = (int) (track.width / target.getScaleX());
|
||||||
int h = (int)(track.height / target.getScaleY());
|
int h = (int) (track.height / target.getScaleY());
|
||||||
BufferedImage source = target.getCurrentImage();
|
BufferedImage source = target.getCurrentImage();
|
||||||
int type = source.getType();
|
int type = source.getType();
|
||||||
if(type == BufferedImage.TYPE_CUSTOM) {
|
if (type == BufferedImage.TYPE_CUSTOM) {
|
||||||
type = BufferedImage.TYPE_INT_ARGB;
|
type = BufferedImage.TYPE_INT_ARGB;
|
||||||
}
|
}
|
||||||
BufferedImage dest = new BufferedImage(w, h, type);
|
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) {
|
public void drawTrack(Graphics2D g, int width, int height, float scaleX, float scaleY) {
|
||||||
if(track != null) {
|
if (track != null) {
|
||||||
g.setPaint(Color.GREEN);
|
g.setPaint(Color.GREEN);
|
||||||
g.setStroke(stroke);
|
g.setStroke(stroke);
|
||||||
g.draw(track);
|
g.draw(track);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user