public EntityCamera(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     m_yawFixed = true;
     m_globalPosition = new OMV.Vector3d(40f, 40f, 30f);
     m_heading = new OMV.Quaternion(0f, 1f, 0f);
 }
        public LLRegionContext(RegionContextBase rcontext, AssetContextBase acontext,
                               LLTerrainInfo tinfo, OMV.Simulator sim)
            : base(rcontext, acontext)
        {
            m_terrainInfo = tinfo;

            // until we have a better protocol, we know the sims are a fixed size
            m_size = new OMV.Vector3(256f, 256f, 8000f);

            // believe it or not the world coordinates of a sim are hidden in the handle
            uint x, y;

            OMV.Utils.LongToUInts(sim.Handle, out x, out y);
            m_worldBase = new OMV.Vector3d((double)x, (double)y, 0d);

            m_simulator = sim;

            // this should be more general as "GRID/SIM"
            m_name = new EntityName(sim.Name);

            // a cache of requested localIDs so we don't ask too often
            m_recentLocalIDRequests = new Dictionary <uint, int>();

            this.RegisterInterface <LLRegionContext>(this);
        }
 public LLEntityBase(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     this.Prim = null;
     this.Sim = null;
     this.RegionHandle = LLEntityBase.NOREGION;
     this.LocalID = LLEntityBase.NOLOCALID;
 }
 public LLEntityBase(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     this.Prim         = null;
     this.Sim          = null;
     this.RegionHandle = LLEntityBase.NOREGION;
     this.LocalID      = LLEntityBase.NOLOCALID;
 }
 public RegionContextBase(RegionContextBase rcontext, AssetContextBase acontext) 
             : base(rcontext, acontext) {
     m_regionState = new RegionState();
     m_regionStateChangedCallback = new RegionStateChangedCallback(State_OnChange);
     State.OnStateChanged += m_regionStateChangedCallback;
     m_entityCollection = new EntityCollection(this.Name.Name);
     this.RegisterInterface<IEntityCollection>(m_entityCollection);
     this.RegisterInterface<IRegionContext>(this);
 }
