private void setWoodGrain(final UIPanel panel) { panel.setTooltipText("Dark wood grain."); final Texture tex = new Texture2D(); // Build up our function final Function3D baseWood = new CylinderFunction3D(18); final Function3D woodGrainNoise = new FbmFunction3D(Functions.simplexNoise(), 3, 40, 0.75, 2.3); final Function3D scaledBaseWoodGrain = Functions.scaleInput(woodGrainNoise, 1, .25, 1); final Function3D woodGrain = Functions.scaleBias(scaledBaseWoodGrain, .125, 0); final Function3D combinedWood = Functions.add(baseWood, woodGrain); final Function3D perturbedWood = new TurbulenceFunction3D(combinedWood, 1 / 256.0, 4, 4.0); final Function3D translatedWood = Functions.translateInput(perturbedWood, 0, 0, 1.5); final Function3D rotatedWood = Functions.rotateInput( translatedWood, new Matrix3().fromAngles(MathUtils.DEG_TO_RAD * 6, 0, 0)); final Function3D finalWood = new TurbulenceFunction3D(rotatedWood, 1 / 512.0, 2, 2.0); final ReadOnlyColorRGBA[] woodColors = new ReadOnlyColorRGBA[256]; woodColors[0] = new ColorRGBA(189 / 255f, 94 / 255f, 4 / 255f, 1); woodColors[127] = new ColorRGBA(144 / 255f, 48 / 255f, 6 / 255f, 1); woodColors[255] = new ColorRGBA(60 / 255f, 10 / 255f, 8 / 255f, 1); GeneratedImageFactory.fillInColorTable(woodColors); Image img = GeneratedImageFactory.createLuminance8Image(finalWood, wside, hside, 1); img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, woodColors); tex.setImage(img); tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear)); tex.setMagnificationFilter(MagnificationFilter.Bilinear); tex.setMinificationFilter(MinificationFilter.Trilinear); applyTexture(tex, panel); }
private void setMandelbrot(final UIPanel panel) { panel.setTooltipText("The famous Mandelbrot fractal"); final Texture tex = new Texture2D(); // Build up our function final Function3D mandelBase = new MandelbrotFunction3D(256); final Function3D translatedMandel = Functions.translateInput(mandelBase, -.7, 0, 0); final Function3D finalMandel = Functions.scaleInput(translatedMandel, 1.5, 1.5, 1); final ReadOnlyColorRGBA[] colors = new ReadOnlyColorRGBA[256]; colors[0] = ColorRGBA.BLUE; colors[10] = ColorRGBA.YELLOW; colors[25] = ColorRGBA.BLUE; colors[255] = ColorRGBA.BLACK; GeneratedImageFactory.fillInColorTable(colors); Image img = GeneratedImageFactory.createLuminance8Image( finalMandel, (int) (1.5 * wside), (int) (1.5 * hside), 1); img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, colors); tex.setImage(img); tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear)); tex.setMagnificationFilter(MagnificationFilter.Bilinear); tex.setMinificationFilter(MinificationFilter.Trilinear); applyTexture(tex, panel); }
@Override protected void initExample() { _canvas.setTitle("Generating textures... please wait"); final Camera cam = _canvas.getCanvasRenderer().getCamera(); wside = cam.getWidth() / SPAN; hside = wside; padding = wside / 10; // Set up hud hud = new UIHud(); hud.setupInput(_canvas, _physicalLayer, _logicalLayer); // Set up the frames for (int i = 0; i < views.length; i++) { views[i] = new UIPanel(); views[i].setLocalComponentSize(wside, hside); views[i].layout(); hud.add(views[i]); } // Set up the panels for (int i = 0; i < COUNT; i++) { srcs[i] = new UIPanel(null) { @Override public boolean mousePressed( final com.ardor3d.input.MouseButton button, final com.ardor3d.input.InputState state) { if (zoom || this == zoomed) { toggleZoom(this); } return true; }; }; srcs[i].setTooltipPopTime(25); } // set up our different textures... int index = 0; // check setCheck(srcs[index++]); // mandelbrot setMandelbrot(srcs[index++]); // voronoi setVoronoi(srcs[index++]); // *** 'Planet' example: final Function3D terrain = Functions.scaleInput(Functions.simplexNoise(), 2, 2, 1); terrainColors = new ReadOnlyColorRGBA[256]; terrainColors[0] = new ColorRGBA(0, 0, .5f, 1); terrainColors[95] = new ColorRGBA(0, 0, 1, 1); terrainColors[127] = new ColorRGBA(0, .5f, 1, 1); terrainColors[137] = new ColorRGBA(240 / 255f, 240 / 255f, 64 / 255f, 1); terrainColors[143] = new ColorRGBA(32 / 255f, 160 / 255f, 0, 1); terrainColors[175] = new ColorRGBA(224 / 255f, 224 / 255f, 0, 1); terrainColors[223] = new ColorRGBA(128 / 255f, 128 / 255f, 128 / 255f, 1); terrainColors[255] = ColorRGBA.WHITE; GeneratedImageFactory.fillInColorTable(terrainColors); // simplex - luminance setTerrain(srcs[index], terrain, false, false); srcs[index++].setTooltipText("Simplex noise."); // simplex + FBM - luminance setTerrain(srcs[index], terrain, true, false); srcs[index++].setTooltipText("Simplex noise + Fractional Brownian Motion (fBm)."); // color ramp setColors(srcs[index++]); // simplex + FBM - color setTerrain(srcs[index], terrain, true, true); srcs[index++].setTooltipText("Noise + Colormap == Something that looks like a map. :)"); // *** A few textures derived from samples in the libnoise project. // *** Perhaps we can get an some better ones from the community :) // A simple wood grain setWoodGrain(srcs[index++]); // Jade setJade(srcs[index++]); // Slime setSlime(srcs[index++]); _canvas.setTitle("Generated Textures Example - Ardor3D"); }
/**