コード例 #1
0
ファイル: TestCcd.java プロジェクト: wufuyue/TCL_S820
  @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);
  }
コード例 #2
0
  /**
   * 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);
  }
コード例 #3
0
ファイル: BlockTex.java プロジェクト: warriordog/Boxle-Game
 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;
 }
コード例 #4
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);
  }
コード例 #5
0
  // 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;
  }
コード例 #6
0
  @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);
  }
コード例 #7
0
ファイル: AIPlanetEdge.java プロジェクト: gormed/solarwars
  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;
  }
コード例 #8
0
 private void readAdditionalRenderState(List<Statement> renderStates) throws IOException {
   renderState = material.getAdditionalRenderState();
   for (Statement statement : renderStates) {
     readRenderStateStatement(statement);
   }
   renderState = null;
 }
コード例 #9
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;
  }
コード例 #10
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;
 }
コード例 #11
0
ファイル: AbstractApplication.java プロジェクト: kumarrr/ice
  /**
   * Generates a new, basic material for use in the jME3 app.
   *
   * @param color The color of the material.
   * @return A jME3 Material using Lighting.j3md.
   */
  public Material createLitMaterial(ColorRGBA color) {
    Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    material.setBoolean("UseMaterialColors", true);
    material.setColor("Diffuse", color);
    material.setFloat("Shininess", 12f);
    material.setColor("Specular", ColorRGBA.White);
    material.setColor("Ambient", ColorRGBA.LightGray);
    material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    return material;
  }
コード例 #12
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);
  }
コード例 #13
0
 @Override
 public void modify(ModelObject modelObject) {
   SkeletonControl skeletonControl =
       modelObject.getModelSpatial().getControl(SkeletonControl.class);
   Node headNode = skeletonControl.getAttachmentsNode("head");
   float width = 1.6f;
   float height = (width * (4f / 5));
   Quad quad = new Quad(width, height, true);
   Spatial plane = new Geometry(null, quad);
   plane.setLocalTranslation((width / -2), 0.3f, -0.73f);
   JMonkeyUtil.setLocalRotation(plane, new Vector3f(0, -0.7f, 1));
   Material material = MaterialFactory.generateUnshadedMaterial("Models/cow/resources/baron.png");
   material.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
   plane.setMaterial(material);
   headNode.attachChild(plane);
 }
コード例 #14
0
  private void createMarker() {
    // collision marker
    Sphere sphere = new Sphere(8, 8, 0.5f);
    marker = new Geometry("Marker");
    marker.setMesh(sphere);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.6f));
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    marker.setMaterial(mat);
    rootNode.attachChild(marker);

    // surface normal marker
    Arrow arrow = new Arrow(new Vector3f(0, 1, 0));
    markerNormal = new Geometry("MarkerNormal");
    markerNormal.setMesh(arrow);
    markerNormal.setMaterial(mat);
    rootNode.attachChild(markerNormal);
  }
