/// <summary>
        /// Gets the level of detail for circles.
        /// </summary>
        /// <returns>The level of detail.</returns>
        /// <param name="lod">Lod.</param>
        int GetLevelOfDetail(float lod)
        {
            int sides;

            // defaults for LOD
            LevelOfDetail iLOD = (LevelOfDetail)lod;

            switch (iLOD)
            {
            case LevelOfDetail.High:
                sides = 24;
                break;

            case LevelOfDetail.Medium:
                sides = 12;
                break;

            case LevelOfDetail.Low:
                sides = 6;
                break;

            case LevelOfDetail.VeryLow:
                sides = 3;
                break;

            default:
                sides = 24;
                break;
            }

            return(sides);
        }
Beispiel #2
0
 public TileCacheTrackerLevel(TileInfo tileInfo, LevelOfDetail level)
 {
     TileInfo           = tileInfo ?? throw new ArgumentNullException(nameof(tileInfo));
     LevelOfDetail      = level ?? throw new ArgumentNullException(nameof(level));
     TileWidthMapUnits  = level.Resolution * tileInfo.TileWidth;
     TileHeightMapUnits = level.Resolution * tileInfo.TileHeight;
 }
Beispiel #3
0
        /// <summary>
        /// Gets the nearest level of detail for the specified level of detail
        /// </summary>
        /// <param name="lod">Level of detail</param>
        /// <returns>Returns the nearest level of detail for the specified level of detail</returns>
        internal LevelOfDetail GetLODNearest(LevelOfDetail lod)
        {
            if (this.meshesByLOD == null)
            {
                return(LevelOfDetail.None);
            }

            if (this.meshesByLOD.Keys.Count == 0)
            {
                return(this.defaultLevelOfDetail);
            }
            else
            {
                if (this.meshesByLOD.Keys.Count == 1)
                {
                    return(this.meshesByLOD.Keys.First());
                }
                else
                {
                    int i = (int)lod;

                    for (int l = i; l > 0; l /= 2)
                    {
                        if (this.meshesByLOD.ContainsKey((LevelOfDetail)l))
                        {
                            return((LevelOfDetail)l);
                        }
                    }

                    return(this.defaultLevelOfDetail);
                }
            }
        }
Beispiel #4
0
        void SetLod()
        {
            MeshingSettings.lod = levelOfDetail;
#if UNITY_EDITOR
            m_CachedLod = levelOfDetail;
#endif
        }
Beispiel #5
0
 public TileCacheTrackerLevel(VectorTileSourceInfo vectorTileInfo, LevelOfDetail level)
 {
     VectorTileInfo     = vectorTileInfo ?? throw new ArgumentNullException(nameof(vectorTileInfo));
     LevelOfDetail      = level ?? throw new ArgumentNullException(nameof(level));
     TileWidthMapUnits  = level.Resolution * 256;
     TileHeightMapUnits = level.Resolution * 256;
 }
        void SetLod()
        {
            Api.UnityMagicLeap_MeshingSetLod(levelOfDetail);
#if UNITY_EDITOR
            m_CachedLod = levelOfDetail;
#endif
        }
Beispiel #7
0
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     if (lod != LevelOfDetail.Low)
     {
         RenderBackground(graphics);
     }
     RenderBar(graphics);
 }
Beispiel #8
0
        protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
        {
            var   borderBrush = new SolidBrush(Color);
            var   b           = Bounds;
            float t           = 3f;

            graphics.FillRectangle(borderBrush, b);
            graphics.FillRectangle(Brushes.White, b.X + t, b.Y + t, b.Width - 2 * t, b.Height - 2 * t - ChinHeight);
            borderBrush.Dispose();
        }
Beispiel #9
0
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     if (lod == LevelOfDetail.High)
     {
         var brush = new SolidBrush(Color);
         var pen   = new Pen(brush, Thk);
         graphics.DrawLine(pen, Pivot, Pivot + new SizeF(0, Height));
         brush.Dispose();
         pen.Dispose();
     }
 }
Beispiel #10
0
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     if (lod == LevelOfDetail.High)
     {
         RenderTag(graphics);
         RenderText(graphics);
     }
     else if (lod == LevelOfDetail.Medium)
     {
         RenderTagMedium(graphics);
     }
 }
