예제 #1
0
        /// <summary>
        /// Function to save the animation to a stream.
        /// </summary>
        /// <param name="stream">Stream to write the animation into.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        public void Save(Stream stream)
        {
            GorgonDebug.AssertNull(stream, "stream");

            using (var chunk = new GorgonChunkWriter(stream))
            {
                chunk.Begin(GorgonAnimationController <T> .AnimationVersion);

                // Write out animation header data.
                chunk.Begin("ANIMDATA");
                chunk.WriteString(AnimationController.AnimatedObjectType.FullName);
                chunk.WriteString(Name);
                chunk.WriteFloat(Length);
                chunk.WriteBoolean(IsLooped);
                chunk.End();

                // Put out the tracks with the most keys first.
                var activeTracks = from GorgonAnimationTrack <T> track in Tracks
                                   where track.KeyFrames.Count > 0
                                   orderby track.KeyFrames.Count
                                   select track;

                foreach (var track in activeTracks)
                {
                    if (track.KeyFrames.Count <= 0)
                    {
                        continue;
                    }

                    chunk.Begin("TRCKDATA");
                    track.ToChunk(chunk);
                    chunk.End();
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Function to write the brush elements out to a chunked file.
 /// </summary>
 /// <param name="chunk">Chunk writer used to persist the data.</param>
 internal override void Write(GorgonChunkWriter chunk)
 {
     chunk.Begin("BRSHDATA");
     chunk.Write(BrushType);
     chunk.Write(Color);
     chunk.End();
 }
예제 #3
0
 /// <summary>
 /// Function to write the brush elements out to a chunked file.
 /// </summary>
 /// <param name="chunk">Chunk writer used to persist the data.</param>
 internal override void Write(GorgonChunkWriter chunk)
 {
     chunk.Begin("BRSHDATA");
     chunk.Write(BrushType);
     chunk.Write(HatchStyle);
     chunk.Write(ForegroundColor);
     chunk.Write(BackgroundColor);
     chunk.End();
 }
예제 #4
0
        /// <summary>
        /// Function to write the track data to a data chunk.
        /// </summary>
        /// <param name="chunk">Chunk to write.</param>
        internal void ToChunk(GorgonChunkWriter chunk)
        {
            chunk.WriteString(Name);
            chunk.Write(InterpolationMode);

            foreach (IKeyFrame keyFrame in KeyFrames)
            {
                chunk.Begin("KEYFRAME");
                keyFrame.ToChunk(chunk);
                chunk.End();
            }
        }
        /// <summary>
        /// Function to write the brush elements out to a chunked file.
        /// </summary>
        /// <param name="chunk">Chunk writer used to persist the data.</param>
        internal override void Write(GorgonChunkWriter chunk)
        {
            chunk.Begin("BRSHDATA");
            chunk.Write(BrushType);
            chunk.Write(GammaCorrection);
            chunk.Write(Angle);
            chunk.Write(ScaleAngle);

            chunk.Write(Interpolation.Count);

            foreach (GorgonGlyphBrushInterpolator interpolation in Interpolation)
            {
                interpolation.WriteChunk(chunk);
            }

            chunk.End();
        }
        /// <summary>
        /// Function to write the brush elements out to a chunked file.
        /// </summary>
        /// <param name="chunk">Chunk writer used to persist the data.</param>
        internal override void Write(GorgonChunkWriter chunk)
        {
            chunk.Begin("BRSHDATA");
            chunk.Write(BrushType);
            chunk.Write(WrapMode);
            chunk.Write(Points.Count);

            foreach (Vector2 point in Points)
            {
                chunk.Write(point);
            }

            chunk.Write(BlendFactors.Count);

            foreach (float factor in BlendFactors)
            {
                chunk.Write(factor);
            }

            chunk.Write(BlendPositions.Count);

            foreach (float position in BlendPositions)
            {
                chunk.Write(position);
            }

            chunk.Write(CenterColor);
            chunk.Write(CenterPoint);
            chunk.Write(FocusScales);

            chunk.Write(Interpolation.Count);

            foreach (GorgonGlyphBrushInterpolator interpolator in Interpolation)
            {
                interpolator.WriteChunk(chunk);
            }

            chunk.Write(SurroundColors.Count);

            foreach (GorgonColor color in SurroundColors)
            {
                chunk.Write(color);
            }

            chunk.End();
        }
예제 #7
0
        /// <summary>
        /// Function to write the brush elements out to a chunked file.
        /// </summary>
        /// <param name="chunk">Chunk writer used to persist the data.</param>
        internal override void Write(GorgonChunkWriter chunk)
        {
            // We have no texture.
            if (Texture == null)
            {
                return;
            }

            chunk.Begin("BRSHDATA");
            chunk.Write(BrushType);
            chunk.Write(WrapMode);

            chunk.WriteRectangle(TextureRegion);
            chunk.WriteString(_texture.Name);
            chunk.Write(_texture.Settings.Width);
            chunk.Write(_texture.Settings.Height);
            chunk.Write(_texture.Settings.Format);
            chunk.Write(_texture.Settings.ArrayCount);
            chunk.Write(_texture.Settings.MipCount);

            chunk.End();
        }
예제 #8
0
        /// <summary>
        /// Function to save the sprite data into a stream.
        /// </summary>
        /// <param name="stream">Stream that is used to write out the sprite data.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.IO.IOException">Thrown when the stream parameter is not opened for writing data.</exception>
        public void Save(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (!stream.CanWrite)
            {
                throw new IOException(Resources.GOR2D_STREAM_READ_ONLY);
            }

            // Chunk the file.
            using (var chunk = new GorgonChunkWriter(stream))
            {
                // Write anchor information.
                chunk.Begin(FileHeader);

                chunk.Begin("SPRTDATA");
                chunk.Write(Anchor);
                chunk.Write(Size);
                chunk.WriteBoolean(HorizontalFlip);
                chunk.WriteBoolean(VerticalFlip);

                // Write vertex colors.
                for (int i = 0; i < Vertices.Length; i++)
                {
                    chunk.Write(Vertices[i].Color);
                }

                // Write vertex offsets.
                chunk.WriteRange(_offsets);
                chunk.End();

                // Write rendering information.
                chunk.Begin("RNDRDATA");
                chunk.Write(CullingMode);
                chunk.Write(AlphaTestValues);
                chunk.Write(Blending.AlphaOperation);
                chunk.Write(Blending.BlendOperation);
                chunk.Write(Blending.BlendFactor);
                chunk.Write(Blending.DestinationAlphaBlend);
                chunk.Write(Blending.DestinationBlend);
                chunk.Write(Blending.SourceAlphaBlend);
                chunk.Write(Blending.SourceBlend);
                chunk.Write(Blending.WriteMask);
                chunk.Write(DepthStencil.BackFace.ComparisonOperator);
                chunk.Write(DepthStencil.BackFace.DepthFailOperation);
                chunk.Write(DepthStencil.BackFace.FailOperation);
                chunk.Write(DepthStencil.BackFace.PassOperation);
                chunk.Write(DepthStencil.FrontFace.ComparisonOperator);
                chunk.Write(DepthStencil.FrontFace.DepthFailOperation);
                chunk.Write(DepthStencil.FrontFace.FailOperation);
                chunk.Write(DepthStencil.FrontFace.PassOperation);
                chunk.WriteInt32(DepthStencil.DepthBias);
                chunk.Write(DepthStencil.DepthComparison);
                chunk.WriteInt32(DepthStencil.StencilReference);
                chunk.WriteBoolean(DepthStencil.IsDepthWriteEnabled);
                chunk.WriteByte(DepthStencil.StencilReadMask);
                chunk.WriteByte(DepthStencil.StencilWriteMask);
                chunk.End();

                // Write collider information.
                if (_collider != null)
                {
                    chunk.Begin("COLLIDER");
                    _collider.WriteToChunk(chunk);
                    chunk.End();
                }

                // Write texture information.
                if (string.IsNullOrWhiteSpace(DeferredTextureName))
                {
                    return;
                }

                chunk.Begin("TXTRDATA");
                chunk.Write(TextureSampler.BorderColor);
                chunk.Write(TextureSampler.HorizontalWrapping);
                chunk.Write(TextureSampler.VerticalWrapping);
                chunk.Write(TextureSampler.TextureFilter);
                chunk.WriteString(DeferredTextureName);
                chunk.WriteRectangle(TextureRegion);
                chunk.End();
            }
        }