@Override protected void process(int entityId) { NodeComponent nodeComponent = nodeMapper.get(entityId); ParticleEffectComponent particleEffectComponent = particleEffectMapper.get(entityId); renderableProviders.add(particleSystem); if (particleEffectComponent.state == ParticleEffectComponent.State.READY) { ParticleEffect particleEffect = particleEffectComponent.particleEffect; if (!particleEffectComponent.added) { particleSystem.add(particleEffect); particleEffectComponent.added = true; } particleEffect.setTransform(nodeComponent.getTransform()); } }
public void dispose() { ParticleSystem particleSystem = ParticleSystem.get(); for (ParticleEffect pfx : particleEffects) { particleSystem.remove(pfx); pfx.dispose(); } particleEffects.clear(); navMesh.dispose(); for (Array<GameObject> objs : gameObjects.values()) { for (GameObject obj : objs) { obj.dispose(); } } gameObjects.clear(); assets.dispose(); }
@Override public void dispose() { SpaceShipProperties.properties.setCurrentInternalFuel(SpaceShipProperties.properties.getFuelCapacity()); particleSystem.removeAll(); particleSystem.getBatches().clear(); planetController.dispose(); modelBatch.dispose(); rocket.dispose(); assetManager.dispose(); //sphereModel.dispose(); //shapeRenderer.dispose(); for (ParticleEffect e : effectThrust) { e.dispose(); } effectExplosion.dispose(); effectPortal.dispose(); if (App.config.debugMode) { placementRenderer.dispose(); } App.TUTORIAL_CONTROLLER.onLeavePlanet(); renderEnabled = false; multiplexer.removeProcessor(stage); multiplexer.removeProcessor(this); multiplexer.removeProcessor(firstPersonCameraController); }
@Override public void load (AssetManager manager, ResourceData resources) { SaveData data = resources.getSaveData(); Array<IntArray>effectsIndices = data.load("indices"); AssetDescriptor descriptor; Iterator<IntArray> iterator = effectsIndices.iterator(); while((descriptor = data.loadAsset()) != null){ ParticleEffect effect = (ParticleEffect)manager.get(descriptor); if(effect == null) throw new RuntimeException("Template is null"); Array<ParticleController> effectControllers = effect.getControllers(); IntArray effectIndices = iterator.next(); for (int i = 0, n = effectIndices.size; i < n; i++) { templates.add(effectControllers.get(effectIndices.get(i))); } } }
public FlameMain () { super("Flame"); MathUtils.random = new RandomXS128(); particleSystem = ParticleSystem.get(); effect = new ParticleEffect(); particleSystem.add(effect); assetManager = new AssetManager(); assetManager.setErrorListener(this); assetManager.setLoader(ParticleEffect.class, new ParticleEffectLoader(new InternalFileHandleResolver())); controllersData = new Array<ControllerData>(); lwjglCanvas = new LwjglCanvas(renderer = new AppRenderer()); addWindowListener(new WindowAdapter() { public void windowClosed (WindowEvent event) { //System.exit(0); Gdx.app.exit(); } }); initializeComponents(); setSize(1280, 950); setLocationRelativeTo(null); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setVisible(true); }
public Array<ParticleEffect> getParticleEffects (Array<ParticleController> controllers, Array<ParticleEffect> out) { out.clear(); assetManager.getAll(ParticleEffect.class, out); for(int i=0; i < out.size;){ ParticleEffect effect = out.get(i); Array<ParticleController> effectControllers = effect.getControllers(); boolean remove = true; for(ParticleController controller : controllers){ if(effectControllers.contains(controller, true)){ remove = false; break; } } if(remove){ out.removeIndex(i); continue; } ++i; } return out; }
public ParticleEffect openEffect (File file, boolean replaceCurrentWorkspace) { try { ParticleEffect loadedEffect = load(file.getAbsolutePath(), ParticleEffect.class, null, new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches())); loadedEffect = loadedEffect.copy(); loadedEffect.init(); if(replaceCurrentWorkspace){ effect = loadedEffect; controllersData.clear(); particleSystem.removeAll(); particleSystem.add(effect); for(ParticleController controller : effect.getControllers()) controllersData.add(new ControllerData(controller)); rebuildActiveControllers(); } reloadRows(); return loadedEffect; } catch (Exception ex) { System.out.println("Error loading effect: " + file.getAbsolutePath()); ex.printStackTrace(); JOptionPane.showMessageDialog(this, "Error opening effect."); } return null; }
public SceneManager(Messaging messaging, Entities entities, Assets assets) { this.messaging = messaging; this.entities = entities; this.assets = assets; modelMapper = entities.getMapper(ModelComponent.class); rigidBodyMapper = entities.getMapper(RigidBodyComponent.class); vehicleMapper = entities.getMapper(VehicleComponent.class); vehicleWheelMapper = entities.getMapper(WheelComponent.class); particleEffectMapper = entities.getMapper(ParticleEffectComponent.class); SceneUtils.addComponentJsonMapping("message", MessageComponentJson.class); SceneUtils.addComponentJsonMapping("camera", CameraComponentJson.class); SceneUtils.addComponentJsonMapping("light", LightComponentJson.class); SceneUtils.addComponentJsonMapping("model", ModelComponentJson.class); SceneUtils.addComponentJsonMapping("rigidBody", RigidBodyComponentJson.class); SceneUtils.addComponentJsonMapping("vehicle", VehicleComponentJson.class); SceneUtils.addComponentJsonMapping("wheel", WheelComponentJson.class); SceneUtils.addComponentJsonMapping("particleEffect", ParticleEffectComponentJson.class); SceneUtils.addComponentJsonMapping("ui", UiComponentJson.class); SceneUtils.addAssetClassMapping("model", Model.class); SceneUtils.addAssetClassMapping("texture", Texture.class); SceneUtils.addAssetClassMapping("particleEffect", ParticleEffect.class); SceneUtils.addAssetClassMapping("hdr", HDRData2.class); SceneUtils.addAssetClassMapping("textureAtlas", TextureAtlas.class); SceneUtils.addAssetClassMapping("bitmapFont", BitmapFont.class); }
private void processAssets(Array<Asset> assets) { for (Asset asset : assets) { if (asset.isType(ParticleEffect.class)) { ParticleRenderingSystem particleRenderingSystem = entities.getEntitySystem(ParticleRenderingSystem.class); asset.parameters = new ParticleEffectLoader.ParticleEffectLoadParameter(particleRenderingSystem.getParticleSystem().getBatches()); } } }
public void build(Assets assets, ParticleEffectProvider particleEffectProvider) { ParticleEffect particleEffect = assets.get(asset); particleEffectProvider.addParticleEffect(asset, particleEffect); this.particleEffect = particleEffectProvider.obtainParticleEffect(asset); this.particleEffect.init(); }
@Override public void free(ParticleEffect pfx) { // ParticleSystem.get().remove(pfx); if(pfx==null) return; Emitter emitter = pfx.getControllers().first().emitter; if (emitter instanceof RegularEmitter) { RegularEmitter reg = (RegularEmitter) emitter; reg.setEmissionMode(RegularEmitter.EmissionMode.Disabled); } super.free(pfx); }
@Override protected ParticleEffect newObject() { ParticleEffect newEffect = sourceEffect.copy(); newEffect.init(); ParticleSystem.get().add(newEffect); return newEffect; }
@Override public ParticleEffect obtain() { ParticleEffect newEffect = super.obtain(); // ParticleSystem.get().add(newEffect); Emitter emitter = newEffect.getControllers().first().emitter; if (emitter instanceof RegularEmitter) { RegularEmitter reg = (RegularEmitter) emitter; reg.setEmissionMode(RegularEmitter.EmissionMode.Enabled); } newEffect.reset(); return newEffect; }
public void cloudPoof(Vector3 translation) { ParticleEffect effect = particleManager.get(Particles.PARTICLE_CLOUD_PUFF, ParticleEffect.class).copy(); effect.init(); effect.start(); effect.translate(translation.add(0, -2.5f, 0)); effect.scale(1.5f, 1.5f, 1.5f); effect.rotate(new Vector3(0, 1, 0), 90); particleSystem.add(effect); }
public void caveDust(Matrix4 transform) { ParticleEffect effect = particleManager.get(Particles.PARTICLE_CAVE_DUST, ParticleEffect.class).copy(); effect.init(); effect.start(); effect.setTransform(transform); particleSystem.add(effect); }
private void initManager() { particleManager = new AssetManager(); ParticleEffectLoader.ParticleEffectLoadParameter loadParam = new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches()); ParticleEffectLoader loader = new ParticleEffectLoader(new InternalFileHandleResolver()); particleManager.setLoader(ParticleEffect.class, loader); particleManager.load(Particles.PARTICLE_CLOUD_PUFF, ParticleEffect.class, loadParam); particleManager.load(Particles.PARTICLE_CAVE_DUST, ParticleEffect.class, loadParam); particleManager.finishLoading(); }
public void drawModel(ModelBatch modelBatch, Environment environment, ParticleEffect[] thrustEffect, ParticleEffect effectExplosion) { if (!exploded) { modelBatch.render(rocketModelInstance, environment); long damageDelay = System.currentTimeMillis() - lastDamageTime; if (damageDelay < MIN_DAMAGE_DELAY_MILLIS) { float opacity = (float) damageDelay / (float) (MIN_DAMAGE_DELAY_MILLIS); ((BlendingAttribute) shieldModelInstance.materials.get(0).get(BlendingAttribute.Type)).opacity = opacity; modelBatch.render(shieldModelInstance, environment); } if (tractorBeamVisible) { modelBatch.render(tractorBeamModelInstance, environment); } } thrustMatrix1.set(rocketModelInstance.transform); tmpMatrix.setToRotation(0, 1, 0, drill); tmpMatrix.trn(0, 1, 0.35f); thrustMatrix1.mul(tmpMatrix); thrustEffect[0].setTransform(thrustMatrix1); thrustMatrix2.set(rocketModelInstance.transform); tmpMatrix.setToRotation(0, 1, 0, drill); tmpMatrix.trn(-0.35f, 1, -0.20f); thrustMatrix2.mul(tmpMatrix); thrustEffect[1].setTransform(thrustMatrix2); thrustMatrix3.set(rocketModelInstance.transform); tmpMatrix.setToRotation(0, 1, 0, drill); tmpMatrix.trn(0.350f, 1, -0.25f); thrustMatrix3.mul(tmpMatrix); thrustEffect[2].setTransform(thrustMatrix3); effectExplosion.setTransform(rocketModelInstance.transform); }
@Override public void onRocketDisabledThrust() { fuelProgressBar.updateFromShipProperties(); showToast("Landing procedure..."); for (ParticleEffect e : effectThrust) { particleSystem.remove(e); } }
@Override public void onRocketExploded() { App.audioController.playSound("explosion.mp3"); for (ParticleEffect e : effectThrust) { particleSystem.remove(e); } effectExplosion.start(); particleSystem.add(effectExplosion); onGameOver(); }
public void saveEffect (File file) { Writer fileWriter = null; try { ParticleEffectLoader loader = (ParticleEffectLoader)assetManager.getLoader(ParticleEffect.class); loader.save(effect, new ParticleEffectSaveParameter(new FileHandle(file.getAbsolutePath()), assetManager, particleSystem.getBatches())); } catch (Exception ex) { System.out.println("Error saving effect: " + file.getAbsolutePath()); ex.printStackTrace(); JOptionPane.showMessageDialog(this, "Error saving effect."); } finally { StreamUtils.closeQuietly(fileWriter); } }
private void reloadControllers () { Array<ParticleEffect> effects = new Array<ParticleEffect>(); Array<ParticleController> controllers = new Array<ParticleController>(); editor.assetManager.getAll(ParticleEffect.class, effects); for(ParticleEffect effect : effects){ controllers.addAll(effect.getControllers()); } controllerPicker.setLoadedTemplates(controllers); }
@Override public void handle (int aEventType, Object aEventData) { if(aEventType == FlameMain.EVT_ASSET_RELOADED){ Object[] data = (Object[])aEventData; if(data[0] instanceof ParticleEffect){ ParticleEffect oldEffect = (ParticleEffect) data[0]; int currentCount = value.templates.size; value.templates.removeAll(oldEffect.getControllers(), true); if(value.templates.size != currentCount){ int diff = currentCount - value.templates.size; if(diff > 0){ ParticleEffect newEffect = (ParticleEffect) data[1]; Array<ParticleController> newControllers = newEffect.getControllers(); if(newControllers.size > 0){ for(int i=0, c=Math.min(diff, newControllers.size); i<c; ++i) value.templates.add(newControllers.get(i)); } } else { value.templates.addAll( ((ParticleEffect)editor.assetManager.get(FlameMain.DEFAULT_BILLBOARD_PARTICLE)).getControllers()); } controllerPicker.reloadTemplates(); controllerPicker.setValue(value.templates); editor.restart(); } } } }
private ParticleController createDefaultParticleController () { //Emission RegularEmitter emitter = new RegularEmitter(); emitter.getDuration().setLow(3000); emitter.getEmission().setHigh(90); emitter.getLife().setHigh(3000); emitter.setMaxParticleCount(100); //Spawn EllipseSpawnShapeValue pointSpawnShapeValue = new EllipseSpawnShapeValue(); pointSpawnShapeValue.setDimensions(1, 1, 1); pointSpawnShapeValue.setSide(SpawnSide.top); SpawnInfluencer spawnSource = new SpawnInfluencer(pointSpawnShapeValue); //Scale ScaleInfluencer scaleInfluencer = new ScaleInfluencer(); scaleInfluencer.value.setHigh(1); scaleInfluencer.value.setLow(0); scaleInfluencer.value.setTimeline(new float[]{0,1}); scaleInfluencer.value.setScaling(new float[]{1, 0}); //Velocity DynamicsInfluencer velocityInfluencer = new DynamicsInfluencer(); //Directional DynamicsModifier.CentripetalAcceleration velocityValue = new DynamicsModifier.CentripetalAcceleration(); velocityValue.strengthValue.setHigh(5, 10); velocityValue.strengthValue.setActive(true); velocityInfluencer.velocities.add(velocityValue); return new ParticleController("ParticleController Controller", emitter, new ParticleControllerControllerRenderer(), new ParticleControllerInfluencer.Single(editor.assetManager.get(FlameMain.DEFAULT_TEMPLATE_PFX, ParticleEffect.class).getControllers().get(0)), spawnSource, scaleInfluencer, velocityInfluencer, new ParticleControllerFinalizerInfluencer() ); }
protected void importEffect () { File file = editor.showFileLoadDialog(); if(file != null){ ParticleEffect effect; if( (effect = editor.openEffect(file, false)) != null){ for(ParticleController controller : effect.getControllers()) addEmitter(controller, false); editIndex = 0; emitterTable.getSelectionModel().setSelectionInterval(editIndex, editIndex); } } }
public static void loadParticleEffects(ParticleSystem particleSystem) { ParticleEffectLoader.ParticleEffectLoadParameter loadParam = new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches()); ParticleEffectLoader loader = new ParticleEffectLoader(new InternalFileHandleResolver()); manager.setLoader(ParticleEffect.class, loader); manager.load("particle/bullet-hit.pfx", ParticleEffect.class, loadParam); manager.load("particle/blue-explosion.pfx", ParticleEffect.class, loadParam); manager.finishLoading(); }
public Particles() { inst = this; system = ParticleSystem.get(); PointSpriteParticleBatch psBatch = new PointSpriteParticleBatch(); psBatch.setCamera(View.inst.getCamera()); system.add(psBatch); Assets.loadParticleEffects(system); ParticleEffect bulletHit = Assets.manager.get("particle/bullet-hit.pfx"); ParticleEffect blueExplosion = Assets.manager.get("particle/blue-explosion.pfx"); bulletHitPool = new PFXPool(bulletHit); blueExplosionPool = new PFXPool(blueExplosion); }
public ParticleEffectPool(ParticleEffect originalEffect) { this.originalEffect = originalEffect; }
@Override public void free(ParticleEffect object) { object.reset(); super.free(object); }
@Override protected ParticleEffect newObject() { return originalEffect.copy(); }
public void addParticleEffect(String asset, ParticleEffect effect) { if (!particleEffectPoolMap.containsKey(asset)) { ParticleEffectPool particleEffectPool = new ParticleEffectPool(effect); particleEffectPoolMap.put(asset, particleEffectPool); } }
public ParticleEffect obtainParticleEffect(String asset) { return particleEffectPoolMap.get(asset).obtain(); }
public PFXPool(ParticleEffect sourceEffect) { this.sourceEffect = sourceEffect; }
private void initParticles() { // particles particleSystem = ParticleSystem.get(); particleSpriteBatch = new BillboardParticleBatch(); particleSpriteBatch.setCamera(camera); particleSystem.add(particleSpriteBatch); assetManager = new AssetManager(); ParticleEffectLoader.ParticleEffectLoadParameter loadParam = new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches()); ParticleEffectLoader loader = new ParticleEffectLoader(new InternalFileHandleResolver()); assetManager.setLoader(ParticleEffect.class, loader); assetManager.load("particles/3D/rocket_thruster.pfx", ParticleEffect.class, loadParam); assetManager.load("particles/3D/rocket_explosion.pfx", ParticleEffect.class, loadParam); assetManager.load("particles/3D/planet_portal.pfx", ParticleEffect.class, loadParam); assetManager.finishLoading(); effectThrust = new ParticleEffect[3]; effectThrust[0] = ((ParticleEffect) assetManager.get("particles/3D/rocket_thruster.pfx")).copy(); effectThrust[1] = ((ParticleEffect) assetManager.get("particles/3D/rocket_thruster.pfx")).copy(); effectThrust[2] = ((ParticleEffect) assetManager.get("particles/3D/rocket_thruster.pfx")).copy(); effectExplosion = ((ParticleEffect) assetManager.get("particles/3D/rocket_explosion.pfx")).copy(); effectPortal = ((ParticleEffect) assetManager.get("particles/3D/planet_portal.pfx")).copy(); effectExplosion.init(); for (ParticleEffect e : effectThrust) { e.init(); e.start(); particleSystem.add(e); } effectPortal.init(); effectPortal.start(); effectPortal.translate(new Vector3(-30, 0, 135)); effectPortal.rotate(Vector3.Z, 90); effectPortal.rotate(Vector3.X, 30); effectPortal.scale(2f, 2f, 2f); particleSystem.add(effectPortal); }
@Override public void onRocketEnabledThrust() { for (ParticleEffect e : effectThrust) { particleSystem.add(e); } }
@Override public Class<? extends ParticleEffect> getType() { return ParticleEffect.class; }
@Override public void onResourceLoaded (ParticleEffect resource) { reloadControllers(); }
public ParticleEffectLoaderButton (FlameMain editor, Listener<ParticleEffect> listener) { super(editor, "Load Controller", listener); }
public ParticleEffect obtainBulletHit() { //System.out.println("free bullet-hit count: " + bulletHitPool.getFree()); return bulletHitPool.obtain(); }
public void freeBulletHit(ParticleEffect pfx) { system.remove(pfx); bulletHitPool.free(pfx); }
public ParticleEffect obtainBlueExplosion() { //System.out.println("free bullet-hit count: " + blueExplosionPool.getFree()); return blueExplosionPool.obtain(); }