Search in sources :

Example 56 with ColorRGBA

use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.

the class MipMapImageRaster method getPixel.

@Override
public ColorRGBA getPixel(int x, int y, ColorRGBA store) {
    rangeCheck(x, y);
    codec.readComponents(getBuffer(), x, y, width[mipLevel], offsets[mipLevel], components, temp);
    if (store == null) {
        store = new ColorRGBA();
    }
    switch(codec.type) {
        case ImageCodec.FLAG_F16:
            store.set(FastMath.convertHalfToFloat((short) components[1]), FastMath.convertHalfToFloat((short) components[2]), FastMath.convertHalfToFloat((short) components[3]), FastMath.convertHalfToFloat((short) components[0]));
            break;
        case ImageCodec.FLAG_F32:
            store.set(Float.intBitsToFloat((int) components[1]), Float.intBitsToFloat((int) components[2]), Float.intBitsToFloat((int) components[3]), Float.intBitsToFloat((int) components[0]));
            break;
        case 0:
            // Convert to float and divide by bitsize to get into range 0.0 - 1.0.
            store.set((float) components[1] / codec.maxRed, (float) components[2] / codec.maxGreen, (float) components[3] / codec.maxBlue, (float) components[0] / codec.maxAlpha);
            break;
    }
    if (codec.isGray) {
        store.g = store.b = store.r;
    } else {
        if (codec.maxRed == 0) {
            store.r = 1;
        }
        if (codec.maxGreen == 0) {
            store.g = 1;
        }
        if (codec.maxBlue == 0) {
            store.b = 1;
        }
        if (codec.maxAlpha == 0) {
            store.a = 1;
        }
    }
    return store;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA)

Example 57 with ColorRGBA

use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.

the class TerrainGridTileLoaderTest method simpleInitApp.

@Override
public void simpleInitApp() {
    File file = new File("TerrainGridTestData.zip");
    if (!file.exists()) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/TerrainGridTestData.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("TerrainGridTestData.zip", ZipLocator.class);
    }
    this.flyCam.setMoveSpeed(100f);
    ScreenshotAppState state = new ScreenshotAppState();
    this.stateManager.attach(state);
    // TERRAIN TEXTURE material
    this.mat_terrain = new Material(this.assetManager, "Common/MatDefs/Terrain/HeightBasedTerrain.j3md");
    // Parameters to material:
    // regionXColorMap: X = 1..4 the texture that should be appliad to state X
    // regionX: a Vector3f containing the following information:
    //      regionX.x: the start height of the region
    //      regionX.y: the end height of the region
    //      regionX.z: the texture scale for the region
    //  it might not be the most elegant way for storing these 3 values, but it packs the data nicely :)
    // slopeColorMap: the texture to be used for cliffs, and steep mountain sites
    // slopeTileFactor: the texture scale for slopes
    // terrainSize: the total size of the terrain (used for scaling the texture)
    // GRASS texture
    Texture grass = this.assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    this.mat_terrain.setTexture("region1ColorMap", grass);
    this.mat_terrain.setVector3("region1", new Vector3f(88, 200, this.grassScale));
    // DIRT texture
    Texture dirt = this.assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    this.mat_terrain.setTexture("region2ColorMap", dirt);
    this.mat_terrain.setVector3("region2", new Vector3f(0, 90, this.dirtScale));
    // ROCK texture
    Texture rock = this.assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
    rock.setWrap(WrapMode.Repeat);
    this.mat_terrain.setTexture("region3ColorMap", rock);
    this.mat_terrain.setVector3("region3", new Vector3f(198, 260, this.rockScale));
    this.mat_terrain.setTexture("region4ColorMap", rock);
    this.mat_terrain.setVector3("region4", new Vector3f(198, 260, this.rockScale));
    this.mat_terrain.setTexture("slopeColorMap", rock);
    this.mat_terrain.setFloat("slopeTileFactor", 32);
    this.mat_terrain.setFloat("terrainSize", 129);
    //quad.getHeightMap(), terrain.getLocalScale()), 0
    AssetTileLoader grid = new AssetTileLoader(assetManager, "testgrid", "TerrainGrid");
    this.terrain = new TerrainGrid("terrain", 65, 257, grid);
    this.terrain.setMaterial(this.mat_terrain);
    this.terrain.setLocalTranslation(0, 0, 0);
    this.terrain.setLocalScale(2f, 1f, 2f);
    //        try {
    //            BinaryExporter.getInstance().save(terrain, new File("/Users/normenhansen/Documents/Code/jme3/engine/src/test-data/TerrainGrid/"
    //                    + "TerrainGrid.j3o"));
    //        } catch (IOException ex) {
    //            Logger.getLogger(TerrainFractalGridTest.class.getName()).log(Level.SEVERE, null, ex);
    //        }
    this.rootNode.attachChild(this.terrain);
    TerrainLodControl control = new TerrainGridLodControl(this.terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
    this.terrain.addControl(control);
    final BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    this.getCamera().setLocation(new Vector3f(0, 256, 0));
    this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
    if (usePhysics) {
        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
        player3 = new CharacterControl(capsuleShape, 0.5f);
        player3.setJumpSpeed(20);
        player3.setFallSpeed(10);
        player3.setGravity(10);
        player3.setPhysicsLocation(new Vector3f(cam.getLocation().x, 256, cam.getLocation().z));
        bulletAppState.getPhysicsSpace().add(player3);
        terrain.addListener(new TerrainGridListener() {

            public void gridMoved(Vector3f newCenter) {
            }

            public void tileAttached(Vector3f cell, TerrainQuad quad) {
                while (quad.getControl(RigidBodyControl.class) != null) {
                    quad.removeControl(RigidBodyControl.class);
                }
                quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
                bulletAppState.getPhysicsSpace().add(quad);
            }

            public void tileDetached(Vector3f cell, TerrainQuad quad) {
                if (quad.getControl(RigidBodyControl.class) != null) {
                    bulletAppState.getPhysicsSpace().remove(quad);
                    quad.removeControl(RigidBodyControl.class);
                }
            }
        });
    }
    this.initKeys();
}
Also used : CharacterControl(com.jme3.bullet.control.CharacterControl) TerrainGrid(com.jme3.terrain.geomipmap.TerrainGrid) TerrainGridListener(com.jme3.terrain.geomipmap.TerrainGridListener) Material(com.jme3.material.Material) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) Texture(com.jme3.texture.Texture) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) TerrainGridLodControl(com.jme3.terrain.geomipmap.TerrainGridLodControl) AssetTileLoader(com.jme3.terrain.geomipmap.grid.AssetTileLoader) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) BulletAppState(com.jme3.bullet.BulletAppState) HeightfieldCollisionShape(com.jme3.bullet.collision.shapes.HeightfieldCollisionShape) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) ScreenshotAppState(com.jme3.app.state.ScreenshotAppState) File(java.io.File) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad)

