import artofillusion.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Stripes2 extends Texture3D { RGBColor color1, color2; float width; public Stripes2() { color1 = new RGBColor(1.0f, 0.0f, 0.0f); color2 = new RGBColor(1.0f, 1.0f, 1.0f); width = 0.5f; } public static String getTypeName() { return "Stripes 2"; } public void getAverageSpec(TextureSpec spec) { float w = 1.0f-width; spec.diffuse.setRGB(width*color1.getRed() + w*color2.getRed(), width*color1.getGreen() + w*color2.getGreen(), width*color1.getBlue() + w*color2.getBlue()); spec.specular.setRGB(0.0f, 0.0f, 0.0f); spec.transparent.setRGB(0.0f, 0.0f, 0.0f); spec.emissive.setRGB(0.0f, 0.0f, 0.0f); spec.bumpGrad.set(0.0, 0.0, 0.0); spec.roughness = spec.cloudiness = 0.0; } public void getTextureSpec(TextureSpec spec, double x, double y, double z, double xsize, double ysize, double zsize, double t, float param[]) { if (x-Math.floor(x) < width) spec.diffuse.copy(color1); else spec.diffuse.copy(color2); spec.specular.setRGB(0.0f, 0.0f, 0.0f); spec.transparent.setRGB(0.0f, 0.0f, 0.0f); spec.emissive.setRGB(0.0f, 0.0f, 0.0f); spec.bumpGrad.set(0.0, 0.0, 0.0); spec.roughness = spec.cloudiness = 0.0; } public void getTransparency(RGBColor trans, double x, double y, double z, double xsize, double ysize, double zsize, double t, float param[]) { trans.setRGB(0.0f, 0.0f, 0.0f); } public Texture duplicate() { Stripes2 s = new Stripes2(); s.color1.copy(color1); s.color2.copy(color2); s.width = width; return s; } public void edit(Frame fr, Scene sc) { RGBColor oldColor1 = color1.duplicate(), oldColor2 = color2.duplicate(); float oldWidth = width; final Panel color1Patch = color1.getSample(50, 30), color2Patch = color2.getSample(50, 30); final ValueSlider widthSlider = new ValueSlider(0.0, 1.0, 100, width); final MaterialPreviewer preview = new MaterialPreviewer(this, null, 200, 160); final Frame parent = fr; TextField nameField = new TextField(getName()); ComponentsDialog dlg; color1Patch.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { new ColorChooser(parent, "Color 1", color1); color1Patch.setBackground(color1.getColor()); color1Patch.repaint(); preview.render(); } }); color2Patch.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { new ColorChooser(parent, "Color 2", color2); color2Patch.setBackground(color2.getColor()); color2Patch.repaint(); preview.render(); } }); widthSlider.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { width = (float) widthSlider.getValue(); preview.render(); } }); dlg = new ComponentsDialog(parent, getName(), new Component [] {preview, nameField, color1Patch, color2Patch, widthSlider}, new String [] {"", "Name", "Color 1", "Color 2", "Stripe Width"}); if (!dlg.clickedOk()) { color1.copy(oldColor1); color2.copy(oldColor2); width = oldWidth; } else setName(nameField.getText()); } public Stripes2(DataInputStream in, Scene theScene) throws IOException, InvalidObjectException { setName(in.readUTF()); color1 = new RGBColor(in); color2 = new RGBColor(in); width = in.readFloat(); } public void writeToFile(DataOutputStream out, Scene theScene) throws IOException { out.writeUTF(getName()); color1.writeToFile(out); color2.writeToFile(out); out.writeFloat(width); } }