Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="resourcePath">texture resource path</param>
        /// <param name="info">particle information structure</param>
        /// <param name="textureSequence">texture sequence class</param>
        public Particle(string resourcePath, ParticleInfo info, 
                        TextureSequence textureSequence) : base()
        {
            if (String.IsNullOrEmpty(resourcePath))
                throw new ArgumentNullException("resourcePath");
            if (info == null)
                throw new ArgumentNullException("info");

            this.sequenceInfo = info;            

            this.textureSequence = textureSequence;
            this.resourcePath = resourcePath;

            //  Create particle's scene root
            this.sceneRoot = new GameSceneNode();
            this.sceneRoot.Name = "Particle Scene Root";

            AddChild(this.sceneRoot);

            Create();
        }
        private ParticleInfo ReadParticleInfo()
        {
            ParticleInfo particleInfo = new ParticleInfo();

            particleInfo.Name         = input.ReadString();
            particleInfo.ParticleType =
                (ParticleInfo.ParticleObjectType)input.ReadInt32();

            // read a MeshData structure.
            if (input.ReadBoolean())
            {
                particleInfo.MeshData = ReadMeshData();
            }

            particleInfo.TextureFileName    = input.ReadString();
            particleInfo.AlphaBlendEnable   = input.ReadBoolean();
            particleInfo.DepthBufferEnable  = input.ReadBoolean();
            particleInfo.SourceBlend        = (Blend)input.ReadInt32();
            particleInfo.DestinationBlend   = (Blend)input.ReadInt32();
            particleInfo.BlendFunction      = (BlendFunction)input.ReadInt32();
            particleInfo.LifeTime           = input.ReadSingle();
            particleInfo.ObjectLifeTime     = input.ReadSingle();
            particleInfo.MassMin            = input.ReadSingle();
            particleInfo.MassMax            = input.ReadSingle();
            particleInfo.InitialObjectCount = input.ReadInt32();
            particleInfo.MaxObjectCount     = input.ReadInt32();
            particleInfo.EmitCount          = input.ReadInt32();
            particleInfo.Volatile           = input.ReadBoolean();

            particleInfo.EmitType      = (ParticleInfo.EmitObjectType)input.ReadInt32();
            particleInfo.EmitPosition  = input.ReadVector3();
            particleInfo.EmitDirection = input.ReadVector3();
            particleInfo.EmitAngle     = input.ReadSingle();
            particleInfo.EmitInterval  = input.ReadSingle();
            particleInfo.UpVector      = input.ReadVector3();

            /////////////////////////////////////////// Position
            particleInfo.PositionStyle          = input.ReadUInt32();
            particleInfo.PositionUpdateInterval = input.ReadSingle();

            // read PositionFunc structures.
            int positionFuncCount = input.ReadInt32();

            if (positionFuncCount > 0)
            {
                particleInfo.PositionFunc = new List <ParticleInfo.FuncType>();

                for (int i = 0; i < positionFuncCount; i++)
                {
                    particleInfo.PositionFunc.Add(
                        (ParticleInfo.FuncType)input.ReadInt32());
                }
            }

            // read PositionInit structures.
            int positionInitCount = input.ReadInt32();

            if (positionInitCount > 0)
            {
                particleInfo.PositionInit = new List <float>();

                for (int i = 0; i < positionInitCount; i++)
                {
                    particleInfo.PositionInit.Add(input.ReadSingle());
                }
            }

            // read PositionFactor structures.
            int positionFactorCount = input.ReadInt32();

            if (positionFactorCount > 0)
            {
                particleInfo.PositionFactor = new List <float>();

                for (int i = 0; i < positionFactorCount; i++)
                {
                    particleInfo.PositionFactor.Add(input.ReadSingle());
                }
            }

            // read PositionTable structures.
            int positionTableCount = input.ReadInt32();

            if (positionTableCount > 0)
            {
                particleInfo.PositionTable = new List <KeyFrameTable>();

                for (int i = 0; i < positionTableCount; i++)
                {
                    particleInfo.PositionTable.Add(ReadKeyFrameTable());
                }
            }

            particleInfo.PositionMin = input.ReadSingle();
            particleInfo.PositionMax = input.ReadSingle();
            particleInfo.PositionInitialRandomFactor = input.ReadSingle();
            particleInfo.PositionRandomFactor        = input.ReadVector3();
            particleInfo.PositionRandomInterval      = input.ReadSingle();

            /////////////////////////////////////////// Scale
            particleInfo.ScaleStyle          = input.ReadUInt32();
            particleInfo.ScaleUpdateInterval = input.ReadSingle();

            // read ScaleFunc structures.
            int scaleFuncCount = input.ReadInt32();

            if (scaleFuncCount > 0)
            {
                particleInfo.ScaleFunc = new List <ParticleInfo.FuncType>();

                for (int i = 0; i < scaleFuncCount; i++)
                {
                    particleInfo.ScaleFunc.Add((ParticleInfo.FuncType)input.ReadInt32());
                }
            }

            // read ScaleInit structures.
            int scaleInitCount = input.ReadInt32();

            if (scaleInitCount > 0)
            {
                particleInfo.ScaleInit = new List <float>();

                for (int i = 0; i < scaleInitCount; i++)
                {
                    particleInfo.ScaleInit.Add(input.ReadSingle());
                }
            }

            // read ScaleFactor structures.
            int scaleFactorCount = input.ReadInt32();

            if (scaleFactorCount > 0)
            {
                particleInfo.ScaleFactor = new List <float>();

                for (int i = 0; i < scaleFactorCount; i++)
                {
                    particleInfo.ScaleFactor.Add(input.ReadSingle());
                }
            }

            // read ScaleTable structures.
            int scaleTableCount = input.ReadInt32();

            if (scaleTableCount > 0)
            {
                particleInfo.ScaleTable = new List <KeyFrameTable>();

                for (int i = 0; i < scaleTableCount; i++)
                {
                    particleInfo.ScaleTable.Add(ReadKeyFrameTable());
                }
            }

            particleInfo.ScaleInitialRandomFactor = input.ReadSingle();
            particleInfo.ScaleMin             = input.ReadSingle();
            particleInfo.ScaleMax             = input.ReadSingle();
            particleInfo.ScaleMask            = input.ReadVector3();
            particleInfo.ScaleBillboardFactor = input.ReadSingle();

            /////////////////////////////////////////// Rotate
            particleInfo.RotateStyle          = input.ReadUInt32();
            particleInfo.RotateUpdateInterval = input.ReadSingle();
            particleInfo.RotateRandomFactor   = input.ReadSingle();
            particleInfo.RotateFunc           = (ParticleInfo.FuncType)input.ReadInt32();
            particleInfo.RotateInit           = input.ReadSingle();
            particleInfo.RotateFactor         = input.ReadSingle();

            // read RotateTable structures.
            if (input.ReadInt32() > 0)
            {
                particleInfo.RotateTable = ReadKeyFrameTable();
            }

            /////////////////////////////////////////// Color
            particleInfo.ColorStyle          = input.ReadUInt32();
            particleInfo.ColorUpdateInterval = input.ReadSingle();
            particleInfo.RgbFunc             = (ParticleInfo.FuncType)input.ReadInt32();
            particleInfo.RgbInit             = input.ReadString();

            // read Rtable structures.
            if (input.ReadInt32() > 0)
            {
                particleInfo.Rtable = ReadKeyFrameTable();
            }

            // read Gtable structures.
            if (input.ReadInt32() > 0)
            {
                particleInfo.Gtable = ReadKeyFrameTable();
            }

            // read Btable structures.
            if (input.ReadInt32() > 0)
            {
                particleInfo.Btable = ReadKeyFrameTable();
            }

            // read Atable structures.
            if (input.ReadInt32() > 0)
            {
                particleInfo.Atable = ReadKeyFrameTable();
            }

            particleInfo.AlphaFunc = (ParticleInfo.FuncType)input.ReadInt32();
            particleInfo.AlphaInit = input.ReadUInt32();

            return(particleInfo);
        }