Search in sources :

Example 66 with ColorRGBA

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

the class MatParam method getValueAsString.

/**
     * Returns the material parameter value as it would appear in a J3M
     * file. E.g.<br/>
     * <code>
     * MaterialParameters {<br/>
     *     ABC : 1 2 3 4<br/>
     * }<br/>
     * </code>
     * Assuming "ABC" is a Vector4 parameter, then the value
     * "1 2 3 4" would be returned by this method.
     * <br/><br/>
     * @return material parameter value as it would appear in a J3M file.
     */
public String getValueAsString() {
    switch(type) {
        case Boolean:
        case Float:
        case Int:
            return value.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) value;
            return v2.getX() + " " + v2.getY();
        /* 
This may get used at a later point of time
When arrays can be inserted in J3M files

            case Vector2Array:
                Vector2f[] v2Arr = (Vector2f[]) value;
                String v2str = "";
                for (int i = 0; i < v2Arr.length ; i++) {
                    v2str += v2Arr[i].getX() + " " + v2Arr[i].getY() + "\n";
                }
                return v2str;
*/
        case Vector3:
            Vector3f v3 = (Vector3f) value;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        /*
            case Vector3Array:
                Vector3f[] v3Arr = (Vector3f[]) value;
                String v3str = "";
                for (int i = 0; i < v3Arr.length ; i++) {
                    v3str += v3Arr[i].getX() + " "
                            + v3Arr[i].getY() + " "
                            + v3Arr[i].getZ() + "\n";
                }
                return v3str;
            case Vector4Array:
                // can be either ColorRGBA, Vector4f or Quaternion
                if (value instanceof Vector4f) {
                    Vector4f[] v4arr = (Vector4f[]) value;
                    String v4str = "";
                    for (int i = 0; i < v4arr.length ; i++) {
                        v4str += v4arr[i].getX() + " "
                                + v4arr[i].getY() + " "
                                + v4arr[i].getZ() + " "
                                + v4arr[i].getW() + "\n";
                    }
                    return v4str;
                } else if (value instanceof ColorRGBA) {
                    ColorRGBA[] colorArr = (ColorRGBA[]) value;
                    String colStr = "";
                    for (int i = 0; i < colorArr.length ; i++) {
                        colStr += colorArr[i].getRed() + " "
                                + colorArr[i].getGreen() + " "
                                + colorArr[i].getBlue() + " "
                                + colorArr[i].getAlpha() + "\n";
                    }
                    return colStr;
                } else if (value instanceof Quaternion) {
                    Quaternion[] quatArr = (Quaternion[]) value;
                    String quatStr = "";
                    for (int i = 0; i < quatArr.length ; i++) {
                        quatStr += quatArr[i].getX() + " "
                                + quatArr[i].getY() + " "
                                + quatArr[i].getZ() + " "
                                + quatArr[i].getW() + "\n";
                    }
                    return quatStr;
                } else {
                    throw new UnsupportedOperationException("Unexpected Vector4Array type: " + value);
                }
*/
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (value instanceof Vector4f) {
                Vector4f v4 = (Vector4f) value;
                return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
            } else if (value instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) value;
                return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
            } else if (value instanceof Quaternion) {
                Quaternion quat = (Quaternion) value;
                return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + value);
            }
        case Texture2D:
        case Texture3D:
        case TextureArray:
        case TextureBuffer:
        case TextureCubeMap:
            Texture texVal = (Texture) value;
            TextureKey texKey = (TextureKey) texVal.getKey();
            if (texKey == null) {
                // often does as well, even implicitly. 
                return texVal + ":returned null key";
            }
            String ret = "";
            if (texKey.isFlipY()) {
                ret += "Flip ";
            }
            //Wrap mode
            ret += getWrapMode(texVal, Texture.WrapAxis.S);
            ret += getWrapMode(texVal, Texture.WrapAxis.T);
            ret += getWrapMode(texVal, Texture.WrapAxis.R);
            //Min and Mag filter
            Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
            if (texVal.getImage().hasMipmaps() || texKey.isGenerateMips()) {
                def = Texture.MinFilter.Trilinear;
            }
            if (texVal.getMinFilter() != def) {
                ret += "Min" + texVal.getMinFilter().name() + " ";
            }
            if (texVal.getMagFilter() != Texture.MagFilter.Bilinear) {
                ret += "Mag" + texVal.getMagFilter().name() + " ";
            }
            return ret + "\"" + texKey.getName() + "\"";
        default:
            // parameter type not supported in J3M
            return null;
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture(com.jme3.texture.Texture)

Example 67 with ColorRGBA

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