Beispiel #11
0
        public void Deserialize(IBlock parent, Stream input, Endian endian)
        {
            var count = input.ReadValueS32(endian);

            this.Items.Clear();
            for (int i = 0; i < count; i++)
            {
                var lod = new LevelOfDetail();
                lod.Deserialize(input, endian);
                this.Items.Add(lod);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Convert a Openmetaverse.Primitive to a PrimMesh
        /// </summary>
        /// <param name="thePrim"></param>
        /// <param name="detail"></param>
        /// <param name="pos"></param>
        /// <param name="rot"></param>
        /// <returns></returns>
        public PrimMesh PrimitiveToPrimMesh(Primitive thePrim, LevelOfDetail detail, Vector3 Scale, Quaternion rot)
        {
            bool     UseExtremeDetail = Scale.X + Scale.Y + Scale.Z > UseExtremeDetailSize;
            PrimMesh mesh             = ConstructionDataToPrimMesh(thePrim.PrimData, detail, UseExtremeDetail ? 2 : 1);

#if COLLIDER_ODE
            mesh.PBS = PrimToBaseShape(thePrim);
#endif
            mesh.Scale(Scale.X, Scale.Y, Scale.Z);
            // if (rot != Quaternion.Identity)
            mesh.AddRot(QuaternionToQuat(rot));
            return(mesh);
        }
Beispiel #13
0
        private LevelHighlights GetHighlights(LevelOfDetail lod)
        {
            if (_highlights.TryGetValue(lod, out var highlights))
            {
                return(highlights);
            }

            highlights = new LevelHighlights();
            highlights.Overlay.IsVisible = _show;
            _highlights.Add(lod, highlights);
            _mapView.GraphicsOverlays.Add(highlights.Overlay);
            return(highlights);
        }
        /// <summary>
        /// Updates instancing data buffer
        /// </summary>
        /// <param name="context">Update context</param>
        private void UpdateInstancingData(UpdateContext context)
        {
            if (!this.instancesTmp.Any())
            {
                return;
            }

            this.SortInstances(context.EyePosition);

            LevelOfDetail lastLod       = LevelOfDetail.None;
            DrawingData   drawingData   = null;
            int           instanceIndex = 0;

            for (int i = 0; i < this.instancesTmp.Length; i++)
            {
                var current = this.instancesTmp[i];
                if (current == null)
                {
                    continue;
                }

                if (lastLod != current.LevelOfDetail)
                {
                    lastLod     = current.LevelOfDetail;
                    drawingData = this.GetDrawingData(lastLod);
                }

                uint animationOffset = 0;

                if (drawingData?.SkinningData != null)
                {
                    if (current.AnimationController.Playing)
                    {
                        current.InvalidateCache();
                    }

                    current.AnimationController.Update(context.GameTime.ElapsedSeconds, drawingData.SkinningData);
                    animationOffset = current.AnimationController.GetAnimationOffset(drawingData.SkinningData);
                }

                this.instancingData[instanceIndex].Local           = current.Manipulator.LocalTransform;
                this.instancingData[instanceIndex].TextureIndex    = current.TextureIndex;
                this.instancingData[instanceIndex].AnimationOffset = animationOffset;

                instanceIndex++;
            }

            //Mark to write instancing data
            hasDataToWrite = instanceIndex > 0;
        }
Beispiel #15
0
        public int CompareTo(TileId other)
        {
            var num = LevelOfDetail.CompareTo(other.LevelOfDetail);

            if (num == 0)
            {
                num = X.CompareTo(other.X);
                if (num == 0)
                {
                    num = Y.CompareTo(other.Y);
                }
            }
            return(num);
        }
Beispiel #16
0
        /// <summary>
        /// Gets the drawing data by level of detail
        /// </summary>
        /// <param name="lod">Level of detail</param>
        /// <returns>Returns the drawing data object</returns>
        internal DrawingData GetDrawingData(LevelOfDetail lod)
        {
            if (this.meshesByLOD == null)
            {
                return(null);
            }

            if (this.meshesByLOD.ContainsKey(lod))
            {
                return(this.meshesByLOD[lod]);
            }

            return(null);
        }
Beispiel #17
0
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     if (lod == LevelOfDetail.High)
     {
         RenderIcon(graphics);
         RenderText(graphics);
     }
     else if (lod == LevelOfDetail.Medium)
     {
         var brush = new SolidBrush(FontColor.Lighten());
         graphics.FillRectangle(brush, Bounds.Shrink(PaddingH, PaddingV));
         brush.Dispose();
     }
 }
Beispiel #18
0
        private static async Task <byte[]> DownloadDefaultAvatarAsync(LevelOfDetail levelOfDetail, Dictionary <string, string> additionalParameters = null)
        {
            Dictionary <string, string> queryParameters = new Dictionary <string, string>();

            queryParameters.Add("lod", Convert.ToInt32(levelOfDetail).ToString());
            if (additionalParameters != null)
            {
                foreach (var parameter in additionalParameters)
                {
                    queryParameters.Add(parameter.Key, parameter.Value);
                }
            }
            return(await DownloadFile(DEFAULT_AVATAR_URL, null, queryParameters));
        }
Beispiel #19
0
        private static async Task <byte[]> DownloadAvatarAsync(string avatarId, LevelOfDetail levelOfDetail, string snapAccessToken, Dictionary <string, string> additionalParameters = null)
        {
            Dictionary <string, string> queryParameters = new Dictionary <string, string>();

            queryParameters.Add("lod", Convert.ToInt32(levelOfDetail).ToString());
            queryParameters.Add("avatar_id", avatarId);
            if (additionalParameters != null)
            {
                foreach (var parameter in additionalParameters)
                {
                    queryParameters.Add(parameter.Key, parameter.Value);
                }
            }
            return(await DownloadFile(AVATAR_URL, snapAccessToken, queryParameters));
        }
        private static TileInfo CreateTileInfo()
        {
            var    levels     = new LevelOfDetail[19];
            double resolution = 20037508.3427892 * 2 / 256;
            double scale      = resolution * 96 * 39.37;

            for (int i = 0; i < levels.Length; i++)
            {
                levels[i]   = new LevelOfDetail(i, resolution, scale);
                resolution /= 2;
                scale      /= 2;
            }
            return(new TileInfo(96, TileImageFormat.Png, levels, new MapPoint(-20037508.3427892, 20037508.3427892, SpatialReferences.WebMercator),
                                SpatialReferences.WebMercator, 256, 256));
        }
Beispiel #21
0
 public static float LevelOfDetailToDensity(LevelOfDetail lod)
 {
     if (lod == LevelOfDetail.Minimum)
     {
         return(0.0f);
     }
     else if (lod == LevelOfDetail.Medium)
     {
         return(0.5f);
     }
     else
     {
         return(1.0f);
     }
 }
Beispiel #22
0
        public AdvancedImportViewModel(XivMdl xivMdl, IItemModel itemModel, XivRace selectedRace, AdvancedModelImportView view)
        {
            var appStyle = ThemeManager.DetectAppStyle(System.Windows.Application.Current);

            if (appStyle.Item1.Name.Equals("BaseDark"))
            {
                _textColor = "White";
            }

            _view         = view;
            _xivMdl       = xivMdl;
            _lod          = xivMdl.LoDList[0];
            _itemModel    = itemModel;
            _selectedRace = selectedRace;
            _dae          = new Dae(new DirectoryInfo(Settings.Default.FFXIV_Directory), itemModel.DataFile);
            Initialize();
        }
Beispiel #23
0
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     if (lod == LevelOfDetail.High)
     {
         var imageBounds = new RectangleF(
             Pivot.X + PaddingH,
             Pivot.Y + PaddingV,
             Size.Width - 2 * PaddingH,
             Size.Height - 2 * PaddingV);
         graphics.DrawImage(Icon, imageBounds);
     }
     else if (lod == LevelOfDetail.Medium)
     {
         var brush = new SolidBrush(Color.Gray);
         graphics.FillRectangle(brush, Bounds.Shrink(PaddingH, PaddingV));
         brush.Dispose();
     }
 }
