예제 #1
0
 private void readTransparentStatement(String statement) throws IOException {
   String[] split = statement.split(whitespacePattern);
   if (split.length != 2) {
     throw new IOException("Transparent statement syntax incorrect");
   }
   material.setTransparent(parseBoolean(split[1]));
 }
예제 #2
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;
 }
예제 #3
0
  protected void createMaterial() {
    Material material;

    if (alpha < 1f && transparent) {
      diffuse.a = alpha;
    }

    if (shadeless) {
      material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
      material.setColor("Color", diffuse.clone());
      material.setTexture("ColorMap", diffuseMap);
      // TODO: Add handling for alpha map?
    } else {
      material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
      material.setBoolean("UseMaterialColors", true);
      material.setColor("Ambient", ambient.clone());
      material.setColor("Diffuse", diffuse.clone());
      material.setColor("Specular", specular.clone());
      material.setFloat("Shininess", shininess); // prevents "premature culling" bug

      if (diffuseMap != null) material.setTexture("DiffuseMap", diffuseMap);
      if (specularMap != null) material.setTexture("SpecularMap", specularMap);
      if (normalMap != null) material.setTexture("NormalMap", normalMap);
      if (alphaMap != null) material.setTexture("AlphaMap", alphaMap);
    }

    if (transparent) {
      material.setTransparent(true);
      material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
      material.getAdditionalRenderState().setAlphaTest(true);
      material.getAdditionalRenderState().setAlphaFallOff(0.01f);
    }

    material.setName(matName);
    matList.put(matName, material);
  }
  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));
  }