@Override
  public void simpleInitApp() {
    loadHintText();
    initCrossHairs();
    setupKeys();

    createMarker();

    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);

    createTerrain();
    // createTerrainGrid();

    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);

    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);

    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1f, 0).normalizeLocal(), Vector3f.UNIT_X);
  }
Beispiel #2
0
  private void setupEnvironments() {
    // カメラ設定
    cam.setFrustumPerspective(80f, 1f, 1f, 1000f);
    cam.setLocation(new Vector3f(0, 1.5f, 10));
    // cam.lookAt(new Vector3f(0, 1.6f, 0), Vector3f.UNIT_Y);
    flyCam.setDragToRotate(true);

    // ライティング
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.mult(3.0f));
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);

    // マテリアル設定
    Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg"));
    Material whitemat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m");

    // 床面
    Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(textureMat);
    floorGeom.setLocalTranslation(0, 0, 0);
    rootNode.attachChild(floorGeom);

    // 壁面
    wallGeom[0] = new Geometry("Wall1", new Box(Vector3f.ZERO, 20f, 4f, 0.1f));
    wallGeom[1] = new Geometry("Wall2", new Box(Vector3f.ZERO, 20f, 4f, 0.1f));
    wallGeom[2] = new Geometry("Wall3", new Box(Vector3f.ZERO, 20f, 4f, 0.1f));
    wallGeom[0].setMaterial(whitemat);
    wallGeom[1].setMaterial(whitemat);
    wallGeom[2].setMaterial(whitemat);
    wallGeom[0].setLocalTranslation(0, 4, -2);
    wallGeom[1].setLocalTranslation(-20, 4, 0);
    wallGeom[2].setLocalTranslation(20, 4, 0);
    wallGeom[1].rotate(0, (float) (Math.PI / 2f), 0);
    wallGeom[2].rotate(0, (float) (Math.PI / 2f), 0);
    rootNode.attachChild(wallGeom[0]);
    rootNode.attachChild(wallGeom[1]);
    rootNode.attachChild(wallGeom[2]);

    // 女性をランダムに追加
    for (int i = 0; i < girl.length; i++) {
      girl[i] = assetManager.loadModel("myAssets/Models/WalkingGirl/WalkingGirl.obj");
      girlPos[i] =
          new Vector3f((float) (Math.random() * 16.0f - 8f), 0, (float) (Math.random() * 8f));
      // 移動スピードをランダムに
      girlSpeed[i] = (float) (Math.random() * -0.02f) + 0.01f;
      if (girlSpeed[i] < 0) {
        girl[i].rotate(0, (float) (-Math.PI / 2.0f), 0);
      } else {
        girl[i].rotate(0, (float) (Math.PI / 2.0f), 0);
      }
      girl[i].setLocalTranslation(girlPos[i]);
      this.rootNode.attachChild(girl[i]);
    }
  }
  protected void makeLight() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(2));
    reflectNode.addLight(al);

    DirectionalLight dl1 = new DirectionalLight();
    dl1.setDirection(new Vector3f(0.98f, -0.98f, 0.94f).normalizeLocal());
    dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    reflectNode.addLight(dl1);
  }
  @Override
  public void setUpLight() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(1.3f));
    app.getRootNode().addLight(al);

    sun = new DirectionalLight();
    sun.setColor(ColorRGBA.White);
    sun.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
    app.getRootNode().addLight(sun);
  }
Beispiel #5
0
  protected Spatial makeCharacter() {
    // load a character from jme3test-test-data
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    golem.addLight(sun);
    return golem;
  }
  /** This method adds lighting to the game world. */
  private void setupLights() {
    // Add simple light so we can see the world
    com.jme3.light.DirectionalLight sun = new com.jme3.light.DirectionalLight();
    sun.setColor(com.jme3.math.ColorRGBA.White.mult(0.5f));
    sun.setDirection(new com.jme3.math.Vector3f(-0.2f, -1.0f, -0.2f));
    rootNode.addLight(sun);

    // Add ambient light for a more realistic look
    com.jme3.light.AmbientLight al = new com.jme3.light.AmbientLight();
    al.setColor(com.jme3.math.ColorRGBA.White.mult(2.0f));
    rootNode.addLight(al);
  }
