Search in sources :

Example 1 with ParticleInfluencer

use of com.jme3.effect.influencers.ParticleInfluencer in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(shape, "shape", DEFAULT_SHAPE);
    oc.write(meshType, "meshType", ParticleMesh.Type.Triangle);
    oc.write(enabled, "enabled", true);
    oc.write(particles.length, "numParticles", 0);
    oc.write(particlesPerSec, "particlesPerSec", 0);
    oc.write(lowLife, "lowLife", 0);
    oc.write(highLife, "highLife", 0);
    oc.write(gravity, "gravity", null);
    oc.write(imagesX, "imagesX", 1);
    oc.write(imagesY, "imagesY", 1);
    oc.write(startColor, "startColor", null);
    oc.write(endColor, "endColor", null);
    oc.write(startSize, "startSize", 0);
    oc.write(endSize, "endSize", 0);
    oc.write(worldSpace, "worldSpace", false);
    oc.write(facingVelocity, "facingVelocity", false);
    oc.write(faceNormal, "faceNormal", new Vector3f(Vector3f.NAN));
    oc.write(selectRandomImage, "selectRandomImage", false);
    oc.write(randomAngle, "randomAngle", false);
    oc.write(rotateSpeed, "rotateSpeed", 0);
    oc.write(particleInfluencer, "influencer", DEFAULT_INFLUENCER);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 2 with ParticleInfluencer

use of com.jme3.effect.influencers.ParticleInfluencer 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 3 with ParticleInfluencer

use of com.jme3.effect.influencers.ParticleInfluencer in project jmonkeyengine by jMonkeyEngine.

the class ParticlesHelper method toParticleEmitter.

