Beispiel #1
0
        public string ToSpec(string partSysName)
        {
            var cols = new object[ColCount];

            cols[ColPartsysName] = partSysName;
            cols[ColEmitterName] = Name;

            // Lifetime + Particle Count
            cols[ColDelay] = DelaySecs;

            cols[ColBounce] = 0; // Unused but this is used in the vanilla files

            if (Permanent)
            {
                cols[ColLifespan] = "perm";
            }
            else
            {
                cols[ColLifespan] = LifespanSecs;
            }

            if (ParticlesPermanent)
            {
                cols[ColPartLifespan] = "perm";
            }
            else
            {
                cols[ColPartLifespan] = ParticleLifespan;
            }

            cols[ColParticleRate] = ParticlesPerSec;

            // Emit type is not actually used and seems to be Point
            cols[ColEmitType]     = "Point";
            cols[ColParticleType] = ParticleType;

            cols[ColMaterial] = Material;

            cols[ColEmitterSpace] = EmitterSpaceHelper.ToString(Space);

            cols[ColEmitterNodeName] = NodeName;

            cols[ColEmitterCoordSys]       = CoordSysHelper.ToString(CoordSys);
            cols[ColEmitterOffsetCoordSys] = CoordSysHelper.ToString(OffsetCoordSys);
            cols[ColParticleSpace]         = ParticleSpaceHelper.ToString(ParticleSpace);

            cols[ColParticlePosCoordSys]      = CoordSysHelper.ToString(ParticlePosCoordSys);
            cols[ColParticleVelocityCoordSys] = CoordSysHelper.ToString(ParticleVelocityCoordSys);

            cols[ColBlendMode] = BlendModeHelper.ToString(BlendMode);
            cols[ColModel]     = Model;

            cols[ColBbLeft]   = BoundingBoxLeft;
            cols[ColBbTop]    = BoundingBoxTop;
            cols[ColBbRight]  = BoundingBoxRight;
            cols[ColBbBottom] = BoundingBoxBottom;

            if (MinActiveParticles.HasValue)
            {
                cols[ColMinParticles] = MinActiveParticles;
            }

            foreach (var param in Params)
            {
                if (param != null)
                {
                    cols[ColFirstParam + (int)param.Id] = param.Value;
                }
            }

            return(FormatColumns(cols));
        }
Beispiel #2
0
        public static EmitterSpec Parse(string line)
        {
            var result = new EmitterSpec();

            var cols = line.Split('\t');

            // Sanitize line parts (vertical tabs, spaces)
            for (var i = 0; i < cols.Length; ++i)
            {
                cols[i] = cols[i].Trim(' ', '\v');
            }

            result.Name            = cols[ColEmitterName];
            result.ParticlesPerSec = float.Parse(cols[ColParticleRate], CultureInfo.InvariantCulture);

            result.ParticleType = ParticleTypeHelper.Parse(cols[ColParticleType]);

            if (cols[ColLifespan].Equals("perm", StringComparison.InvariantCultureIgnoreCase))
            {
                result.Permanent = true;
            }
            else
            {
                result.LifespanSecs = float.Parse(cols[ColLifespan]);
            }

            if (cols[ColPartLifespan].Equals("perm", StringComparison.InvariantCultureIgnoreCase))
            {
                result.ParticlesPermanent = true;
            }
            else
            {
                float floatVal;
                if (float.TryParse(cols[ColPartLifespan], out floatVal))
                {
                    result.ParticleLifespan = floatVal;
                }
            }

            result.Material = cols[ColMaterial];

            result.Space    = EmitterSpaceHelper.ParseString(cols[ColEmitterSpace]);
            result.NodeName = cols[ColEmitterNodeName];

            result.CoordSys       = CoordSysHelper.ParseString(cols[ColEmitterCoordSys]);
            result.OffsetCoordSys = CoordSysHelper.ParseString(cols[ColEmitterOffsetCoordSys]);

            result.ParticleSpace            = ParticleSpaceHelper.ParseString(cols[ColParticleSpace]);
            result.ParticlePosCoordSys      = CoordSysHelper.ParseString(cols[ColParticlePosCoordSys]);
            result.ParticleVelocityCoordSys = CoordSysHelper.ParseString(cols[ColParticleVelocityCoordSys]);

            result.BlendMode = BlendModeHelper.ParseString(cols[ColBlendMode]);
            result.Model     = cols[ColModel];

            float bbVal;

            if (float.TryParse(cols[ColBbLeft], out bbVal))
            {
                result.BoundingBoxLeft = bbVal;
            }
            if (float.TryParse(cols[ColBbTop], out bbVal))
            {
                result.BoundingBoxTop = bbVal;
            }
            if (float.TryParse(cols[ColBbRight], out bbVal))
            {
                result.BoundingBoxRight = bbVal;
            }
            if (float.TryParse(cols[ColBbBottom], out bbVal))
            {
                result.BoundingBoxBottom = bbVal;
            }

            int minActiveParts;

            if (int.TryParse(cols[ColMinParticles], out minActiveParts))
            {
                result.MinActiveParticles = minActiveParts;
            }

            // Parse the variable parameters
            foreach (ParamId paramId in Enum.GetValues(typeof(ParamId)))
            {
                var col   = ColFirstParam + (int)paramId;
                var param = new VariableParamSpec
                {
                    Id    = paramId,
                    Value = cols[col]
                };
                if (!string.IsNullOrWhiteSpace(param.Value))
                {
                    result.Params.Add(param);
                }
            }

            return(result);
        }