Java Code Examples for com.jme3.material.Material#setColor()

The following examples show how to use com.jme3.material.Material#setColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubeField.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
     * Randomly Places a cube on the map between 30 and 90 paces away from player
     */
    private void randomizeCube() {
        Geometry cube = fcube.clone();
        int playerX = (int) player.getLocalTranslation().getX();
        int playerZ = (int) player.getLocalTranslation().getZ();
//        float x = FastMath.nextRandomInt(playerX + difficulty + 10, playerX + difficulty + 150);
        float x = FastMath.nextRandomInt(playerX + difficulty + 30, playerX + difficulty + 90);
        float z = FastMath.nextRandomInt(playerZ - difficulty - 50, playerZ + difficulty + 50);
        cube.getLocalTranslation().set(x, 0, z);

//        playerX+difficulty+30,playerX+difficulty+90

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        if (!solidBox){
            mat.getAdditionalRenderState().setWireframe(true);
        }
        mat.setColor("Color", obstacleColors.get(FastMath.nextRandomInt(0, obstacleColors.size() - 1)));
        cube.setMaterial(mat);

        rootNode.attachChild(cube);
        cubeField.add(cube);
    }
 
Example 2
Source File: TranslucentBucketFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager rm, ViewPort vp, int w, int h) {
    this.renderManager = rm;
    this.viewPort = vp;
    material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md");
    material.setColor("Color", ColorRGBA.White);
    Texture2D tex = processor.getFilterTexture();
    material.setTexture("Texture", tex);
    if (tex.getImage().getMultiSamples() > 1) {
        material.setInt("NumSamples", tex.getImage().getMultiSamples());
    } else {
        material.clearParam("NumSamples");
    }
    renderManager.setHandleTranslucentBucket(false);
    if (enabledSoftParticles && depthTexture != null) {
        initSoftParticles(vp, true);
    }
}
 
Example 3
Source File: TestTransparentCartoonEdge.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void makeToonish(Spatial spatial){
        if (spatial instanceof Node){
            Node n = (Node) spatial;
            for (Spatial child : n.getChildren())
                makeToonish(child);
        }else if (spatial instanceof Geometry){
            Geometry g = (Geometry) spatial;
            Material m = g.getMaterial();
            if (m.getMaterialDef().getName().equals("Phong Lighting")){
                Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png");
//                t.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
//                t.setMagFilter(Texture.MagFilter.Nearest);
                m.setTexture("ColorRamp", t);
                m.setBoolean("UseMaterialColors", true);
                m.setColor("Specular", ColorRGBA.Black);
                m.setColor("Diffuse", ColorRGBA.White);
                m.setBoolean("VertexLighting", true);
            }
        }
    }
 
Example 4
Source File: BulletDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialize the materials.
 *
 * @param app the application which owns this state (not null)
 */
private void setupMaterials(Application app) {
    AssetManager manager = app.getAssetManager();
    DEBUG_BLUE = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_BLUE.getAdditionalRenderState().setWireframe(true);
    DEBUG_BLUE.setColor("Color", ColorRGBA.Blue);
    DEBUG_GREEN = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_GREEN.getAdditionalRenderState().setWireframe(true);
    DEBUG_GREEN.setColor("Color", ColorRGBA.Green);
    DEBUG_RED = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_RED.getAdditionalRenderState().setWireframe(true);
    DEBUG_RED.setColor("Color", ColorRGBA.Red);
    DEBUG_YELLOW = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_YELLOW.getAdditionalRenderState().setWireframe(true);
    DEBUG_YELLOW.setColor("Color", ColorRGBA.Yellow);
    DEBUG_MAGENTA = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_MAGENTA.getAdditionalRenderState().setWireframe(true);
    DEBUG_MAGENTA.setColor("Color", ColorRGBA.Magenta);
    DEBUG_PINK = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_PINK.getAdditionalRenderState().setWireframe(true);
    DEBUG_PINK.setColor("Color", ColorRGBA.Pink);
}
 
Example 5
Source File: TestBlendEquations.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Adds a "transparent" quad to the scene, that limits the color values of the scene behind the object.<br/>
 * This effect can be good seen on bright areas of the scene (e.g. areas with specular lighting effects).
 */