Beispiel #7
0
  @Override
  public void simpleInitApp() {
    // sun
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
    dl.setColor(ColorRGBA.Orange);
    rootNode.addLight(dl);
    // ambient light
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
    rootNode.addLight(al);

    // floor
    Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg"));
    Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(textureMat);
    rootNode.attachChild(floorGeom);

    // object
    Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    tree.setQueueBucket(Bucket.Transparent);
    rootNode.attachChild(tree);

    // projector
    PApplet applet = new ColorBarsPApplet();
    PAppletProjectorNode projectorNode =
        new PAppletProjectorNode("projector0", assetManager, applet, 200, 200, true);
    rootNode.attachChild(projectorNode);
    rootNode.attachChild(
        projectorNode
            .getFrustmMdel()); // if you don't want to see frustum, please don't attach it to
    // rootNode.
    // projector should be added to TextureProjectorRenderer, and TextureProjectorRenderer should be
    // added to ViewPort.
    TextureProjectorRenderer ptr = new TextureProjectorRenderer(assetManager);
    ptr.getTextureProjectors().add(projectorNode.getProjector());
    viewPort.addProcessor(ptr);

    // projector is a kind of Shadow, and following processes are necessary for Shadow Rendering.
    floorGeom.setShadowMode(ShadowMode.Receive);
    tree.setShadowMode(ShadowMode.CastAndReceive); // tree makes and receives shadow

    projectorNode.setLocalTranslation(new Vector3f(0, 10, 0)); // move the projector,
    projectorNode.lookAt(
        new Vector3f(0, 0, 0), Vector3f.UNIT_X); // and make it to look at where you want.

    // cam
    cam.setLocation(Vector3f.UNIT_XYZ.mult(10.0f)); // camera moves to 10, 10, 10
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); // and looks at 0,0,0.
  }
  public void showCar() {
    for (int i = 0; i < 4; i++) {
      cars[i] = factory.getCar(car_names[i], assetManager);
      car_con[i] = cars[i].getControl(VehicleControl.class);
    }
    Camera camera = cam.clone();

    camera.setViewPort(.25f, .9f, .1f, .75f);
    carView = this.app.getRenderManager().createPostView("carview", camera);

    space.add(car_con[index]);
    dl = new DirectionalLight();
    localRootNode.addLight(dl);
    ai = new AmbientLight();
    localRootNode.addLight(ai);
    car_con[index].setPhysicsLocation(new Vector3f(0, 1, 0));
    localRootNode.attachChild(cars[index]);
    floor = assetManager.loadModel("Models/garage/garage.mesh.j3o");
    control = new RigidBodyControl(0);
    floor.addControl(control);
    control.setPhysicsLocation(Vector3f.ZERO);
    space.add(control);
    localRootNode.attachChild(floor);

    camera.setLocation(car_con[index].getPhysicsLocation().add(new Vector3f(3, 1f, 0)));
    camera.lookAt(car_con[index].getPhysicsLocation().add(new Vector3f(0, -1, 0)), Vector3f.UNIT_Y);
    dl.setDirection(camera.getDirection());

    carView.attachScene(localRootNode);
  }
Beispiel #9
0
  public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    flyCam.setMoveSpeed(100);
    setupKeys();

    this.cam.setFrustumFar(2000);

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.clone().multLocal(2));
    dl.setDirection(new Vector3f(-1, -1, -1).normalize());
    rootNode.addLight(dl);

    AmbientLight am = new AmbientLight();
    am.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(am);

    // load the level from zip or http zip
    if (useHttp) {
      assetManager.registerLocator(
          "http://jmonkeyengine.googlecode.com/files/quake3level.zip",
          HttpZipLocator.class.getName());
    } else {
      assetManager.registerLocator("basic.scene", ZipLocator.class.getName());
    }

    // create the geometry and attach it
    MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
    OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
    gameLevel = (Node) assetManager.loadAsset(key);
    gameLevel.setLocalScale(0.1f);

    // add a physics control, it will generate a MeshCollisionShape based on the gameLevel
    gameLevel.addControl(new RigidBodyControl(0));

    player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);

    player.setPhysicsLocation(new Vector3f(60, 10, -60));

    rootNode.attachChild(gameLevel);

    getPhysicsSpace().addAll(gameLevel);
    getPhysicsSpace().add(player);
  }
Beispiel #10
0
  @Override
  public void simpleInitApp() {

    Spatial gameLevel = assetManager.loadModel("Scenes/town/main.j3o");
    gameLevel.setLocalTranslation(0, -5.2f, 0);
    gameLevel.setLocalScale(2);
    rootNode.attachChild(gameLevel);

    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teapot.setMaterial(mat_default);
    rootNode.attachChild(teapot);

    // Create a wall with a simple texture from test data
    Box box = new Box(Vector3f.ZERO, 2.5f, 2.5f, 2.5f);
    Spatial wall = new Geometry("Box", box);
    Material mat_brick = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_brick.setTexture(
        "ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    wall.setMaterial(mat_brick);
    wall.setLocalTranslation(2.0f, -2.5f, 0.0f);
    rootNode.attachChild(wall);

    // Display a line of text with a default font
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("Hello World");
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);

    // Load a model from test_data (OgreXML+material+texture)
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    ninja.scale(0.05f, 0.05f, 0.05f);
    ninja.rotate(0.0f, -3.0f, 0.0f);
    ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
    rootNode.attachChild(ninja);
    // You must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
  }
