com.jme3.effect.ParticleMesh.Type Java Examples

The following examples show how to use com.jme3.effect.ParticleMesh.Type. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void prepareEffect() {
        int COUNT_FACTOR = 1;
        float COUNT_FACTOR_F = 1f;
        effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
        effect.setSelectRandomImage(true);
        effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
        effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
        effect.setStartSize(1.3f);
        effect.setEndSize(2f);
        effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        effect.setParticlesPerSec(0);
        effect.setGravity(0, -5, 0);
        effect.setLowLife(.4f);
        effect.setHighLife(.5f);
        effect.getParticleInfluencer()
                .setInitialVelocity(new Vector3f(0, 7, 0));
        effect.getParticleInfluencer().setVelocityVariation(1f);
        effect.setImagesX(2);
        effect.setImagesY(2);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
        effect.setMaterial(mat);
//        effect.setLocalScale(100);
        rootNode.attachChild(effect);
    }
 
Example #2
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 * 
 * @param rm
 * @param vp 
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example #3
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Sets the type of mesh used by the particle emitter.
 * @param meshType The mesh type to use
 */
public void setMeshType(ParticleMesh.Type meshType) {
    this.meshType = meshType;
    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(particles.length);
}
 
Example #4
Source File: TestMovingParticle.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
    emit.setGravity(0, 0, 0);
    emit.setVelocityVariation(1);
    emit.setLowLife(1);
    emit.setHighLife(1);
    emit.setInitialVelocity(new Vector3f(0, .5f, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);
    
    rootNode.attachChild(emit);
    
    inputManager.addListener(new ActionListener() {
        
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(1000);
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #5
Source File: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createShockwave(){
        shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
//        shockwave.setRandomAngle(true);
        shockwave.setFaceNormal(Vector3f.UNIT_Y);
        shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, (float) (.8f / COUNT_FACTOR_F)));
        shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));

        shockwave.setStartSize(0f);
        shockwave.setEndSize(7f);

        shockwave.setParticlesPerSec(0);
        shockwave.setGravity(0, 0, 0);
        shockwave.setLowLife(0.5f);
        shockwave.setHighLife(0.5f);
        shockwave.setInitialVelocity(new Vector3f(0, 0, 0));
        shockwave.setVelocityVariation(0f);
        shockwave.setImagesX(1);
        shockwave.setImagesY(1);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/shockwave.png"));
        shockwave.setMaterial(mat);
        explosionEffect.attachChild(shockwave);
    }
 
Example #6
Source File: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createDebris(){
        debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
        debris.setSelectRandomImage(true);
        debris.setRandomAngle(true);
        debris.setRotateSpeed(FastMath.TWO_PI * 4);
        debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, (float) (1.0f / COUNT_FACTOR_F)));
        debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
        debris.setStartSize(.2f);
        debris.setEndSize(.2f);

//        debris.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
        debris.setParticlesPerSec(0);
        debris.setGravity(0, 12f, 0);
        debris.setLowLife(1.4f);
        debris.setHighLife(1.5f);
        debris.setInitialVelocity(new Vector3f(0, 15, 0));
        debris.setVelocityVariation(.60f);
        debris.setImagesX(3);
        debris.setImagesY(3);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/Debris.png"));
        debris.setMaterial(mat);
        explosionEffect.attachChild(debris);
    }
 
Example #7
Source File: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createSmokeTrail(){
        smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
        smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F)));
        smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
        smoketrail.setStartSize(.2f);
        smoketrail.setEndSize(1f);

//        smoketrail.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        smoketrail.setFacingVelocity(true);
        smoketrail.setParticlesPerSec(0);
        smoketrail.setGravity(0, 1, 0);
        smoketrail.setLowLife(.4f);
        smoketrail.setHighLife(.5f);
        smoketrail.setInitialVelocity(new Vector3f(0, 12, 0));
        smoketrail.setVelocityVariation(1);
        smoketrail.setImagesX(1);
        smoketrail.setImagesY(3);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/smoketrail.png"));
        smoketrail.setMaterial(mat);
        explosionEffect.attachChild(smoketrail);
    }
 
Example #8
Source File: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createSpark(){
    spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
    spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F)));
    spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
    spark.setStartSize(.5f);
    spark.setEndSize(.5f);
    spark.setFacingVelocity(true);
    spark.setParticlesPerSec(0);
    spark.setGravity(0, 5, 0);
    spark.setLowLife(1.1f);
    spark.setHighLife(1.5f);
    spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
    spark.getParticleInfluencer().setVelocityVariation(1);
    spark.setImagesX(1);
    spark.setImagesY(1);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/spark.png"));
    spark.setMaterial(mat);
    explosionEffect.attachChild(spark);
}
 