private void createRightQuad() {
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor("Color", new ColorRGBA(0.4f, 0.4f, 0.4f, 1f));

    // Min( Source , Destination)
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Custom);
    material.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Min);
    material.getAdditionalRenderState().setBlendEquationAlpha(RenderState.BlendEquationAlpha.Min);

    // In OpenGL no blend factors are used, when using the blend equations Min or Max!
    //material.getAdditionalRenderState().setCustomBlendFactors(
    //        RenderState.BlendFunc.One, RenderState.BlendFunc.One,
    //        RenderState.BlendFunc.One, RenderState.BlendFunc.One);

    rightQuad = new Geometry("RightQuad", new Quad(1f, 1f));
    rightQuad.setMaterial(material);
    rightQuad.setQueueBucket(RenderQueue.Bucket.Transparent);
    rootNode.attachChild(rightQuad);
}
 
Example 6
Source File: DebugTools.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialize all the DebugTools materials.
 */
protected void setupMaterials() {
    DEBUG_BLUE = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_BLUE.getAdditionalRenderState().setWireframe(true);
    DEBUG_BLUE.setColor("Color", ColorRGBA.Blue);
    DEBUG_GREEN = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_GREEN.getAdditionalRenderState().setWireframe(true);
    DEBUG_GREEN.setColor("Color", ColorRGBA.Green);
    DEBUG_RED = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_RED.getAdditionalRenderState().setWireframe(true);
    DEBUG_RED.setColor("Color", ColorRGBA.Red);
    DEBUG_YELLOW = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_YELLOW.getAdditionalRenderState().setWireframe(true);
    DEBUG_YELLOW.setColor("Color", ColorRGBA.Yellow);
    DEBUG_MAGENTA = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_MAGENTA.getAdditionalRenderState().setWireframe(true);
    DEBUG_MAGENTA.setColor("Color", ColorRGBA.Magenta);
    DEBUG_PINK = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    DEBUG_PINK.getAdditionalRenderState().setWireframe(true);
    DEBUG_PINK.setColor("Color", ColorRGBA.Pink);
}
 
Example 7
Source File: TestIssue801.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1f));

    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);
    inputManager.addMapping("changeBpp", new KeyTrigger(KeyInput.KEY_P));
    ActionListener listener = new ActionListener() {
        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("changeBpp") && keyPressed) {
                goWindowed();
            }
        }
    };
    inputManager.addListener(listener, "changeBpp");
}
 
Example 8
Source File: TestMousePick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** A floor to show that the "shot" can go through several objects. */
protected Geometry makeFloor() {
    Box box = new Box(15, .2f, 15);
    Geometry floor = new Geometry("the Floor", box);
    floor.setLocalTranslation(0, -4, -5);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.Gray);
    floor.setMaterial(mat1);
    return floor;
}
 
Example 9
Source File: TestAmbient.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
  float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
    1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f,
    0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f,
    0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f};
  Environment env = new Environment(eax);
  audioRenderer.setEnvironment(env);

  waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg",
          DataType.Buffer);
  waves.setPositional(true);
  waves.setLocalTranslation(new Vector3f(0, 0,0));
  waves.setMaxDistance(100);
  waves.setRefDistance(5);

  nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg",
          DataType.Stream);
  nature.setPositional(false);
  nature.setVolume(3);
  
  waves.playInstance();
  nature.play();
  
  // just a blue box to mark the spot
  Box box1 = new Box(.5f, .5f, .5f);
  Geometry player = new Geometry("Player", box1);
  Material mat1 = new Material(assetManager,
          "Common/MatDefs/Misc/Unshaded.j3md");
  mat1.setColor("Color", ColorRGBA.Blue);
  player.setMaterial(mat1);
  rootNode.attachChild(player);
}
 
Example 10
Source File: TestMousePick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** A cube object for target practice */
protected Geometry makeCube(String name, float x, float y, float z) {
    Box box = new Box(1, 1, 1);
    Geometry cube = new Geometry(name, box);
    cube.setLocalTranslation(x, y, z);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.randomColor());
    cube.setMaterial(mat1);
    return cube;
}
 
Example 11
Source File: TestMotionPath.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createScene() {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 1f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Black);
    mat.setColor("Diffuse", ColorRGBA.DarkGray);
    mat.setColor("Specular", ColorRGBA.White.mult(0.6f));
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Black);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Black);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setName("Teapot");
    teapot.setLocalScale(3);
    teapot.setMaterial(mat);


    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -1.0f, 0), 50, 1, 50));
    soil.setMaterial(matSoil);

    rootNode.attachChild(soil);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
}
 