Beispiel #24
0
        /// <summary>
        /// Gets the first drawing data avaliable for the specified level of detail, from the specified one
        /// </summary>
        /// <param name="lod">First level of detail</param>
        /// <returns>Returns the first available level of detail drawing data</returns>
        internal DrawingData GetFirstDrawingData(LevelOfDetail lod)
        {
            if (this.meshesByLOD == null)
            {
                return(null);
            }

            while (lod > LevelOfDetail.None)
            {
                if (this.meshesByLOD.ContainsKey(lod))
                {
                    return(this.meshesByLOD[lod]);
                }

                lod = (LevelOfDetail)((int)lod / 2);
            }

            return(null);
        }
Beispiel #25
0
 public override void RenderAt(PointF pivot, Graphics graphics, LevelOfDetail lod)
 {
     Pivot = pivot;
     if (pressed && hover)
     {
         RenderPressedOn(graphics, lod);
     }
     else if (pressed)
     {
         RenderPressedOff(graphics, lod);
     }
     else if (hover)
     {
         RenderHover(graphics, lod);
     }
     else
     {
         RenderBase(graphics, lod);
     }
 }
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     //Doesn't do any base rendering
 }
Beispiel #27
0
        /// <summary>
        /// Generate the co-ords and faces necessary to construct a mesh from the shape data the accompanies a prim.
        /// </summary>
        /// <param name="primName"></param>
        /// <param name="primShape"></param>
        /// <param name="size"></param>
        /// <param name="coords">Coords are added to this list by the method.</param>
        /// <param name="faces">Faces are added to this list by the method.</param>
        /// <returns>true if coords and faces were successfully generated, false if not</returns>
        private bool GenerateCoordsAndFacesFromPrimShapeData(
            string primName, PrimitiveBaseShape primShape, Vector3 size, float lod, out List <Coord> coords, out List <Face> faces)
        {
            PrimMesh primMesh;

            coords = new List <Coord>();
            faces  = new List <Face>();

            float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f;
            float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f;
            float pathBegin  = (float)primShape.PathBegin * 2.0e-5f;
            float pathEnd    = 1.0f - (float)primShape.PathEnd * 2.0e-5f;
            float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f;
            float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f;

            float profileBegin  = (float)primShape.ProfileBegin * 2.0e-5f;
            float profileEnd    = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f;
            float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f;

            if (profileHollow > 0.95f)
            {
                profileHollow = 0.95f;
            }

            int           sides = 4;
            LevelOfDetail iLOD  = (LevelOfDetail)lod;

            if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
            {
                sides = 3;
            }
            else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
            {
                switch (iLOD)
                {
                case LevelOfDetail.High:    sides = 24;     break;

                case LevelOfDetail.Medium:  sides = 12;     break;

                case LevelOfDetail.Low:     sides = 6;      break;

                case LevelOfDetail.VeryLow: sides = 3;      break;

                default:                    sides = 24;     break;
                }
            }
            else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
            { // half circle, prim is a sphere
                switch (iLOD)
                {
                case LevelOfDetail.High:    sides = 24;     break;

                case LevelOfDetail.Medium:  sides = 12;     break;

                case LevelOfDetail.Low:     sides = 6;      break;

                case LevelOfDetail.VeryLow: sides = 3;      break;

                default:                    sides = 24;     break;
                }

                profileBegin = 0.5f * profileBegin + 0.5f;
                profileEnd   = 0.5f * profileEnd + 0.5f;
            }

            int hollowSides = sides;

            if (primShape.HollowShape == HollowShape.Circle)
            {
                switch (iLOD)
                {
                case LevelOfDetail.High:    hollowSides = 24;     break;

                case LevelOfDetail.Medium:  hollowSides = 12;     break;

                case LevelOfDetail.Low:     hollowSides = 6;      break;

                case LevelOfDetail.VeryLow: hollowSides = 3;      break;

                default:                    hollowSides = 24;     break;
                }
            }
            else if (primShape.HollowShape == HollowShape.Square)
            {
                hollowSides = 4;
            }
            else if (primShape.HollowShape == HollowShape.Triangle)
            {
                hollowSides = 3;
            }

            primMesh = new PrimMesh(sides, profileBegin, profileEnd, profileHollow, hollowSides);

            if (primMesh.errorMessage != null)
            {
                if (primMesh.errorMessage.Length > 0)
                {
                    m_log.Error("[ERROR] " + primMesh.errorMessage);
                }
            }

            primMesh.topShearX    = pathShearX;
            primMesh.topShearY    = pathShearY;
            primMesh.pathCutBegin = pathBegin;
            primMesh.pathCutEnd   = pathEnd;

            if (primShape.PathCurve == (byte)Extrusion.Straight || primShape.PathCurve == (byte)Extrusion.Flexible)
            {
                primMesh.twistBegin = primShape.PathTwistBegin * 18 / 10;
                primMesh.twistEnd   = primShape.PathTwist * 18 / 10;
                primMesh.taperX     = pathScaleX;
                primMesh.taperY     = pathScaleY;

                if (profileBegin < 0.0f || profileBegin >= profileEnd || profileEnd > 1.0f)
                {
                    ReportPrimError("*** CORRUPT PRIM!! ***", primName, primMesh);
                    if (profileBegin < 0.0f)
                    {
                        profileBegin = 0.0f;
                    }
                    if (profileEnd > 1.0f)
                    {
                        profileEnd = 1.0f;
                    }
                }
#if SPAM
                m_log.Debug("****** PrimMesh Parameters (Linear) ******\n" + primMesh.ParamsToDisplayString());
#endif
                try
                {
                    primMesh.ExtrudeLinear();
                }
                catch (Exception ex)
                {
                    ReportPrimError("Extrusion failure: exception: " + ex.ToString(), primName, primMesh);
                    return(false);
                }
            }
            else
            {
                primMesh.holeSizeX   = (200 - primShape.PathScaleX) * 0.01f;
                primMesh.holeSizeY   = (200 - primShape.PathScaleY) * 0.01f;
                primMesh.radius      = 0.01f * primShape.PathRadiusOffset;
                primMesh.revolutions = 1.0f + 0.015f * primShape.PathRevolutions;
                primMesh.skew        = 0.01f * primShape.PathSkew;
                primMesh.twistBegin  = primShape.PathTwistBegin * 36 / 10;
                primMesh.twistEnd    = primShape.PathTwist * 36 / 10;
                primMesh.taperX      = primShape.PathTaperX * 0.01f;
                primMesh.taperY      = primShape.PathTaperY * 0.01f;

                if (profileBegin < 0.0f || profileBegin >= profileEnd || profileEnd > 1.0f)
                {
                    ReportPrimError("*** CORRUPT PRIM!! ***", primName, primMesh);
                    if (profileBegin < 0.0f)
                    {
                        profileBegin = 0.0f;
                    }
                    if (profileEnd > 1.0f)
                    {
                        profileEnd = 1.0f;
                    }
                }
#if SPAM
                m_log.Debug("****** PrimMesh Parameters (Circular) ******\n" + primMesh.ParamsToDisplayString());
#endif
                try
                {
                    primMesh.ExtrudeCircular();
                }
                catch (Exception ex)
                {
                    ReportPrimError("Extrusion failure: exception: " + ex.ToString(), primName, primMesh);
                    return(false);
                }
            }

            primMesh.DumpRaw(baseDir, primName, "primMesh");

            primMesh.Scale(size.X, size.Y, size.Z);

            coords = primMesh.coords;
            faces  = primMesh.faces;

            return(true);
        }
