Search in sources :

Example 1 with EmitterShape

use of com.jme3.effect.shapes.EmitterShape in project jmonkeyengine by jMonkeyEngine.

the class ParticlesModifier method postMeshCreationApply.

@Override
public void postMeshCreationApply(Node node, BlenderContext blenderContext) {
    LOGGER.log(Level.FINE, "Applying particles modifier to: {0}", node);
    MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
    ParticleEmitter emitter = particleEmitter.clone();
    // veryfying the alpha function for particles' texture
    Integer alphaFunction = MaterialHelper.ALPHA_MASK_HYPERBOLE;
    char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1);
    if (nameSuffix == 'B' || nameSuffix == 'N') {
        alphaFunction = MaterialHelper.ALPHA_MASK_NONE;
    }
    // removing the type suffix from the name
    emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1));
    // applying emitter shape
    EmitterShape emitterShape = emitter.getShape();
    List<Mesh> meshes = new ArrayList<Mesh>();
    for (Spatial spatial : node.getChildren()) {
        if (spatial instanceof Geometry) {
            Mesh mesh = ((Geometry) spatial).getMesh();
            if (mesh != null) {
                meshes.add(mesh);
                Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext);
                // TODO: divide into several pieces
                emitter.setMaterial(material);
            }
        }
    }
    if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) {
        ((EmitterMeshVertexShape) emitterShape).setMeshes(meshes);
    }
    node.attachChild(emitter);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) EmitterShape(com.jme3.effect.shapes.EmitterShape) ArrayList(java.util.ArrayList) MaterialHelper(com.jme3.scene.plugins.blender.materials.MaterialHelper) TemporalMesh(com.jme3.scene.plugins.blender.meshes.TemporalMesh) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) EmitterMeshVertexShape(com.jme3.effect.shapes.EmitterMeshVertexShape)

Example 2 with EmitterShape

use of com.jme3.effect.shapes.EmitterShape 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 EmitterShape

use of com.jme3.effect.shapes.EmitterShape in project jmonkeyengine by jMonkeyEngine.

the class EmitterMeshVertexShape method deepClone.

@Override
public EmitterShape deepClone() {
    try {
        EmitterMeshVertexShape clone = (EmitterMeshVertexShape) super.clone();
        if (this.vertices != null) {
            clone.vertices = new ArrayList<List<Vector3f>>(vertices.size());
            for (List<Vector3f> list : vertices) {
                List<Vector3f> vectorList = new ArrayList<Vector3f>(list.size());
                for (Vector3f vector : list) {
                    vectorList.add(vector.clone());
                }
                clone.vertices.add(vectorList);
            }
        }
        if (this.normals != null) {
            clone.normals = new ArrayList<List<Vector3f>>(normals.size());
            for (List<Vector3f> list : normals) {
                List<Vector3f> vectorList = new ArrayList<Vector3f>(list.size());
                for (Vector3f vector : list) {
                    vectorList.add(vector.clone());
                }
                clone.normals.add(vectorList);
            }
        }
        return clone;
    } catch (CloneNotSupportedException e) {
        throw new AssertionError();
    }
}
Also used : Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with EmitterShape

use of com.jme3.effect.shapes.EmitterShape in project jmonkeyengine by jMonkeyEngine.

the class NewtonianParticleInfluencer method influenceParticle.

@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPointAndNormal(particle.position, particle.velocity);
    // influencing the particle's velocity
    if (surfaceTangentFactor == 0.0f) {
        particle.velocity.multLocal(normalVelocity);
    } else {
        // calculating surface tangent (velocity contains the 'normal' value)
        temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor);
        if (surfaceTangentRotation != 0.0f) {
            // rotating the tangent
            Matrix3f m = new Matrix3f();
            m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity);
            temp = m.multLocal(temp);
        }
        // applying normal factor (this must be done first)
        particle.velocity.multLocal(normalVelocity);
        // adding tangent vector
        particle.velocity.addLocal(temp);
    }
    if (velocityVariation != 0.0f) {
        this.applyVelocityVariation(particle);
    }
}
Also used : Matrix3f(com.jme3.math.Matrix3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)2 ArrayList (java.util.ArrayList)2 ParticleEmitter (com.jme3.effect.ParticleEmitter)1 Type (com.jme3.effect.ParticleMesh.Type)1 EmitterMeshVertexShape (com.jme3.effect.shapes.EmitterMeshVertexShape)1 EmitterShape (com.jme3.effect.shapes.EmitterShape)1 InputCapsule (com.jme3.export.InputCapsule)1 Material (com.jme3.material.Material)1 Matrix3f (com.jme3.math.Matrix3f)1 Geometry (com.jme3.scene.Geometry)1 Mesh (com.jme3.scene.Mesh)1 Spatial (com.jme3.scene.Spatial)1 MaterialHelper (com.jme3.scene.plugins.blender.materials.MaterialHelper)1 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)1 List (java.util.List)1