Example 12
Source File: TerrainGridAlphaMapTest.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Node createAxisMarker(float arrowSize) {

        Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        redMat.getAdditionalRenderState().setWireframe(true);
        redMat.setColor("Color", ColorRGBA.Red);
        
        Material greenMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        greenMat.getAdditionalRenderState().setWireframe(true);
        greenMat.setColor("Color", ColorRGBA.Green);
        
        Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        blueMat.getAdditionalRenderState().setWireframe(true);
        blueMat.setColor("Color", ColorRGBA.Blue);

        Node axis = new Node();

        // create arrows
        Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0)));
        arrowX.setMaterial(redMat);
        Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0)));
        arrowY.setMaterial(greenMat);
        Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize)));
        arrowZ.setMaterial(blueMat);
        axis.attachChild(arrowX);
        axis.attachChild(arrowY);
        axis.attachChild(arrowZ);

        //axis.setModelBound(new BoundingBox());
        return axis;
    }
 
Example 13
Source File: TerrainTestAdvanced.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Node createAxisMarker(float arrowSize) {

        Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        redMat.getAdditionalRenderState().setWireframe(true);
        redMat.setColor("Color", ColorRGBA.Red);
        
        Material greenMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        greenMat.getAdditionalRenderState().setWireframe(true);
        greenMat.setColor("Color", ColorRGBA.Green);
        
        Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        blueMat.getAdditionalRenderState().setWireframe(true);
        blueMat.setColor("Color", ColorRGBA.Blue);

        Node axis = new Node();

        // create arrows
        Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0)));
        arrowX.setMaterial(redMat);
        Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0)));
        arrowY.setMaterial(greenMat);
        Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize)));
        arrowZ.setMaterial(blueMat);
        axis.attachChild(arrowX);
        axis.attachChild(arrowY);
        axis.attachChild(arrowZ);

        //axis.setModelBound(new BoundingBox());
        return axis;
    }
 
Example 14
Source File: TestOgreComplexAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");

    control = model.getControl(AnimControl.class);

    AnimChannel feet = control.createChannel();
    AnimChannel leftHand = control.createChannel();
    AnimChannel rightHand = control.createChannel();

    // feet will dodge
    feet.addFromRootBone("hip.right");
    feet.addFromRootBone("hip.left");
    feet.setAnim("Dodge");
    feet.setSpeed(2);
    feet.setLoopMode(LoopMode.Cycle);

    // will blend over 15 seconds to stand
    feet.setAnim("Walk", 15);
    feet.setSpeed(0.25f);
    feet.setLoopMode(LoopMode.Cycle);

    // left hand will pull
    leftHand.addFromRootBone("uparm.right");
    leftHand.setAnim("pull");
    leftHand.setSpeed(.5f);

    // will blend over 15 seconds to stand
    leftHand.setAnim("stand", 15);

    // right hand will push
    rightHand.addBone("spinehigh");
    rightHand.addFromRootBone("uparm.left");
    rightHand.setAnim("push");

    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat.getAdditionalRenderState().setDepthTest(false);
    skeletonDebug.setMaterial(mat);

    model.attachChild(skeletonDebug);
    rootNode.attachChild(model);
}
 
Example 15
Source File: TestPosterization.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));

    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));

    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);

    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

    Geometry soil = new Geometry("soil", new Box(800, 10, 700));
    soil.setLocalTranslation(0, -13, 550);
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", SkyFactory.EnvMapType.CubeMap);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    pf = new PosterizationFilter();
    fpp.addFilter(pf);

    viewPort.addProcessor(fpp);
    initInputs();

}
 
