コード例 #1
0
ファイル: BlendLoader.cs プロジェクト: yazici/BlendReader
 public _StructureDeclBoolTuple(_StructureDecl item1, bool item2)
 {
     Item1 = item1;
     Item2 = item2;
 }
コード例 #2
0
ファイル: BlendLoader.cs プロジェクト: yazici/BlendReader
        private static List <_StructureDecl> _ReadDna1Block(ReadValueContext context)
        {
            var declList = new List <_StructureDecl>();
            var header   = BlendStructures.GlobalHeader.ReadValue(context);

            if (header.GetMember("pointer_size").GetRawValue <char>() == '_')
            {
                throw new BlenderException("32bit pointer-size is unsupported");
            }

            if (header.GetMember("endianness").GetRawValue <char>() == 'V')
            {
                throw new BlenderException("big endian is unsupported");
            }

            while (true)
            {
                var fileBlock = BlendStructures.FileBlockHeader.ReadValue(context);
                var code      = fileBlock.GetMember("code").GetAllValueAsString();
                int size      = fileBlock.GetMember("size").GetRawValue <int>();

                if (code == "DNA1")
                {
                    context.reader.ReadBytes(4);                    // SDNA
                    context.reader.ReadBytes(4);                    // NAME

                    int nameCount     = context.reader.ReadInt32();
                    var names         = new string[nameCount];
                    int readByteCount = 0;
                    for (int index = 0; index < nameCount; ++index)
                    {
                        string s = BinaryUtil.ReadAsciiString(context.reader);
                        names[index]   = s;
                        readByteCount += (s.Length + 1);
                    }

                    context.reader.ReadBytes(readByteCount * 3 % 4); // align
                    context.reader.ReadBytes(4);                     // TYPE

                    int typeCount = context.reader.ReadInt32();
                    readByteCount = 0;
                    var types = new string[typeCount];
                    for (int index = 0; index < typeCount; ++index)
                    {
                        string s = BinaryUtil.ReadAsciiString(context.reader);
                        types[index]   = s;
                        readByteCount += (s.Length + 1);
                    }

                    context.reader.ReadBytes(readByteCount * 3 % 4); // align
                    context.reader.ReadBytes(4);                     // TLEN

                    readByteCount = 0;
                    var tLens = new int[typeCount];
                    for (int index = 0; index < typeCount; ++index)
                    {
                        int len = context.reader.ReadUInt16();
                        tLens[index]   = len;
                        readByteCount += 2;
                    }

                    context.reader.ReadBytes(readByteCount * 3 % 4); // align
                    context.reader.ReadBytes(4);                     // STRC

                    int structCount = context.reader.ReadInt32();
                    readByteCount = 0;
                    for (int index = 0; index < structCount; ++index)
                    {
                        var decl = new _StructureDecl();

                        int typeIndex = context.reader.ReadInt16();
                        decl.name      = types[typeIndex];
                        decl.sdnaIndex = index;
                        decl.size      = tLens[typeIndex];

                        int fieldCount = context.reader.ReadInt16();
                        decl.fieldTypes   = new string[fieldCount];
                        decl.fieldLengths = new int[fieldCount];
                        decl.fieldNames   = new string[fieldCount];
                        for (int fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex)
                        {
                            int fieldTypeIndex = context.reader.ReadInt16();
                            int fieldNameIndex = context.reader.ReadInt16();

                            decl.fieldTypes[fieldIndex]   = types[fieldTypeIndex];
                            decl.fieldLengths[fieldIndex] = tLens[fieldTypeIndex];
                            decl.fieldNames[fieldIndex]   = names[fieldNameIndex];
                        }

                        declList.Add(decl);
                    }
                }
                else if (code == "ENDB")
                {
                    // END
                    break;
                }
                else
                {
                    // Skip
                    context.reader.ReadBytes(size);
                }
            }

            return(declList);
        }