/**
   * renders a filter on a fullscreen quad
   *
   * @param r
   * @param buff
   * @param mat
   */
  private void renderProcessing(Renderer r, FrameBuffer buff, Material mat) {
    if (buff == outputBuffer) {
      fsQuad.setWidth(width);
      fsQuad.setHeight(height);
      filterCam.resize(originalWidth, originalHeight, true);
      fsQuad.setPosition(left * originalWidth, bottom * originalHeight);
    } else {
      fsQuad.setWidth(buff.getWidth());
      fsQuad.setHeight(buff.getHeight());
      filterCam.resize(buff.getWidth(), buff.getHeight(), true);
      fsQuad.setPosition(0, 0);
    }

    if (mat.getAdditionalRenderState().isDepthWrite()) {
      mat.getAdditionalRenderState().setDepthTest(false);
      mat.getAdditionalRenderState().setDepthWrite(false);
    }

    fsQuad.setMaterial(mat);
    fsQuad.updateGeometricState();

    renderManager.setCamera(filterCam, true);
    r.setFrameBuffer(buff);
    r.clearBuffers(false, true, true);
    renderManager.renderGeometry(fsQuad);
  }
  @Override
  public void simpleInitApp() {
    JmeCanvasContext ctx = (JmeCanvasContext) getContext();
    gui = new GUI(this, ctx.getCanvas());
    gui.show();

    flyCam.setEnabled(false);
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(mat);

    rootNode.attachChild(geom);

    cinematic = new Cinematic(rootNode, 5);
    MotionPath path = new MotionPath();
    path.addWayPoint(Vector3f.ZERO.clone());
    path.addWayPoint(new Vector3f(10, 0, 0));
    MotionEvent motionEvent = new MotionEvent(geom, path, 5);
    cinematic.addCinematicEvent(0, motionEvent);
    cinematic.fitDuration();
    cinematic.setLoopMode(LoopMode.Loop);
    stateManager.attach(cinematic);
  }
Esempio n. 3
0
  @Override
  public void simpleInitApp() {

    /** create a blue box at coordinates (1,-1,1) */
    Box box1 = new Box(new Vector3f(1, -1, 1), 1, 1, 1);
    Geometry blue = new Geometry("Box", box1);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
    mat1.setColor("Color", ColorRGBA.Blue);
    blue.setMaterial(mat1);

    /** create a red box straight above the blue one at (1,3,1) */
    Box box2 = new Box(new Vector3f(1, 3, 1), 1, 1, 1);
    Geometry red = new Geometry("Box", box2);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
    mat2.setColor("Color", ColorRGBA.Red);
    red.setMaterial(mat2);

    /** Create a pivot node at (0,0,0) and attach it to the root node */
    Node pivot = new Node("pivot");
    rootNode.attachChild(pivot); // put this node in the scene

    /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
    pivot.attachChild(blue);
    pivot.attachChild(red);
    /** Rotate the pivot node: Note that both boxes have rotated! */
    pivot.rotate(.4f, .4f, 0f);
  }
  @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);
  }
Esempio n. 5
0
  @Override
  public void simpleInitApp() {
    // add a random cube
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.randomColor());
    geom.setMaterial(mat);
    geom.move(
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * -10));
    rootNode.attachChild(geom);

    // add saved cubes
    String userHome = System.getProperty("user.home");
    BinaryImporter importer = BinaryImporter.getInstance();
    importer.setAssetManager(assetManager);
    try {
      File file = new File(userHome + "/mycoolgame/savedgame.j3o");
      Node sceneNode = (Node) importer.load(file);
      sceneNode.setName("My restored node");
      rootNode.attachChild(sceneNode);
      Logger.getLogger(SaveAndLoad.class.getName()).log(Level.INFO, "Success: Loaded saved node.");
    } catch (IOException ex) {
      Logger.getLogger(SaveAndLoad.class.getName())
          .log(Level.INFO, "Warning: Could not load saved node.", ex);
    }
  }
  private void displayPlayersPositions() {
    Map<Vector3f, Integer> playerPositions = gm.getMapManager().getBoard().getPlayerPositions();

    Iterator it = playerPositions.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      Vector3f pos = (Vector3f) pairs.getKey();
      Integer number = (Integer) pairs.getValue();

      Box b = new Box(Vector3f.ZERO, 2.0f, 1.0f, 2.0f);
      Geometry geom = new Geometry("Box", b);
      Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setColor("Color", ColorRGBA.randomColor());

      geom.setMaterial(mat);
      geom.setLocalTranslation(pos.x, 0, pos.z);

      String geomName = "PLAYERMARKER";
      geom.setName(geomName);
      geom.setUserData(geomName, pos);

      playerNodes.attachChild(geom);

      displayLocationName(number.toString(), new Vector3f(pos.x, 1, pos.z));
    }
  }
