Package com.jme3.effect

Examples of com.jme3.effect.ParticleEmitter


      sun.setShadowMode(ShadowMode.Off);
     
  }
 
  private ParticleEmitter getEmitter(String name) {
    ParticleEmitter flame = new ParticleEmitter(name, Type.Triangle, 32);
        flame.setSelectRandomImage(false);
        flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, 1f));
        flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
        flame.setStartSize(size);
        flame.setEndSize(size);
        //flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        flame.setShape(new EmitterPointShape(Vector3f.ZERO));
        flame.setParticlesPerSec(20);
        flame.setGravity(-5f);
        flame.setLowLife(1f);
        flame.setHighLife(1.5f);
        //flame.setInitialVelocity(new Vector3f(0, 7, 0));
        flame.setRandomAngle(true);
        flame.setInitialVelocity(new Vector3f(0, 3, 0));
        //flame.setVelocityVariation(1f);
        flame.setVelocityVariation(1.5f);
        flame.setImagesX(8);
        flame.setImagesY(1);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        //mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
        mat.setTexture("Texture", assetManager.loadTexture("Textures/d3.png"));
        mat.setBoolean("PointSprite", true);
        flame.setMaterial(mat);
        //flame.setLocalTranslation(100, 0, 0);
        return flame;
  }
View Full Code Here


     * @return
     */
    private ParticleEmitter findEmitter(Spatial spat) {
        if (spat instanceof ParticleEmitter) {
            //spat is a PArticleEmitter
            ParticleEmitter em = (ParticleEmitter) spat;
            //getting the UserData TrackInfo so check if it should be attached to this Track
            TrackInfo t = (TrackInfo) em.getUserData("TrackInfo");
            if (t != null && t.getTracks().contains(this)) {
                return em;
            }
            return null;

        } else if (spat instanceof Node) {
            for (Spatial child : ((Node) spat).getChildren()) {
                ParticleEmitter em = findEmitter(child);
                if (em != null) {
                    return em;
                }
            }
        }
View Full Code Here

            for (Spatial child : n.getChildren()) {
                makeSoftParticleEmitter(child, enabled);
            }
        }
        if (scene instanceof ParticleEmitter) {
            ParticleEmitter emitter = (ParticleEmitter) scene;
            if (enabled) {
                enabledSoftParticles = enabled;

                if( processor.getNumSamples()>1){
                    emitter.getMaterial().selectTechnique("SoftParticles15", renderManager);
                    emitter.getMaterial().setInt("NumSamplesDepth", processor.getNumSamples());
                }else{
                    emitter.getMaterial().selectTechnique("SoftParticles", renderManager);
                }
                emitter.getMaterial().setTexture("DepthTexture", processor.getDepthTexture());              
                emitter.setQueueBucket(RenderQueue.Bucket.Translucent);

                logger.log(Level.FINE, "Made particle Emitter {0} soft.", emitter.getName());
            } else {
                emitter.getMaterial().clearParam("DepthTexture");
                emitter.getMaterial().selectTechnique("Default", renderManager);
               // emitter.setQueueBucket(RenderQueue.Bucket.Transparent);
                logger.log(Level.FINE, "Particle Emitter {0} is not soft anymore.", emitter.getName());
            }
        }
    }