Beispiel #28
0
        // from IdealistViewer.PrimMesherG.cs
        public PrimMesh ConstructionDataToPrimMesh(Primitive.ConstructionData primData, LevelOfDetail detail, float detailMult)
        {

            this.sides = 4;
            this.hollowsides = 4;

            float profileBegin = primData.ProfileBegin;
            float profileEnd = primData.ProfileEnd;
            bool isSphere = false;

            if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.Circle)
            {
                switch (detail)
                {
                    case LevelOfDetail.Low:
                        sides = 6;
                        break;
                    case LevelOfDetail.Medium:
                        sides = 12;
                        break;
                    default:
                        sides = 24;
                        break;
                }
            }
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.EqualTriangle)
                sides = 3;
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.HalfCircle)
            { // half circle, prim is a sphere
                isSphere = true;
                switch (detail)
                {
                    case LevelOfDetail.Low:
                        sides = 6;
                        break;
                    case LevelOfDetail.Medium:
                        sides = 12;
                        break;
                    default:
                        sides = 24;
                        break;
                }
                profileBegin = 0.5f * profileBegin + 0.5f;
                profileEnd = 0.5f * profileEnd + 0.5f;
            }

            if ((HoleType)primData.ProfileHole == HoleType.Same)
                hollowsides = sides;
            else if ((HoleType)primData.ProfileHole == HoleType.Circle)
            {
                switch (detail)
                {
                    case LevelOfDetail.Low:
                        hollowsides = 6;
                        break;
                    case LevelOfDetail.Medium:
                        hollowsides = 12;
                        break;
                    default:
                        hollowsides = 24;
                        break;
                }

            }
            else if ((HoleType)primData.ProfileHole == HoleType.Triangle)
                hollowsides = 3;

            //  if (UseExtremeDetail)
            {
                sides = (int)(sides * detailMult);
                hollowsides = (int)(hollowsides * detailMult);
            }
            PrimMesh primMesh = new PrimMesh(sides, profileBegin, profileEnd, (float)primData.ProfileHollow, hollowsides);
            primMesh.viewerMode = UseViewerMode;
            primMesh.holeSizeX = primData.PathScaleX;
            primMesh.holeSizeY = primData.PathScaleY;
            primMesh.pathCutBegin = primData.PathBegin;
            primMesh.pathCutEnd = primData.PathEnd;
            primMesh.topShearX = primData.PathShearX;
            primMesh.topShearY = primData.PathShearY;
            primMesh.radius = primData.PathRadiusOffset;
            primMesh.revolutions = primData.PathRevolutions;
            primMesh.skew = primData.PathSkew;
            switch (detail)
            {
                case LevelOfDetail.Low:
                    primMesh.stepsPerRevolution = 6;
                    break;
                case LevelOfDetail.Medium:
                    primMesh.stepsPerRevolution = 12;
                    break;
                default:
                    primMesh.stepsPerRevolution = 24;
                    break;
            }

            //if (UseExtremeDetail)
            {
                primMesh.stepsPerRevolution = (int)(primMesh.stepsPerRevolution * detailMult);
            }


            if (primData.PathCurve == PathCurve.Line)
            {
                primMesh.taperX = 1.0f - primData.PathScaleX;
                primMesh.taperY = 1.0f - primData.PathScaleY;
                primMesh.twistBegin = (int)(180 * primData.PathTwistBegin);
                primMesh.twistEnd = (int)(180 * primData.PathTwist);
                primMesh.ExtrudeLinear();
            }
            else
            {
                primMesh.taperX = primData.PathTaperX;
                primMesh.taperY = primData.PathTaperY;
                primMesh.twistBegin = (int)(360 * primData.PathTwistBegin);
                primMesh.twistEnd = (int)(360 * primData.PathTwist);
                primMesh.ExtrudeCircular();
            }


            if (UseViewerMode)
            {
                int numViewerFaces = primMesh.viewerFaces.Count;
                for (uint i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace vf = primMesh.viewerFaces[(int)i];

                    if (isSphere)
                    {
                        vf.uv1.U = (vf.uv1.U - 0.5f) * 2.0f;
                        vf.uv2.U = (vf.uv2.U - 0.5f) * 2.0f;
                        vf.uv3.U = (vf.uv3.U - 0.5f) * 2.0f;
                    }
                }
            }
            return primMesh;
        }