Esempio n. 7
0
  public void renderImage(
      RenderImage image, int x, int y, int width, int height, Color color, float imageScale) {

    RenderImageJme jmeImage = (RenderImageJme) image;

    textureColorMaterial.setColor("Color", convertColor(color, tempColor));
    textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture());

    quad.clearBuffer(Type.TexCoord);
    quad.setBuffer(quadDefaultTC);

    float x0 = x + 0.5f * width * (1f - imageScale);
    float y0 = y + 0.5f * height * (1f - imageScale);

    tempMat.loadIdentity();
    tempMat.setTranslation(x0, getHeight() - y0, 0);
    tempMat.setScale(width * imageScale, height * imageScale, 0);

    rm.setWorldMatrix(tempMat);
    rm.setForcedRenderState(renderState);
    textureColorMaterial.render(quadGeom, rm);

    // System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n",
    // jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(),
    // imageScale);
  }
  public void UserJoin(HostedConnection source, Message message) {
    boolean bfound = false;

    // SMObjectShare SMObjshare = (SMObjectShare)smobj;

    for (SMObjectPlayerController player : players) {
      if (source.getId() == Integer.parseInt(player.smobjshare.userid)) {
        SMObjectShare shareobject = (SMObjectShare) message;
        player.smobjshare = shareobject;
        // player.getSpatial().setLocalTranslation(shareobject.x, shareobject.y, shareobject.z);
        bfound = true;
      }
    }

    if (!bfound) {
      Box objplayer = new Box(Vector3f.ZERO, 1, 1, 1);
      Geometry geomplayer = new Geometry("Box", objplayer);
      Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setColor("m_Color", ColorRGBA.Brown);
      geomplayer.setMaterial(mat);
      Spatial spl = (Spatial) geomplayer;

      SMObjectPlayerController newplayer = new SMObjectPlayerController(spl);
      newplayer.smobjshare = new SMObjectShare();
      newplayer.smobjshare.userid = Integer.toString(source.getId());
      newplayer.smobjshare.userid = Integer.toString(source.getId());

      source.send(newplayer.smobjshare);
      rootNode.attachChild(newplayer.getSpatial());
      players.add(newplayer);
    }
  }
  // debug function that create a displayable frustrum
  protected Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
      case 0:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
        break;
      case 1:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
        break;
      case 2:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
        break;
      case 3:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
        break;
      default:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
        break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
  }
Esempio n. 10
0
  Node createDebugGeometry() {
    Line l = new Line(from.getPlanet().getPosition(), to.getPlanet().getPosition());

    line = new Geometry("Line #" + from.getPlanet().getID() + " to #" + to.getPlanet().getID(), l);

    Material material =
        new Material(
            SolarWarsApplication.getInstance().getAssetManager(),
            "Common/MatDefs/Misc/Unshaded.j3md");

    Player p = from.getPlanet().getOwner();
    ColorRGBA c;
    if (p == null) {
      c = ColorRGBA.White.clone();
      c.a = 0.5f;
      material.setColor("Color", c);
    } else {
      c = p.getColor();
      c.a = 0.5f;
      material.setColor("Color", c);
    }
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    line.setMaterial(material);

    createLabel();
    Node lineNode = new Node(line.getName() + "_Node");
    lineNode.attachChild(line);
    lineNode.attachChild(label);
    //        Vector3f pos = to.getPlanet().getPosition().
    //                subtract(from.getPlanet().getPosition());
    //        lineNode.setLocalTranslation(pos.mult(0.5f));
    return lineNode;
  }
Esempio n. 11
0
 /** for internal use only */
 protected void setPostShadowParams() {
   setMaterialParameters(postshadowMat);
   for (int j = 0; j < nbShadowMaps; j++) {
     postshadowMat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]);
     postshadowMat.setTexture("ShadowMap" + j, shadowMaps[j]);
   }
 }
Esempio n. 12
0
  private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];

    // DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);

    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);

    for (int i = 0; i < nbShadowMaps; i++) {
      lightViewProjectionsMatrices[i] = new Matrix4f();
      shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
      shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);

      shadowFB[i].setDepthTexture(shadowMaps[i]);

      // DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
      shadowFB[i].setColorTexture(dummyTex);

      postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]);

      // quads for debuging purpose
      dispPic[i] = new Picture("Picture" + i);
      dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }

    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
  }