Example 16
Source File: TestCustomMesh.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
      
        Mesh m = new Mesh();

        // Vertex positions in space
        Vector3f [] vertices = new Vector3f[4];
        vertices[0] = new Vector3f(0,0,0);
        vertices[1] = new Vector3f(3,0,0);
        vertices[2] = new Vector3f(0,3,0);
        vertices[3] = new Vector3f(3,3,0);

        // Texture coordinates
        Vector2f [] texCoord = new Vector2f[4];
        texCoord[0] = new Vector2f(0,0);
        texCoord[1] = new Vector2f(1,0);
        texCoord[2] = new Vector2f(0,1);
        texCoord[3] = new Vector2f(1,1);

        // Indexes. We define the order in which mesh should be constructed
        short[] indexes = {2, 0, 1, 1, 3, 2};

        // Setting buffers
        m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
        m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
        m.setBuffer(Type.Index, 1, BufferUtils.createShortBuffer(indexes));
        m.updateBound();

        // *************************************************************************
        // First mesh uses one solid color
        // *************************************************************************

        // Creating a geometry, and apply a single color material to it
        Geometry geom = new Geometry("OurMesh", m);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);

        // Attaching our geometry to the root node.
        rootNode.attachChild(geom);

        // *************************************************************************
        // Second mesh uses vertex colors to color each vertex
        // *************************************************************************
        Mesh cMesh = m.clone();
        Geometry coloredMesh = new Geometry ("ColoredMesh", cMesh);
        Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matVC.setBoolean("VertexColor", true);

        //We have 4 vertices and 4 color values for each of them.
        //If you have more vertices, you need 'new float[yourVertexCount * 4]' here!
        float[] colorArray = new float[4*4];
        int colorIndex = 0;

        //Set custom RGBA value for each Vertex. Values range from 0.0f to 1.0f
        for(int i = 0; i < 4; i++){
           // Red value (is increased by .2 on each next vertex here)
           colorArray[colorIndex++]= 0.1f+(.2f*i);
           // Green value (is reduced by .2 on each next vertex)
           colorArray[colorIndex++]= 0.9f-(0.2f*i);
           // Blue value (remains the same in our case)
           colorArray[colorIndex++]= 0.5f;
           // Alpha value (no transparency set here)
           colorArray[colorIndex++]= 1.0f;
        }
        // Set the color buffer
        cMesh.setBuffer(Type.Color, 4, colorArray);
        coloredMesh.setMaterial(matVC);
        // move mesh a bit so that it doesn't intersect with the first one
        coloredMesh.setLocalTranslation(4, 0, 0);
        rootNode.attachChild(coloredMesh);

//        /** Alternatively, you can show the mesh vertixes as points
//          * instead of coloring the faces. */
//        cMesh.setMode(Mesh.Mode.Points);
//        cMesh.setPointSize(10f);
//        cMesh.updateBound();
//        cMesh.setStatic();
//        Geometry points = new Geometry("Points", m);
//        points.setMaterial(mat);
//        rootNode.attachChild(points);

        // *************************************************************************
        // Third mesh will use a wireframe shader to show wireframe
        // *************************************************************************
        Mesh wfMesh = m.clone();
        Geometry wfGeom = new Geometry("wireframeGeometry", wfMesh);
        Material matWireframe = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matWireframe.setColor("Color", ColorRGBA.Green);
        matWireframe.getAdditionalRenderState().setWireframe(true);
        wfGeom.setMaterial(matWireframe);
        wfGeom.setLocalTranslation(4, 4, 0);
        rootNode.attachChild(wfGeom);
        
    }
 
