Пример #1
0
        void DeserializeTextObj(Package.Asset asset, byte[] bytes, int index)
        {
            TextObj to;

            using (MemStream stream = new MemStream(bytes, 0))
                using (MemReader reader = new MemReader(stream))
                {
                    Type t = DeserializeHeader(reader);

                    if (t != typeof(Texture2D) && t != typeof(Image))
                    {
                        throw new IOException("Asset " + asset.fullName + " should be Texture2D or Image");
                    }

                    string name       = reader.ReadString();
                    bool   linear     = reader.ReadBoolean();
                    int    anisoLevel = asset.package.version >= 6 ? reader.ReadInt32() : 1;
                    int    count      = reader.ReadInt32();
                    Image  image      = new Image(reader.ReadBytes(count));
                    byte[] pix        = image.GetAllPixels();

                    to = new TextObj {
                        name   = name, pixels = pix, width = image.width, height = image.height, anisoLevel = anisoLevel,
                        format = image.format, mipmap = image.mipmapCount > 1, linear = linear
                    };

                    // image.Clear(); TODO test
                    image = null;
                }

            lock (mutex)
            {
                data[asset.checksum] = new KeyValuePair <int, object>(index, to);
            }
        }
Пример #2
0
 internal static object Instantiate(Package package, byte[] bytes, bool isMain)
 {
     using (MemStream stream = new MemStream(bytes, 0))
         using (PackageReader reader = new MemReader(stream))
         {
             return(new AssetDeserializer(package, reader, isMain).Deserialize());
         }
 }
Пример #3
0
        void DeserializeMeshObj(Package.Asset asset, byte[] bytes, int index)
        {
            MeshObj mo;

            using (MemStream stream = new MemStream(bytes, 0))
                using (MemReader reader = new MemReader(stream))
                {
                    if (DeserializeHeader(reader) != typeof(Mesh))
                    {
                        throw new IOException("Asset " + asset.fullName + " should be Mesh");
                    }

                    string       name        = reader.ReadString();
                    Vector3[]    vertices    = reader.ReadVector3Array();
                    Color[]      colors      = reader.ReadColorArray();
                    Vector2[]    uv          = reader.ReadVector2Array();
                    Vector3[]    normals     = reader.ReadVector3Array();
                    Vector4[]    tangents    = reader.ReadVector4Array();
                    BoneWeight[] boneWeights = reader.ReadBoneWeightsArray();
                    Matrix4x4[]  bindposes   = reader.ReadMatrix4x4Array();
                    int          count       = reader.ReadInt32();
                    int[][]      triangles   = new int[count][];

                    for (int i = 0; i < count; i++)
                    {
                        triangles[i] = reader.ReadInt32Array();
                    }

                    mo = new MeshObj {
                        name     = name, vertices = vertices, colors = colors, uv = uv, normals = normals,
                        tangents = tangents, boneWeights = boneWeights, bindposes = bindposes, triangles = triangles
                    };
                }

            lock (mutex)
            {
                data[asset.checksum] = new KeyValuePair <int, object>(index, mo);
            }
        }
Пример #4
0
        internal PackageReader GetReader(Stream stream)
        {
            MemStream ms = stream as MemStream;

            return(ms != null ? new MemReader(ms) : new PackageReader(stream));
        }
Пример #5
0
 internal MemReader(MemStream stream) : base(stream)
 {
     this.stream = stream;
 }
Пример #6
0
 protected override void Dispose(bool b)
 {
     stream = null; charBuf = null; base.Dispose(b);
 }