Exemplo n.º 1
0
        void ProcessMaterialChunk(ThreeDSChunk chunk)
        {
            string          name = string.Empty;
            ThreeDSMaterial m    = new ThreeDSMaterial();

            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);

                switch ((ThreeDSChunkType)child.ID)
                {
                case ThreeDSChunkType.MaterialName:

                    name = ProcessString(child);
                    Console.WriteLine("Material: {0}", name);
                    break;

                case ThreeDSChunkType.AmbientColor:

                    m.Ambient = ProcessColorChunk(child);
                    break;

                case ThreeDSChunkType.DiffuseColor:

                    m.Diffuse = ProcessColorChunk(child);
                    break;

                case ThreeDSChunkType.SpecularColor:

                    m.Specular = ProcessColorChunk(child);
                    break;

                case ThreeDSChunkType.C_MATSHININESS:

                    m.Shininess = ProcessPercentageChunk(child);
                    //Console.WriteLine ( "SHININESS: {0}", m.Shininess );
                    break;

                case ThreeDSChunkType.TextureMap:

                    ProcessPercentageChunk(child);

                    //SkipChunk ( child );
                    ProcessTexMapChunk(child, m);

                    break;

                default:

                    SkipChunk(child);
                    break;
                }
                chunk.BytesRead += child.BytesRead;
            }
            materials.Add(name, m);
        }
Exemplo n.º 2
0
        void ProcessTexMapChunk(ThreeDSChunk chunk, ThreeDSMaterial m)
        {
            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);
                switch ((ThreeDSChunkType)child.ID)
                {
                case ThreeDSChunkType.MappingFilename:

                    string name = ProcessString(child);
                    Console.WriteLine("	Texture File: {0}", name);

                    //FileStream fStream;
                    Bitmap bmp;
                    try
                    {
                        //fStream = new FileStream(base_dir + name, FileMode.Open, FileAccess.Read);
                        bmp = new Bitmap(base_dir + name);
                    }
                    catch (Exception e)
                    {
                        // couldn't find the file
                        Console.WriteLine("	ERROR: could not load file '{0}'", base_dir + name);
                        Console.WriteLine(e);
                        break;
                    }

                    // Flip image (needed so texture are the correct way around!)
                    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                    System.Drawing.Imaging.BitmapData imgData = bmp.LockBits(new Rectangle(new Point(0, 0), bmp.Size),
                                                                             System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                                             System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    //								System.Drawing.Imaging.PixelFormat.Format24bppRgb );

                    m.BindTexture(imgData.Width, imgData.Height, imgData.Scan0);

                    bmp.UnlockBits(imgData);
                    bmp.Dispose();

                    /*
                     * BinaryReader br = new BinaryReader(fStream);
                     *
                     * br.ReadBytes ( 14 ); // skip file header
                     *
                     * uint offset = br.ReadUInt32 (  );
                     * //br.ReadBytes ( 4 ); // skip image header
                     * uint biWidth = br.ReadUInt32 ();
                     * uint biHeight = br.ReadUInt32 ();
                     * Console.WriteLine ( "w {0} h {1}", biWidth, biHeight );
                     * br.ReadBytes ( (int) offset - 12  ); // skip rest of image header
                     *
                     * byte[,,] tex = new byte [ biHeight , biWidth , 4 ];
                     *
                     * for ( int ii=0 ; ii <  biHeight ; ii++ )
                     * {
                     *  for ( int jj=0 ; jj < biWidth ; jj++ )
                     *  {
                     *      tex [ ii, jj, 0 ] = br.ReadByte();
                     *      tex [ ii, jj, 1 ] = br.ReadByte();
                     *      tex [ ii, jj, 2 ] = br.ReadByte();
                     *      tex [ ii, jj, 3 ] = 255;
                     *      //Console.Write ( ii + " " );
                     *  }
                     * }
                     *
                     * br.Close();
                     * fStream.Close();
                     * m.BindTexture ( (int) biWidth, (int) biHeight, tex );
                     */
                    break;

                default:

                    SkipChunk(child, (int)(chunk.Length - chunk.BytesRead - child.BytesRead));
                    break;
                }
                chunk.BytesRead += child.BytesRead;
            }
        }
