Java examples for Game:JME3
jme3 Cartoon Filter
package Effects;//from ww w.j a v a 2 s . com import com.jme3.app.SimpleApplication; import com.jme3.asset.plugins.ZipLocator; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; import com.jme3.post.filters.CartoonEdgeFilter; import com.jme3.renderer.RenderManager; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.texture.Texture; /** * test * * @author normenhansen */ public class CartoonFilter extends SimpleApplication { private Spatial sceneGeo; private FilterPostProcessor fpp; private CartoonEdgeFilter toon; public static void main(String[] args) { CartoonFilter app = new CartoonFilter(); app.start(); } @Override public void simpleInitApp() { fpp = new FilterPostProcessor(assetManager); viewPort.addProcessor(fpp); toon = new CartoonEdgeFilter(); fpp.addFilter(toon); assetManager.registerLocator("town.zip", ZipLocator.class); sceneGeo = assetManager.loadModel("main.scene"); rootNode.attachChild(sceneGeo); DirectionalLight sunLight = new DirectionalLight(); sunLight.setDirection(new Vector3f(0.3f, -0.5f, -0.5f)); rootNode.addLight(sunLight); Geometry teapotGeo = (Geometry) assetManager .loadModel("Models/Teapot/Teapot.j3o"); Material teapotMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); teapotMat.setBoolean("UseMaterialColors", true); teapotMat.setColor("Diffuse", ColorRGBA.Pink); teapotGeo.setMaterial(teapotMat); teapotGeo.scale(3); teapotGeo.setLocalTranslation(32, 3, -24); rootNode.attachChild(teapotGeo); makeToonish(rootNode); } public void makeToonish(Spatial spatial) { if (spatial instanceof Node) { Node n = (Node) spatial; for (Spatial child : n.getChildren()) { makeToonish(child); } } else if (spatial instanceof Geometry) { Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")) { Texture t = assetManager .loadTexture("Textures/ColorRamp/toon.png"); m.setTexture("ColorRamp", t); m.setBoolean("VertexLighting", true); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); } } } @Override public void simpleUpdate(float tpf) { //TODO: add update code } @Override public void simpleRender(RenderManager rm) { //TODO: add render code } }