Hi.
I just typed the “toon effect” exercise from the beginner’s book, and can’t really see any visible difference. The geometries have that black edge, but it does not seem to make a difference if I call the makeToonish() method or not. I was actually expecting a really strong effect here. So, did I type something wrong, or is the toon effect meant to be hardly visible? I know it does “hit” the geometries, because if I put traces in it, they come out on the console…
Here’s the code:
[java]package mygame;
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;
public class Cartoon extends SimpleApplication {
private FilterPostProcessor fpp;
private Spatial sceneGeo;
private CartoonEdgeFilter toon;
public static void main(String[] args) {
Cartoon app = new Cartoon();
app.start();
}
private void makeToonish(Spatial spatial) {
if (spatial instanceof Node) {
for (Spatial s : ((Node) spatial).getChildren()) {
makeToonish(s);
}
} 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 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 sun = new DirectionalLight();
sun.setDirection(new Vector3f(0.3f, -0.5f, -0.5f));
rootNode.addLight(sun);
makeToonish(rootNode);
// Default speed is too slow
flyCam.setMoveSpeed(20f);
flyCam.setZoomSpeed(5f);
}
@Override
public void simpleUpdate(float tpf) {
// NOP
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]