Beispiel #29
0
 void StartLOD()
 {
     _levelOfDetail = new LevelOfDetail(this);
 }
Beispiel #30
0
        public static Mesh PrimitiveToIrrMesh(Primitive prim, LevelOfDetail detail)
        {
            Primitive.ConstructionData primData = prim.PrimData;
            int sides = 4;
            int hollowsides = 4;

            float profileBegin = primData.ProfileBegin;
            float profileEnd = primData.ProfileEnd;
            bool isSphere = false;

            if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.Circle)
            {
                switch (detail)
                {
                    case LevelOfDetail.Low:
                        sides = 6;
                        break;
                    case LevelOfDetail.Medium:
                        sides = 12;
                        break;
                    default:
                        sides = 24;
                        break;
                }
            }
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.EqualTriangle)
            {
                sides = 3;
            }
            // half circle, prim is a sphere
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.HalfCircle)
            {
                isSphere = true;
                switch (detail)
                {
                    case LevelOfDetail.Low:
                        sides = 6;
                        break;
                    case LevelOfDetail.Medium:
                        sides = 12;
                        break;
                    default:
                        sides = 24;
                        break;
                }
                profileBegin = 0.5f * profileBegin + 0.5f;
                profileEnd = 0.5f * profileEnd + 0.5f;
            }

            if ((HoleType)primData.ProfileHole == HoleType.Same)
            {
                hollowsides = sides;
            }
            else if ((HoleType)primData.ProfileHole == HoleType.Circle)
            {
                switch (detail)
                {
                    case LevelOfDetail.Low:
                        hollowsides = 6;
                        break;
                    case LevelOfDetail.Medium:
                        hollowsides = 12;
                        break;
                    default:
                        hollowsides = 24;
                        break;
                }

            }
            else if ((HoleType)primData.ProfileHole == HoleType.Triangle)
                hollowsides = 3;

            PrimMesh newPrim = new PrimMesh(sides, profileBegin, profileEnd, (float)primData.ProfileHollow, hollowsides);
            newPrim.viewerMode = true;
            newPrim.holeSizeX = primData.PathScaleX;
            newPrim.holeSizeY = primData.PathScaleY;
            newPrim.pathCutBegin = primData.PathBegin;
            newPrim.pathCutEnd = primData.PathEnd;
            newPrim.topShearX = primData.PathShearX;
            newPrim.topShearY = primData.PathShearY;
            newPrim.radius = primData.PathRadiusOffset;
            newPrim.revolutions = primData.PathRevolutions;
            newPrim.skew = primData.PathSkew;

            switch (detail)
            {
                case LevelOfDetail.Low:
                    newPrim.stepsPerRevolution = 6;
                    break;
                case LevelOfDetail.Medium:
                    newPrim.stepsPerRevolution = 12;
                    break;
                default:
                    newPrim.stepsPerRevolution = 24;
                    break;
            }

            if (primData.PathCurve == PathCurve.Line)
            {
                newPrim.taperX = 1.0f - primData.PathScaleX;
                newPrim.taperY = 1.0f - primData.PathScaleY;
                newPrim.twistBegin = (int)(180 * primData.PathTwistBegin);
                newPrim.twistEnd = (int)(180 * primData.PathTwist);
                newPrim.ExtrudeLinear();
            }
            else if (primData.PathCurve == PathCurve.Flexible)
            {
                newPrim.taperX = 1.0f - primData.PathScaleX;
                newPrim.taperY = 1.0f - primData.PathScaleY;
                newPrim.twistBegin = (int)(180 * primData.PathTwistBegin);
                newPrim.twistEnd = (int)(180 * primData.PathTwist);
                newPrim.ExtrudeLinear();
            }
            else
            {
                newPrim.taperX = primData.PathTaperX;
                newPrim.taperY = primData.PathTaperY;
                newPrim.twistBegin = (int)(360 * primData.PathTwistBegin);
                newPrim.twistEnd = (int)(360 * primData.PathTwist);
                newPrim.ExtrudeCircular();
            }

            int numViewerFaces = newPrim.viewerFaces.Count;

            for (uint i = 0; i < numViewerFaces; i++)
            {
                ViewerFace vf = newPrim.viewerFaces[(int)i];

                if (isSphere)
                {
                    vf.uv1.U = (vf.uv1.U - 0.5f) * 2.0f;
                    vf.uv2.U = (vf.uv2.U - 0.5f) * 2.0f;
                    vf.uv3.U = (vf.uv3.U - 0.5f) * 2.0f;
                }
            }

            return FacesToIrrMesh(newPrim.viewerFaces, newPrim.numPrimFaces);
        }
