Пример #1
0
        void ProcessTexMapChunk( ThreeDSChunk chunk, Material m )
        {
            while ( chunk.BytesRead < chunk.Length )
            {
                ThreeDSChunk child = new ThreeDSChunk ( reader );
                switch ((Groups) child.ID)
                {
                    case Groups.C_MATMAPFILE:

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

                        // use System.Drawing to try and load this image

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

                        // Flip image (needed so texture is 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 );
                        break;

                }
                chunk.BytesRead += child.BytesRead;
            }
        }
Пример #2
0
        void ProcessMaterialChunk( ThreeDSChunk chunk )
        {
            string name = string.Empty;
            Material m = new Material ();

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

                switch ((Groups) child.ID)
                {
                    case Groups.C_MATNAME:

                        name = ProcessString ( child );

                        break;

                    case Groups.C_MATAMBIENT:

                        m.Ambient = ProcessColorChunk ( child );
                        break;

                    case Groups.C_MATDIFFUSE:

                        m.Diffuse = ProcessColorChunk ( child );
                        break;

                    case Groups.C_MATSPECULAR:

                        m.Specular = ProcessColorChunk ( child );
                        break;

                    case Groups.C_MATSHININESS:

                        m.Shininess = ProcessPercentageChunk ( child );

                        break;

                    case Groups.C_MATMAP:

                        ProcessPercentageChunk ( child );

                        ProcessTexMapChunk ( child , m );

                        break;

                    default:

                        SkipChunk ( child );
                        break;

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