View Full Code Here

    public void apply(Node node, BlenderContext blenderContext) {
        if (invalid) {
            LOGGER.log(Level.WARNING, "Particles modifier is invalid! Cannot be applied to: {0}", node.getName());
        } else {
            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);
                        emitter.setMaterial(material);// TODO: divide into several pieces
                    }
                }
            }
            if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) {
                ((EmitterMeshVertexShape) emitterShape).setMeshes(meshes);
View Full Code Here

        super(blenderVersion, blenderContext);
    }

    @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();
            char nameSuffix;// P - point, L - line, N - None, B - Bilboard
            switch (drawAs) {
                case PART_DRAW_NOT:
                    nameSuffix = 'N';
                    totPart = 0;// no need to generate particles in this case
                    break;
                case PART_DRAW_BB:
                    nameSuffix = 'B';
                    break;
                case PART_DRAW_OB:
                case PART_DRAW_GR:
                    nameSuffix = 'P';
                    LOGGER.warning("Neither object nor group particles supported yet! Using point representation instead!");// TODO: support groups and aobjects
                    break;
                case PART_DRAW_LINE:
                    nameSuffix = 'L';
                    LOGGER.warning("Lines not yet supported! Using point representation instead!");// TODO: support lines
                default:// all others are rendered as points in blender
                    nameSuffix = 'P';
            }
            result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart);
            if (nameSuffix == 'N') {
                return result;// no need to set anything else
            }

            // 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 PART_PHYS_KEYED:// TODO: support other influencers
                    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;
    }
View Full Code Here

    inputManager.addListener(this, "Shoot");

  }

  protected Geometry makeSphere(String name, float radius) {
    ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 50);
    Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    fire.setMaterial(mat_red);
    fire.setImagesX(15);
    fire.setEndColor(new ColorRGBA(0f, 0f, 1f, 1f));
    fire.setStartColor(new ColorRGBA(0f, 1f, 1f, 0.5f));
    fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, .5f, 0));
    fire.setGravity(0, 0, 0);
    fire.setLowLife(1f);
    fire.setHighLife(1.1f);
    fire.getParticleInfluencer().setVelocityVariation(1f);
    // Cylinder quad = new Cylinder(10, 10, 1f,3f);
    // Geometry sphereG = new Geometry(name, quad);
    // Material material = new Material(assetManager,
    // "Common/MatDefs/Misc/Unshaded.j3md");
    // Texture texture = assetManager
View Full Code Here

   
  }
 
  @Override
  public void simpleInitApp() {
    ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 1);
      Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
      mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/shockwave.png"));
      fire.setMaterial(mat_red);
      fire.setImagesX(1); fire.setImagesY(1); // 2x2 texture animation
      fire.setEndColornew ColorRGBA(0f, 0f, 0.1f, 1f));  
      fire.setStartColor(new ColorRGBA(0f, 0f, 0.6f, 1f));
      fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0,0,-25f));
      fire.setStartSize(1.5f);
      fire.setEndSize(0.05f);
      fire.setGravity(0,0,0);
//      fire.setLowLife(6f);
//      fire.setHighLife(6f);
//      fire.getParticleInfluencer().setVelocityVariation(0.3f);
      rootNode.attachChild(fire);
  }
View Full Code Here

*
*/
public class JetNozzleParticle extends AbstractParticle {

  public JetNozzleParticle(String name, AssetManager assetManager){
    emitter = new ParticleEmitter(name, ParticleMesh.Type.Triangle, 25);
    Material material = new Material(assetManager,
        "Common/MatDefs/Misc/Particle.j3md");
    material.setTexture("Texture",
        assetManager.loadTexture("effects/smoketrail.png"));
    emitter.setMaterial(material);
View Full Code Here

*
*/
public class DustParticle extends AbstractParticle {

  public DustParticle(String name,AssetManager assetManager) {
    emitter = new ParticleEmitter(name, ParticleMesh.Type.Triangle, 20);
    Material material = new Material(assetManager,
        "Common/MatDefs/Misc/Particle.j3md");
    material.setTexture("Texture",
        assetManager.loadTexture("effects/Dust.png"));
    emitter.setMaterial(material);
View Full Code Here

*
*/
public class GearParticle extends AbstractParticle {

  public GearParticle(String name, AssetManager assetManager) {
    emitter = new ParticleEmitter(name, ParticleMesh.Type.Triangle, 300);
    Material material = new Material(assetManager,
        "Common/MatDefs/Misc/Particle.j3md");
    material.setTexture("Texture",
        assetManager.loadTexture("effects/Flare1.png"));
    emitter.setMaterial(material);
View Full Code Here

TOP

Related Classes of com.jme3.effect.ParticleEmitter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.