Beispiel #31
0
 // Change LOD setting
 public static void ChangeLOD(QualityLevel qualityLevel)
 {
     currentLOD = levelOfDetails[(int)qualityLevel];
 }
Beispiel #32
0
        /// <summary>
        /// Generates a index for a triangle soup quad with the specified shape
        /// </summary>
        /// <param name="lod">Level of detail</param>
        /// <param name="bufferShape">Buffer shape</param>
        /// <param name="triangles">Triangle count</param>
        /// <returns>Returns the generated index list</returns>
        public static uint[] GenerateIndices(LevelOfDetail lod, IndexBufferShapes bufferShape, int triangles)
        {
            uint offset   = (uint)lod;
            uint fullSide = (uint)Math.Sqrt(triangles / 2f);

            int tris = triangles / (int)Math.Pow(offset, 2);

            int  nodes    = tris / 2;
            uint side     = (uint)Math.Sqrt(nodes);
            uint sideLoss = side / 2;

            bool topSide =
                bufferShape == IndexBufferShapes.CornerTopLeft ||
                bufferShape == IndexBufferShapes.CornerTopRight ||
                bufferShape == IndexBufferShapes.SideTop;

            bool bottomSide =
                bufferShape == IndexBufferShapes.CornerBottomLeft ||
                bufferShape == IndexBufferShapes.CornerBottomRight ||
                bufferShape == IndexBufferShapes.SideBottom;

            bool leftSide =
                bufferShape == IndexBufferShapes.CornerBottomLeft ||
                bufferShape == IndexBufferShapes.CornerTopLeft ||
                bufferShape == IndexBufferShapes.SideLeft;

            bool rightSide =
                bufferShape == IndexBufferShapes.CornerBottomRight ||
                bufferShape == IndexBufferShapes.CornerTopRight ||
                bufferShape == IndexBufferShapes.SideRight;

            uint totalTriangles = (uint)tris;

            if (topSide)
            {
                totalTriangles -= sideLoss;
            }
            if (bottomSide)
            {
                totalTriangles -= sideLoss;
            }
            if (leftSide)
            {
                totalTriangles -= sideLoss;
            }
            if (rightSide)
            {
                totalTriangles -= sideLoss;
            }

            List <uint> indices = new List <uint>((int)totalTriangles * 3);

            for (uint y = 1; y < side; y += 2)
            {
                for (uint x = 1; x < side; x += 2)
                {
                    uint indexPRow = (((y - 1) * offset) * (fullSide + 1)) + (x * offset);
                    uint indexCRow = (((y + 0) * offset) * (fullSide + 1)) + (x * offset);
                    uint indexNRow = (((y + 1) * offset) * (fullSide + 1)) + (x * offset);

                    bool firstRow    = y == 1;
                    bool lastRow     = y == side - 1;
                    bool firstColumn = x == 1;
                    bool lastColumn  = x == side - 1;

                    //Top side
                    var top = ComputeTopSide(firstRow, topSide, offset, indexPRow, indexCRow);

                    //Bottom side
                    var bottom = ComputeBottomSide(lastRow, bottomSide, offset, indexCRow, indexNRow);

                    //Left side
                    var left = ComputeLeftSide(firstColumn, leftSide, offset, indexPRow, indexCRow, indexNRow);

                    //Right side
                    var right = ComputeRightSide(lastColumn, rightSide, offset, indexPRow, indexCRow, indexNRow);

                    indices.AddRange(top);
                    indices.AddRange(bottom);
                    indices.AddRange(left);
                    indices.AddRange(right);
                }
            }

            return(indices.ToArray());
        }
