/// <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(); } } }
/// <summary> /// Function to send the key frame data to the data chunk. /// </summary> /// <param name="chunk">Chunk to write.</param> void IKeyFrame.ToChunk(GorgonChunkWriter chunk) { chunk.WriteFloat(Time); chunk.WriteBoolean(Value != null); chunk.WriteRectangle(TextureRegion); if (Value == null) { return; } chunk.WriteString(Value.Name); chunk.WriteInt32(Value.Settings.ArrayCount); chunk.Write(Value.Settings.Format); chunk.WriteSize(Value.Settings.Size); chunk.WriteBoolean(Value.Settings.IsTextureCube); chunk.WriteInt32(Value.Settings.MipCount); chunk.WriteInt32(Value.Settings.Multisampling.Count); chunk.WriteInt32(Value.Settings.Multisampling.Quality); }
/// <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(); } }