Beispiel #11
0
  public static void toJMELight(DirectionalLight JMEdl, DirectionalLighting dl) {
    JMEdl.setColor(toColorRGBA(dl.color).multLocal((float) (dl.intensity)));
    Node world = new Node();

    Node yaw = new Node();
    world.attachChild(yaw);

    Node pitch = new Node();
    yaw.attachChild(pitch);

    Node offset = new Node();
    pitch.attachChild(offset);
    offset.setLocalTranslation(Vector3f.UNIT_X);

    pitch.rotate(0, (float) dl.pitch, 0);

    yaw.rotate(0, 0, (float) dl.yaw);
    JMEdl.setDirection(offset.getWorldTranslation());
  }
  @Override
  public void simpleInitApp() {

    Sphere sphereMesh = new Sphere(32, 32, 1f);

    Geometry spherePlainGeo = new Geometry("rough sphere", sphereMesh);
    Material spherePlainMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    spherePlainMat.setFloat("Shininess", 0f); // [1,128]
    spherePlainMat.setBoolean("UseMaterialColors", true);
    spherePlainMat.setColor("Ambient", ColorRGBA.Black);
    spherePlainMat.setColor("Diffuse", ColorRGBA.Cyan);
    spherePlainMat.setColor("Specular", ColorRGBA.White);
    spherePlainGeo.setMaterial(spherePlainMat);
    spherePlainGeo.move(-2.5f, 0, 0);
    rootNode.attachChild(spherePlainGeo);

    Geometry sphereShinyGeo = new Geometry("normal sphere", sphereMesh);
    Material sphereShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereShinyMat.setBoolean("UseMaterialColors", true);
    sphereShinyMat.setColor("Ambient", ColorRGBA.Black);
    sphereShinyMat.setColor("Diffuse", ColorRGBA.Cyan);
    sphereShinyMat.setColor("Specular", ColorRGBA.White);
    sphereShinyMat.setFloat("Shininess", 4f); // [1,128]
    sphereShinyGeo.setMaterial(sphereShinyMat);
    rootNode.attachChild(sphereShinyGeo);

    Geometry sphereVeryShinyGeo = new Geometry("Smooth sphere", sphereMesh);
    Material sphereVeryShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereVeryShinyMat.setBoolean("UseMaterialColors", true);
    sphereVeryShinyMat.setColor("Ambient", ColorRGBA.Black);
    sphereVeryShinyMat.setColor("Diffuse", ColorRGBA.Cyan);
    sphereVeryShinyMat.setColor("Specular", ColorRGBA.White);
    sphereVeryShinyMat.setFloat("Shininess", 100f); // [1,128]
    sphereVeryShinyGeo.setMaterial(sphereVeryShinyMat);
    sphereVeryShinyGeo.move(2.5f, 0, 0);
    rootNode.attachChild(sphereVeryShinyGeo);

    /** Must add a light to make the lit object visible! */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(1, 0, -2));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
  }
  // シーンを定義
  private void setupScene() {
    // カメラの位置、向き、移動速度を設定
    cam.setLocation(new Vector3f(0.0f, 1.6f, 24.0f));
    cam.lookAt(new Vector3f(0f, 1.6f, 0f), Vector3f.UNIT_Y);
    flyCam.setMoveSpeed(5);
    flyCam.setDragToRotate(true);

    // 空を追加
    Texture west = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_west.jpg");
    Texture east = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_east.jpg");
    Texture north = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_north.jpg");
    Texture south = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_south.jpg");
    Texture up = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_up.jpg");
    Texture down = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_down.jpg");
    Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down);
    rootNode.attachChild(sky);

    // 床面を生成
    Material floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    floor_mat.setColor("Color", ColorRGBA.Gray);
    Box floor = new Box(Vector3f.ZERO, 1500f, 0.01f, 1500f);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(floor_mat);
    rootNode.attachChild(floorGeom);

    // 照明
    DirectionalLight sun = new DirectionalLight();
    sun.setColor(ColorRGBA.White.mult(3.0f));
    sun.setDirection(new Vector3f(-.5f, -.5f, -.5f).normalizeLocal());
    rootNode.addLight(sun);

    // 女性を追加
    Spatial girl = assetManager.loadModel("myAssets/Models/WalkingGirl/WalkingGirl.obj");
    girl.rotate(0, (float) (Math.PI), 0);
    girl.setLocalTranslation(0f, 0f, 20f);
    this.rootNode.attachChild(girl);
  }
  public void simpleInitApp() {
    renderManager.setAlphaToCoverage(true);
    cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f));
    cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f));

    //        cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f));
    //        cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f,
    // -0.13857932f));

    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    Quad q = new Quad(20, 20);
    q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5));
    Geometry geom = new Geometry("floor", q);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    geom.setMaterial(mat);

    geom.rotate(-FastMath.HALF_PI, 0, 0);
    geom.center();
    geom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(geom);

    // create the geometry and attach it
    Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    teaGeom.setQueueBucket(Bucket.Transparent);
    teaGeom.setShadowMode(ShadowMode.Cast);
    makeToonish(teaGeom);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(al);

    DirectionalLight dl1 = new DirectionalLight();
    dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal());
    dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl1);

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl);

    rootNode.attachChild(teaGeom);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    CartoonEdgeFilter toon = new CartoonEdgeFilter();
    toon.setEdgeWidth(0.5f);
    toon.setEdgeIntensity(1.0f);
    toon.setNormalThreshold(0.8f);
    fpp.addFilter(toon);
    viewPort.addProcessor(fpp);
  }
