Rain effect

barrigudo said:

I noticed that out by the rain is nothing more than a visual effect for the camera. I wanted to see if it would be possible to make particles fall to the ground that to simulate erosion or the like. Anyone have any ideas to help me?


if you want particles to stop falling at the ground, you can always take a look at FloorInfluence, this is but for simple plain Plane floors. But the concept should work ...

There are various ideas some ironic, but it is an area of interest, I thought of using it to generate chaotic and effects that simulate natural disasters such as Haiti and Rio de Janeiro, as Tisunamis, Hurricanes and Avalanches.



I'll look at this "FloorInfluence" to try to understand how this works.

Galun said:

This is the class I used.

A word of warning though: I just copy and paste it. This is about two years old so it might not compile as is.


/*
 * Copyright (c) 2005-2006 World of Mystery Project Team
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package de.worldofmystery.client.effects;

import java.util.Properties;
import java.util.logging.Logger;

import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.math.FastMath;
import com.jme.math.Ring;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.effects.particles.Particle;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleInfluence;
import com.jmex.effects.particles.ParticleMesh;
import com.jmex.effects.particles.SimpleParticleInfluenceFactory;

import de.worldofmystery.client.Config;
import de.worldofmystery.client.world.Environment;

/**
 * a point particle effect for rain
 * @author galun
 * @version $Id: Rain.java,v 1.4 2006/11/11 22:23:29 galun Exp $
 */
public class Rain extends Node {

   private static final long serialVersionUID = -1057124936652689175L;
   private static Logger log = Logger.getLogger(Rain.class.getCanonicalName());
   private ParticleMesh points;
   private SimpleParticleInfluenceFactory.BasicGravity gravity;
   private boolean useGravity = false;

   public Rain(Properties prop) {
      super("rain");
      points = ParticleFactory.buildParticles("rainPoints", 1000, ParticleMesh.PT_QUAD);
      applyParameters(prop);
      if (useGravity) {
         gravity = (SimpleParticleInfluenceFactory.BasicGravity)SimpleParticleInfluenceFactory.createBasicGravity(new Vector3f(0, -1, 0), false);
         points.getParticleController().addInfluence(gravity);
      }
      points.addInfluence(new BoundInfluence());
      TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        ts.setTexture(
                TextureManager.loadTexture(
                        Config.TEXTUREPATH + "/rain.dds",
                        Texture.MM_LINEAR,
                        Texture.FM_LINEAR));
        ts.setEnabled(true);
        points.setRenderState(ts);
      points.warmUp(10);
      attachChild(points);
        AlphaState as1 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
        as1.setBlendEnabled(true);
        as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as1.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
        as1.setTestEnabled(true);
        as1.setTestFunction(AlphaState.TF_GREATER);
        as1.setEnabled(true);
        points.setRenderState(as1);
        points.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
        points.setModelBound(new BoundingSphere());
        points.updateModelBound();
        points.setIsCollidable(false);
        ZBufferState zstate = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
      zstate.setEnabled(false);
//      setRenderState(zstate);
        setIsCollidable(false);
        updateRenderState();
   }

   public void applyParameters(Properties prop) {
        points.setGeometry(new Ring(new Vector3f(0, 0, 0), new Vector3f(0, 1, 0), 100,
              Float.parseFloat(prop.getProperty("radius", "1000"))));
      points.setNumParticles(Integer.parseInt(prop.getProperty("particles", "1000")));
      points.setEmissionDirection(new Vector3f(0, -1, 0));
      points.setOriginOffset(new Vector3f(0, 0, 0));
        points.setInitialVelocity(Float.parseFloat(prop.getProperty("velocity", "0.75f")));
        points.setParticleMass(Float.parseFloat(prop.getProperty("mass", "0.5f")));
        points.setStartSize(Float.parseFloat(prop.getProperty("startSize", "3")));
        points.setEndSize(Float.parseFloat(prop.getProperty("endSize", "3")));
        points.setMinimumLifeTime(Float.parseFloat(prop.getProperty("minLifeTime", "3500")));
        points.setMaximumLifeTime(Float.parseFloat(prop.getProperty("maxLifeTime", "5000")));
        points.setStartColor(parseColor(prop.getProperty("startColor", "0.6, 0.6, 0.6, 1")));
        points.setEndColor(parseColor(prop.getProperty("endColor", "0.6, 0.6, 0.6, 1")));
        points.setMaximumAngle(Float.parseFloat(prop.getProperty("maxAngle", "5f")) * FastMath.DEG_TO_RAD);
        points.getParticleController().setControlFlow(false);
        points.setLightCombineMode(LightState.OFF);
        if (gravity != null)
           gravity.setGravityForce(new Vector3f(0, Float.parseFloat(prop.getProperty("gravity", "-1")), 0));
        points.updateRenderState();
   }

   private ColorRGBA parseColor(String s) {
      ColorRGBA color = new ColorRGBA(ColorRGBA.white);
      try {
         float r = 1;
         float g = 1;
         float b = 1;
         float a = 1;
         String[] p = s.split(",\s+");
         r = Float.parseFloat(p[0]);
         if (p.length > 1)
            g = Float.parseFloat(p[1]);
         if (p.length > 2)
            b = Float.parseFloat(p[2]);
         if (p.length > 3)
            a = Float.parseFloat(p[3]);
         color.set(r, g, b, a);
      } catch (Exception ex) {
         log.warning("unparsable color: " + s + " (" + ex.toString() + ")");
      }
      return color;
   }

   class BoundInfluence extends ParticleInfluence {

      public void apply(float dt, Particle particle, int index) {
         if (Environment.getInstance().collides(particle.getPosition()))
            particle.setStatus(Particle.DEAD);
      }
      
   }
}




Hi,

I'm trying to adapt this script for jME2. But I have two problems :
- My rain doesn't move on the screen
- I don't have the rain.dds file  :D

Can you help me ? Thanks.