/* * ParticleProcessor.cs * Authors: Brian Murphy * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content.Pipeline; using System.Xml; namespace TACParticleEngine.FileProcessing { /// /// Custom content processor for Particle Engines /// [ContentProcessor] class ParticleProcessor : ContentProcessor { public override ParticleCompiled Process(ParticleSource input, ContentProcessorContext context) { ParticleCompiled ret = new ParticleCompiled(); XmlDocument xml = input.Xml; foreach (XmlNode node in xml.GetElementsByTagName("particle")[0].ChildNodes) { EmitterInfo emitter = new EmitterInfo(); foreach (XmlNode info in node.ChildNodes) { if (info.Name.Equals("textureName")) emitter.TextureName = info.InnerText; if (info.Name.Equals("blendEffect")) emitter.BlendEffect = (SpriteBlendMode)Enum.Parse(emitter.BlendEffect.GetType(), info.InnerText, true); if (info.Name.Equals("positions")) { List vertices = new List(); String[] dots = info.InnerText.TrimStart('(').TrimEnd(')').Replace(")(", " ").Split(' '); foreach (String point in dots) { String[] vertex = point.Split(','); vertices.Add(new Vector3(float.Parse(vertex[0]), float.Parse(vertex[1]), float.Parse(vertex[2]))); } emitter.Positions = vertices; } if (info.Name.Equals("minVel")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MinVel = new Vector3( float.Parse(component[0]), float.Parse(component[1]), float.Parse(component[2])); } if (info.Name.Equals("maxVel")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MaxVel = new Vector3( float.Parse(component[0]), float.Parse(component[1]), float.Parse(component[2])); } if (info.Name.Equals("emitLifetime")) emitter.EmitLifetime = float.Parse(info.InnerText); if (info.Name.Equals("particlesPerSec")) emitter.ParticlePersSec = int.Parse(info.InnerText); if (info.Name.Equals("particleLifetime")) emitter.ParticleLifetime = float.Parse(info.InnerText); if (info.Name.Equals("particleAmount")) emitter.ParticleAmount = short.Parse(info.InnerText); if (info.Name.Equals("minStartSpeed")) emitter.MaxStartSpeed = float.Parse(info.InnerText); if (info.Name.Equals("maxStartSpeed")) emitter.MaxStartSpeed = float.Parse(info.InnerText); if (info.Name.Equals("minEndSpeed")) emitter.MinEndSpeed = float.Parse(info.InnerText); if (info.Name.Equals("maxEndSpeed")) emitter.MinStartSpeed = float.Parse(info.InnerText); if (info.Name.Equals("minStartColor")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MinStartColor = new Vector4( float.Parse(component[0]), float.Parse(component[1]), float.Parse(component[2]), float.Parse(component[3])); } if (info.Name.Equals("maxStartColor")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MaxStartColor = new Vector4( float.Parse(component[0]), float.Parse(component[1]), float.Parse(component[2]), float.Parse(component[3])); } if (info.Name.Equals("minEndColor")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MinEndColor = new Vector4( float.Parse(component[0]), float.Parse(component[1]), float.Parse(component[2]), float.Parse(component[3])); } if (info.Name.Equals("maxEndColor")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MaxEndColor = new Vector4( float.Parse(component[0]), float.Parse(component[1]), float.Parse(component[2]), float.Parse(component[3])); } if (info.Name.Equals("minStartSize")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MinStartSize = new Vector2( float.Parse(component[0]), float.Parse(component[1])); } if (info.Name.Equals("maxStartSize")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MaxStartSize = new Vector2( float.Parse(component[0]), float.Parse(component[1])); } if (info.Name.Equals("minEndSize")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MinEndSize = new Vector2( float.Parse(component[0]), float.Parse(component[1])); } if (info.Name.Equals("maxEndSize")) { String[] component = info.InnerText.TrimStart('(').TrimEnd(')').Split(','); emitter.MaxEndSize = new Vector2( float.Parse(component[0]), float.Parse(component[1])); } } ret.EmitterInfoList.Add(emitter); } return ret; } } }