Beispiel #1
0
        /// <summary>
        /// Generates a basic mesh structure from a primitive
        /// </summary>
        /// <param name="prim">Primitive to generate the mesh from</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh or null on failure</returns>
        public OMVR.SimpleMesh GenerateSimpleMesh(OMV.Primitive prim, OMVR.DetailLevel lod)
        {
            PrimMesher.PrimMesh newPrim = GeneratePrimMesh(prim, lod, false);
            if (newPrim == null)
                return null;

            SimpleMesh mesh = new SimpleMesh();
            mesh.Path = new Path();
            mesh.Prim = prim;
            mesh.Profile = new Profile();
            mesh.Vertices = new List<Vertex>(newPrim.coords.Count);
            for (int i = 0; i < newPrim.coords.Count; i++)
            {
                PrimMesher.Coord c = newPrim.coords[i];
                mesh.Vertices.Add(new Vertex { Position = new Vector3(c.X, c.Y, c.Z) });
            }

            mesh.Indices = new List<ushort>(newPrim.faces.Count * 3);
            for (int i = 0; i < newPrim.faces.Count; i++)
            {
                PrimMesher.Face face = newPrim.faces[i];
                mesh.Indices.Add((ushort)face.v1);
                mesh.Indices.Add((ushort)face.v2);
                mesh.Indices.Add((ushort)face.v3);
            }

            return mesh;
        }
        /// <summary>
        /// Generates a basic mesh structure from a primitive
        /// </summary>
        /// <param name="prim">Primitive to generate the mesh from</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh or null on failure</returns>
        public OMVR.SimpleMesh GenerateSimpleMesh(OMV.Primitive prim, OMVR.DetailLevel lod)
        {
            PrimMesher.PrimMesh newPrim = GeneratePrimMesh(prim, lod, false);
            if (newPrim == null)
            {
                return(null);
            }

            SimpleMesh mesh = new SimpleMesh();

            mesh.Path     = new Path();
            mesh.Prim     = prim;
            mesh.Profile  = new Profile();
            mesh.Vertices = new List <Vertex>(newPrim.coords.Count);
            for (int i = 0; i < newPrim.coords.Count; i++)
            {
                PrimMesher.Coord c = newPrim.coords[i];
                mesh.Vertices.Add(new Vertex {
                    Position = new Vector3(c.X, c.Y, c.Z)
                });
            }

            mesh.Indices = new List <ushort>(newPrim.faces.Count * 3);
            for (int i = 0; i < newPrim.faces.Count; i++)
            {
                PrimMesher.Face face = newPrim.faces[i];
                mesh.Indices.Add((ushort)face.v1);
                mesh.Indices.Add((ushort)face.v2);
                mesh.Indices.Add((ushort)face.v3);
            }

            return(mesh);
        }
Beispiel #3
0
        /// <summary>
        /// Generates a basic mesh structure from a primitive
        /// A 'SimpleMesh' is just the prim's overall shape with no material information.
        /// </summary>
        /// <param name="prim">Primitive to generate the mesh from</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh or null on failure</returns>
        public OMVR.SimpleMesh GenerateSimpleMesh(OMV.Primitive prim, OMVR.DetailLevel lod)
        {
            LibreMetaverse.PrimMesher.PrimMesh newPrim = GeneratePrimMesh(prim, lod, false);
            if (newPrim == null)
            {
                return(null);
            }

            SimpleMesh mesh = new SimpleMesh
            {
                Path     = new Path(),
                Prim     = prim,
                Profile  = new Profile(),
                Vertices = new List <Vertex>(newPrim.coords.Count)
            };

            foreach (Coord c in newPrim.coords)
            {
                mesh.Vertices.Add(new Vertex {
                    Position = new Vector3(c.X, c.Y, c.Z)
                });
            }

            mesh.Indices = new List <ushort>(newPrim.faces.Count * 3);
            foreach (LibreMetaverse.PrimMesher.Face face in newPrim.faces)
            {
                mesh.Indices.Add((ushort)face.v1);
                mesh.Indices.Add((ushort)face.v2);
                mesh.Indices.Add((ushort)face.v3);
            }

            return(mesh);
        }
