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);
  }
  @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);
  }
  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);
  }
Esempio n. 4
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]);
    }
  }
Esempio n. 5
0
  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);
  }
Esempio n. 7
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);
  }
Esempio n. 9
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.
  }
Esempio n. 10
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);
  }
Esempio n. 11
0
  @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);
  }
Esempio n. 12
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);
  }
Esempio n. 13
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());
  }
  // シーンを定義
  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 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);
        }
      }
    }
  }
Esempio n. 16
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 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));
  }
  @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);
  }