Beispiel #15
0
 /** @param l */
 public LightModel(Light l) {
   light = l;
   if (!(l instanceof AmbientLight)) {
     symbolMaterial =
         new Material(
             CurrentData.getEditorWindow().getB3DApp().getAssetManager(),
             "Common/MatDefs/Misc/Unshaded.j3md");
     symbolMaterial.setColor("Color", l.getColor());
     representativeMaterial =
         new Material(
             CurrentData.getEditorWindow().getB3DApp().getAssetManager(),
             "Common/MatDefs/Light/Lighting.j3md");
     if (l instanceof DirectionalLight) {
       /*Light*/
       DirectionalLight dLight = (DirectionalLight) l;
       /*Representativ*/
       representativeMaterial.setTexture(
           "DiffuseMap",
           CurrentData.getEditorWindow()
               .getB3DApp()
               .getAssetManager()
               .loadTexture("Textures/showDirectionalLightTexture.PNG"));
       representative = new Geometry("LightModel", new Box(1, 1, 1));
       representative.setMaterial(representativeMaterial);
       /*Symbol*/
       Vector3f end =
           CurrentData.getEditorWindow()
               .getB3DApp()
               .getCamera()
               .getLocation()
               .add(CurrentData.getEditorWindow().getB3DApp().getCamera().getDirection().mult(20))
               .add(dLight.getDirection().mult(100));
       Line symbolMesh = new Line(representative.getWorldTranslation(), end);
       symbolMesh.setPointSize(5);
       symbol = new Geometry("LightSymbol", symbolMesh);
       symbol.setMaterial(symbolMaterial);
     } else if (l instanceof PointLight) {
       PointLight pLight = (PointLight) l;
       representativeMaterial.setTexture(
           "DiffuseMap",
           CurrentData.getEditorWindow()
               .getB3DApp()
               .getAssetManager()
               .loadTexture("Textures/showPointLightTexture.PNG"));
       representative = new Geometry("LightModel", new Box(1, 1, 1));
       representative.setMaterial(representativeMaterial);
       representative.setLocalTranslation(pLight.getPosition());
       symbol = new Geometry("LightSymbol", new Sphere(15, 15, pLight.getRadius()));
       symbol.setMaterial(symbolMaterial);
       symbolMaterial.getAdditionalRenderState().setWireframe(true);
     } else if (l instanceof SpotLight) {
       /*Light*/
       SpotLight sLight = (SpotLight) l;
       /*Representativ*/
       representativeMaterial.setTexture(
           "DiffuseMap",
           CurrentData.getEditorWindow()
               .getB3DApp()
               .getAssetManager()
               .loadTexture("Textures/showSpotLightTexture.PNG"));
       representative = new Geometry("LightModel", new Box(1, 1, 1));
       representative.setLocalTranslation(sLight.getPosition());
       representative.setMaterial(representativeMaterial);
       /*Symbol*/
       Vector3f end = sLight.getPosition().add(sLight.getDirection().mult(sLight.getSpotRange()));
       Line symbolMesh = new Line(representative.getWorldTranslation(), end);
       symbolMesh.setPointSize(5);
       symbol = new Geometry("LightSymbol", symbolMesh);
       symbol.setMaterial(symbolMaterial);
     }
     node.attachChild(representative);
     if (symbol != null) {
       node.attachChild(symbol);
     }
   }
 }
Beispiel #16
0
  /**
   * Uploads the lights in the light list as two uniform arrays.<br>
   * <br>
   * *
   *
   * <p><code>uniform vec4 g_LightColor[numLights];</code><br>
   * // g_LightColor.rgb is the diffuse/specular color of the light.<br>
   * // g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br>
   * // 2 = Spot. <br>
   * <br>
   * <code>uniform vec4 g_LightPosition[numLights];</code><br>
   * // g_LightPosition.xyz is the position of the light (for point lights)<br>
   * // or the direction of the light (for directional lights).<br>
   * // g_LightPosition.w is the inverse radius (1/r) of the light (for attenuation) <br>
   */
  protected void updateLightListUniforms(Shader shader, Geometry g, int numLights) {
    if (numLights == 0) { // this shader does not do lighting, ignore.
      return;
    }

    LightList lightList = g.getWorldLightList();
    Uniform lightColor = shader.getUniform("g_LightColor");
    Uniform lightPos = shader.getUniform("g_LightPosition");
    Uniform lightDir = shader.getUniform("g_LightDirection");
    lightColor.setVector4Length(numLights);
    lightPos.setVector4Length(numLights);
    lightDir.setVector4Length(numLights);

    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));

    int lightIndex = 0;

    for (int i = 0; i < numLights; i++) {
      if (lightList.size() <= i) {
        lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
        lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
      } else {
        Light l = lightList.get(i);
        ColorRGBA color = l.getColor();
        lightColor.setVector4InArray(
            color.getRed(), color.getGreen(), color.getBlue(), l.getType().getId(), i);

        switch (l.getType()) {
          case Directional:
            DirectionalLight dl = (DirectionalLight) l;
            Vector3f dir = dl.getDirection();
            lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, lightIndex);
            break;
          case Point:
            PointLight pl = (PointLight) l;
            Vector3f pos = pl.getPosition();
            float invRadius = pl.getInvRadius();
            lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, lightIndex);
            break;
          case Spot:
            SpotLight sl = (SpotLight) l;
            Vector3f pos2 = sl.getPosition();
            Vector3f dir2 = sl.getDirection();
            float invRange = sl.getInvSpotRange();
            float spotAngleCos = sl.getPackedAngleCos();

            lightPos.setVector4InArray(pos2.getX(), pos2.getY(), pos2.getZ(), invRange, lightIndex);
            lightDir.setVector4InArray(
                dir2.getX(), dir2.getY(), dir2.getZ(), spotAngleCos, lightIndex);
            break;
          case Ambient:
            // skip this light. Does not increase lightIndex
            continue;
          default:
            throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
        }
      }

      lightIndex++;
    }

    while (lightIndex < numLights) {
      lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
      lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);

      lightIndex++;
    }
  }