Exemplo n.º 3
0
        void ProcessTexMapChunk(ThreeDSChunk chunk, ThreeDSMaterial m)
        {
            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);
                switch ((ThreeDSChunkType)child.ID)
                {
                    case ThreeDSChunkType.MappingFilename:

                        string name = ProcessString(child);
                        Console.WriteLine("	Texture File: {0}", name);

                        //FileStream fStream;
                        Bitmap bmp;
                        try
                        {
                            //fStream = new FileStream(base_dir + name, FileMode.Open, FileAccess.Read);
                            bmp = new Bitmap(base_dir + name);
                        }
                        catch (Exception e)
                        {
                            // couldn't find the file
                            Console.WriteLine("	ERROR: could not load file '{0}'", base_dir + name);
                            Console.WriteLine(e);
                            break;
                        }

                        // Flip image (needed so texture are the correct way around!)
                        bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                        System.Drawing.Imaging.BitmapData imgData = bmp.LockBits(new Rectangle(new Point(0, 0), bmp.Size),
                                System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        //								System.Drawing.Imaging.PixelFormat.Format24bppRgb ); 

                        m.BindTexture(imgData.Width, imgData.Height, imgData.Scan0);

                        bmp.UnlockBits(imgData);
                        bmp.Dispose();

                        /*
                        BinaryReader br = new BinaryReader(fStream);

                        br.ReadBytes ( 14 ); // skip file header
					
                        uint offset = br.ReadUInt32 (  );
                        //br.ReadBytes ( 4 ); // skip image header
                        uint biWidth = br.ReadUInt32 ();
                        uint biHeight = br.ReadUInt32 ();
                        Console.WriteLine ( "w {0} h {1}", biWidth, biHeight );
                        br.ReadBytes ( (int) offset - 12  ); // skip rest of image header
						
                        byte[,,] tex = new byte [ biHeight , biWidth , 4 ];
						
                        for ( int ii=0 ; ii <  biHeight ; ii++ )
                        {
                            for ( int jj=0 ; jj < biWidth ; jj++ )
                            {
                                tex [ ii, jj, 0 ] = br.ReadByte();
                                tex [ ii, jj, 1 ] = br.ReadByte();
                                tex [ ii, jj, 2 ] = br.ReadByte();
                                tex [ ii, jj, 3 ] = 255;
                                //Console.Write ( ii + " " );
                            }
                        }

                        br.Close();
                        fStream.Close();
                        m.BindTexture ( (int) biWidth, (int) biHeight, tex );
                        */
                        break;

                    default:

                        SkipChunk(child, (int)(chunk.Length - chunk.BytesRead - child.BytesRead));
                        break;

                }
                chunk.BytesRead += child.BytesRead;
            }
        }
Exemplo n.º 4
0
        void ProcessMaterialChunk(ThreeDSChunk chunk)
        {
            string name = string.Empty;
            ThreeDSMaterial m = new ThreeDSMaterial();

            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);

                switch ((ThreeDSChunkType)child.ID)
                {
                    case ThreeDSChunkType.MaterialName:

                        name = ProcessString(child);
                        Console.WriteLine("Material: {0}", name);
                        break;

                    case ThreeDSChunkType.AmbientColor:

                        m.Ambient = ProcessColorChunk(child);
                        break;

                    case ThreeDSChunkType.DiffuseColor:

                        m.Diffuse = ProcessColorChunk(child);
                        break;

                    case ThreeDSChunkType.SpecularColor:

                        m.Specular = ProcessColorChunk(child);
                        break;

                    case ThreeDSChunkType.C_MATSHININESS:

                        m.Shininess = ProcessPercentageChunk(child);
                        //Console.WriteLine ( "SHININESS: {0}", m.Shininess );
                        break;

                    case ThreeDSChunkType.TextureMap:

                        ProcessPercentageChunk(child);

                        //SkipChunk ( child );
                        ProcessTexMapChunk(child, m);

                        break;

                    default:

                        SkipChunk(child);
                        break;
                }
                chunk.BytesRead += child.BytesRead;
            }
            materials.Add(name, m);
        }