示例#1
0
        protected override object LoadData(Stream stream)
        {
            //	We use a binary reader for this data.
            BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII);

            //	Create a scene.
            Scene scene = new Scene();

            //	First, read the header.
            CaligariFileHeader header = new CaligariFileHeader();

            header.Read(reader);

            //	Here we can make sure that it really is a Caligari File.
            if (header.id != "Caligari " || header.dataMode != 'B')
            {
                System.Diagnostics.Debugger.Log(1, "File I/O", "File is not internally compatible.\n");
                return(false);
            }

            //	Now we go through the file, peeping at chunks.
            while (true)
            {
                //	Peep at the next chunk.
                string type = Peep(reader);

                //	Check for every type of chunk.
                if (type == "PolH")
                {
                    //	Read a polygon into the scene.
                    PolygonChunk polyChunk = new PolygonChunk();
                    scene.Polygons.Add((Polygon)polyChunk.Read(reader));
                }
                else if (type == "END ")
                {
                    //	It's the end of the file, so we may as well break.
                    break;
                }
                else
                {
                    //	Well we don't know what type it is, so just read the generic chunk.
                    CaligariChunk chunk = new CaligariChunk();
                    chunk.Read(reader);
                }
            }

            return(scene);
        }
示例#2
0
        protected override object LoadData(Stream stream)
        {
            //	We use a binary reader for this data.
            BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII);

            //	Create a scene.
            Scene scene = new Scene();

            //	First, read the header.
            CaligariFileHeader header = new CaligariFileHeader();
            header.Read(reader);

            //	Here we can make sure that it really is a Caligari File.
            if(header.id != "Caligari " || header.dataMode != 'B')
            {
                System.Diagnostics.Debugger.Log(1, "File I/O", "File is not internally compatible.\n");
                return false;
            }

            //	Now we go through the file, peeping at chunks.
            while(true)
            {
                //	Peep at the next chunk.
                string type = Peep(reader);

                //	Check for every type of chunk.
                if(type == "PolH")
                {
                    //	Read a polygon into the scene.
                    PolygonChunk polyChunk = new PolygonChunk();
                    scene.Polygons.Add((Polygon)polyChunk.Read(reader));
                }
                else if(type == "END ")
                {
                    //	It's the end of the file, so we may as well break.
                    break;
                }
                else
                {
                    //	Well we don't know what type it is, so just read the generic chunk.
                    CaligariChunk chunk = new CaligariChunk();
                    chunk.Read(reader);
                }

            }

            return scene;
        }