public void initialize( string name, Vector3 position, Vector3 direction, Color color, float scaleModifier = 1.0f, int nParticlesModifier = 0, float lifetimeModifier = 0.0f) { particles.Clear(); data = ParticleManager.Instance.getBaseParticleSystemData(name); this.position = position; this.direction = direction; // modify the base data with the parameters if (nParticlesModifier != 0) { data.nParticles = nParticlesModifier; } if (lifetimeModifier != 0.0f) { data.systemLife = lifetimeModifier; data.particlesLife = lifetimeModifier; } data.size *= scaleModifier; data.sizeIni *= scaleModifier; data.sizeEnd *= scaleModifier; data.positionVarianceMin *= scaleModifier; data.positionVarianceMax *= scaleModifier; data.directionVarianceMin *= scaleModifier; data.directionVarianceMax *= scaleModifier; data.accelerationVarianceMin *= scaleModifier; data.accelerationVarianceMax *= scaleModifier; data.color = new Color(data.color.ToVector4() * color.ToVector4()); // get an aproximate number of the simultaneous particles that will have the system float spawnRatio = data.particlesLife / (float)data.nParticles; particles.Capacity = data.nParticles; switch(data.type) { case ParticleSystemData.tParticleSystem.Burst: for(int i=0; i<data.nParticles; i++) { Particle p = new Particle(); p.isDead = true; initializeParticle(p); particles.Add(p); } break; case ParticleSystemData.tParticleSystem.Fountain: for(int i=0; i<data.nParticles; i++) { Particle p = new Particle(); // we want particles prepared to be spawned with the spawnRatio ratio, so we set'em all alive but invisible p.life = 1.3f + spawnRatio * i; p.isDead = false; p.color *= 0; particles.Add(p); } break; default: break; } }
public void loadXML() { baseParticleSystems.Clear(); XDocument xml = XDocument.Load(SB.content.RootDirectory + "/xml/particles/particleSystems2.xml"); IEnumerable<XElement> baseParticleSystemList = xml.Descendants("particleSystem"); foreach (XElement bps in baseParticleSystemList) { ParticleSystemData data = new ParticleSystemData(); data.name = bps.Attribute("name").Value; string type = bps.Attribute("type").Value; data.type = type == "burst" ? data.type = ParticleSystemData.tParticleSystem.Burst : data.type = ParticleSystemData.tParticleSystem.Fountain; string render = bps.Attribute("render").Value; bool additive = render == "additive"; string path = bps.Attribute("texturePath").Value; data.textureName = path; data.texture = TextureManager.Instance.getTexture("particles/" + path); data.nParticles = bps.Attribute("nParticles").Value.toInt(); data.systemLife = bps.Attribute("systemLife").Value.toFloat(); data.position = bps.Attribute("position").Value.toVector3(); data.positionVarianceMin = bps.Attribute("positionVarianceMin").Value.toVector3(); data.positionVarianceMax = bps.Attribute("positionVarianceMax").Value.toVector3(); data.direction = bps.Attribute("direction").Value.toVector3(); data.directionVarianceMin = bps.Attribute("directionVarianceMin").Value.toVector3(); data.directionVarianceMax = bps.Attribute("directionVarianceMax").Value.toVector3(); data.acceleration = bps.Attribute("acceleration").Value.toVector3(); data.accelerationVarianceMin = bps.Attribute("accelerationVarianceMin").Value.toVector3(); data.accelerationVarianceMax = bps.Attribute("accelerationVarianceMax").Value.toVector3(); data.color = bps.Attribute("color").Value.toColor(); data.colorVarianceMin = bps.Attribute("colorVarianceMin").Value.toColor(); data.colorVarianceMax = bps.Attribute("colorVarianceMax").Value.toColor(); data.particlesRotation = bps.Attribute("particlesRotation").Value.toFloat(); data.particlesRotationVariance = bps.Attribute("particlesRotationVariance").Value.toFloat(); data.particlesRotationSpeed = bps.Attribute("particlesRotationSpeed").Value.toFloat(); data.particlesRotationSpeedVariance = bps.Attribute("particlesRotationSpeedVariance").Value.toFloat(); data.size = bps.Attribute("size").Value.toFloat(); data.sizeIni = bps.Attribute("sizeIni").Value.toFloat(); data.sizeEnd = bps.Attribute("sizeEnd").Value.toFloat(); data.fadeIn = bps.Attribute("fadeIn").Value.toFloat(); data.fadeOut = bps.Attribute("fadeOut").Value.toFloat(); data.particlesLife = bps.Attribute("particlesLife").Value.toFloat(); // we are using premultiplied alpha so in order to render those particles in additive mode we need to set alpha to 0 if (additive) { data.color.A = 0; data.colorVarianceMin.A = 0; data.colorVarianceMax.A = 0; } //SB::ownAssert(info.fadeIn + info.fadeOut <= info.particlesLife); //SB::ownAssert(info.positionVarianceMin.x <= info.positionVarianceMax.x); //SB::ownAssert(info.positionVarianceMin.y <= info.positionVarianceMax.y); //SB::ownAssert(info.positionVarianceMin.z <= info.positionVarianceMax.z); //SB::ownAssert(info.directionVarianceMin.x <= info.directionVarianceMax.x); //SB::ownAssert(info.directionVarianceMin.y <= info.directionVarianceMax.y); //SB::ownAssert(info.directionVarianceMin.z <= info.directionVarianceMax.z); //SB::ownAssert(info.accelerationVarianceMin.x <= info.accelerationVarianceMax.x); //SB::ownAssert(info.accelerationVarianceMin.y <= info.accelerationVarianceMax.y); //SB::ownAssert(info.accelerationVarianceMin.z <= info.accelerationVarianceMax.z); baseParticleSystems.Add(data.name, data); } }
public void setBaseParticleSystemData(string name, ParticleSystemData data) { baseParticleSystems[name] = data; }