Beispiel #17
0
  protected void renderMultipassLighting(Shader shader, Geometry g, RenderManager rm) {

    Renderer r = rm.getRenderer();
    LightList lightList = g.getWorldLightList();
    Uniform lightDir = shader.getUniform("g_LightDirection");
    Uniform lightColor = shader.getUniform("g_LightColor");
    Uniform lightPos = shader.getUniform("g_LightPosition");
    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    boolean isFirstLight = true;
    boolean isSecondLight = false;

    for (int i = 0; i < lightList.size(); i++) {
      Light l = lightList.get(i);
      if (l instanceof AmbientLight) {
        continue;
      }

      if (isFirstLight) {
        // set ambient color for first light only
        ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
        isFirstLight = false;
        isSecondLight = true;
      } else if (isSecondLight) {
        ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
        // apply additive blending for 2nd and future lights
        r.applyRenderState(additiveLight);
        isSecondLight = false;
      }

      TempVars vars = TempVars.get();
      Quaternion tmpLightDirection = vars.quat1;
      Quaternion tmpLightPosition = vars.quat2;
      ColorRGBA tmpLightColor = vars.color;
      Vector4f tmpVec = vars.vect4f;

      ColorRGBA color = l.getColor();
      tmpLightColor.set(color);
      tmpLightColor.a = l.getType().getId();
      lightColor.setValue(VarType.Vector4, tmpLightColor);

      switch (l.getType()) {
        case Directional:
          DirectionalLight dl = (DirectionalLight) l;
          Vector3f dir = dl.getDirection();

          tmpLightPosition.set(dir.getX(), dir.getY(), dir.getZ(), -1);
          lightPos.setValue(VarType.Vector4, tmpLightPosition);
          tmpLightDirection.set(0, 0, 0, 0);
          lightDir.setValue(VarType.Vector4, tmpLightDirection);
          break;
        case Point:
          PointLight pl = (PointLight) l;
          Vector3f pos = pl.getPosition();
          float invRadius = pl.getInvRadius();

          tmpLightPosition.set(pos.getX(), pos.getY(), pos.getZ(), invRadius);
          lightPos.setValue(VarType.Vector4, tmpLightPosition);
          tmpLightDirection.set(0, 0, 0, 0);
          lightDir.setValue(VarType.Vector4, tmpLightDirection);
          break;
        case Spot:
          SpotLight sl = (SpotLight) l;
          Vector3f pos2 = sl.getPosition();
          Vector3f dir2 = sl.getDirection();
          float invRange = sl.getInvSpotRange();
          float spotAngleCos = sl.getPackedAngleCos();

          tmpLightPosition.set(pos2.getX(), pos2.getY(), pos2.getZ(), invRange);
          lightPos.setValue(VarType.Vector4, tmpLightPosition);

          // We transform the spot directoin in view space here to save 5 varying later in the
          // lighting shader
          // one vec4 less and a vec4 that becomes a vec3
          // the downside is that spotAngleCos decoding happen now in the frag shader.
          tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0);
          rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
          tmpLightDirection.set(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos);

          lightDir.setValue(VarType.Vector4, tmpLightDirection);

          break;
        default:
          throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
      }
      vars.release();
      r.setShader(shader);
      r.renderMesh(g.getMesh(), g.getLodLevel(), 1);
    }

    if (isFirstLight && lightList.size() > 0) {
      // There are only ambient lights in the scene. Render
      // a dummy "normal light" so we can see the ambient
      ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
      lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha);
      lightPos.setValue(VarType.Vector4, nullDirLight);
      r.setShader(shader);
      r.renderMesh(g.getMesh(), g.getLodLevel(), 1);
    }
  }
