|
| 1 | +/* |
| 2 | + * Copyright (c) 2009-2022 jMonkeyEngine |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are |
| 7 | + * met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | +package jme3test.post; |
| 33 | + |
| 34 | +import com.jme3.app.SimpleApplication; |
| 35 | +import com.jme3.light.DirectionalLight; |
| 36 | +import com.jme3.material.Material; |
| 37 | +import com.jme3.math.ColorRGBA; |
| 38 | +import com.jme3.math.Vector3f; |
| 39 | +import com.jme3.post.FilterPostProcessor; |
| 40 | +import com.jme3.post.filters.CartoonEdgeFilter; |
| 41 | +import com.jme3.scene.Geometry; |
| 42 | +import com.jme3.scene.Node; |
| 43 | +import com.jme3.scene.Spatial; |
| 44 | +import com.jme3.system.AppSettings; |
| 45 | +import com.jme3.texture.Texture; |
| 46 | + |
| 47 | +/** |
| 48 | + * Test case for JME issue #1798: filtered scenes are squeezed by resizable |
| 49 | + * windows. |
| 50 | + * <p> |
| 51 | + * If successful, a cartoon monkey head will be shown, and resizing the window |
| 52 | + * (using the system's window manager) will not change its shape. |
| 53 | + * <p> |
| 54 | + * If unsuccessful, then making the window taller will make the head taller, and |
| 55 | + * making the window wider will make the head wider. |
| 56 | + * <p> |
| 57 | + * Based on the TestCartoonEdge application. |
| 58 | + */ |
| 59 | +public class TestIssue1798 extends SimpleApplication { |
| 60 | + // ************************************************************************* |
| 61 | + // fields |
| 62 | + |
| 63 | + private FilterPostProcessor fpp; |
| 64 | + // ************************************************************************* |
| 65 | + // new methods exposed |
| 66 | + |
| 67 | + public static void main(String[] args) { |
| 68 | + AppSettings s = new AppSettings(true); |
| 69 | + s.setResizable(true); |
| 70 | + TestIssue1798 app = new TestIssue1798(); |
| 71 | + app.setSettings(s); |
| 72 | + app.start(); |
| 73 | + } |
| 74 | + // ************************************************************************* |
| 75 | + // SimpleApplication methods |
| 76 | + |
| 77 | + /** |
| 78 | + * Initialize this application. |
| 79 | + */ |
| 80 | + @Override |
| 81 | + public void simpleInitApp() { |
| 82 | + viewPort.setBackgroundColor(ColorRGBA.Gray); |
| 83 | + flyCam.setDragToRotate(true); |
| 84 | + setupLighting(); |
| 85 | + setupModel(); |
| 86 | + setupFilters(); |
| 87 | + } |
| 88 | + // ************************************************************************* |
| 89 | + // private methods |
| 90 | + |
| 91 | + private void makeToonish(Spatial spatial) { |
| 92 | + if (spatial instanceof Node) { |
| 93 | + Node n = (Node) spatial; |
| 94 | + for (Spatial child : n.getChildren()) { |
| 95 | + makeToonish(child); |
| 96 | + } |
| 97 | + } else if (spatial instanceof Geometry) { |
| 98 | + Geometry g = (Geometry) spatial; |
| 99 | + Material m = g.getMaterial(); |
| 100 | + if (m.getMaterialDef().getMaterialParam("UseMaterialColors") != null) { |
| 101 | + Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); |
| 102 | + m.setTexture("ColorRamp", t); |
| 103 | + m.setBoolean("UseMaterialColors", true); |
| 104 | + m.setColor("Specular", ColorRGBA.Black); |
| 105 | + m.setColor("Diffuse", ColorRGBA.White); |
| 106 | + m.setBoolean("VertexLighting", true); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + private void setupFilters() { |
| 112 | + fpp = new FilterPostProcessor(assetManager); |
| 113 | + int numSamples = getContext().getSettings().getSamples(); |
| 114 | + if (numSamples > 0) { |
| 115 | + fpp.setNumSamples(numSamples); |
| 116 | + } |
| 117 | + CartoonEdgeFilter toon = new CartoonEdgeFilter(); |
| 118 | + toon.setEdgeColor(ColorRGBA.Yellow); |
| 119 | + fpp.addFilter(toon); |
| 120 | + viewPort.addProcessor(fpp); |
| 121 | + } |
| 122 | + |
| 123 | + private void setupLighting() { |
| 124 | + DirectionalLight dl = new DirectionalLight(); |
| 125 | + dl.setDirection(new Vector3f(-1, -1, 1).normalizeLocal()); |
| 126 | + dl.setColor(new ColorRGBA(2, 2, 2, 1)); |
| 127 | + rootNode.addLight(dl); |
| 128 | + } |
| 129 | + |
| 130 | + private void setupModel() { |
| 131 | + Spatial model = assetManager.loadModel("Models/MonkeyHead/MonkeyHead.mesh.xml"); |
| 132 | + makeToonish(model); |
| 133 | + rootNode.attachChild(model); |
| 134 | + } |
| 135 | +} |
0 commit comments