Beispiel #4
0
        public SimpleMesh GetWorldMesh(DetailLevel lod, SimulationObject parent)
        {
            int i = (int)lod;

            if (WorldTransformedMeshes[i] != null)
            {
                return WorldTransformedMeshes[i];
            }
            else
            {
                // Get the untransformed mesh
                SimpleMesh mesh = GetMesh(lod);

                // Copy to our new mesh
                SimpleMesh transformedMesh = new SimpleMesh();
                transformedMesh.Indices = new List<ushort>(mesh.Indices);
                transformedMesh.Path.Open = mesh.Path.Open;
                transformedMesh.Path.Points = new List<PathPoint>(mesh.Path.Points);
                transformedMesh.Prim = mesh.Prim;
                transformedMesh.Profile.Concave = mesh.Profile.Concave;
                transformedMesh.Profile.Faces = new List<ProfileFace>(mesh.Profile.Faces);
                transformedMesh.Profile.MaxX = mesh.Profile.MaxX;
                transformedMesh.Profile.MinX = mesh.Profile.MinX;
                transformedMesh.Profile.Open = mesh.Profile.Open;
                transformedMesh.Profile.Positions = new List<Vector3>(mesh.Profile.Positions);
                transformedMesh.Profile.TotalOutsidePoints = mesh.Profile.TotalOutsidePoints;
                transformedMesh.Vertices = new List<Vertex>(mesh.Vertices);

                // Construct a matrix to transform to world space
                Matrix4 transform = Matrix4.Identity;

                if (parent != null)
                {
                    // Apply parent rotation and translation first
                    transform *= Matrix4.CreateFromQuaternion(parent.Prim.Rotation);
                    transform *= Matrix4.CreateTranslation(parent.Prim.Position);
                }

                transform *= Matrix4.CreateScale(this.Prim.Scale);
                transform *= Matrix4.CreateFromQuaternion(this.Prim.Rotation);
                transform *= Matrix4.CreateTranslation(this.Prim.Position);

                // Transform the mesh
                for (int j = 0; j < transformedMesh.Vertices.Count; j++)
                {
                    Vertex vertex = transformedMesh.Vertices[j];
                    vertex.Position *= transform;
                    transformedMesh.Vertices[j] = vertex;
                }

                WorldTransformedMeshes[i] = transformedMesh;
                return transformedMesh;
            }
        }
        public SimpleMesh GenerateSimpleMesh(Primitive prim, DetailLevel lod)
        {
            Path path = GeneratePath();
            Profile profile = GenerateProfile();

            SimpleMesh mesh = new SimpleMesh();
            mesh.Prim = prim;
            mesh.Path = path;
            mesh.Profile = profile;
            mesh.Vertices = GenerateVertices();
            mesh.Indices = GenerateIndices();

            return mesh;
        }
Beispiel #6
0
        public SimpleMesh GenerateSimpleMesh(Primitive prim, DetailLevel lod)
        {
            Path    path    = GeneratePath();
            Profile profile = GenerateProfile();

            SimpleMesh mesh = new SimpleMesh();

            mesh.Prim     = prim;
            mesh.Path     = path;
            mesh.Profile  = profile;
            mesh.Vertices = GenerateVertices();
            mesh.Indices  = GenerateIndices();

            return(mesh);
        }
Beispiel #7
0
 public SimpleMesh(SimpleMesh mesh)
 {
     this.Indices                    = new List <ushort>(mesh.Indices);
     this.Path.Open                  = mesh.Path.Open;
     this.Path.Points                = new List <PathPoint>(mesh.Path.Points);
     this.Prim                       = mesh.Prim;
     this.Profile.Concave            = mesh.Profile.Concave;
     this.Profile.Faces              = new List <ProfileFace>(mesh.Profile.Faces);
     this.Profile.MaxX               = mesh.Profile.MaxX;
     this.Profile.MinX               = mesh.Profile.MinX;
     this.Profile.Open               = mesh.Profile.Open;
     this.Profile.Positions          = new List <Vector3>(mesh.Profile.Positions);
     this.Profile.TotalOutsidePoints = mesh.Profile.TotalOutsidePoints;
     this.Vertices                   = new List <Vertex>(mesh.Vertices);
 }
Beispiel #8
0
        // Add the submesh to the passed SimpleMesh
        private void AddSubMesh(OSD subMeshOsd, ref OMVR.SimpleMesh holdingMesh)
        {
            if (subMeshOsd is OSDMap subMeshMap)
            {
                // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level
                // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no
                // geometry for this submesh.
                if (subMeshMap.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshMap["NoGeometry"]))
                {
                    return;
                }

                holdingMesh.Vertices.AddRange(CollectVertices(subMeshMap));
                holdingMesh.Indices.AddRange(CollectIndices(subMeshMap));
            }
        }
