@Override public void simpleInitApp() { ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture( "Effects/Explosion/flame.png")); fire.setMaterial(mat_red); fire.setImagesX(2); fire.setImagesY(2); // 2x2 texture animation fire.setEndColor( new ColorRGBA(1f, 0f, 0f, 1f)); // red fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0)); fire.setStartSize(1.5f); fire.setEndSize(0.1f); fire.setGravity(0, 0, 0); fire.setLowLife(1f); fire.setHighLife(3f); fire.getParticleInfluencer().setVelocityVariation(0.3f); rootNode.attachChild(fire); new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10); Material debris_mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); debris_mat.setTexture("Texture", assetManager.loadTexture( "Effects/Explosion/Debris.png")); debris.setMaterial(debris_mat); debris.setImagesX(3); debris.setImagesY(3); // 3x3 texture animation
private void makeSoftParticleEmitter(Spatial scene, boolean enabled) { if (scene instanceof Node) { Node n = (Node) scene; for (Spatial child : n.getChildren()) { makeSoftParticleEmitter(child, enabled); } } if (scene instanceof ParticleEmitter) { ParticleEmitter emitter = (ParticleEmitter) scene; if (enabled) { enabledSoftParticles = enabled; emitter.getMaterial().selectTechnique("SoftParticles", renderManager); if( processor.getNumSamples()>1){ emitter.getMaterial().setInt("NumSamplesDepth", processor.getNumSamples()); } 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()); } } } }
emitter.setCullHint(CullHint.Dynamic); emitter.setEnabled(true); emitter.emitAllParticles(); if (!killParticles.stopRequested) { emitter.addControl(killParticles); killParticles.stopRequested = true; emitter.setParticlesPerSec(particlesPerSeconds);
private void stop() { emitter.setParticlesPerSec(0); emitted = false; if (!killParticles.stopRequested) { emitter.addControl(killParticles); killParticles.stopRequested = true; } }
@Override protected void controlUpdate(float tpf) { if (remove) { emitter.removeControl(this); return; } if (emitter.getNumVisibleParticles() == 0) { emitter.setCullHint(CullHint.Always); emitter.setEnabled(false); emitter.removeControl(this); stopRequested = false; } }
public void onAction(String name, boolean isPressed, float tpf) { if ("setNum".equals(name) && isPressed) { emit.setNumParticles(5000); emit.emitAllParticles(); } } }, "setNum");
private void createFire() { /** * Uses Texture from jme3-test-data library! */ ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png")); fire.setMaterial(mat_red); fire.setImagesX(2); fire.setImagesY(2); // 2x2 texture animation fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0)); fire.setStartSize(10f); fire.setEndSize(1f); fire.setGravity(0, 0, 0); fire.setLowLife(0.5f); fire.setHighLife(1.5f); fire.getParticleInfluencer().setVelocityVariation(0.3f); fire.setLocalTranslation(-600, 50, 300); fire.setQueueBucket(Bucket.Translucent); rootNode.attachChild(fire); }
ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30); fire.setMaterial(material); fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f)); fire.setImagesX(2); fire.setImagesY(2); // 2x2 texture animation fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow fire.setStartSize(0.6f); fire.setEndSize(0.01f); fire.setGravity(0, -0.3f, 0); fire.setLowLife(0.5f); fire.setHighLife(3f); fire.setLocalTranslation(0, 0.2f, 0); ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30); smoke.setMaterial(material); smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5)); smoke.setImagesX(1); smoke.setImagesY(1); // 2x2 texture animation smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f,1f)); // dark gray smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f)); // gray smoke.setStartSize(3f); smoke.setEndSize(5f); smoke.setGravity(0, -0.001f, 0); smoke.setLowLife(100f); smoke.setHighLife(100f); smoke.setLocalTranslation(0, 0.1f, 0); smoke.emitAllParticles();
@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); }
result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart); if (nameSuffix == 'N') { return result;// no need to set anything else 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: result.setGravity(-acc.get(0).floatValue(), -acc.get(1).floatValue(), -acc.get(2).floatValue()); result.setEndColor(new ColorRGBA(1f, 1f, 1f, 1f)); result.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f)); result.setStartSize(size); result.setEndSize(size); 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);
public ParticleEmitter(String name, Type type, int numParticles) { super(name); setBatchHint(BatchHint.Never); this.setIgnoreTransform(true); this.setShadowMode(ShadowMode.Off); this.setQueueBucket(Bucket.Transparent); 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);
@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() { 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)); }
/** * This method clone the Track and search for the cloned counterpart of the * original emitter in the given cloned spatial. The spatial is assumed to * be the Spatial holding the AnimControl controlling the animation using * this Track. * * @param spatial the Spatial holding the AnimControl * @return the cloned Track with proper reference */ @Override public Track cloneForSpatial(Spatial spatial) { EffectTrack effectTrack = new EffectTrack(); effectTrack.particlesPerSeconds = this.particlesPerSeconds; effectTrack.length = this.length; effectTrack.startOffset = this.startOffset; //searching for the newly cloned ParticleEmitter effectTrack.emitter = findEmitter(spatial); if (effectTrack.emitter == null) { logger.log(Level.WARNING, "{0} was not found in {1} or is not bound to this track", new Object[]{emitter.getName(), spatial.getName()}); effectTrack.emitter = emitter; } removeUserData(this); //setting user data on the new emmitter and marking it with a reference to the cloned Track. setUserData(effectTrack); effectTrack.emitter.setParticlesPerSec(0); return effectTrack; }
ParticleEmitter emitter = particleEmitter.clone(); char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1); if (nameSuffix == 'B' || nameSuffix == 'N') { alphaFunction = MaterialHelper.ALPHA_MASK_NONE; emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1)); EmitterShape emitterShape = emitter.getShape(); List<Mesh> meshes = new ArrayList<Mesh>(); for (Spatial spatial : node.getChildren()) { meshes.add(mesh); Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext); emitter.setMaterial(material);// TODO: divide into several pieces
/** * Sets the Emitter to use in this track * * @param emitter */ public void setEmitter(ParticleEmitter emitter) { if (this.emitter != null) { TrackInfo data = (TrackInfo) emitter.getUserData("TrackInfo"); data.getTracks().remove(this); } this.emitter = emitter; //saving particles per second value this.particlesPerSeconds = emitter.getParticlesPerSec(); //setting the emmitter to not emmit. this.emitter.setParticlesPerSec(0); setUserData(this); }
/** * Creates and EffectTrack * * @param emitter the emitter of the track * @param length the length of the track (usually the length of the * animation you want to add the track to) */ public EffectTrack(ParticleEmitter emitter, float length) { this.emitter = emitter; //saving particles per second value this.particlesPerSeconds = emitter.getParticlesPerSec(); //setting the emmitter to not emmit. this.emitter.setParticlesPerSec(0); this.length = length; //Marking the emitter with a reference to this track for further use in deserialization. setUserData(this); }
/** * 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(); } }
/** * Internal use only serialization * * @param ex exporter * @throws IOException exception */ @Override public void write(JmeExporter ex) throws IOException { OutputCapsule out = ex.getCapsule(this); //reset the particle emission rate on the emitter before saving. emitter.setParticlesPerSec(particlesPerSeconds); out.write(emitter, "emitter", null); out.write(particlesPerSeconds, "particlesPerSeconds", 0); out.write(length, "length", 0); out.write(startOffset, "startOffset", 0); //Setting emission rate to 0 so that this track can go on being used. emitter.setParticlesPerSec(0); }
public void collision(PhysicsCollisionEvent event) { if (space == null) { return; } if (event.getObjectA() == this || event.getObjectB() == this) { space.add(ghostObject); ghostObject.setPhysicsLocation(getPhysicsLocation(vector)); space.addTickListener(this); if (effect != null && spatial.getParent() != null) { curTime = 0; effect.setLocalTranslation(spatial.getLocalTranslation()); spatial.getParent().attachChild(effect); effect.emitAllParticles(); } space.remove(this); spatial.removeFromParent(); } }
public void collision(PhysicsCollisionEvent event) { if (event.getObjectA() instanceof BombControl) { final Spatial node = event.getNodeA(); effect.killAllParticles(); effect.setLocalTranslation(node.getLocalTranslation()); effect.emitAllParticles(); } else if (event.getObjectB() instanceof BombControl) { final Spatial node = event.getNodeB(); effect.killAllParticles(); effect.setLocalTranslation(node.getLocalTranslation()); effect.emitAllParticles(); } }