Example 58 with ColorRGBA

use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestTile method simpleInitApp.

@Override
public void simpleInitApp() {
    loadHintText();
    setupKeys();
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    terrain = new TiledTerrain();
    rootNode.attachChild(terrain);
    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, -1, -1).normalizeLocal(), Vector3f.UNIT_Y);
    Sphere s = new Sphere(12, 12, 3);
    Geometry g = new Geometry("marker");
    g.setMesh(s);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Red);
    g.setMaterial(mat);
    g.setLocalTranslation(0, -100, 0);
    rootNode.attachChild(g);
    Geometry g2 = new Geometry("marker");
    g2.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g2.setMaterial(mat);
    g2.setLocalTranslation(10, -100, 0);
    rootNode.attachChild(g2);
    Geometry g3 = new Geometry("marker");
    g3.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g3.setMaterial(mat);
    g3.setLocalTranslation(0, -100, 10);
    rootNode.attachChild(g3);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) AmbientLight(com.jme3.light.AmbientLight)

Example 59 with ColorRGBA

use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.

the class TestImageRaster method createTestImage.

private Image createTestImage() {
    Image testImage = new Image(Format.BGR8, 4, 3, BufferUtils.createByteBuffer(4 * 4 * 3), null, ColorSpace.Linear);
    ImageRaster io = ImageRaster.create(testImage);
    io.setPixel(0, 0, ColorRGBA.Black);
    io.setPixel(1, 0, ColorRGBA.Gray);
    io.setPixel(2, 0, ColorRGBA.White);
    // HDR color
    io.setPixel(3, 0, ColorRGBA.White.mult(4));
    io.setPixel(0, 1, ColorRGBA.Red);
    io.setPixel(1, 1, ColorRGBA.Green);
    io.setPixel(2, 1, ColorRGBA.Blue);
    io.setPixel(3, 1, new ColorRGBA(0, 0, 0, 0));
    io.setPixel(0, 2, ColorRGBA.Yellow);
    io.setPixel(1, 2, ColorRGBA.Magenta);
    io.setPixel(2, 2, ColorRGBA.Cyan);
    io.setPixel(3, 2, new ColorRGBA(1, 1, 1, 0));
    return testImage;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) ImageRaster(com.jme3.texture.image.ImageRaster) Image(com.jme3.texture.Image)

Example 60 with ColorRGBA

use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.

the class TestBlendEquations method simpleInitApp.

public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(6);
    teaGeom.getMaterial().getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Add);
    teaGeom.move(0, -2f, 0);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.Red);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0.5f, 0f, 1f, 0.3f));
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Color);
    mat.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Subtract);
    Geometry geo = new Geometry("BottomLeft", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(mat);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(0, 0, 1);
    guiNode.attachChild(geo);
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.ReverseSubtract);
    m.setColor("Color", new ColorRGBA(0.0f, 1f, 1.f, 1f));
    m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.AlphaAdditive);
    geo = new Geometry("BottomRight", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(m);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(guiViewPort.getCamera().getWidth() / 2, 0, 1);
    guiNode.attachChild(geo);
    m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Min);
    m.setColor("Color", new ColorRGBA(0.3f, 0f, 0.1f, 0.3f));
    m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive);
    geo = new Geometry("TopRight", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(m);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2, 1);
    guiNode.attachChild(geo);
    geo = new Geometry("OverTeaPot", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(mat);
    geo.setQueueBucket(RenderQueue.Bucket.Transparent);
    geo.setLocalTranslation(0, -100, 5);
    rootNode.attachChild(geo);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material)

Aggregations

ColorRGBA (com.jme3.math.ColorRGBA)98 Vector3f (com.jme3.math.Vector3f)65 Material (com.jme3.material.Material)44 DirectionalLight (com.jme3.light.DirectionalLight)42 Geometry (com.jme3.scene.Geometry)23 ParticleEmitter (com.jme3.effect.ParticleEmitter)14 PointLight (com.jme3.light.PointLight)14 Quaternion (com.jme3.math.Quaternion)14 Spatial (com.jme3.scene.Spatial)14 AmbientLight (com.jme3.light.AmbientLight)13 Sphere (com.jme3.scene.shape.Sphere)12 Node (com.jme3.scene.Node)11 KeyTrigger (com.jme3.input.controls.KeyTrigger)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)10 Texture (com.jme3.texture.Texture)9 BulletAppState (com.jme3.bullet.BulletAppState)8 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)7 Quad (com.jme3.scene.shape.Quad)7 TextureCubeMap (com.jme3.texture.TextureCubeMap)7 EmitterSphereShape (com.jme3.effect.shapes.EmitterSphereShape)6