Example #9
Source File: TestWalkingChar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void prepareEffect() {
        int COUNT_FACTOR = 1;
        float COUNT_FACTOR_F = 1f;
        effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
        effect.setSelectRandomImage(true);
        effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
        effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
        effect.setStartSize(1.3f);
        effect.setEndSize(2f);
        effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        effect.setParticlesPerSec(0);
        effect.setGravity(0, -5, 0);
        effect.setLowLife(.4f);
        effect.setHighLife(.5f);
        effect.setInitialVelocity(new Vector3f(0, 7, 0));
        effect.setVelocityVariation(1f);
        effect.setImagesX(2);
        effect.setImagesY(2);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
        effect.setMaterial(mat);
//        effect.setLocalScale(100);
        rootNode.attachChild(effect);
    }
 
Example #10
Source File: BombControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void prepareEffect(AssetManager assetManager) {
    int COUNT_FACTOR = 1;
    float COUNT_FACTOR_F = 1f;
    effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
    effect.setSelectRandomImage(true);
    effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
    effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    effect.setStartSize(1.3f);
    effect.setEndSize(2f);
    effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    effect.setParticlesPerSec(0);
    effect.setGravity(0, -5f, 0);
    effect.setLowLife(.4f);
    effect.setHighLife(.5f);
    effect.setInitialVelocity(new Vector3f(0, 7, 0));
    effect.setVelocityVariation(1f);
    effect.setImagesX(2);
    effect.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    effect.setMaterial(mat);
}
 
Example #11
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 * 
 * @param rm
 * @param vp 
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example #12
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 6 votes vote down vote up
/**
 * Sets the type of mesh used by the particle emitter.
 * @param meshType The mesh type to use
 */
@Override
public void setMeshType(ParticleMesh.Type meshType) {
    this.meshType = meshType;
    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.setNumParticles2(particles.length);
}
 
Example #13
Source File: BombControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void prepareEffect(AssetManager assetManager) {
    int COUNT_FACTOR = 1;
    float COUNT_FACTOR_F = 1f;
    effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
    effect.setSelectRandomImage(true);
    effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
    effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    effect.setStartSize(1.3f);
    effect.setEndSize(2f);
    effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    effect.setParticlesPerSec(0);
    effect.setGravity(0, -5f, 0);
    effect.setLowLife(.4f);
    effect.setHighLife(.5f);
    effect.getParticleInfluencer()
            .setInitialVelocity(new Vector3f(0, 7, 0));
    effect.getParticleInfluencer().setVelocityVariation(1f);
    effect.setImagesX(2);
    effect.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    effect.setMaterial(mat);
}
 
Example #14
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets the type of mesh used by the particle emitter.
 * @param meshType The mesh type to use
 */
public void setMeshType(ParticleMesh.Type meshType) {
    this.meshType = meshType;
    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(particles.length);
}
 
Example #15
Source File: TestParticleExportingCloning.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Triangle, 200);
    emit.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    emit.setGravity(0, 0, 0);
    emit.setLowLife(5);
    emit.setHighLife(10);
    emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);

    ParticleEmitter emit2 = emit.clone();
    emit2.move(3, 0, 0);
    
    rootNode.attachChild(emit);
    rootNode.attachChild(emit2);
    
    ParticleEmitter emit3 = BinaryExporter.saveAndLoad(assetManager, emit);
    emit3.move(-3, 0, 0);
    rootNode.attachChild(emit3);
}
 
Example #16
Source File: TestExplosionEffect.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createSpark(){
    spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
    spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
    spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
    spark.setStartSize(.5f);
    spark.setEndSize(.5f);
    spark.setFacingVelocity(true);
    spark.setParticlesPerSec(0);
    spark.setGravity(0, 5, 0);
    spark.setLowLife(1.1f);
    spark.setHighLife(1.5f);
    spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
    spark.getParticleInfluencer().setVelocityVariation(1);
    spark.setImagesX(1);
    spark.setImagesY(1);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/spark.png"));
    spark.setMaterial(mat);
    explosionEffect.attachChild(spark);
}
 
