예제 #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
        static Type DeserializeHeader(MemReader reader)
        {
            if (reader.ReadBoolean())
            {
                return(null);
            }

            return(Type.GetType(reader.ReadString()));
        }
예제 #4
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);
            }
        }