Exemple #6
0
 public LLEntityPhysical(AssetContextBase acontext, LLRegionContext rcontext,
                         ulong regionHandle, uint localID, OMV.Primitive prim) : base(rcontext, acontext)
 {
     this.Sim          = rcontext.Simulator;
     this.RegionHandle = regionHandle;
     this.LocalID      = localID;
     this.Prim         = prim;
     this.Name         = new EntityNameLL(acontext, m_prim.ID.ToString());
 }
 public LLEntityPhysical(AssetContextBase acontext, LLRegionContext rcontext, 
         ulong regionHandle, uint localID, OMV.Primitive prim)
     : base(rcontext, acontext)
 {
     this.Sim = rcontext.Simulator;
     this.RegionHandle = regionHandle;
     this.LocalID = localID;
     this.Prim = prim;
     this.Name = new EntityNameLL(acontext, m_prim.ID.ToString());
 }
 public LLEntityAvatar(AssetContextBase acontext, LLRegionContext rcontext,
                       ulong regionHandle, OMV.Avatar av) : base(rcontext, acontext)
 {
     // base(acontext, rcontext, regionHandle, av.LocalID, null) { // base for EntityPhysical
     // let people looking at IEntity's get at my avatarness
     RegisterInterface <IEntityAvatar>(this);
     this.Sim          = rcontext.Simulator;
     this.RegionHandle = regionHandle;
     this.LocalID      = av.LocalID;
     this.Avatar       = av;
     this.Name         = AvatarEntityNameFromID(acontext, m_avatar.ID);
     LogManager.Log.Log(LogLevel.DCOMMDETAIL, "LLEntityAvatar: create id={0}, lid={1}",
                        av.ID.ToString(), this.LocalID);
 }
 public LLEntityAvatar(AssetContextBase acontext, LLRegionContext rcontext, 
         ulong regionHandle, OMV.Avatar av)
     : base(rcontext, acontext)
 {
     // base(acontext, rcontext, regionHandle, av.LocalID, null) { // base for EntityPhysical
     // let people looking at IEntity's get at my avatarness
     RegisterInterface<IEntityAvatar>(this);
     this.Sim = rcontext.Simulator;
     this.RegionHandle = regionHandle;
     this.LocalID = av.LocalID;
     this.Avatar = av;
     this.Name = AvatarEntityNameFromID(acontext, m_avatar.ID);
     LogManager.Log.Log(LogLevel.DCOMMDETAIL, "LLEntityAvatar: create id={0}, lid={1}",
                     av.ID.ToString(), this.LocalID);
 }
        private void GenerateMipMaps(AssetContextBase acontext, OMV.UUID textureUUID, out int textureID)
        {
            EntityNameLL textureEntityName = EntityNameLL.ConvertTextureWorldIDToEntityName(acontext, textureUUID);

            // see if the cache file exists -- if not, we don't get a texture this frame
            if (!acontext.CheckIfCached(textureEntityName))
            {
                textureID = 0;
                return;
            }

            int id = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, id);

            try {
                using (Bitmap bmp = acontext.GetTexture(textureEntityName)) {
                    BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                                       ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                                  OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

                    bmp.UnlockBits(bmp_data);
                }
                // GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                // GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);

                // We haven't uploaded mipmaps, so disable mipmapping (otherwise the texture will not appear).
                // On newer video cards, we can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
                // mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            }
            catch (Exception e) {
                m_log.Log(LogLevel.DBADERROR, "Failed binding texture id={0}, uuid={1}: {2}", id, textureUUID, e);
                textureID = 0;
            }

            textureID = id;
            return;
        }
        public LLRegionContext(RegionContextBase rcontext, AssetContextBase acontext, 
                        LLTerrainInfo tinfo, OMV.Simulator sim)
            : base(rcontext, acontext)
        {
            m_terrainInfo = tinfo;

            // until we have a better protocol, we know the sims are a fixed size
            m_size = new OMV.Vector3(256f, 256f, 8000f);

            // believe it or not the world coordinates of a sim are hidden in the handle
            uint x, y;
            OMV.Utils.LongToUInts(sim.Handle, out x, out y);
            m_worldBase = new OMV.Vector3d((double)x, (double)y, 0d);

            m_simulator = sim;

            // this should be more general as "GRID/SIM"
            m_name = new EntityName(sim.Name);

            // a cache of requested localIDs so we don't ask too often
            m_recentLocalIDRequests = new Dictionary<uint, int>();

            this.RegisterInterface<LLRegionContext>(this);
        }
 public static EntityNameLL ConvertTextureWorldIDToEntityName(AssetContextBase context, OMV.UUID textureWorldID)
 {
     return ConvertTextureWorldIDToEntityName(context, textureWorldID.ToString());
 }
 public static EntityName AvatarEntityNameFromID(AssetContextBase acontext, OMV.UUID ID)
 {
     return new EntityNameLL(acontext, "Avatar/" + ID.ToString());
 }
 public EntityAvatarBase(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
 }
 public static EntityNameLL ConvertTextureWorldIDToEntityName(AssetContextBase context, OMV.UUID textureWorldID)
 {
     return(ConvertTextureWorldIDToEntityName(context, textureWorldID.ToString()));
 }
 public static EntityNameLL ConvertTextureWorldIDToEntityName(AssetContextBase context, string textureWorldID)
 {
     return(new EntityNameLL(context, textureWorldID));
 }
 // created with a hosting asset server.
 // Extract the host name handle from the asset context and use the passed name
 // as teh name of the entity in that context.
 public EntityName(AssetContextBase acontext, string name)
 {
     if (acontext != null) {
     m_header = "";
     m_host = acontext.Name;
     m_entity = name;
     }
     else {
     m_header = "";
     m_host = "LOOKINGGLASS";
     m_entity = name;
     }
     // m_fullName is created when it is asked for
 }
 public EntityNameLL(AssetContextBase acontext, string name)
     : base(acontext, name)
 {
 }
 public static EntityName AvatarEntityNameFromID(AssetContextBase acontext, OMV.UUID ID)
 {
     return(new EntityNameLL(acontext, "Avatar/" + ID.ToString()));
 }
 public TerrainInfoBase(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
 }
 public EntityLight(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
 }
        private void GenerateMipMaps(AssetContextBase acontext, OMV.UUID textureUUID, out int textureID)
        {
            EntityNameLL textureEntityName = EntityNameLL.ConvertTextureWorldIDToEntityName(acontext, textureUUID);

            // see if the cache file exists -- if not, we don't get a texture this frame
            if (!acontext.CheckIfCached(textureEntityName)) {
            textureID = 0;
            return;
            }

            int id = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, id);

            try {
            using (Bitmap bmp = acontext.GetTexture(textureEntityName)) {
                BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                        ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                        OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

                bmp.UnlockBits(bmp_data);
            }
            // GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            // GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);

            // We haven't uploaded mipmaps, so disable mipmapping (otherwise the texture will not appear).
            // On newer video cards, we can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
            // mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            }
            catch (Exception e) {
            m_log.Log(LogLevel.DBADERROR, "Failed binding texture id={0}, uuid={1}: {2}", id, textureUUID, e);
            textureID = 0;
            }

            textureID = id;
            return;
        }
 public static EntityNameLL ConvertTextureWorldIDToEntityName(AssetContextBase context, string textureWorldID)
 {
     return new EntityNameLL(context, textureWorldID);
 }
 /// <summary>
 /// Implementation routine that the parent class uses to create communication specific entity
 /// names.
 /// </summary>
 /// <param name="acb"></param>
 /// <param name="at"></param>
 protected override EntityName ConvertToEntityName(AssetContextBase acb, string worldID)
 {
     return EntityNameLL.ConvertTextureWorldIDToEntityName(acb, worldID);
 }
