Ejemplo n.º 1
0
        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]);
                }
            }
        }
Ejemplo n.º 2
0
        public RenderingMesh GetRenderingMesh(LLPrimitive prim, DetailLevel lod)
        {
            RenderingMesh mesh;
            ulong         physicsKey = prim.GetPhysicsKey();

            // Try a cache lookup first
            if (m_meshCache != null && m_meshCache.TryGetRenderingMesh(physicsKey, lod, out mesh))
            {
                return(mesh);
            }

            // Can't go any further without a prim renderer
            if (m_renderer == null)
            {
                return(null);
            }

            // Convert our DetailLevel to the OpenMetaverse.Rendering DetailLevel
            OpenMetaverse.Rendering.DetailLevel detailLevel;
            switch (lod)
            {
            case DetailLevel.Low:
                detailLevel = OpenMetaverse.Rendering.DetailLevel.Low;
                break;

            case DetailLevel.Medium:
                detailLevel = OpenMetaverse.Rendering.DetailLevel.Medium;
                break;

            case DetailLevel.High:
                detailLevel = OpenMetaverse.Rendering.DetailLevel.High;
                break;

            case DetailLevel.Highest:
            default:
                detailLevel = OpenMetaverse.Rendering.DetailLevel.Highest;
                break;
            }

            FacetedMesh facetedMesh = null;

            if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero)
            {
                // Sculpty meshing
                Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture);
                if (sculptTexture != null)
                {
                    facetedMesh = m_renderer.GenerateFacetedSculptMesh(prim.Prim, sculptTexture, detailLevel);
                }
            }
            else
            {
                // Basic prim meshing
                facetedMesh = m_renderer.GenerateFacetedMesh(prim.Prim, detailLevel);
            }

            if (facetedMesh != null)
            {
                #region FacetedMesh to RenderingMesh Conversion

                mesh       = new RenderingMesh();
                mesh.Faces = new RenderingMesh.Face[facetedMesh.Faces.Count];
                for (int i = 0; i < facetedMesh.Faces.Count; i++)
                {
                    Face face = facetedMesh.Faces[i];

                    Vertex[] vertices = new Vertex[face.Vertices.Count];
                    for (int j = 0; j < face.Vertices.Count; j++)
                    {
                        OpenMetaverse.Rendering.Vertex omvrVertex = face.Vertices[j];
                        vertices[j] = new Vertex {
                            Position = omvrVertex.Position, Normal = omvrVertex.Normal, TexCoord = omvrVertex.TexCoord
                        };
                    }
                    ushort[] indices = face.Indices.ToArray();

                    mesh.Faces[i] = new RenderingMesh.Face {
                        Vertices = vertices, Indices = indices
                    };
                }

                #endregion FacetedMesh to RenderingMesh Conversion

                // Store the result in the mesh cache, if we have one
                if (m_meshCache != null)
                {
                    m_meshCache.StoreRenderingMesh(physicsKey, lod, mesh);
                }

                return(mesh);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        private static RenderingMesh CreateCubeRenderingMesh()
        {
            // Set up the 8 corners of the cube
            RenderingMesh cube = new RenderingMesh();
            cube.Faces = new RenderingMesh.Face[1];
            cube.Faces[0] = new RenderingMesh.Face();
            cube.Faces[0].Vertices = new Vertex[]
            {
                // FIXME: Set normals and UV coords too
                new Vertex() { Position = new Vector3(left, bottom, front) }, // 0
                new Vertex() { Position = new Vector3(right, bottom, front) }, // 1
                new Vertex() { Position = new Vector3(left, top, front) }, // 2
                new Vertex() { Position = new Vector3(right, top, front) }, // 3
                new Vertex() { Position = new Vector3(left, bottom, back) }, // 4
                new Vertex() { Position = new Vector3(right, bottom, back) }, // 5
                new Vertex() { Position = new Vector3(left, top, back) }, // 6
                new Vertex() { Position = new Vector3(right, top, back) }, // 7
            };

            // Set up the index information for the 12 faces
            cube.Faces[0].Indices = new ushort[]
            {
                // Left faces
                lefttopfront,     lefttopback,      leftbottomback,   // 0
                leftbottomback,   leftbottomfront,  lefttopfront,     // 1

                // Front faces
                lefttopfront,     leftbottomfront,  rightbottomfront, // 2
                rightbottomfront, righttopfront,    lefttopfront,     // 3

                // Right faces
                righttopback,     righttopfront,    rightbottomfront, // 4
                rightbottomfront, rightbottomback,  righttopback,     // 5

                // Back faces
                leftbottomback,   lefttopback,      righttopback,     // 6
                righttopback,     rightbottomback,  leftbottomback,   // 7

                // Top faces
                righttopfront,    righttopback,     lefttopback,      // 8
                lefttopback,      lefttopfront,     righttopfront,    // 9

                // Bottom faces
                leftbottomfront,  leftbottomback,   rightbottomback,  // 10
                rightbottomback,  rightbottomfront, leftbottomfront   // 11
            };

            return cube;
        }
Ejemplo n.º 4
0
 public BoxMesher()
 {
     m_cubeMesh = CreateCubeMesh();
     m_cubeRenderingMesh = CreateCubeRenderingMesh();
 }
Ejemplo n.º 5
0
        public RenderingMesh GetRenderingMesh(LLPrimitive prim, DetailLevel lod)
        {
            RenderingMesh mesh;
            ulong physicsKey = prim.GetPhysicsKey();

            // Try a cache lookup first
            if (m_meshCache != null && m_meshCache.TryGetRenderingMesh(physicsKey, lod, out mesh))
                return mesh;

            // Can't go any further without a prim renderer
            if (m_renderer == null)
                return null;

            // Convert our DetailLevel to the OpenMetaverse.Rendering DetailLevel
            OpenMetaverse.Rendering.DetailLevel detailLevel;
            switch (lod)
            {
                case DetailLevel.Low:
                    detailLevel = OpenMetaverse.Rendering.DetailLevel.Low;
                    break;
                case DetailLevel.Medium:
                    detailLevel = OpenMetaverse.Rendering.DetailLevel.Medium;
                    break;
                case DetailLevel.High:
                    detailLevel = OpenMetaverse.Rendering.DetailLevel.High;
                    break;
                case DetailLevel.Highest:
                default:
                    detailLevel = OpenMetaverse.Rendering.DetailLevel.Highest;
                    break;
            }

            FacetedMesh facetedMesh = null;

            if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero)
            {
                // Sculpty meshing
                Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture);
                if (sculptTexture != null)
                    facetedMesh = m_renderer.GenerateFacetedSculptMesh(prim.Prim, sculptTexture, detailLevel);
            }
            else
            {
                // Basic prim meshing
                facetedMesh = m_renderer.GenerateFacetedMesh(prim.Prim, detailLevel);
            }

            if (facetedMesh != null)
            {
                #region FacetedMesh to RenderingMesh Conversion

                mesh = new RenderingMesh();
                mesh.Faces = new RenderingMesh.Face[facetedMesh.Faces.Count];
                for (int i = 0; i < facetedMesh.Faces.Count; i++)
                {
                    Face face = facetedMesh.Faces[i];

                    Vertex[] vertices = new Vertex[face.Vertices.Count];
                    for (int j = 0; j < face.Vertices.Count; j++)
                    {
                        OpenMetaverse.Rendering.Vertex omvrVertex = face.Vertices[j];
                        vertices[j] = new Vertex { Position = omvrVertex.Position, Normal = omvrVertex.Normal, TexCoord = omvrVertex.TexCoord };
                    }
                    ushort[] indices = face.Indices.ToArray();

                    mesh.Faces[i] = new RenderingMesh.Face { Vertices = vertices, Indices = indices };
                }

                #endregion FacetedMesh to RenderingMesh Conversion

                // Store the result in the mesh cache, if we have one
                if (m_meshCache != null)
                    m_meshCache.StoreRenderingMesh(physicsKey, lod, mesh);

                return mesh;
            }
            else
            {
                return null;
            }
        }