Example #17
Source File: TestExplosionEffect.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createSmokeTrail(){
        smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
        smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
        smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
        smoketrail.setStartSize(.2f);
        smoketrail.setEndSize(1f);

//        smoketrail.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        smoketrail.setFacingVelocity(true);
        smoketrail.setParticlesPerSec(0);
        smoketrail.setGravity(0, 1, 0);
        smoketrail.setLowLife(.4f);
        smoketrail.setHighLife(.5f);
        smoketrail.getParticleInfluencer()
                .setInitialVelocity(new Vector3f(0, 12, 0));
        smoketrail.getParticleInfluencer().setVelocityVariation(1);
        smoketrail.setImagesX(1);
        smoketrail.setImagesY(3);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/smoketrail.png"));
        smoketrail.setMaterial(mat);
        explosionEffect.attachChild(smoketrail);
    }
 
Example #18
Source File: TestExplosionEffect.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createDebris(){
        debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
        debris.setSelectRandomImage(true);
        debris.setRandomAngle(true);
        debris.setRotateSpeed(FastMath.TWO_PI * 4);
        debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, 1.0f / COUNT_FACTOR_F));
        debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
        debris.setStartSize(.2f);
        debris.setEndSize(.2f);

//        debris.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
        debris.setParticlesPerSec(0);
        debris.setGravity(0, 12f, 0);
        debris.setLowLife(1.4f);
        debris.setHighLife(1.5f);
        debris.getParticleInfluencer()
                .setInitialVelocity(new Vector3f(0, 15, 0));
        debris.getParticleInfluencer().setVelocityVariation(.60f);
        debris.setImagesX(3);
        debris.setImagesY(3);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/Debris.png"));
        debris.setMaterial(mat);
        explosionEffect.attachChild(debris);
    }
 
Example #19
Source File: TestExplosionEffect.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createShockwave(){
        shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
//        shockwave.setRandomAngle(true);
        shockwave.setFaceNormal(Vector3f.UNIT_Y);
        shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, .8f / COUNT_FACTOR_F));
        shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));

        shockwave.setStartSize(0f);
        shockwave.setEndSize(7f);

        shockwave.setParticlesPerSec(0);
        shockwave.setGravity(0, 0, 0);
        shockwave.setLowLife(0.5f);
        shockwave.setHighLife(0.5f);
        shockwave.getParticleInfluencer()
                .setInitialVelocity(new Vector3f(0, 0, 0));
        shockwave.getParticleInfluencer().setVelocityVariation(0f);
        shockwave.setImagesX(1);
        shockwave.setImagesY(1);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/shockwave.png"));
        shockwave.setMaterial(mat);
        explosionEffect.attachChild(shockwave);
    }
 
Example #20
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 *
 * @param rm
 * @param vp
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example #21
Source File: TestParticleExportingCloning.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Triangle, 200);
    emit.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    emit.setGravity(0, 0, 0);
    emit.setLowLife(5);
    emit.setHighLife(10);
    emit.setInitialVelocity(new Vector3f(0, 0, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);

    ParticleEmitter emit2 = emit.clone();
    emit2.move(3, 0, 0);
    
    rootNode.attachChild(emit);
    rootNode.attachChild(emit2);
    
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        BinaryExporter.getInstance().save(emit, out);
        
        BinaryImporter imp = new BinaryImporter();
        imp.setAssetManager(assetManager);
        ParticleEmitter emit3 = (ParticleEmitter) imp.load(out.toByteArray());
        
        emit3.move(-3, 0, 0);
        rootNode.attachChild(emit3);
    } catch (IOException ex) {
        ex.printStackTrace();
    }

        //        Camera cam2 = cam.clone();
//        cam.setViewPortTop(0.5f);
//        cam2.setViewPortBottom(0.5f);
//        ViewPort vp = renderManager.createMainView("SecondView", cam2);
//        viewPort.setClearEnabled(false);
//        vp.attachScene(rootNode);
}
 