Esempio n. 13
0
  private Spatial getSpatial(String name) {
    Node node = new Node(name);
    //        load picture
    Picture pic = new Picture(name);
    Texture2D tex = (Texture2D) assetManager.loadTexture("Textures/" + name + ".png");
    pic.setTexture(assetManager, tex, true);

    //        adjust picture
    float width = tex.getImage().getWidth();
    float height = tex.getImage().getHeight();
    pic.setWidth(width);
    pic.setHeight(height);
    pic.move(-width / 2f, -height / 2f, 0);

    //        add a material to the picture
    Material picMat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
    picMat.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);
    node.setMaterial(new Material());

    //        set the radius of the spatial
    //        (using width only as a simple approximation)
    // node.setUserData("radius", width/2);

    //        attach the picture to the node and return it
    node.attachChild(pic);
    return node;
  }
Esempio n. 14
0
 /** A red ball that marks the last spot that was "hit" by the "shot". */
 protected void initMark() {
   Sphere sphere = new Sphere(30, 30, 0.2f);
   mark = new Geometry("BOOM!", sphere);
   Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mark_mat.setColor("Color", ColorRGBA.Red);
   mark.setMaterial(mark_mat);
 }
 protected void applyTextures(Material mat) {
   mat.setTexture("water_reflection", reflectionTexture);
   mat.setTexture("water_refraction", refractionTexture);
   mat.setTexture("water_depthmap", depthTexture);
   mat.setTexture("water_normalmap", normalTexture);
   mat.setTexture("water_dudvmap", dudvTexture);
 }
Esempio n. 16
0
  @Override
  public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.1f);
    setupKeys();

    mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);

    mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Red);

    // An obstacle mesh, does not move (mass=0)
    Node node2 = new Node();
    node2.setName("mesh");
    node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
    node2.addControl(
        new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // The floor, does not move (mass=0)
    Node node3 = new Node();
    node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
    node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
  }
 private void createMaterial() {
   mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat1.setColor("Color", ColorRGBA.Green);
   mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat2.setColor("Color", ColorRGBA.Red);
   mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat3.setColor("Color", ColorRGBA.Yellow);
 }
Esempio n. 18
0
 /** A cube object for target practice */
 protected Geometry makeCube(String name, float x, float y, float z) {
   Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);
   Geometry cube = new Geometry(name, box);
   Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat1.setColor("Color", ColorRGBA.randomColor());
   cube.setMaterial(mat1);
   return cube;
 }
Esempio n. 19
0
 /** A floor to show that the "shot" can go through several objects. */
 protected Geometry makeFloor() {
   Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15);
   Geometry floor = new Geometry("the Floor", box);
   Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat1.setColor("Color", ColorRGBA.Gray);
   floor.setMaterial(mat1);
   return floor;
 }
Esempio n. 20
0
  /**
   * iterate through the filter list and renders filters
   *
   * @param r
   * @param sceneFb
   */
  private void renderFilterChain(Renderer r, FrameBuffer sceneFb) {
    Texture2D tex = filterTexture;
    FrameBuffer buff = sceneFb;
    boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1;
    for (int i = 0; i < filters.size(); i++) {
      Filter filter = filters.get(i);
      if (filter.isEnabled()) {
        if (filter.getPostRenderPasses() != null) {
          for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator();
              it1.hasNext(); ) {
            Filter.Pass pass = it1.next();
            pass.beforeRender();
            if (pass.requiresSceneAsTexture()) {
              pass.getPassMaterial().setTexture("Texture", tex);
              if (tex.getImage().getMultiSamples() > 1) {
                pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples());
              } else {
                pass.getPassMaterial().clearParam("NumSamples");
              }
            }
            if (pass.requiresDepthAsTexture()) {
              pass.getPassMaterial().setTexture("DepthTexture", depthTexture);
              if (msDepth) {
                pass.getPassMaterial()
                    .setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
              } else {
                pass.getPassMaterial().clearParam("NumSamplesDepth");
              }
            }
            renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial());
          }
        }

        filter.postFrame(renderManager, viewPort, buff, sceneFb);

        Material mat = filter.getMaterial();
        if (msDepth && filter.isRequiresDepthTexture()) {
          mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
        }

        if (filter.isRequiresSceneTexture()) {
          mat.setTexture("Texture", tex);
          if (tex.getImage().getMultiSamples() > 1) {
            mat.setInt("NumSamples", tex.getImage().getMultiSamples());
          } else {
            mat.clearParam("NumSamples");
          }
        }

        buff = outputBuffer;
        if (i != lastFilterIndex) {
          buff = filter.getRenderFrameBuffer();
          tex = filter.getRenderedTexture();
        }
        renderProcessing(r, buff, mat);
      }
    }
  }
