예제 #1
0
파일: Mesh.cs 프로젝트: jhurliman/simian
        public void StoreRenderingMesh(ulong meshKey, DetailLevel lod, RenderingMesh mesh)
        {
            UUID   dataID      = new UUID(meshKey);
            string contentType = RENDER_MESH_BASE_CONTENT_TYPE + "-" + lod.ToString().ToLower();

            byte[] data = mesh.Serialize();

            m_dataStore.AddOrUpdateAsset(dataID, contentType, data, true);
        }
예제 #2
0
파일: Mesh.cs 프로젝트: jhurliman/simian
        public static RenderingMesh Deserialize(byte[] data)
        {
            int pos = 0;

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

            pos += 2;

            RenderingMesh mesh = new RenderingMesh();

            mesh.Faces = new Face[faceCount];

            for (int i = 0; i < faceCount; i++)
            {
                Face face = new Face();

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

                face.Vertices = new Vertex[vertexCount];
                for (int j = 0; j < vertexCount; j++)
                {
                    Vertex v = new Vertex();

                    v.Position = new Vector3(data, pos);
                    pos       += 12;

                    v.Normal = new Vector3(data, pos);
                    pos     += 12;

                    v.TexCoord = new Vector2(Utils.BytesToFloat(data, pos), Utils.BytesToFloat(data, pos + 4));
                    pos       += 8;

                    face.Vertices[j] = v;
                }

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

                face.Indices = new ushort[indexCount];
                Buffer.BlockCopy(data, pos, face.Indices, 0, indexCount * 2);
                pos += indexCount * 2;

                mesh.Faces[i] = face;
            }

            return(mesh);
        }
예제 #3
0
파일: Mesh.cs 프로젝트: jhurliman/simian
        public bool TryGetRenderingMesh(ulong meshKey, DetailLevel lod, out RenderingMesh mesh)
        {
            UUID   dataID      = new UUID(meshKey);
            string contentType = RENDER_MESH_BASE_CONTENT_TYPE + "-" + LOD_NAMES[(int)lod];

            mesh = null;

            byte[] meshData;
            if (m_dataStore.TryGetAsset(dataID, contentType, out meshData))
            {
                try
                {
                    mesh = RenderingMesh.Deserialize(meshData);
                }
                catch (Exception ex)
                {
                    m_log.WarnFormat("Failed to deserialize rendering mesh {0} ({1}): {2}", dataID, contentType, ex.Message);
                }
            }

            return(mesh != null);
        }
예제 #4
0
        public static RenderingMesh Deserialize(byte[] data)
        {
            int pos = 0;

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

            RenderingMesh mesh = new RenderingMesh();
            mesh.Faces = new Face[faceCount];

            for (int i = 0; i < faceCount; i++)
            {
                Face face = new Face();

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

                face.Vertices = new Vertex[vertexCount];
                for (int j = 0; j < vertexCount; j++)
                {
                    Vertex v = new Vertex();

                    v.Position = new Vector3(data, pos);
                    pos += 12;

                    v.Normal = new Vector3(data, pos);
                    pos += 12;

                    v.TexCoord = new Vector2(Utils.BytesToFloat(data, pos), Utils.BytesToFloat(data, pos + 4));
                    pos += 8;

                    face.Vertices[j] = v;
                }

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

                face.Indices = new ushort[indexCount];
                Buffer.BlockCopy(data, pos, face.Indices, 0, indexCount * sizeof(ushort));
                pos += indexCount * sizeof(ushort);

                mesh.Faces[i] = face;
            }

            return mesh;
        }
예제 #5
0
        public bool TryGetRenderingMesh(ulong meshKey, DetailLevel lod, out RenderingMesh mesh)
        {
            UUID dataID = new UUID(meshKey);
            string contentType = MESH_BASE_CONTENT_TYPE + "-" + lod.ToString().ToLower();

            mesh = null;

            byte[] meshData;
            if (m_dataStore.TryGetAsset(dataID, contentType, out meshData))
            {
                try
                {
                    mesh = RenderingMesh.Deserialize(meshData);
                }
                catch (Exception ex)
                {
                    m_log.WarnFormat("Failed to deserialize mesh {0} ({1}): {2}", dataID, contentType, ex.Message);
                }
            }

            return (mesh != null);
        }
예제 #6
0
        public void StoreRenderingMesh(ulong meshKey, DetailLevel lod, RenderingMesh mesh)
        {
            UUID dataID = new UUID(meshKey);
            string contentType = MESH_BASE_CONTENT_TYPE + "-" + lod.ToString().ToLower();
            byte[] data = mesh.Serialize();

            m_dataStore.AddOrUpdateAsset(dataID, contentType, data, true);
        }
예제 #7
0
파일: MeshTests.cs 프로젝트: thoys/simian
        public void RenderingMeshSerializationTest()
        {
            const int FACES = 13;
            const int MAX_VERTICES = 499;
            const int MAX_INDICES = 1009;

            RenderingMesh mesh = new RenderingMesh();
            mesh.Faces = new RenderingMesh.Face[FACES];

            for (int i = 0; i < FACES; i++)
            {
                RenderingMesh.Face face = new RenderingMesh.Face();
                face.Vertices = new Vertex[m_rng.Next(MAX_VERTICES)];
                for (int j = 0; j < face.Vertices.Length; j++)
                    face.Vertices[j] = new Vertex { Normal = RandomVector(), Position = RandomVector(), TexCoord = new Vector2(0.5f, 0.5f) };

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

                mesh.Faces[i] = face;
            }

            byte[] data = mesh.Serialize();

            RenderingMesh mesh2 = RenderingMesh.Deserialize(data);

            Assert.AreEqual(mesh.Faces.Length, mesh2.Faces.Length);

            for (int i = 0; i < mesh.Faces.Length; i++)
            {
                RenderingMesh.Face face = mesh.Faces[i];
                RenderingMesh.Face face2 = mesh2.Faces[i];

                Assert.AreEqual(face.Vertices.Length, face2.Vertices.Length);
                Assert.AreEqual(face.Indices.Length, face2.Indices.Length);

                for (int j = 0; j < face.Vertices.Length; j++)
                {
                    Vertex v = face.Vertices[j];
                    Vertex v2 = face2.Vertices[j];

                    Assert.AreEqual(v.Position, v2.Position);
                    Assert.AreEqual(v.Normal, v2.Normal);
                    Assert.AreEqual(v.TexCoord, v2.TexCoord);
                }

                for (int j = 0; j < face.Indices.Length; j++)
                    Assert.AreEqual(face.Indices[j], face2.Indices[j]);
            }
        }