the class ParticleEmitter method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    shape = (EmitterShape) ic.readSavable("shape", DEFAULT_SHAPE);
    if (shape == DEFAULT_SHAPE) {
        // Prevent reference to static
        shape = shape.deepClone();
    }
    meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle);
    int numParticles = ic.readInt("numParticles", 0);
    enabled = ic.readBoolean("enabled", true);
    particlesPerSec = ic.readFloat("particlesPerSec", 0);
    lowLife = ic.readFloat("lowLife", 0);
    highLife = ic.readFloat("highLife", 0);
    gravity = (Vector3f) ic.readSavable("gravity", null);
    imagesX = ic.readInt("imagesX", 1);
    imagesY = ic.readInt("imagesY", 1);
    startColor = (ColorRGBA) ic.readSavable("startColor", null);
    endColor = (ColorRGBA) ic.readSavable("endColor", null);
    startSize = ic.readFloat("startSize", 0);
    endSize = ic.readFloat("endSize", 0);
    worldSpace = ic.readBoolean("worldSpace", false);
    this.setIgnoreTransform(worldSpace);
    facingVelocity = ic.readBoolean("facingVelocity", false);
    faceNormal = (Vector3f) ic.readSavable("faceNormal", new Vector3f(Vector3f.NAN));
    selectRandomImage = ic.readBoolean("selectRandomImage", false);
    randomAngle = ic.readBoolean("randomAngle", false);
    rotateSpeed = ic.readFloat("rotateSpeed", 0);
    switch(meshType) {
        case Point:
            particleMesh = new ParticlePointMesh();
            this.setMesh(particleMesh);
            break;
        case Triangle:
            particleMesh = new ParticleTriMesh();
            this.setMesh(particleMesh);
            break;
        default:
            throw new IllegalStateException("Unrecognized particle type: " + meshType);
    }
    this.setNumParticles(numParticles);
    //        particleMesh.initParticleData(this, particles.length);
    //        particleMesh.setImagesXY(imagesX, imagesY);
    particleInfluencer = (ParticleInfluencer) ic.readSavable("influencer", DEFAULT_INFLUENCER);
    if (particleInfluencer == DEFAULT_INFLUENCER) {
        particleInfluencer = particleInfluencer.clone();
    }
    if (im.getFormatVersion() == 0) {
        // find it in the controls and take it out, then add the proper one in
        for (int i = 0; i < controls.size(); i++) {
            Object obj = controls.get(i);
            if (obj instanceof ParticleEmitter) {
                controls.remove(i);
                // now add the proper one in
                controls.add(new ParticleEmitterControl(this));
                break;
            }
        }
        // compatability before gravity was not a vector but a float
        if (gravity == null) {
            gravity = new Vector3f();
            gravity.y = ic.readFloat("gravity", 0);
        }
    } else {
        // since the parentEmitter is not loaded, it must be
        // loaded separately
        control = getControl(ParticleEmitterControl.class);
        control.parentEmitter = this;
    }
}
Also used : Type(com.jme3.effect.ParticleMesh.Type) InputCapsule(com.jme3.export.InputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 68 with ColorRGBA

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

the class CubeMapWrapper method getPixel.

/**
     * 
     * Reads a pixel from the cube map given the coordinate vector
     * @param vector the direction vector to fetch the texel
     * @param mipLevel the mip level to read from
     * @param store the color in which to store the pixel color read.
     * @return the color of the pixel read.
     */
public ColorRGBA getPixel(Vector3f vector, int mipLevel, ColorRGBA store) {
    if (mipMapRaster == null) {
        throw new IllegalArgumentException("This cube map has no mip maps");
    }
    if (store == null) {
        store = new ColorRGBA();
    }
    int face = EnvMapUtils.getCubemapFaceTexCoordFromVector(vector, sizes[mipLevel], uvs, EnvMapUtils.FixSeamsMethod.Stretch);
    mipMapRaster.setSlice(face);
    mipMapRaster.setMipLevel(mipLevel);
    return mipMapRaster.getPixel((int) uvs.x, (int) uvs.y, store);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA)

Example 69 with ColorRGBA

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

the class CubeMapWrapper method getPixel.

/**
     * Reads a pixel from the cube map given the 2D coordinates and the face and 
     * the mip level to read from
     * @param x the x tex coordinate (from 0 to width)
     * @param y the y tex coordinate (from 0 to height)
     * @param face the face to read from
     * @param mipLevel the miplevel to read from
     * @param store the color where the result is stored.
     * @return the color read.
     */
public ColorRGBA getPixel(int x, int y, int face, int mipLevel, ColorRGBA store) {
    if (mipMapRaster == null) {
        throw new IllegalArgumentException("This cube map has no mip maps");
    }
    if (store == null) {
        store = new ColorRGBA();
    }
    mipMapRaster.setSlice(face);
    mipMapRaster.setMipLevel(mipLevel);
    return mipMapRaster.getPixel((int) x, (int) y, store);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA)

Example 70 with ColorRGBA

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

the class TestJaime method setupLights.

public void setupLights() {
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1));
    rootNode.addLight(al);
    SpotLight sl = new SpotLight();
    sl.setColor(ColorRGBA.White.mult(1.0f));
    sl.setPosition(new Vector3f(1.2074411f, 10.6868908f, 4.1489987f));
    sl.setDirection(sl.getPosition().mult(-1));
    sl.setSpotOuterAngle(0.1f);
    sl.setSpotInnerAngle(0.004f);
    rootNode.addLight(sl);
    //pointlight to fake indirect light coming from the ground
    PointLight pl = new PointLight();
    pl.setColor(ColorRGBA.White.mult(1.5f));
    pl.setPosition(new Vector3f(0, 0, 1));
    pl.setRadius(2);
    rootNode.addLight(pl);
    SpotLightShadowRenderer shadows = new SpotLightShadowRenderer(assetManager, 1024);
    shadows.setLight(sl);
    shadows.setShadowIntensity(0.3f);
    shadows.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
    viewPort.addProcessor(shadows);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter filter = new SSAOFilter(0.10997847f, 0.440001f, 0.39999998f, -0.008000026f);
    ;
    fpp.addFilter(filter);
    fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new FXAAFilter());
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) FXAAFilter(com.jme3.post.filters.FXAAFilter) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) FilterPostProcessor(com.jme3.post.FilterPostProcessor) PointLight(com.jme3.light.PointLight) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight)

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