コード例 #15
0
  public Recording(TerrainHeighmapCreator app, Camera cam, Node sceneNode) {
    this.app = app;
    this.cam = cam;
    this.sceneNode = new Node("record");
    sceneNode.attachChild(this.sceneNode);
    this.points = new ArrayList<>();

    sphereMesh = new Sphere(8, 8, 0.25f * TerrainHeighmapCreator.TERRAIN_SCALE);
    sphereMat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    sphereMat.setColor("Color", ColorRGBA.Blue);
    arrowMat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    arrowMat.getAdditionalRenderState().setWireframe(true);
    arrowMat.setColor("Color", ColorRGBA.Red);

    app.getNifty().addXml("org/shaman/terrain/vegetation/DummyScreen.xml");
    app.getInputManager()
        .addMapping("RecordingAdd", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    app.getInputManager()
        .addMapping("RecordingSpeed-", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    app.getInputManager()
        .addMapping("RecordingSpeed+", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    app.getInputManager().addListener(this, "RecordingAdd", "RecordingSpeed-", "RecordingSpeed+");
  }
コード例 #16
0
ファイル: LightModel.java プロジェクト: TheRDavid/Banana3D
 /** @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);
     }
   }
 }
コード例 #17
0
  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));
  }
コード例 #18
0
ファイル: MaterialManager.java プロジェクト: sean-tll/OpenRTS
  private static void initBaseMaterials() {
    ColorRGBA lotColorBase = new ColorRGBA(200f / 255f, 200f / 255f, 200f / 255f, 255f / 255f);
    ColorRGBA concreteColor = new ColorRGBA(90f / 255f, 100f / 255f, 255f / 255f, 255f / 255f);
    ColorRGBA redConcreteColor = ColorRGBA.Red;
    ColorRGBA blueConcreteColor = ColorRGBA.Blue;
    ColorRGBA yellowConcreteColor = ColorRGBA.Yellow;
    ColorRGBA cyanConcreteColor = new ColorRGBA(0, 1, 1, 0.4f);
    ColorRGBA blackConcreteColor = ColorRGBA.Black;
    ColorRGBA greenConcreteColor = ColorRGBA.Green;
    ColorRGBA floorColor = ColorRGBA.Gray;
    ColorRGBA windowsColor = ColorRGBA.White;
    ColorRGBA itemColor = ColorRGBA.LightGray;
    ColorRGBA roadsColor = ColorRGBA.LightGray;
    ColorRGBA terrainColor = new ColorRGBA(0f / 255f, 50f / 255f, 14f / 255f, 255f / 255f);

    am.registerLocator("assets/", FileLocator.class.getName());

    contourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    contourMaterial.setColor("Color", blackConcreteColor);

    blockContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    blockContourMaterial.setColor("Color", redConcreteColor);

    lotContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotContourMaterial.setColor("Color", blueConcreteColor);

    lotMaterial1 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotMaterial1.setColor("Color", lotColorBase);

    lotMaterial2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotMaterial2.setColor("Color", lotColorBase);

    lotMaterial3 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotMaterial3.setColor("Color", lotColorBase);

    // debug material
    debugMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterial.setColor("Color", redConcreteColor);
    // debug texture material
    // debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
    // debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    // debugTextureMaterial.setTexture("DiffuseMap",
    // assetManager.loadTexture("Textures/UVTest.jpg"));
    // debugTextureMaterial.setFloat("Shininess", 128f); // [0,128]

    // Red Material
    redMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    redMaterial.setColor("Color", redConcreteColor);
    redMaterial.setColor("GlowColor", redConcreteColor);

    // Concrete Material
    yellowMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    yellowMaterial.setColor("Color", yellowConcreteColor);

    // Concrete Material
    cyanMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    cyanMaterial.setColor("Color", cyanConcreteColor);
    cyanMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    // Concrete Material
    blackMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    blackMaterial.setColor("Color", blackConcreteColor);

    // Concrete Material
    greenMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    greenMaterial.setColor("Color", greenConcreteColor);
    greenMaterial.setColor("GlowColor", greenConcreteColor);

    // Item Material
    itemMaterial = new Material(am, "Common/MatDefs/Light/Lighting.j3md");
    itemMaterial.setColor("Diffuse", itemColor);
    itemMaterial.setBoolean("UseMaterialColors", true);

    // gradient blue
    for (int i = 0; i < 4; i++) {
      gradientMaterial.add(new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"));
      gradientMaterial
          .get(i)
          .setColor("Color", new ColorRGBA(i * 30 / 255f, i * 30 / 255f, i * 85 / 255f, 1));
    }
  }
コード例 #19
0
  @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);
  }
コード例 #20
0
  public static void main(String[] args) {
    AssetManager assetManager =
        JmeSystem.newAssetManager(
            TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));

    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);

    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);

    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);

    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);

    // Comparing same textures
    TextureKey originalKey =
        (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);

    // Texture keys from the original and the loaded texture
    // must be identical, otherwise the resultant textures not identical
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)) {
      System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }

    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);

    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);

    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);

    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);

    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
  }