Beispiel #33
0
        /// <summary>
        /// Convert a Openmetaverse.Primitive to a PrimMesh
        /// </summary>
        /// <param name="thePrim"></param>
        /// <param name="detail"></param>
        /// <param name="pos"></param>
        /// <param name="rot"></param>
        /// <returns></returns>
        public PrimMesh PrimitiveToPrimMesh(Primitive thePrim, LevelOfDetail detail, Vector3 Scale, Quaternion rot)
        {
            bool UseExtremeDetail = Scale.X + Scale.Y + Scale.Z > UseExtremeDetailSize;
            PrimMesh mesh = ConstructionDataToPrimMesh(thePrim.PrimData, detail, UseExtremeDetail ? 2 : 1);
#if COLLIDER_ODE
            mesh.PBS = PrimToBaseShape(thePrim);
#endif
            mesh.Scale(Scale.X, Scale.Y, Scale.Z);
            // if (rot != Quaternion.Identity)                
            mesh.AddRot(QuaternionToQuat(rot));
            return mesh;
        }
Beispiel #34
0
        public Mesh PrimitiveToMesh(Primitive primitive, Vector3 Scale, Quaternion rot)
        {

            bool wasSculpt = primitive.Sculpt != null;
            if (wasSculpt && WorldPathSystem.SculptCollisions)
            {
                Primitive.SculptData SD = primitive.Sculpt;
                UUID Id = SD.SculptTexture;
                SculptMesh SM;
                if (!SculptedMeshes.TryGetValue(Id, out SM))
                {
                    byte[] bytes = WorldObjects.GridMaster.TextureBytesForUUID(SD.SculptTexture);
                    SM = ToSculptMesh(bytes, primitive.Sculpt, "" + primitive);
                    if (MaintainSculptPool) SculptedMeshes[Id] = SM;
                    //  SM.DumpRaw(".", primitive.ID.ToString(), "sculptMesh" + primitive.LocalID);
                }
                if (SM != null)
                {
                    SM = SM.Copy();
                    SM.Scale(Scale.X, Scale.Y, Scale.Z);
                    SM.AddRot(QuaternionToQuat(rot));
                    return ToMesh(
#if COLLIDER_ODE
                        PrimToBaseShape(primitive),
                        #endif

                        SM.coords, SM.faces, SM.viewerFaces, primitive.Type == PrimType.Sphere);
                }
            }

            this.scaleSize = Scale.X + Scale.Y + Scale.Z;
            bool UseExtremeDetail = scaleSize > UseExtremeDetailSize;
            //LevelOfDetail detail;
            if (scaleSize < UseLowDetailSize)
                detail = LevelOfDetail.Low;
            else
                detail = LevelOfDetail.Medium;
            if (UseExtremeDetail)
            {
                if (primitive.Type == PrimType.Box)
                {
                    detail = LevelOfDetail.Medium;
                } else
                {
                    detail = LevelOfDetail.High;
                }
            }

            PrimMesh primMesh = ConstructionDataToPrimMesh(primitive.PrimData, detail, UseExtremeDetail ? 2 : 1);
            primMesh.Scale(Scale.X, Scale.Y, Scale.Z);
            primMesh.AddRot(QuaternionToQuat(rot));
            Mesh m = PrimMeshToMesh(primMesh);
#if COLLIDER_ODE
            m.PBS = PrimToBaseShape(primitive);
#endif
            return m;
        }