Example #22
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #23
Source File: TestPointSprite.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000);
    emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f),
                                      new Vector3f(1.8f, 1.8f, 1.8f)));
    emit.setGravity(0, 0, 0);
    emit.setLowLife(60);
    emit.setHighLife(60);
    emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
    emit.setImagesX(15);
    emit.setStartSize(0.05f);
    emit.setEndSize(0.05f);
    emit.setStartColor(ColorRGBA.White);
    emit.setEndColor(ColorRGBA.White);
    emit.setSelectRandomImage(true);
    emit.emitAllParticles();
    
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setBoolean("PointSprite", true);
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);

    rootNode.attachChild(emit);
    inputManager.addListener(new ActionListener() {
        
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(5000);
                emit.emitAllParticles();
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
    
}
 
Example #24
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ParticleEmitter(String name, Type type, int numParticles) {
        super(name);

        // ignore world transform, unless user sets inLocalSpace
        this.setIgnoreTransform(true);

        // particles neither receive nor cast shadows
        this.setShadowMode(ShadowMode.Off);

        // particles are usually transparent
        this.setQueueBucket(Bucket.Transparent);

        meshType = type;

        // Must create clone of shape/influencer so that a reference to a static is 
        // not maintained
        shape = shape.deepClone();
        particleInfluencer = particleInfluencer.clone();

        control = new ParticleEmitterControl(this);
        controls.add(control);

        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);
    }
 
Example #25
Source File: TestPointSprite.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000);
    emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f),
                                      new Vector3f(1.8f, 1.8f, 1.8f)));
    emit.setGravity(0, 0, 0);
    emit.setLowLife(60);
    emit.setHighLife(60);
    emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
    emit.setImagesX(15);
    emit.setStartSize(0.05f);
    emit.setEndSize(0.05f);
    emit.setStartColor(ColorRGBA.White);
    emit.setEndColor(ColorRGBA.White);
    emit.setSelectRandomImage(true);
    emit.emitAllParticles();
    
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setBoolean("PointSprite", true);
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);

    rootNode.attachChild(emit);
    inputManager.addListener(new ActionListener() {
        
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(5000);
                emit.emitAllParticles();
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
    
}
 
Example #26
Source File: TestMovingParticle.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
    emit.setGravity(0, 0, 0);
    emit.getParticleInfluencer().setVelocityVariation(1);
    emit.setLowLife(1);
    emit.setHighLife(1);
    emit.getParticleInfluencer()
            .setInitialVelocity(new Vector3f(0, .5f, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);
    
    rootNode.attachChild(emit);
    
    inputManager.addListener(new ActionListener() {
        
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(1000);
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #27
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ParticleEmitter(String name, Type type, int numParticles) {
        super(name);
        setBatchHint(BatchHint.Never);
        // ignore world transform, unless user sets inLocalSpace
        this.setIgnoreTransform(true);

        // particles neither receive nor cast shadows
        this.setShadowMode(ShadowMode.Off);

        // particles are usually transparent
        this.setQueueBucket(Bucket.Transparent);

        meshType = type;

        // Must create clone of shape/influencer so that a reference to a static is
        // not maintained
        shape = shape.deepClone();
        particleInfluencer = particleInfluencer.clone();

        control = new ParticleEmitterControl(this);
        controls.add(control);

        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);
    }
 
Example #28
Source File: TestMovingParticle.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
    emit.setGravity(0, 0, 0);
    emit.setVelocityVariation(1);
    emit.setLowLife(1);
    emit.setHighLife(1);
    emit.setInitialVelocity(new Vector3f(0, .5f, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);
    
    rootNode.attachChild(emit);
    
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.84f, 0.80f, 0.80f, 1.0f));
    rootNode.addLight(al);
    
    
    
    inputManager.addListener(new ActionListener() {
        
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(1000);
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #29
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 5 votes vote down vote up
@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);
}
 
Example #30
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 5 votes vote down vote up
public MyParticleEmitter(String name, Type type, int numParticles) {
        super();
        this.name = name;
        setBatchHint(BatchHint.Never);
        // ignore world transform, unless user sets inLocalSpace
        this.setIgnoreTransform(true);

        // particles neither receive nor cast shadows
        this.setShadowMode(ShadowMode.Off);

        // particles are usually transparent
        this.setQueueBucket(Bucket.Transparent);

        meshType = type;

        // Must create clone of shape/influencer so that a reference to a static is 
        // not maintained
        shape = shape.deepClone();
        particleInfluencer = particleInfluencer.clone();

        control = new MyParticleEmitter.ParticleEmitterControl(this);
        controls.add(control);

        switch (meshType) {
            case Point:
                particleMesh = new ParticlePointMesh();
                this.setMesh(particleMesh);
                break;
            case Triangle:
                particleMesh = new ParticlePointMesh();
                this.setMesh(particleMesh);
                break;
            default:
                throw new IllegalStateException("Unrecognized particle type: " + meshType);
        }
        this.setNumParticles2(numParticles);
//        particleMesh.initParticleData(this, particles.length);
    }