Beispiel #9
0
        public SimpleMesh GenerateSimpleMesh(Primitive prim, DetailLevel lod)
        {
            float detail = DETAIL_LEVELS[(int)lod];

            Path path = GeneratePath(prim.Data, detail);
            Profile profile = GenerateProfile(prim.Data, path, detail);

            SimpleMesh mesh = new SimpleMesh();
            mesh.Prim = prim;
            mesh.Path = path;
            mesh.Profile = profile;
            mesh.Vertices = GenerateVertices(prim.Data, detail, path, profile);
            mesh.Indices = GenerateIndices(prim.Data, path, profile);

            return mesh;
        }
Beispiel #10
0
        // Convert a compressed submesh buffer into a SimpleMesh.
        public OMVR.SimpleMesh MeshSubMeshAsSimpleMesh(OMV.Primitive prim, byte[] compressedMeshData)
        {
            OMVR.SimpleMesh ret     = null;
            OSD             meshOSD = Helpers.DecompressOSD(compressedMeshData);

            OSDArray meshFaces = meshOSD as OSDArray;

            if (meshOSD != null)
            {
                ret = new SimpleMesh();
                foreach (OSD subMesh in meshFaces)
                {
                    AddSubMesh(subMesh, ref ret);
                }
            }
            return(ret);
        }
Beispiel #11
0
        public SimpleMesh GenerateSimpleSculptMesh(Primitive prim, Bitmap sculptTexture, DetailLevel lod)
        {
            FacetedMesh facetedMesh = GenerateFacetedSculptMesh(prim, sculptTexture, lod);

            if (facetedMesh != null && facetedMesh.Faces.Count == 1)
            {
                Face face = facetedMesh.Faces[0];

                SimpleMesh mesh = new SimpleMesh();
                mesh.Indices = face.Indices;
                mesh.Vertices = face.Vertices;
                mesh.Path = facetedMesh.Path;
                mesh.Profile = facetedMesh.Profile;
                mesh.Prim = facetedMesh.Prim;

                return mesh;
            }

            return null;
        }
        /// <summary>
        /// Generates a sculpt mesh structure from a primitive
        /// </summary>
        /// <param name="prim">Primitive to generate the mesh from</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh</returns>
        public OMVR.SimpleMesh GenerateSimpleSculptMesh(OMV.Primitive prim, Bitmap bits, OMVR.DetailLevel lod)
        {
            OMVR.FacetedMesh faceted = GenerateFacetedSculptMesh(prim, bits, lod);

            if (faceted != null && faceted.Faces.Count == 1)
            {
                OMVR.Face face = faceted.Faces[0];

                OMVR.SimpleMesh mesh = new OMVR.SimpleMesh();
                mesh.Indices  = face.Indices;
                mesh.Vertices = face.Vertices;
                mesh.Path     = faceted.Path;
                mesh.Prim     = prim;
                mesh.Profile  = faceted.Profile;
                mesh.Vertices = face.Vertices;

                return(mesh);
            }
            return(null);
        }
Beispiel #13
0
        public SimpleMesh GenerateSimpleMesh(Primitive prim, DetailLevel lod)
        {
            Path    path    = GeneratePath();
            Profile profile = GenerateProfile();

            MeshmerizerMesh meshmerizer = new MeshmerizerMesh();

            meshmerizer = GenerateMeshmerizerMesh(prim);

            // Create the vertex array
            List <Vertex> vertices = new List <Vertex>(meshmerizer.primMesh.coords.Count);

            for (int i = 0; i < meshmerizer.primMesh.coords.Count; i++)
            {
                Coord  c      = meshmerizer.primMesh.coords[i];
                Vertex vertex = new Vertex();
                vertex.Position = new Vector3(c.X, c.Y, c.Z);
                vertices.Add(vertex);
            }

            // Create the index array
            List <ushort> indices = new List <ushort>(meshmerizer.primMesh.faces.Count * 3);

            for (int i = 0; i < meshmerizer.primMesh.faces.Count; i++)
            {
                MeshmerizerFace f = meshmerizer.primMesh.faces[i];
                indices.Add((ushort)f.v1);
                indices.Add((ushort)f.v2);
                indices.Add((ushort)f.v3);
            }

            SimpleMesh mesh = new SimpleMesh();

            mesh.Prim     = prim;
            mesh.Path     = path;
            mesh.Profile  = profile;
            mesh.Vertices = vertices;
            mesh.Indices  = indices;

            return(mesh);
        }