Example 17
Source File: TestBitmapFontAlignment.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    int width = getCamera().getWidth();
    int height = getCamera().getHeight();

    // VAlign.Top
    BitmapText labelAlignTop = guiFont.createLabel("This text has VAlign.Top.");
    Rectangle textboxAlignTop = new Rectangle(width * 0.2f, height * 0.7f, 120, 120);
    labelAlignTop.setBox(textboxAlignTop);
    labelAlignTop.setVerticalAlignment(BitmapFont.VAlign.Top);
    getGuiNode().attachChild(labelAlignTop);

    Geometry backgroundBoxAlignTop = new Geometry("", new Quad(textboxAlignTop.width, -textboxAlignTop.height));
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor("Color", ColorRGBA.Blue);
    backgroundBoxAlignTop.setMaterial(material);
    backgroundBoxAlignTop.setLocalTranslation(textboxAlignTop.x, textboxAlignTop.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignTop);

    // VAlign.Center
    BitmapText labelAlignCenter = guiFont.createLabel("This text has VAlign.Center");
    Rectangle textboxAlignCenter = new Rectangle(width * 0.4f, height * 0.7f, 120, 120);
    labelAlignCenter.setBox(textboxAlignCenter);
    labelAlignCenter.setVerticalAlignment(BitmapFont.VAlign.Center);
    getGuiNode().attachChild(labelAlignCenter);

    Geometry backgroundBoxAlignCenter = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignCenter.setLocalTranslation(textboxAlignCenter.x, textboxAlignCenter.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignCenter);

    // VAlign.Bottom
    BitmapText labelAlignBottom = guiFont.createLabel("This text has VAlign.Bottom");
    Rectangle textboxAlignBottom = new Rectangle(width * 0.6f, height * 0.7f, 120, 120);
    labelAlignBottom.setBox(textboxAlignBottom);
    labelAlignBottom.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    getGuiNode().attachChild(labelAlignBottom);

    Geometry backgroundBoxAlignBottom = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignBottom.setLocalTranslation(textboxAlignBottom.x, textboxAlignBottom.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignBottom);

    // VAlign.Top + Align.Right
    BitmapText labelAlignTopRight = guiFont.createLabel("This text has VAlign.Top and Align.Right");
    Rectangle textboxAlignTopRight = new Rectangle(width * 0.2f, height * 0.3f, 120, 120);
    labelAlignTopRight.setBox(textboxAlignTopRight);
    labelAlignTopRight.setVerticalAlignment(BitmapFont.VAlign.Top);
    labelAlignTopRight.setAlignment(BitmapFont.Align.Right);
    getGuiNode().attachChild(labelAlignTopRight);

    Geometry backgroundBoxAlignTopRight = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignTopRight.setLocalTranslation(textboxAlignTopRight.x, textboxAlignTopRight.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignTopRight);

    // VAlign.Center + Align.Center
    BitmapText labelAlignCenterCenter = guiFont.createLabel("This text has VAlign.Center and Align.Center");
    Rectangle textboxAlignCenterCenter = new Rectangle(width * 0.4f, height * 0.3f, 120, 120);
    labelAlignCenterCenter.setBox(textboxAlignCenterCenter);
    labelAlignCenterCenter.setVerticalAlignment(BitmapFont.VAlign.Center);
    labelAlignCenterCenter.setAlignment(BitmapFont.Align.Center);
    getGuiNode().attachChild(labelAlignCenterCenter);

    Geometry backgroundBoxAlignCenterCenter = backgroundBoxAlignCenter.clone(false);
    backgroundBoxAlignCenterCenter.setLocalTranslation(textboxAlignCenterCenter.x, textboxAlignCenterCenter.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignCenterCenter);

    // VAlign.Bottom + Align.Left
    BitmapText labelAlignBottomLeft = guiFont.createLabel("This text has VAlign.Bottom and Align.Left");
    Rectangle textboxAlignBottomLeft = new Rectangle(width * 0.6f, height * 0.3f, 120, 120);
    labelAlignBottomLeft.setBox(textboxAlignBottomLeft);
    labelAlignBottomLeft.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    labelAlignBottomLeft.setAlignment(BitmapFont.Align.Left);
    getGuiNode().attachChild(labelAlignBottomLeft);

    Geometry backgroundBoxAlignBottomLeft = backgroundBoxAlignBottom.clone(false);
    backgroundBoxAlignBottomLeft.setLocalTranslation(textboxAlignBottomLeft.x, textboxAlignBottomLeft.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignBottomLeft);

    // Large quad with VAlign.Center and Align.Center
    BitmapText label = guiFont.createLabel("This text is centered, both horizontally and vertically.");
    Rectangle box = new Rectangle(width * 0.05f, height * 0.95f, width * 0.9f, height * 0.1f);
    label.setBox(box);
    label.setAlignment(BitmapFont.Align.Center);
    label.setVerticalAlignment(BitmapFont.VAlign.Center);
    getGuiNode().attachChild(label);

    Geometry background = new Geometry("background", new Quad(box.width, -box.height));
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Green);
    background.setMaterial(mat);
    background.setLocalTranslation(box.x, box.y, -1);
    getGuiNode().attachChild(background);
}
 
Example 18
Source File: TestBatchNodeCluster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        timer = new NanoTimer();

        batchNode = new SimpleBatchNode("BatchNode");


        xPosition.add(0);
        yPosition.add(0);
        zPosition.add(0);

        mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat1.setColor("Color", ColorRGBA.White);
        mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));

        mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setColor("Color", ColorRGBA.White);
        mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));

        mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat3.setColor("Color", ColorRGBA.White);
        mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));

        mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat4.setColor("Color", ColorRGBA.White);
        mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));

        randomGenerator();

        //rootNode.attachChild(SkyFactory.createSky(
        //  assetManager, "Textures/SKY02.zip", false));
        inputManager.addMapping("Start Game", new KeyTrigger(KeyInput.KEY_J));
        inputManager.addListener(al, new String[]{"Start Game"});


        cam.setLocation(new Vector3f(-34.403286f, 126.65158f, 434.791f));
        cam.setRotation(new Quaternion(0.022630932f, 0.9749435f, -0.18736298f, 0.11776358f));


        batchNode.batch();


        terrain = new Node("terrain");
        terrain.setLocalTranslation(50, 0, 50);
        terrain.attachChild(batchNode);

        flyCam.setMoveSpeed(100);
        rootNode.attachChild(terrain);
        Vector3f pos = new Vector3f(-40, 0, -40);
        batchNode.setLocalTranslation(pos);


        Arrow a = new Arrow(new Vector3f(0, 50, 0));
        Geometry g = new Geometry("a", a);
        g.setLocalTranslation(terrain.getLocalTranslation());
        Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        m.setColor("Color", ColorRGBA.Blue);
        g.setMaterial(m);



        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
