Exemplo n.º 1
0
 public SculptMesh(SculptMesh sm)
 {
     coords      = new List <Coord>(sm.coords);
     faces       = new List <Face>(sm.faces);
     viewerFaces = new List <ViewerFace>(sm.viewerFaces);
     normals     = new List <Coord>(sm.normals);
     uvs         = new List <UVCoord>(sm.uvs);
 }
Exemplo n.º 2
0
        public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode)
        {
            var bitmap     = (Bitmap)Image.FromFile(fileName);
            var sculptMesh = new SculptMesh(bitmap, sculptType, lod, viewerMode);

            bitmap.Dispose();
            return(sculptMesh);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a sculpty faceted mesh. The actual scuplt texture is fetched and passed to this
        /// routine since all the context for finding teh texture is elsewhere.
        /// </summary>
        /// <returns>The faceted mesh or null if can't do it</returns>
        public OMVR.FacetedMesh GenerateFacetedSculptMesh(Primitive prim, Bitmap scupltTexture, DetailLevel lod)
        {
            LibreMetaverse.PrimMesher.SculptMesh.SculptType smSculptType;
            switch (prim.Sculpt.Type)
            {
            case SculptType.Cylinder:
                smSculptType = LibreMetaverse.PrimMesher.SculptMesh.SculptType.cylinder;
                break;

            case SculptType.Plane:
                smSculptType = LibreMetaverse.PrimMesher.SculptMesh.SculptType.plane;
                break;

            case SculptType.Sphere:
                smSculptType = LibreMetaverse.PrimMesher.SculptMesh.SculptType.sphere;
                break;

            case SculptType.Torus:
                smSculptType = LibreMetaverse.PrimMesher.SculptMesh.SculptType.torus;
                break;

            default:
                smSculptType = LibreMetaverse.PrimMesher.SculptMesh.SculptType.plane;
                break;
            }
            // The lod for sculpties is the resolution of the texture passed.
            // The first guess is 1:1 then lower resolutions after that
            // int mesherLod = (int)Math.Sqrt(scupltTexture.Width * scupltTexture.Height);
            int mesherLod = 32; // number used in Idealist viewer

            switch (lod)
            {
            case OMVR.DetailLevel.Highest:
                break;

            case OMVR.DetailLevel.High:
                break;

            case OMVR.DetailLevel.Medium:
                mesherLod /= 2;
                break;

            case OMVR.DetailLevel.Low:
                mesherLod /= 4;
                break;
            }
            LibreMetaverse.PrimMesher.SculptMesh newMesh =
                new LibreMetaverse.PrimMesher.SculptMesh(scupltTexture, smSculptType, mesherLod, true, prim.Sculpt.Mirror, prim.Sculpt.Invert);

            int numPrimFaces = 1;       // a scuplty has only one face

            // copy the vertex information into OMVR.IRendering structures
            FacetedMesh omvrmesh = new OMVR.FacetedMesh
            {
                Faces   = new List <OMVR.Face>(),
                Prim    = prim,
                Profile = new OMVR.Profile
                {
                    Faces     = new List <OMVR.ProfileFace>(),
                    Positions = new List <OMV.Vector3>()
                },
                Path = new OMVR.Path {
                    Points = new List <OMVR.PathPoint>()
                }
            };

            for (int ii = 0; ii < numPrimFaces; ii++)
            {
                Face oface = new OMVR.Face
                {
                    Vertices    = new List <OMVR.Vertex>(),
                    Indices     = new List <ushort>(),
                    TextureFace = prim.Textures.GetFace((uint)ii)
                };
                int faceVertices = newMesh.coords.Count;

                for (int j = 0; j < faceVertices; j++)
                {
                    var vert = new OMVR.Vertex
                    {
                        Position = new Vector3(newMesh.coords[j].X, newMesh.coords[j].Y, newMesh.coords[j].Z),
                        Normal   = new Vector3(newMesh.normals[j].X, newMesh.normals[j].Y, newMesh.normals[j].Z),
                        TexCoord = new Vector2(newMesh.uvs[j].U, newMesh.uvs[j].V)
                    };
                    oface.Vertices.Add(vert);
                }

                for (int j = 0; j < newMesh.faces.Count; j++)
                {
                    oface.Indices.Add((ushort)newMesh.faces[j].v1);
                    oface.Indices.Add((ushort)newMesh.faces[j].v2);
                    oface.Indices.Add((ushort)newMesh.faces[j].v3);
                }

                if (faceVertices > 0)
                {
                    oface.TextureFace = prim.Textures.FaceTextures[ii] ?? prim.Textures.DefaultTexture;
                    oface.ID          = ii;
                    omvrmesh.Faces.Add(oface);
                }
            }

            return(omvrmesh);
        }