Beispiel #14
0
        /// <summary>
        /// Generates a basic mesh structure from a sculpted primitive.
        /// 'SimpleMesh's have a single mesh and no faces or material information.
        /// </summary>
        /// <param name="prim">Sculpted primitive to generate the mesh from</param>
        /// <param name="sculptTexture">Sculpt texture</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh or null on failure</returns>
        public SimpleMesh GenerateSimpleSculptMesh(Primitive prim, Bitmap sculptTexture, DetailLevel lod)
        {
            var faceted = GenerateFacetedSculptMesh(prim, sculptTexture, lod);

            if (faceted != null && faceted.Faces.Count == 1)
            {
                Face face = faceted.Faces[0];

                SimpleMesh mesh = new SimpleMesh
                {
                    Indices  = face.Indices,
                    Vertices = face.Vertices,
                    Path     = faceted.Path,
                    Prim     = prim,
                    Profile  = faceted.Profile
                };
                mesh.Vertices = face.Vertices;

                return(mesh);
            }

            return(null);
        }
Beispiel #15
0
        public SimpleMesh GenerateSimpleMesh(Primitive prim, DetailLevel lod)
        {
            Path path = GeneratePath();
            Profile profile = GenerateProfile();

            MeshmerizerMesh meshmerizer = new MeshmerizerMesh();
            meshmerizer = GenerateMeshmerizerMesh(prim);

            // Create the vertex array
            List<Vertex> vertices = new List<Vertex>(meshmerizer.primMesh.coords.Count);
            for (int i = 0; i < meshmerizer.primMesh.coords.Count; i++)
            {
                Coord c = meshmerizer.primMesh.coords[i];
                Vertex vertex = new Vertex();
                vertex.Position = new Vector3(c.X, c.Y, c.Z);
                vertices.Add(vertex);
            }

            // Create the index array
            List<ushort> indices = new List<ushort>(meshmerizer.primMesh.faces.Count * 3);
            for (int i = 0; i < meshmerizer.primMesh.faces.Count; i++)
            {
                MeshmerizerFace f = meshmerizer.primMesh.faces[i];
                indices.Add((ushort)f.v1);
                indices.Add((ushort)f.v2);
                indices.Add((ushort)f.v3);
            }

            SimpleMesh mesh = new SimpleMesh();
            mesh.Prim = prim;
            mesh.Path = path;
            mesh.Profile = profile;
            mesh.Vertices = vertices;
            mesh.Indices = indices;

            return mesh;
        }
Beispiel #16
0
        public SimpleMesh GetWorldMesh(DetailLevel lod, bool forceMeshing, bool forceTransform)
        {
            int i = (int)lod;

            if (WorldTransformedMeshes == null)
                WorldTransformedMeshes = new SimpleMesh[4];

            if (!forceMeshing && !forceTransform && WorldTransformedMeshes[i] != null)
            {
                return WorldTransformedMeshes[i];
            }
            else
            {
                // Get the untransformed mesh
                SimpleMesh mesh = GetMesh(lod, forceMeshing);

                // Copy to our new mesh
                SimpleMesh transformedMesh = new SimpleMesh(mesh);

                // Construct a matrix to transform to world space
                Matrix4 transform = Matrix4.Identity;

                SimulationObject parent = GetLinksetParent();
                if (parent != this)
                {
                    // Apply parent rotation and translation first
                    transform *= Matrix4.CreateFromQuaternion(parent.Prim.Rotation);
                    transform *= Matrix4.CreateTranslation(parent.Prim.Position);
                }

                transform *= Matrix4.CreateScale(Prim.Scale);
                transform *= Matrix4.CreateFromQuaternion(Prim.Rotation);
                transform *= Matrix4.CreateTranslation(Prim.Position);

                // Transform the mesh
                for (int j = 0; j < transformedMesh.Vertices.Count; j++)
                {
                    Vertex vertex = transformedMesh.Vertices[j];
                    vertex.Position *= transform;
                    transformedMesh.Vertices[j] = vertex;
                }

                WorldTransformedMeshes[i] = transformedMesh;
                return transformedMesh;
            }
        }
Beispiel #17
0
        /// <summary>
        /// Generates a basic mesh structure from a sculpted primitive
        /// </summary>
        /// <param name="prim">Sculpted primitive to generate the mesh from</param>
        /// <param name="sculptTexture">Sculpt texture</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh or null on failure</returns>
        public OMVR.SimpleMesh GenerateSimpleSculptMesh(OMV.Primitive prim, System.Drawing.Bitmap sculptTexture, OMVR.DetailLevel lod)
        {
            OMVR.FacetedMesh faceted = GenerateFacetedSculptMesh(prim, sculptTexture, lod);

            if (faceted != null && faceted.Faces.Count == 1)
            {
                Face face = faceted.Faces[0];

                SimpleMesh mesh = new SimpleMesh();
                mesh.Indices = face.Indices;
                mesh.Vertices = face.Vertices;
                mesh.Path = faceted.Path;
                mesh.Prim = prim;
                mesh.Profile = faceted.Profile;
                mesh.Vertices = face.Vertices;

                return mesh;
            }

            return null;
        }
