示例#1
0
        private static Boolean TryGetNamedMesh(BinaryReader reader,
                                               Double fbxVersion,
                                               FbxNodeMetaData meta,
                                               out NamedMesh mesh)
        {
            var meshName = GetNameFromProperties(reader, meta);

            return(TryGetNamedMesh(reader, meshName, fbxVersion, out mesh));
        }
示例#2
0
        private static FbxNodeMetaData GetNodeMeta64(BinaryReader reader)
        {
            var data = new FbxNodeMetaData(
                reader.ReadInt64(),
                reader.ReadInt64(),
                reader.ReadInt64(),
                reader.ReadByte());

            if (!data.IsValid())
            {
                throw new Exception();
            }

            return(data);
        }
示例#3
0
        private static String GetNameFromProperties(BinaryReader reader,
                                                    FbxNodeMetaData meta)
        {
            String?meshName = null;

            for (var c = 0; c < meta.NumProperties; c++)
            {
                switch (reader.ReadByte())
                {
                case _Double:
                case _Int64:
                    reader.BaseStream.Seek(8, SeekOrigin.Current);
                    break;

                case _Int32:
                case _Single:
                    reader.BaseStream.Seek(4, SeekOrigin.Current);
                    break;

                case _Int16:
                    reader.BaseStream.Seek(2, SeekOrigin.Current);
                    break;

                case _Char:
                    reader.BaseStream.Seek(1, SeekOrigin.Current);
                    break;

                case _String:
                    var len = reader.ReadInt32();
                    if (len == 0)
                    {
                        break;
                    }

                    if (meshName != null)
                    {
                        reader.BaseStream.Seek(len, SeekOrigin.Current);
                    }
                    else
                    {
                        var sb = new StringBuilder();
                        for (var i = 0; i < len; i++)
                        {
                            var current = reader.ReadChar();

                            if (current == '\0')
                            {
                                meshName ??= sb.ToString();
                                //reader.BaseStream.Seek(len - i, SeekOrigin.Current);
                                //break;
                            }
                            else if (meshName == null)
                            {
                                sb.Append(current);
                            }
                        }

                        //meshName = Encoding.ASCII.GetString(reader.ReadBytes(len));
                    }

                    break;

                case _ByteArray:
                    reader.BaseStream.Seek(reader.ReadInt32(), SeekOrigin.Current);
                    break;

                case _BooleanArray:
                    ReadArray(reader, br => br.ReadBoolean());
                    break;

                case _SingleArray:
                    ReadArray(reader, br => br.ReadSingle());
                    break;

                case _DoubleArray:
                    ReadArray(reader, br => br.ReadDouble());
                    break;

                case _IntegerArray:
                    ReadArray(reader, br => br.ReadInt32());
                    break;
                }
            }

            return(meshName ?? throw new MissingFieldException("mesh name"));
        }
示例#4
0
        private static Object[] GetPropertyValues(BinaryReader reader,
                                                  FbxNodeMetaData meta)
        {
            var res = new Object[meta.NumProperties];

            for (var c = 0; c < meta.NumProperties; c++)
            {
                var b = reader.ReadByte();

                switch (b)
                {
                case _Double:
                    res[c] = reader.ReadDouble();
                    break;

                case _Int64:
                    res[c] = reader.ReadInt64();
                    break;

                case _Int32:
                    res[c] = reader.ReadInt32();
                    break;

                case _Single:
                    res[c] = reader.ReadSingle();
                    break;

                case _Int16:
                    res[c] = reader.ReadInt16();
                    break;

                case _Char:
                    res[c] = reader.ReadChar();
                    break;

                case _String:
                    var len = reader.ReadInt32();

                    res[c] = len == 0
                            ? String.Empty
                            : Encoding.ASCII.GetString(reader.ReadBytes(len));
                    break;

                case _ByteArray:
                    res[c] = reader.ReadBytes(reader.ReadInt32());
                    break;

                case _BooleanArray:
                    res[c] = ReadArray(reader, br => br.ReadBoolean());
                    break;

                case _SingleArray:
                    res[c] = ReadArray(reader, br => br.ReadSingle());
                    break;

                case _DoubleArray:
                    res[c] = ReadArray(reader, br => br.ReadDouble());
                    break;

                case _IntegerArray:
                    res[c] = ReadArray(reader, br => br.ReadInt32());
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(res);
        }