Beispiel #18
0
  @Override
  public void simpleInitApp() {

    //        setUpKeys();
    flyCam.setEnabled(false);

    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    Juggernaut = new Character(this, bulletAppState);

    setUpCameraBoxes();
    // Load in the level
    // Material m = assetManager.loadMaterial("Models/levelLayout - Update.mtl");
    Spatial map = assetManager.loadModel("Models/levelLayout - Update_cameraPos.obj");
    rootNode.attachChild(map);

    Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    //       mark_mat.setColor("Color", ColorRGBA.White);
    //       mark.setMaterial(mark_mat);
    //        mark.setLocalTranslation(1f,1f,1f);
    //        rootNode.attachChild(mark);

    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(map);
    landscape = new RigidBodyControl(sceneShape, 0);
    map.addControl(landscape);
    landscape.setCollisionGroup(1);
    landscape.removeCollideWithGroup(2);

    //        //Load Ninja as filler for character model
    //        ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    //        //ninja.rotate(0, -1.5f, 0);
    //        ninja.scale(0.02f, 0.02f, 0.02f);
    //        ninja.setLocalTranslation(new Vector3f(341, 300, 0));
    //        //ninja.setMaterial(mark_mat);
    //        rootNode.attachChild(ninja);
    //        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f, 2f);
    //        player = new CharacterControl(capsuleShape, .05f);
    //        player.setJumpSpeed(50);
    //        player.setFallSpeed(50);
    //        player.setGravity(120);
    //        player.setPhysicsLocation(new Vector3f(1f,8f,1f));
    //        player.setViewDirection(new Vector3f(-1.0f, 0, 0));
    //        player.setCollideWithGroups(2);
    //
    //
    //
    //        playerDebug = player.createDebugShape(assetManager);
    //        ninja.addControl(player);
    //        rootNode.attachChild(playerDebug);
    //
    //        bulletAppState.getPhysicsSpace().add(player);
    bulletAppState.getPhysicsSpace().add(landscape);

    // Elevator 1
    elevator1 = new Geometry("Elevator1", new Box(4, 1, 5));
    elevator1.setLocalTranslation(304, 20, 0);
    elevator1.setMaterial(mark_mat);
    elvtr1 = new RigidBodyControl(10);

    elevator1.addControl(elvtr1);
    elvtr1.setFriction(1000.0f);
    elvtr1.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr1);
    rootNode.attachChild(elevator1);

    // Elevator 2
    elevator2 = new Geometry("Elevator2", new Box(4, 1, 5));
    elevator2.setLocalTranslation(192, 208, 0);
    elevator2.setMaterial(mark_mat);
    elvtr2 = new RigidBodyControl(1000000000);

    elevator2.addControl(elvtr2);
    elvtr2.setAngularDamping(100000.0f);
    elvtr2.setFriction(1000.0f);
    //        elvtr2.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr2);
    rootNode.attachChild(elevator2);

    // Add lights to see the models
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);

    //        cam.setLocation(new Vector3f(player.getPhysicsLocation().x,
    // player.getPhysicsLocation().y + 5, player.getPhysicsLocation().z +40 ));
    //        cam.lookAt(player.getPhysicsLocation(), Vector3f.UNIT_Y);
    cam.setLocation(new Vector3f(0, 5, 40));
    cam.lookAt(new Vector3f(0, 5, 0), Vector3f.UNIT_Y);
  }
  public void setLighting(LightList list) {
    // XXX: This is abuse of setLighting() to
    // apply fixed function bindings
    // and do other book keeping.
    if (list == null || list.size() == 0) {
      glDisable(GL_LIGHTING);
      applyFixedFuncBindings(false);
      setModelView(worldMatrix, viewMatrix);
      return;
    }

    // Number of lights set previously
    int numLightsSetPrev = lightList.size();

    // If more than maxLights are defined, they will be ignored.
    // The GL1 renderer is not permitted to crash due to a
    // GL1 limitation. It must render anything that the GL2 renderer
    // can render (even incorrectly).
    lightList.clear();
    materialAmbientColor.set(0, 0, 0, 0);

    for (int i = 0; i < list.size(); i++) {
      Light l = list.get(i);
      if (l.getType() == Light.Type.Ambient) {
        // Gather
        materialAmbientColor.addLocal(l.getColor());
      } else {
        // Add to list
        lightList.add(l);

        // Once maximum lights reached, exit loop.
        if (lightList.size() >= maxLights) {
          break;
        }
      }
    }

    applyFixedFuncBindings(true);

    glEnable(GL_LIGHTING);

    fb16.clear();
    fb16.put(materialAmbientColor.r)
        .put(materialAmbientColor.g)
        .put(materialAmbientColor.b)
        .put(1)
        .flip();

    glLightModel(GL_LIGHT_MODEL_AMBIENT, fb16);

    if (context.matrixMode != GL_MODELVIEW) {
      glMatrixMode(GL_MODELVIEW);
      context.matrixMode = GL_MODELVIEW;
    }
    // Lights are already in world space, so just convert
    // them to view space.
    glLoadMatrix(storeMatrix(viewMatrix, fb16));

    for (int i = 0; i < lightList.size(); i++) {
      int glLightIndex = GL_LIGHT0 + i;
      Light light = lightList.get(i);
      Light.Type lightType = light.getType();
      ColorRGBA col = light.getColor();
      Vector3f pos;

      // Enable the light
      glEnable(glLightIndex);

      // OGL spec states default value for light ambient is black
      switch (lightType) {
        case Directional:
          DirectionalLight dLight = (DirectionalLight) light;

          fb16.clear();
          fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
          glLight(glLightIndex, GL_DIFFUSE, fb16);
          glLight(glLightIndex, GL_SPECULAR, fb16);

          pos = tempVec.set(dLight.getDirection()).negateLocal().normalizeLocal();
          fb16.clear();
          fb16.put(pos.x).put(pos.y).put(pos.z).put(0.0f).flip();
          glLight(glLightIndex, GL_POSITION, fb16);
          glLightf(glLightIndex, GL_SPOT_CUTOFF, 180);
          break;
        case Point:
          PointLight pLight = (PointLight) light;

          fb16.clear();
          fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
          glLight(glLightIndex, GL_DIFFUSE, fb16);
          glLight(glLightIndex, GL_SPECULAR, fb16);

          pos = pLight.getPosition();
          fb16.clear();
          fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip();
          glLight(glLightIndex, GL_POSITION, fb16);
          glLightf(glLightIndex, GL_SPOT_CUTOFF, 180);

          if (pLight.getRadius() > 0) {
            // Note: this doesn't follow the same attenuation model
            // as the one used in the lighting shader.
            glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1);
            glLightf(glLightIndex, GL_LINEAR_ATTENUATION, pLight.getInvRadius() * 2);
            glLightf(
                glLightIndex,
                GL_QUADRATIC_ATTENUATION,
                pLight.getInvRadius() * pLight.getInvRadius());
          } else {
            glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1);
            glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0);
            glLightf(glLightIndex, GL_QUADRATIC_ATTENUATION, 0);
          }

          break;
        case Spot:
          SpotLight sLight = (SpotLight) light;

          fb16.clear();
          fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
          glLight(glLightIndex, GL_DIFFUSE, fb16);
          glLight(glLightIndex, GL_SPECULAR, fb16);

          pos = sLight.getPosition();
          fb16.clear();
          fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip();
          glLight(glLightIndex, GL_POSITION, fb16);

          Vector3f dir = sLight.getDirection();
          fb16.clear();
          fb16.put(dir.x).put(dir.y).put(dir.z).put(1.0f).flip();
          glLight(glLightIndex, GL_SPOT_DIRECTION, fb16);

          float outerAngleRad = sLight.getSpotOuterAngle();
          float innerAngleRad = sLight.getSpotInnerAngle();
          float spotCut = outerAngleRad * FastMath.RAD_TO_DEG;
          float spotExpo = 0.0f;
          if (outerAngleRad > 0) {
            spotExpo = (1.0f - (innerAngleRad / outerAngleRad)) * 128.0f;
          }

          glLightf(glLightIndex, GL_SPOT_CUTOFF, spotCut);
          glLightf(glLightIndex, GL_SPOT_EXPONENT, spotExpo);

          if (sLight.getSpotRange() > 0) {
            glLightf(glLightIndex, GL_LINEAR_ATTENUATION, sLight.getInvSpotRange());
          } else {
            glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0);
          }

          break;
        default:
          throw new UnsupportedOperationException("Unrecognized light type: " + lightType);
      }
    }

    // Disable lights after the index
    for (int i = lightList.size(); i < numLightsSetPrev; i++) {
      glDisable(GL_LIGHT0 + i);
    }

    // This will set view matrix as well.
    setModelView(worldMatrix, viewMatrix);
  }
  @Override
  public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.White);
    flyCam.setMoveSpeed(50);

    /** A simple textured sphere */
    Sphere sphereMesh = new Sphere(16, 16, 1);
    Geometry sphereGeo = new Geometry("lit textured sphere", sphereMesh);
    Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Interface/Monkey.png"));
    sphereMat.setBoolean("UseMaterialColors", true);
    sphereMat.setColor("Diffuse", ColorRGBA.Gray);
    sphereMat.setColor("Ambient", ColorRGBA.Gray);
    // alpha test start
    sphereMat.getAdditionalRenderState().setAlphaTest(true);
    sphereMat.getAdditionalRenderState().setAlphaFallOff(.5f);
    sphereGeo.setQueueBucket(Bucket.Transparent);
    // alpha test end
    sphereGeo.setMaterial(sphereMat);
    sphereGeo.move(-2f, 0f, 0f);
    sphereGeo.rotate(FastMath.DEG_TO_RAD * -90, FastMath.DEG_TO_RAD * 120, 0f);
    rootNode.attachChild(sphereGeo);

    /**
     * This material turns the box into a stained glass window. The texture has an alpha channel and
     * is partially transparent.
     */
    Box windowMesh = new Box(new Vector3f(0f, 0f, 0f), 1f, 1.4f, 0.01f);
    Geometry windowGeo = new Geometry("stained glass window", windowMesh);
    Material windowMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    windowMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/mucha-window.png"));
    windowMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    windowGeo.setMaterial(windowMat);
    windowGeo.setQueueBucket(Bucket.Transparent);
    windowGeo.setMaterial(windowMat);
    windowGeo.move(1, 0, 0);
    rootNode.attachChild(windowGeo);

    /**
     * A box with its material color "bleeding" through. The texture has an alpha channel and is
     * partially transparent.
     */
    Cylinder logMesh = new Cylinder(32, 32, 1, 8, true);
    TangentBinormalGenerator.generate(logMesh);
    Geometry logGeo = new Geometry("Bleed-through color", logMesh);
    Material logMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    logMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Bark/bark_diffuse.png"));
    logMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Bark/bark_normal.png"));
    logMat.setBoolean("UseMaterialColors", true);
    logMat.setColor("Diffuse", ColorRGBA.Orange);
    logMat.setColor("Ambient", ColorRGBA.Gray);
    logMat.setBoolean("UseAlpha", true);
    logGeo.setMaterial(logMat);
    logGeo.move(0f, 0f, -2f);
    logGeo.rotate(0f, FastMath.DEG_TO_RAD * 90, 0f);
    rootNode.attachChild(logGeo);

    /** Must add a light to make the lit object visible! */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
    AmbientLight ambient = new AmbientLight();
    ambient.setColor(ColorRGBA.White);
    rootNode.addLight(ambient);
  }
  public EffectCenter(Simulator sim) {
    this.sim = sim;
    AssetManager assetManager = sim.getAssetManager();

    WeatherSettings weatherSettings =
        Simulator.getDrivingTask().getScenarioLoader().getWeatherSettings();
    snowingPercentage =
        Math.max(
            weatherSettings.getSnowingPercentage(),
            -1); // use -1 to suppress construction of SnowParticleEmitter
    rainingPercentage =
        Math.max(
            weatherSettings.getRainingPercentage(),
            -1); // use -1 to suppress construction of RainParticleEmitter
    fogPercentage =
        Math.max(
            weatherSettings.getFogPercentage(), -1); // use -1 to suppress construction of FogFilter
    isSnowing = (snowingPercentage >= 0);
    isRaining = (rainingPercentage >= 0);
    isFog = (fogPercentage >= 0);
    isBloom = !Simulator.oculusRiftAttached; // switch off bloom filter when Oculus Rift is used
    isShadow = true;

    if (isSnowing) {
      // init snow
      snowParticleEmitter = new SnowParticleEmitter(assetManager, snowingPercentage);
      sim.getSceneNode().attachChild(snowParticleEmitter);
    }

    if (isRaining) {
      // init rain
      rainParticleEmitter = new RainParticleEmitter(assetManager, rainingPercentage);
      sim.getSceneNode().attachChild(rainParticleEmitter);
    }

    if (isFog || isBloom) {
      for (ViewPort viewPort : CameraFactory.getViewPortList()) {
        FilterPostProcessor processor = new FilterPostProcessor(assetManager);

        int numSamples = sim.getContext().getSettings().getSamples();
        if (numSamples > 0) processor.setNumSamples(numSamples);

        if (isFog) {
          FogFilter fogFilter = new FogFilter();
          fogFilter.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
          fogFilter.setFogDistance(155);
          fogFilter.setFogDensity(2.0f * (fogPercentage / 100f));
          fogFilterList.add(fogFilter);
          processor.addFilter(fogFilter);
        }

        if (isBloom) {
          // ensure any object is set to glow, e.g. car chassis:
          // chassis.getMaterial().setColor("GlowColor", ColorRGBA.Orange);

          BloomFilter bloom = new BloomFilter(GlowMode.Objects);
          processor.addFilter(bloom);
        }

        viewPort.addProcessor(processor);
      }
    }

    if (isShadow) { // TODO
      DirectionalLight sun = new DirectionalLight();
      Vector3f sunLightDirection = new Vector3f(-0.2f, -0.9f, 0.2f); // TODO get from DT files
      sun.setDirection(sunLightDirection.normalizeLocal());

      ArrayList<ViewPort> viewPortList = CameraFactory.getViewPortList();

      if (sim.getNumberOfScreens() > 1) {
        int shadowMapSize = 4096;
        if (viewPortList.size() > 1) shadowMapSize = 1024;

        for (ViewPort viewPort : viewPortList) {
          DirectionalLightShadowRenderer dlsr =
              new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
          dlsr.setLight(sun);
          dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
          viewPort.addProcessor(dlsr);
        }

        shadowMapSize = 1024;
        DirectionalLightShadowRenderer dlsrBack =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrBack.setLight(sun);
        CameraFactory.getBackViewPort().addProcessor(dlsrBack);

        DirectionalLightShadowRenderer dlsrLeft =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrLeft.setLight(sun);
        CameraFactory.getLeftBackViewPort().addProcessor(dlsrLeft);

        DirectionalLightShadowRenderer dlsrRight =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrRight.setLight(sun);
        CameraFactory.getRightBackViewPort().addProcessor(dlsrRight);
      } else {
        // does not work with more than one screen
        for (ViewPort viewPort : viewPortList) {
          DirectionalLightShadowFilter dlsf =
              new DirectionalLightShadowFilter(assetManager, 1024, 3);
          dlsf.setLight(sun);
          dlsf.setLambda(1f);
          dlsf.setShadowIntensity(0.3f);
          dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
          dlsf.setEnabled(true);

          FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
          fpp.addFilter(dlsf);

          viewPort.addProcessor(fpp);
        }
      }
    }
  }
  public void simpleInitApp() {

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.6f));
    rootNode.addLight(al);

    // model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    Spatial s = assetManager.loadModel(MODEL);
    if (s instanceof Node) {
      model = (Node) s;
    } else {
      model = new Node();
      model.attachChild(s);
    }

    BoundingBox b = ((BoundingBox) model.getWorldBound());
    model.setLocalScale(1.2f / (b.getYExtent() * 2));
    //  model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y,
    // 0);
    for (Spatial spatial : model.getChildren()) {
      if (spatial instanceof Geometry) {
        Geometry geom = (Geometry) spatial;
        Material mat = geom.getMaterial();
        mat.setTransparent(true);
        mat.getAdditionalRenderState().setAlphaTest(true);
        mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
        geom.setQueueBucket(RenderQueue.Bucket.Transparent);
        listGeoms.add(geom);
      }
    }
    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    model.addControl(chaseCam);
    chaseCam.setLookAtOffset(b.getCenter());
    chaseCam.setDefaultDistance(5);
    chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);
    chaseCam.setZoomSensitivity(0.5f);

    //           ch = model.getControl(AnimControl.class).createChannel();
    //          ch.setAnim("Wave");
    SkeletonControl c = model.getControl(SkeletonControl.class);
    if (c != null) {
      c.setEnabled(false);
    }

    reductionvalue = 0.80f;
    lodLevel = 1;
    //        for (final Geometry geometry : listGeoms) {
    //            LodGenerator lodGenerator = new LodGenerator(geometry);
    //            lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL,
    // reductionvalue);
    //            geometry.setLodLevel(lodLevel);
    //
    //        }

    rootNode.attachChild(model);
    flyCam.setEnabled(false);

    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    hudText = new BitmapText(guiFont, false);
    hudText.setSize(guiFont.getCharSet().getRenderedSize());
    hudText.setText(computeNbTri() + " tris");
    hudText.setLocalTranslation(cam.getWidth() / 2, hudText.getLineHeight(), 0);
    guiNode.attachChild(hudText);

    inputManager.addListener(
        new ActionListener() {
          public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
              if (name.equals("plus")) {
                //                        lodLevel++;
                //                        for (Geometry geometry : listGeoms) {
                //                            if (geometry.getMesh().getNumLodLevels() <= lodLevel)
                // {
                //                                lodLevel = 0;
                //                            }
                //                            geometry.setLodLevel(lodLevel);
                //                        }
                //                        jaimeText.setText(computeNbTri() + " tris");

                reductionvalue += 0.05f;
                updateLod();
              }
              if (name.equals("minus")) {
                //                        lodLevel--;
                //                        for (Geometry geometry : listGeoms) {
                //                            if (lodLevel < 0) {
                //                                lodLevel = geometry.getMesh().getNumLodLevels() -
                // 1;
                //                            }
                //                            geometry.setLodLevel(lodLevel);
                //                        }
                //                        jaimeText.setText(computeNbTri() + " tris");

                reductionvalue -= 0.05f;
                updateLod();
              }
              if (name.equals("wireFrame")) {
                wireFrame = !wireFrame;
                for (Geometry geometry : listGeoms) {
                  geometry.getMaterial().getAdditionalRenderState().setWireframe(wireFrame);
                }
              }
            }
          }

          private void updateLod() {
            reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f);
            makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1);
          }
        },
        "plus",
        "minus",
        "wireFrame");

    inputManager.addMapping("plus", new KeyTrigger(KeyInput.KEY_ADD));
    inputManager.addMapping("minus", new KeyTrigger(KeyInput.KEY_SUBTRACT));
    inputManager.addMapping("wireFrame", new KeyTrigger(KeyInput.KEY_SPACE));
  }