Beispiel #18
0
        public BasicMesh GetBasicMesh(LLPrimitive prim)
        {
            BasicMesh         mesh;
            OpenMetaverseMesh omvMesh    = null;
            ulong             physicsKey = prim.GetPhysicsKey();

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

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

            if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero)
            {
                // Sculpty meshing
                Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture);
                if (sculptTexture != null)
                {
                    omvMesh = m_renderer.GenerateSimpleSculptMesh(prim.Prim, sculptTexture, OpenMetaverse.Rendering.DetailLevel.Low);
                }
            }
            else
            {
                // Basic prim meshing
                omvMesh = m_renderer.GenerateSimpleMesh(prim.Prim, OpenMetaverse.Rendering.DetailLevel.Medium);
            }

            if (omvMesh == null)
            {
                return(null);
            }

#if DEBUG
            for (int i = 0; i < omvMesh.Indices.Count; i++)
            {
                System.Diagnostics.Debug.Assert(omvMesh.Indices[i] < omvMesh.Vertices.Count, "Mesh index is out of range");
            }
#endif

            // Convert the OpenMetaverse.Rendering mesh to a BasicMesh
            mesh          = new BasicMesh();
            mesh.Vertices = new Vector3[omvMesh.Vertices.Count];
            for (int i = 0; i < omvMesh.Vertices.Count; i++)
            {
                mesh.Vertices[i] = omvMesh.Vertices[i].Position;
            }
            mesh.Indices = omvMesh.Indices.ToArray();

            mesh.Volume = Util.GetMeshVolume(mesh, Vector3.One);

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

            return(mesh);
        }
Beispiel #19
0
 /// <summary>
 /// Helper to parse a meshed prim and needed especially
 /// for accuracy with tortured prims and sculpts.
 /// </summary>
 private void AddBoundingBoxOfSimpleMesh(SimpleMesh mesh, Primitive prim, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count)
 {
     // Quirk: A meshed box contains 10 instead of the 8 necessary vertices.
     if (mesh != null)
     {
         // Parse each vertex in mesh
         foreach (Vertex vertex in mesh.Vertices)
         {
             Vector3 position = vertex.Position;
             position = position * prim.Scale;
             // Rotate part unless part is root
             if (hasParent)
                 position = position * prim.Rotation;
             position = position + prim.Position;
             // Adjust lower and upper bounding box corners if needed
             lower = Vector3.Min(lower, position);
             upper = Vector3.Max(upper, position);
             count++;
         }
     }
 }
Beispiel #20
0
 public SimpleMesh(SimpleMesh mesh)
 {
     this.Indices = new List<ushort>(mesh.Indices);
     this.Path.Open = mesh.Path.Open;
     this.Path.Points = new List<PathPoint>(mesh.Path.Points);
     this.Prim = mesh.Prim;
     this.Profile.Concave = mesh.Profile.Concave;
     this.Profile.Faces = new List<ProfileFace>(mesh.Profile.Faces);
     this.Profile.MaxX = mesh.Profile.MaxX;
     this.Profile.MinX = mesh.Profile.MinX;
     this.Profile.Open = mesh.Profile.Open;
     this.Profile.Positions = new List<Vector3>(mesh.Profile.Positions);
     this.Profile.TotalOutsidePoints = mesh.Profile.TotalOutsidePoints;
     this.Vertices = new List<Vertex>(mesh.Vertices);
 }
        /// <summary>
        /// Generates a sculpt mesh structure from a primitive
        /// </summary>
        /// <param name="prim">Primitive to generate the mesh from</param>
        /// <param name="lod">Level of detail to generate the mesh at</param>
        /// <returns>The generated mesh</returns>
        public OMVR.SimpleMesh GenerateSimpleSculptMesh(OMV.Primitive prim, Bitmap bits, OMVR.DetailLevel lod)
        {
            OMVR.FacetedMesh faceted = GenerateFacetedSculptMesh(prim, bits, lod);

            if (faceted != null && faceted.Faces.Count == 1)
            {
            OMVR.Face face = faceted.Faces[0];

            OMVR.SimpleMesh mesh = new OMVR.SimpleMesh();
            mesh.Indices = face.Indices;
            mesh.Vertices = face.Vertices;
            mesh.Path = faceted.Path;
            mesh.Prim = prim;
            mesh.Profile = faceted.Profile;
            mesh.Vertices = face.Vertices;

            return mesh;
            }
            return null;
        }