Exemple #25
0
        private void CreateNewPrim(LLEntityBase ent)
        {
            m_log.Log(LogLevel.DRENDERDETAIL, "Create new prim {0}", ent.Name.Name);
            // entity render info is kept per region. Get the region prim structure
            RegionRenderInfo rri = GetRegionRenderInfo(ent.RegionContext);
            IEntityAvatar    av;

            if (ent.TryGet <IEntityAvatar>(out av))
            {
                // if this entity is an avatar, just put it on the display list
                lock (rri.renderAvatarList) {
                    if (!rri.renderAvatarList.ContainsKey(av.LGID))
                    {
                        RenderableAvatar ravv = new RenderableAvatar();
                        ravv.avatar = av;
                        rri.renderAvatarList.Add(av.LGID, ravv);
                    }
                }
                return;
            }
            OMV.Primitive prim = ent.Prim;

            /* don't do foliage yet
             * if (prim.PrimData.PCode == OMV.PCode.Grass
             || prim.PrimData.PCode == OMV.PCode.Tree
             || prim.PrimData.PCode == OMV.PCode.NewTree) {
             || lock (renderFoliageList)
             ||     renderFoliageList[prim.LocalID] = prim;
             || return;
             ||}
             */

            RenderablePrim render = new RenderablePrim();

            render.Prim      = prim;
            render.acontext  = ent.AssetContext;
            render.rcontext  = ent.RegionContext;
            render.Position  = prim.Position;
            render.Rotation  = prim.Rotation;
            render.isVisible = true; // initially assume visible

            if (m_meshMaker == null)
            {
                m_meshMaker = new Renderer.Mesher.MeshmerizerR();
                m_meshMaker.ShouldScaleMesh = false;
            }

            if (prim.Sculpt != null)
            {
                EntityNameLL          textureEnt    = EntityNameLL.ConvertTextureWorldIDToEntityName(ent.AssetContext, prim.Sculpt.SculptTexture);
                System.Drawing.Bitmap textureBitmap = ent.AssetContext.GetTexture(textureEnt);
                if (textureBitmap == null)
                {
                    // the texture is not available. Request it.
                    // Note that we just call this routine again when it is available. Hope it's not recursive
                    ent.AssetContext.DoTextureLoad(textureEnt, AssetContextBase.AssetType.SculptieTexture,
                                                   delegate(string name, bool trans) {
                        CreateNewPrim(ent);
                        return;
                    }
                                                   );
                    return;
                }
                render.Mesh = m_meshMaker.GenerateSculptMesh(textureBitmap, prim, OMVR.DetailLevel.Medium);
                textureBitmap.Dispose();
            }
            else
            {
                render.Mesh = m_meshMaker.GenerateFacetedMesh(prim, OMVR.DetailLevel.High);
            }

            if (render.Mesh == null)
            {
                // mesh generation failed
                m_log.Log(LogLevel.DBADERROR, "FAILED MESH GENERATION: not generating new prim {0}", ent.Name.Name);
                return;
            }

            // Create a FaceData struct for each face that stores the 3D data
            // in an OpenGL friendly format
            for (int j = 0; j < render.Mesh.Faces.Count; j++)
            {
                OMVR.Face face = render.Mesh.Faces[j];
                FaceData  data = new FaceData();

                // Vertices for this face
                data.Vertices = new float[face.Vertices.Count * 3];
                for (int k = 0; k < face.Vertices.Count; k++)
                {
                    data.Vertices[k * 3 + 0] = face.Vertices[k].Position.X;
                    data.Vertices[k * 3 + 1] = face.Vertices[k].Position.Y;
                    data.Vertices[k * 3 + 2] = face.Vertices[k].Position.Z;
                }

                // Indices for this face
                data.Indices = face.Indices.ToArray();

                // Texture transform for this face
                OMV.Primitive.TextureEntryFace teFace = prim.Textures.GetFace((uint)j);
                m_meshMaker.TransformTexCoords(face.Vertices, face.Center, teFace);

                // Texcoords for this face
                data.TexCoords = new float[face.Vertices.Count * 2];
                for (int k = 0; k < face.Vertices.Count; k++)
                {
                    data.TexCoords[k * 2 + 0] = face.Vertices[k].TexCoord.X;
                    data.TexCoords[k * 2 + 1] = face.Vertices[k].TexCoord.Y;
                }

                data.Normals = new float[face.Vertices.Count * 3];
                for (int k = 0; k < face.Vertices.Count; k++)
                {
                    data.Normals[k * 3 + 0] = face.Vertices[k].Normal.X;
                    data.Normals[k * 3 + 1] = face.Vertices[k].Normal.Y;
                    data.Normals[k * 3 + 2] = face.Vertices[k].Normal.Z;
                }


                // m_log.Log(LogLevel.DRENDERDETAIL, "CreateNewPrim: v={0}, i={1}, t={2}",
                //     data.Vertices.GetLength(0), data.Indices.GetLength(0), data.TexCoords.GetLength(0));

                // Texture for this face
                if (teFace.TextureID != OMV.UUID.Zero &&
                    teFace.TextureID != OMV.Primitive.TextureEntry.WHITE_TEXTURE)
                {
                    lock (Textures) {
                        if (!Textures.ContainsKey(teFace.TextureID))
                        {
                            // temporarily add the entry to the table so we don't request it multiple times
                            Textures.Add(teFace.TextureID, new TextureInfo(0, true));
                            // We haven't constructed this image in OpenGL yet, get ahold of it
                            AssetContextBase.RequestTextureLoad(
                                EntityNameLL.ConvertTextureWorldIDToEntityName(ent.AssetContext, teFace.TextureID),
                                AssetContextBase.AssetType.Texture,
                                OnTextureDownloadFinished);
                        }
                    }
                }

                // Set the UserData for this face to our FaceData struct
                face.UserData        = data;
                render.Mesh.Faces[j] = face;
            }

            lock (rri.renderPrimList) {
                rri.renderPrimList[prim.LocalID] = render;
            }
        }
 public EntityNameLL(AssetContextBase acontext, string name)
     : base(acontext, name)
 {
 }
 public LLTerrainInfo(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     init();
 }
 public LLTerrainInfo(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     init();
 }
 /// <summary>
 /// Implementation routine that the parent class uses to create communication specific entity
 /// names.
 /// </summary>
 /// <param name="acb"></param>
 /// <param name="at"></param>
 protected override EntityName ConvertToEntityName(AssetContextBase acb, string worldID)
 {
     return(EntityNameLL.ConvertTextureWorldIDToEntityName(acb, worldID));
 }