Esempio n. 21
0
 private Geometry putShape(SimpleApplication game, Mesh shape, ColorRGBA color) {
   Geometry g = new Geometry("coordinate axis", shape);
   Material mat = new Material(game.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
   mat.getAdditionalRenderState().setWireframe(true);
   mat.setColor("Color", color);
   g.setMaterial(mat);
   game.getRootNode().attachChild(g);
   return g;
 }
Esempio n. 22
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. 23
0
  private void initBox() {
    Box b = new Box(1, 1, 1);
    Geometry blue = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    blue.setMaterial(mat);

    /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
    rootNode.attachChild(blue);
  }
Esempio n. 24
0
 /**
  * set the post shadow material for this renderer
  *
  * @param postShadowMat
  */
 protected final void setPostShadowMaterial(Material postShadowMat) {
   this.postshadowMat = postShadowMat;
   postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
   for (int i = 0; i < nbShadowMaps; i++) {
     postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]);
   }
   setShadowCompareMode(shadowCompareMode);
   setEdgeFilteringMode(edgeFilteringMode);
   setShadowIntensity(shadowIntensity);
 }
Esempio n. 25
0
 private Material getMaterial(ColorRGBA color) {
   Material mat = new Material(main.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
   mat.setColor("Diffuse", color);
   ColorRGBA clone = color.clone();
   clone.multLocal(0.8f);
   clone.a = 1f;
   mat.setColor("Ambient", clone);
   mat.setBoolean("UseMaterialColors", true);
   return mat;
 }
  private void setupBox() {
    Box boxshape1 = new Box(new Vector3f(-3f, 1.1f, 0f), 1f, 1f, 1f);
    Geometry cube = new Geometry("My Textured Box", boxshape1);
    Material mat_stl = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    Texture tex_ml = app.getAssetManager().loadTexture("Textures/test.png");
    mat_stl.setTexture("ColorMap", tex_ml);
    cube.setMaterial(mat_stl);

    app.getRootNode().attachChild(cube);
  }
Esempio n. 27
0
 private Material createMaterial(String side) {
   Material mat = new Material(boxle.getAssetManager(), jm3dName);
   mat.setName("block_" + block.getName() + "_" + side);
   mat.setTransparent(
       block.isTransparent()); // Does not actually do anything, but is used as a marker
   mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
   mat.getAdditionalRenderState().setAlphaTest(true);
   mat.getAdditionalRenderState().setAlphaFallOff(.9f);
   return mat;
 }
Esempio n. 28
0
  @Override
  protected void prepare() {
    super.prepare();

    if (subname != null) {
      List<Material> mat = JmeUtils.findMaterials(this, "BarrelMat");
      Texture tex = am.loadTexture("Models/barrel/" + subname + ".jpg");
      for (Material material : mat) {
        material.setParam("DiffuseMap", VarType.Texture2D, tex);
      }
    }
  }
Esempio n. 29
0
  public static void LoadObjectHelper() {
    highlightMat = new Material(Main.s_AssetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture texture = Main.s_AssetManager.loadTexture("Models/tree.png");
    highlightMat.setTexture("ColorMap", texture);

    greenTrans = new Material(Main.s_AssetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    greenTrans.setColor("Color", new ColorRGBA(0, 1, 0, 0.3f));
    greenTrans.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    redTrans = new Material(Main.s_AssetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    redTrans.setColor("Color", new ColorRGBA(1, 0, 0, 0.3f));
    redTrans.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
  }
  private void createTerrain() {
    // First, we load up our textures and the heightmap texture for the terrain

    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    matTerrain.setFloat("Shininess", 0);

    // ALPHA map (for splat textures)
    matTerrain.setTexture(
        "AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));

    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap", grass);
    matTerrain.setFloat("DiffuseMap_0_scale", grassScale);

    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_1", dirt);
    matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);

    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_2", rock);
    matTerrain.setFloat("DiffuseMap_2_scale", rockScale);

    // HEIGHTMAP image (for the terrain heightmap)
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    AbstractHeightMap heightmap = null;
    try {
      heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f);
      heightmap.load();
      heightmap.smooth(0.9f, 1);

    } catch (Exception e) {
      e.printStackTrace();
    }

    // CREATE THE TERRAIN
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f)); // patch size, and a multiplier
    terrain.addControl(control);
    terrain.setMaterial(matTerrain);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(2.5f, 0.5f, 2.5f);
    rootNode.attachChild(terrain);
  }