コード例 #1
0
ファイル: ReadFiles.cs プロジェクト: gleblebedev/toe
		public void LemarchandsBox()
		{
			var r = new AseReader(StreamConverterFactory.Default);
			using (var s = File.OpenRead("lemarchandsbox.ASE"))
			{
				var scene = r.Load(s, null);
				foreach (var geometry in scene.Geometries)
				{
					var reader = geometry.GetStreamReader<Float3>(Streams.Position, 0);
					var normalReader = geometry.GetStreamReader<Float3>(Streams.Normal, 0);
					var texCoordReader = geometry.GetStreamReader<Float3>(Streams.TexCoord, 0);
					var colorReader = geometry.GetStreamReader<Float3>(Streams.Color, 0);
					//for (int i = 0; i < geometry.Count; ++i)
					//{
					//	Debug.Write(string.Format("{0} ", reader[i]));
					//	if (normalReader != null)
					//	Debug.Write(string.Format("{0} ", normalReader[i]));
					//	if (texCoordReader != null)
					//	Debug.Write(string.Format("{0} ", texCoordReader[i]));
					//	if (colorReader != null)
					//	Debug.Write(string.Format("{0} ", colorReader[i]));
					//	Debug.WriteLine("");
					//}
					foreach (var submesh in geometry.Submeshes)
					{
						var positionIndex = submesh.GetIndexReader(Streams.Position, 0);
						var normalIndex = submesh.GetIndexReader(Streams.Normal, 0);
						var texCoordIndex = submesh.GetIndexReader(Streams.TexCoord, 0);
						var colorIndex = submesh.GetIndexReader(Streams.Color, 0);
						for (int i=0; i<submesh.Count;++i)
						{
							Debug.Write(string.Format("{0} ", positionIndex[i]));
							Debug.Write(string.Format("{0} ", reader[positionIndex[i]]));
							if (normalReader != null)
							{
								Debug.Write(string.Format("{0} ", normalIndex[i]));
								Debug.Write(string.Format("{0} ", normalReader[normalIndex[i]]));
							}
								if (texCoordReader != null)
							{
								Debug.Write(string.Format("{0} ", texCoordIndex[i]));
								Debug.Write(string.Format("{0} ", texCoordReader[texCoordIndex[i]]));
							}
								if (colorReader != null)
								{
									Debug.Write(string.Format("{0} ", colorIndex[i]));
									Debug.Write(string.Format("{0} ", colorReader[colorIndex[i]]));
								}
							Debug.WriteLine("");
						}
					}
				}
			}
		}
コード例 #2
0
ファイル: AseInfo.cs プロジェクト: teeagu/Asemator
        public AseInfo(string path)
        {
            using (FileStream stream = File.OpenRead(path))
            {
                AseReader reader = new AseReader(stream);

                reader.DWord(); // File size

                ushort magicNumber = reader.Word();
                if (magicNumber != 0xA5E0)
                {
                    Debug.LogError("File is not in .ase format");
                }

                frameCount = reader.Word();
                width      = reader.Word();
                height     = reader.Word();

                reader.Word();    // Color depth (asemator only supports RGBA)
                reader.DWord();   // Flags
                reader.Word();    // Speed (deprecated)
                reader.DWord();   // Set be 0
                reader.DWord();   // Set be 0
                reader.Byte();    // Palette entry
                reader.Seek(3);   // Ignore these bytes
                reader.Word();    // Number of colors (0 means 256 for old sprites)
                reader.Byte();    // Pixel width
                reader.Byte();    // Pixel height
                reader.Seek(92);  // For Future

                for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                {
                    Frame frame = new Frame();
                    frame.pixels = new Color[width * height];

                    long frameStart, frameEnd;
                    int  chunkCount;

                    frameStart = reader.Position;
                    frameEnd   = frameStart + reader.DWord(); // Bytes in this frame
                    reader.Word();                            // Magic number (always 0xF1FA)
                    chunkCount     = reader.Word();           // Number of chunks in this frame
                    frame.duration = reader.Word();           // Frame duration in milliseconds
                    reader.Seek(6);                           // For future (set to zero)

                    for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++)
                    {
                        long  chunkStart = reader.BaseStream.Position;
                        long  chunkEnd   = chunkStart + reader.DWord();
                        Chunk chunkType  = (Chunk)reader.Word();

                        switch (chunkType)
                        {
                        case Chunk.Cel: HandleCelChunk(reader, ref frame.pixels); break;

                        case Chunk.Tags: HandleTagChunk(reader); break;
                        }

                        reader.Position = chunkEnd;
                    }

                    frames.Add(frame);
                    reader.Position = frameEnd;
                }
            }
        }