//        SSAOFilter ssao = new SSAOFilter(8.630104f,22.970434f,2.9299977f,0.2999997f);    
//        fpp.addFilter(ssao);
        viewPort.addProcessor(fpp);
        //   viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    }
 
Example 19
Source File: EnvMapUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) {
    Node n = new Node("CubeMapDebug" + cubeMap.getName());
    int size = cubeMap.getImage().getWidth();
    int nbMips = cubeMap.getImage().getMipMapSizes().length;
    Picture[] pics = new Picture[6*nbMips];

    float ratio = 1f;// 128f / (float) size;

    int offset = 0;
    int guiOffset = 0;
    for (int mipLevel = 0; mipLevel < nbMips; mipLevel++) {
        size = Math.max(1, cubeMap.getImage().getWidth() >> mipLevel);
        int dataSize = cubeMap.getImage().getMipMapSizes()[mipLevel];
        byte[] dataArray = new byte[dataSize];
        for (int i = 0; i < 6; i++) {
            
            ByteBuffer bb = cubeMap.getImage().getData(i);
          
            bb.rewind();
            bb.position(offset);
            bb.get(dataArray, 0, dataSize);
            ByteBuffer data = BufferUtils.createByteBuffer(dataArray);

            pics[i] = new Picture("bla");
            Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, data, cubeMap.getImage().getColorSpace()));

            pics[i].setTexture(assetManager, tex, true);
            pics[i].setWidth(size);
            pics[i].setHeight(size);
            n.attachChild(pics[i]);
        }
        pics[0].setLocalTranslation(guiOffset + size, guiOffset + size * 2, 1);
        pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1);
        pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1);
        pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1);
        pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1);
        pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1);
        pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        
        guiOffset+=size *2+1;
        offset += dataSize;
        
    }

    Quad q = new Quad(cubeMap.getImage().getWidth() * 4 + nbMips, guiOffset + size);
    Geometry g = new Geometry("bg", q);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Black);
    g.setMaterial(mat);
    g.setLocalTranslation(0, 0, 0);

    n.attachChild(g);
    n.setLocalScale(ratio);
    return n;
}
 
Example 20
Source File: TestOgreComplexAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");

    skinningControl = model.getControl(SkinningControl.class);
    AnimComposer ac = model.getControl(AnimComposer.class);

    ArmatureMask feet = ArmatureMask.createMask(skinningControl.getArmature(), "hip.right", "hip.left");
    Action dodgeAction = ac.action("Dodge");
    dodgeAction.setMask(feet);
    dodgeAction.setSpeed(2f);
    Action walkAction = ac.action("Walk");
    walkAction.setMask(feet);
    walkAction.setSpeed(0.25f);

    ArmatureMask rightHand = ArmatureMask.createMask(skinningControl.getArmature(), "uparm.right");
    Action pullAction = ac.action("pull");
    pullAction.setMask(rightHand);
    pullAction.setSpeed(0.5f);
    Action standAction = ac.action("stand");
    standAction.setMask(rightHand);
    standAction.setSpeed(0.5f);

    ac.actionSequence("complexAction",
            ac.actionSequence("feetAction", dodgeAction, walkAction),
            ac.actionSequence("rightHandAction", pullAction, standAction));

    ac.setCurrentAction("complexAction");

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat.setFloat("PointSize", 7f); // Bug ? do not change size of debug points ?
    mat.getAdditionalRenderState().setDepthTest(false);

    ArmatureDebugger armatureDebug = new ArmatureDebugger("armature", skinningControl.getArmature(),
            skinningControl.getArmature().getJointList());
    armatureDebug.setMaterial(mat);
    model.attachChild(armatureDebug);

    rootNode.attachChild(model);
}