예제 #1
0
        UV[] GetUVs(BinaryReader binReader)
        {
            UInt32 size = binReader.ReadUInt32() / (uint)Marshal.SizeOf(typeof(UV));

            UV[] uv = new UV[size];
            FileTools.BinaryToArray <UV>(binReader, uv);
            return(uv);
        }
예제 #2
0
        Triangle[] GetTriangles(BinaryReader binReader)
        {
            UInt32 size = binReader.ReadUInt32() / (uint)Marshal.SizeOf(typeof(Triangle));

            Triangle[] triangle = new Triangle[size];
            binReader.ReadBytes(12); // nulls
            FileTools.BinaryToArray <Triangle>(binReader, triangle);
            return(triangle);
        }
예제 #3
0
        public Model(byte[] buffer, string modelId)
        {
            MemoryStream memStream = new MemoryStream(buffer);
            BinaryReader binReader = new BinaryReader(memStream);

            Id        = modelId;
            _index    = new List <Index>();
            _indexMap = new List <Table>();
            _geometry = new List <Geometry>();

            type         = binReader.ReadInt32();
            minorVersion = binReader.ReadInt32();
            majorVersion = binReader.ReadInt32();

            fileStructure = new Table[binReader.ReadInt32()];
            FileTools.BinaryToArray <Table>(binReader, fileStructure);

            foreach (Table structure in fileStructure)
            {
                switch (structure.id)
                {
                case (uint)Structure.UnitIndex:
                    _index.Add(GetIndex(binReader));
                    break;

                case (uint)Structure.Geometry:
                    _geometry.Add(GetGeometry(binReader));
                    break;

                case (uint)Structure.Reserved:    // skip this for now
                    binReader.ReadBytes((int)structure.size);
                    //reserved = GetReserved(binReader);
                    break;

                case (uint)Structure.Footer:
                    _footer = GetFooter(binReader);
                    break;
                }
            }
            binReader.ReadBytes(8); // this should bring to EOF
            binReader.Close();
            memStream.Close();
        }
예제 #4
0
        Coordinate[] GetCoordinates(BinaryReader binReader, Detail detail)
        {
            UInt32 size;

            Coordinate[] coordinate;
            switch (detail)
            {
            case Detail.Simple:
            case Detail.Extended:
                size       = binReader.ReadUInt32() / (uint)Marshal.SizeOf(typeof(Coordinate));
                coordinate = new Coordinate[size];
                FileTools.BinaryToArray <Coordinate>(binReader, coordinate);
                return(coordinate);

            case Detail.Full:
                size       = binReader.ReadUInt32() / (uint)Marshal.SizeOf(typeof(Extended));
                coordinate = new Extended[size];
                FileTools.BinaryToArray <Extended>(binReader, (Extended[])coordinate);
                return(coordinate);

            default:
                return(null);
            }
        }