Beispiel #35
0
 /// <summary>
 /// Tests the tiles in a level of detail and writes the results to a text table file.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="layerInfo"></param>
 /// <param name="lod"></param>
 private static void TestLod(Options options, MapService layerInfo, LevelOfDetail lod)
 {
     if ((!options.StartLevel.HasValue || lod.level >= options.StartLevel) && (!options.EndLevel.HasValue || lod.level <= options.EndLevel))
     {
         Debug.WriteLine("Begin testing LOD#{0}...", lod.level);
         var level = lod.level;
         var firstTile = layerInfo.GetFirstTile(level);
         var lastTile = layerInfo.GetLastTile(level);
         ParallelLoopResult plResult = Parallel.For(firstTile.Row, lastTile.Row, _parallelOptions, r => TestRow(options, layerInfo, lod, level, firstTile, lastTile, r));
         while (!plResult.IsCompleted)
         {
             // DO nothing.
         }
         Debug.WriteLine("End testing LOD#{0}...", lod.level);
     }
 }
Beispiel #36
0
        private static void TestRow(Options options, MapService layerInfo, LevelOfDetail lod, int level, Tile firstTile, Tile lastTile, int row)
        {
            // Exit the method if the row is out of the range of user-specified rows.
            if (
                (options.StartLevel.HasValue && options.StartLevel == level && options.StartRow.HasValue && row < options.StartRow)
                ||
                (options.EndLevel.HasValue && options.EndLevel == level && options.EndRow.HasValue && row > options.EndRow)
                )
            {
                return;
            }
            WebRequest webRequest;
            using (var sw = new StreamWriter(Path.Combine(options.OutputDirectory, string.Format("{0:00}_{1:000000}.csv", level, row)), false, System.Text.Encoding.ASCII))
            {
                sw.WriteLine("\"LOD\",\"Row\",\"Col\",\"xmin\",\"ymin\",\"xmax\",\"ymax\",\"ContentLength\",\"Error\"");
                for (int c = firstTile.Column; c < lastTile.Column; c++)
                {
                    var tileUrl = options.Url.GetTileUrl(level, row, c);

                    webRequest = HttpWebRequest.Create(tileUrl);
                    WebResponse response = null;
                    var envelope = layerInfo.GetTileExtent(level, row, c);
                    Exception theException = null;
                    int? contentLength = default(int?);
                    try
                    {
                        webRequest.Method = "HEAD";
                        response = webRequest.GetResponse();
                        string clStr = response.Headers[HttpResponseHeader.ContentLength];
                        int tempCl;
                        if (!string.IsNullOrWhiteSpace(clStr) && int.TryParse(clStr, out tempCl))
                        {
                            contentLength = tempCl;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceWarning("An exception occured at LOD {0}, row {1}, column {2}{3}{4}", lod.level, row, c, Environment.NewLine, ex);
                        theException = ex;
                    }
                    finally
                    {
                        if (response != null)
                        {
                            response.Close();
                        }
                    }
                    if (theException != null ||
                        (options.WriteErrorsOnly.HasValue && !options.WriteErrorsOnly.Value) ||
                        (options.MinimumValidContentLength.HasValue && (!contentLength.HasValue || contentLength.Value < options.MinimumValidContentLength.Value))
                        )
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                            level, row, c, envelope.xmin, envelope.ymin, envelope.xmax, envelope.ymax,
                            contentLength.HasValue ? contentLength.Value.ToString() : string.Empty,
                            theException != null ? string.Format("\"{0}\"", theException.Message) : string.Empty);
                        sw.Flush();
                    }
                }
            }
        }