@SuppressWarnings("unchecked")
public ParticleEmitter toParticleEmitter(Structure particleSystem) throws BlenderFileException {
    ParticleEmitter result = null;
    Pointer pParticleSettings = (Pointer) particleSystem.getFieldValue("part");
    if (pParticleSettings.isNotNull()) {
        Structure particleSettings = pParticleSettings.fetchData().get(0);
        int totPart = ((Number) particleSettings.getFieldValue("totpart")).intValue();
        // draw type will be stored temporarily in the name (it is used during modifier applying operation)
        int drawAs = ((Number) particleSettings.getFieldValue("draw_as")).intValue();
        // P - point, L - line, N - None, B - Bilboard
        char nameSuffix;
        switch(drawAs) {
            case PART_DRAW_NOT:
                nameSuffix = 'N';
                // no need to generate particles in this case
                totPart = 0;
                break;
            case PART_DRAW_BB:
                nameSuffix = 'B';
                break;
            case PART_DRAW_OB:
            case PART_DRAW_GR:
                nameSuffix = 'P';
                // TODO: support groups and aobjects
                LOGGER.warning("Neither object nor group particles supported yet! Using point representation instead!");
                break;
            case PART_DRAW_LINE:
                nameSuffix = 'L';
                // TODO: support lines
                LOGGER.warning("Lines not yet supported! Using point representation instead!");
            default:
                // all others are rendered as points in blender
                nameSuffix = 'P';
        }
        result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart);
        if (nameSuffix == 'N') {
            // no need to set anything else
            return result;
        }
        // setting the emitters shape (the shapes meshes will be set later during modifier applying operation)
        int from = ((Number) particleSettings.getFieldValue("from")).intValue();
        switch(from) {
            case PART_FROM_VERT:
                result.setShape(new EmitterMeshVertexShape());
                break;
            case PART_FROM_FACE:
                result.setShape(new EmitterMeshFaceShape());
                break;
            case PART_FROM_VOLUME:
                result.setShape(new EmitterMeshConvexHullShape());
                break;
            default:
                LOGGER.warning("Default shape used! Unknown emitter shape value ('from' parameter: " + from + ')');
        }
        // reading acceleration
        DynamicArray<Number> acc = (DynamicArray<Number>) particleSettings.getFieldValue("acc");
        result.setGravity(-acc.get(0).floatValue(), -acc.get(1).floatValue(), -acc.get(2).floatValue());
        // setting the colors
        result.setEndColor(new ColorRGBA(1f, 1f, 1f, 1f));
        result.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f));
        // reading size
        float sizeFactor = nameSuffix == 'B' ? 1.0f : 0.3f;
        float size = ((Number) particleSettings.getFieldValue("size")).floatValue() * sizeFactor;
        result.setStartSize(size);
        result.setEndSize(size);
        // reading lifetime
        int fps = blenderContext.getBlenderKey().getFps();
        float lifetime = ((Number) particleSettings.getFieldValue("lifetime")).floatValue() / fps;
        float randlife = ((Number) particleSettings.getFieldValue("randlife")).floatValue() / fps;
        result.setLowLife(lifetime * (1.0f - randlife));
        result.setHighLife(lifetime);
        // preparing influencer
        ParticleInfluencer influencer;
        int phystype = ((Number) particleSettings.getFieldValue("phystype")).intValue();
        switch(phystype) {
            case PART_PHYS_NEWTON:
                influencer = new NewtonianParticleInfluencer();
                ((NewtonianParticleInfluencer) influencer).setNormalVelocity(((Number) particleSettings.getFieldValue("normfac")).floatValue());
                ((NewtonianParticleInfluencer) influencer).setVelocityVariation(((Number) particleSettings.getFieldValue("randfac")).floatValue());
                ((NewtonianParticleInfluencer) influencer).setSurfaceTangentFactor(((Number) particleSettings.getFieldValue("tanfac")).floatValue());
                ((NewtonianParticleInfluencer) influencer).setSurfaceTangentRotation(((Number) particleSettings.getFieldValue("tanphase")).floatValue());
                break;
            case PART_PHYS_BOIDS:
            case // TODO: support other influencers
            PART_PHYS_KEYED:
                LOGGER.warning("Boids and Keyed particles physic not yet supported! Empty influencer used!");
            case PART_PHYS_NO:
            default:
                influencer = new EmptyParticleInfluencer();
        }
        result.setParticleInfluencer(influencer);
    }
    return result;
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) EmptyParticleInfluencer(com.jme3.effect.influencers.EmptyParticleInfluencer) Pointer(com.jme3.scene.plugins.blender.file.Pointer) EmitterMeshVertexShape(com.jme3.effect.shapes.EmitterMeshVertexShape) EmitterMeshFaceShape(com.jme3.effect.shapes.EmitterMeshFaceShape) NewtonianParticleInfluencer(com.jme3.effect.influencers.NewtonianParticleInfluencer) ColorRGBA(com.jme3.math.ColorRGBA) EmitterMeshConvexHullShape(com.jme3.effect.shapes.EmitterMeshConvexHullShape) DynamicArray(com.jme3.scene.plugins.blender.file.DynamicArray) Structure(com.jme3.scene.plugins.blender.file.Structure) EmptyParticleInfluencer(com.jme3.effect.influencers.EmptyParticleInfluencer) ParticleInfluencer(com.jme3.effect.influencers.ParticleInfluencer) NewtonianParticleInfluencer(com.jme3.effect.influencers.NewtonianParticleInfluencer)

Aggregations

Vector3f (com.jme3.math.Vector3f)2 ParticleEmitter (com.jme3.effect.ParticleEmitter)1 Type (com.jme3.effect.ParticleMesh.Type)1 EmptyParticleInfluencer (com.jme3.effect.influencers.EmptyParticleInfluencer)1 NewtonianParticleInfluencer (com.jme3.effect.influencers.NewtonianParticleInfluencer)1 ParticleInfluencer (com.jme3.effect.influencers.ParticleInfluencer)1 EmitterMeshConvexHullShape (com.jme3.effect.shapes.EmitterMeshConvexHullShape)1 EmitterMeshFaceShape (com.jme3.effect.shapes.EmitterMeshFaceShape)1 EmitterMeshVertexShape (com.jme3.effect.shapes.EmitterMeshVertexShape)1 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 ColorRGBA (com.jme3.math.ColorRGBA)1 DynamicArray (com.jme3.scene.plugins.blender.file.DynamicArray)1 Pointer (com.jme3.scene.plugins.blender.file.Pointer)1 Structure (com.jme3.scene.plugins.blender.file.Structure)1