Exemplo n.º 1
0
        public void ConvexHullSetSerializationTest()
        {
            const int HULLS = 13;
            const int MAX_VERTICES = 499;
            const int MAX_INDICES = 1009;

            ConvexHullSet hullSet = new ConvexHullSet();
            hullSet.Volume = 42f;
            hullSet.Parts = new ConvexHullSet.HullPart[HULLS];

            for (int i = 0; i < HULLS; i++)
            {
                ConvexHullSet.HullPart part = new ConvexHullSet.HullPart();
                part.Offset = RandomVector();

                part.Vertices = new Vector3[m_rng.Next(MAX_VERTICES)];
                for (int j = 0; j < part.Vertices.Length; j++)
                    part.Vertices[j] = RandomVector();

                part.Indices = new int[m_rng.Next(MAX_INDICES)];
                for (int j = 0; j < part.Indices.Length; j++)
                    part.Indices[j] = m_rng.Next(part.Vertices.Length);

                hullSet.Parts[i] = part;
            }

            byte[] data = hullSet.Serialize();

            ConvexHullSet hullSet2 = ConvexHullSet.Deserialize(data);

            Assert.AreEqual(hullSet.Volume, hullSet2.Volume);
            Assert.AreEqual(hullSet.Parts.Length, hullSet2.Parts.Length);

            for (int i = 0; i < hullSet.Parts.Length; i++)
            {
                ConvexHullSet.HullPart part = hullSet.Parts[i];
                ConvexHullSet.HullPart part2 = hullSet2.Parts[i];

                Assert.AreEqual(part.Offset, part2.Offset);
                Assert.AreEqual(part.Vertices.Length, part2.Vertices.Length);
                Assert.AreEqual(part.Indices.Length, part2.Indices.Length);

                for (int j = 0; j < part.Vertices.Length; j++)
                {
                    Vector3 v = part.Vertices[j];
                    Vector3 v2 = part2.Vertices[j];

                    Assert.AreEqual(v, v2);
                }

                for (int j = 0; j < part.Indices.Length; j++)
                {
                    int idx = part.Indices[j];
                    int idx2 = part2.Indices[j];

                    Assert.AreEqual(idx, idx2);
                }
            }
        }
Exemplo n.º 2
0
        public void StoreConvexHullSet(ulong meshKey, DetailLevel lod, ConvexHullSet hullSet)
        {
            UUID   dataID      = new UUID(meshKey);
            string contentType = CONVEX_HULL_BASE_CONTENT_TYPE + "-" + lod.ToString().ToLower();

            byte[] data = hullSet.Serialize();

            m_dataStore.AddOrUpdateAsset(dataID, contentType, data, true);
        }
Exemplo n.º 3
0
        public static ConvexHullSet Deserialize(byte[] data)
        {
            int pos = 0;

            ConvexHullSet hullSet = new ConvexHullSet();

            hullSet.Volume = Utils.BytesToFloat(data, pos);
            pos           += 4;

            ushort partCount = Utils.BytesToUInt16(data, pos);

            pos += 2;

            hullSet.Parts = new HullPart[partCount];

            for (int i = 0; i < partCount; i++)
            {
                HullPart part = new HullPart();

                part.Offset = new Vector3(data, pos);
                pos        += 12;

                ushort vertexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Vertices = new Vector3[vertexCount];
                for (int j = 0; j < vertexCount; j++)
                {
                    Vector3 v = new Vector3(data, pos);
                    pos += 12;

                    part.Vertices[j] = v;
                }

                ushort indexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Indices = new int[indexCount];
                for (int j = 0; j < indexCount; j++)
                {
                    ushort index = Utils.BytesToUInt16(data, pos);
                    pos += 2;

                    part.Indices[j] = index;
                }

                hullSet.Parts[i] = part;
            }

            return(hullSet);
        }
Exemplo n.º 4
0
        public bool TryGetConvexHullSet(ulong meshKey, DetailLevel lod, out ConvexHullSet hullSet)
        {
            UUID   dataID      = new UUID(meshKey);
            string contentType = CONVEX_HULL_BASE_CONTENT_TYPE + "-" + LOD_NAMES[(int)lod];

            hullSet = null;

            byte[] hullData;
            if (m_dataStore.TryGetAsset(dataID, contentType, out hullData))
            {
                try
                {
                    hullSet = ConvexHullSet.Deserialize(hullData);
                }
                catch (Exception ex)
                {
                    m_log.WarnFormat("Failed to deserialize convex hull set {0} ({1}): {2}", dataID, contentType, ex.Message);
                }
            }

            return(hullSet != null);
        }
Exemplo n.º 5
0
Arquivo: Mesh.cs Projeto: thoys/simian
        public bool TryGetConvexHullSet(ulong meshKey, DetailLevel lod, out ConvexHullSet hullSet)
        {
            UUID dataID = new UUID(meshKey);
            string contentType = CONVEX_HULL_BASE_CONTENT_TYPE + "-" + LOD_NAMES[(int)lod];

            hullSet = null;

            byte[] hullData;
            if (m_dataStore.TryGetAsset(dataID, contentType, out hullData))
            {
                try
                {
                    hullSet = ConvexHullSet.Deserialize(hullData);
                }
                catch (Exception ex)
                {
                    m_log.WarnFormat("Failed to deserialize convex hull set {0} ({1}): {2}", dataID, contentType, ex.Message);
                }
            }

            return (hullSet != null);
        }
Exemplo n.º 6
0
Arquivo: Mesh.cs Projeto: thoys/simian
        public void StoreConvexHullSet(ulong meshKey, DetailLevel lod, ConvexHullSet hullSet)
        {
            UUID dataID = new UUID(meshKey);
            string contentType = CONVEX_HULL_BASE_CONTENT_TYPE + "-" + lod.ToString().ToLower();
            byte[] data = hullSet.Serialize();

            m_dataStore.AddOrUpdateAsset(dataID, contentType, data, true);
        }
Exemplo n.º 7
0
Arquivo: Mesh.cs Projeto: thoys/simian
        public static ConvexHullSet Deserialize(byte[] data)
        {
            int pos = 0;

            ConvexHullSet hullSet = new ConvexHullSet();
            hullSet.Volume = Utils.BytesToFloat(data, pos);
            pos += 4;

            ushort partCount = Utils.BytesToUInt16(data, pos);
            pos += 2;

            hullSet.Parts = new HullPart[partCount];

            for (int i = 0; i < partCount; i++)
            {
                HullPart part = new HullPart();

                part.Offset = new Vector3(data, pos);
                pos += 12;

                ushort vertexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Vertices = new Vector3[vertexCount];
                for (int j = 0; j < vertexCount; j++)
                {
                    Vector3 v = new Vector3(data, pos);
                    pos += 12;

                    part.Vertices[j] = v;
                }

                ushort indexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Indices = new int[indexCount];
                for (int j = 0; j < indexCount; j++)
                {
                    ushort index = Utils.BytesToUInt16(data, pos);
                    pos += 2;

                    part.Indices[j] = index;
                }

                hullSet.Parts[i] = part;
            }

            return hullSet;
        }