Example #1
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);
            }
        }
Example #2
0
        internal Mesh GetMesh(string checksum, Package package, bool isMain)
        {
            Mesh mesh;
            KeyValuePair <int, object> kvp;

            lock (mutex)
            {
                if (meshes.TryGetValue(checksum, out mesh))
                {
                    meshit++;
                    return(mesh);
                }

                data.TryGetValue(checksum, out kvp);
            }

            MeshObj mo = kvp.Value as MeshObj;

            byte[] bytes;

            if (mo != null)
            {
                mesh             = new Mesh();
                mesh.name        = mo.name;
                mesh.vertices    = mo.vertices;
                mesh.colors      = mo.colors;
                mesh.uv          = mo.uv;
                mesh.normals     = mo.normals;
                mesh.tangents    = mo.tangents;
                mesh.boneWeights = mo.boneWeights;
                mesh.bindposes   = mo.bindposes;

                for (int i = 0; i < mo.triangles.Length; i++)
                {
                    mesh.SetTriangles(mo.triangles[i], i);
                }

                mespre++;
            }
            else if ((bytes = kvp.Value as byte[]) != null)
            {
                mesh = AssetDeserializer.Instantiate(package, bytes, isMain) as Mesh;
                mespre++;
            }
            else
            {
                Package.Asset asset = package.FindByChecksum(checksum);
                mesh = AssetDeserializer.Instantiate(asset, isMain) as Mesh;
                mesload++;
            }

            if (shareMeshes)
            {
                lock (mutex)
                {
                    meshes[checksum] = mesh;

                    if (data.Remove(checksum))
                    {
                        removedCount++;
                    }
                }
            }

            return(mesh);
        }