Ejemplo n.º 1
0
 /// <summary>
 /// Creates a distance metric value for a given hierarchy level depending on the polynomial equation
 /// specified through the coefficients in the supplied LevelOfDetailSettings structure. Assumes Level 0
 /// to have the greatest distance.
 /// </summary>
 public static double QuadraticDistanceFalling(int level, LevelOfDetailSettings settings)
 {
     return((settings.Max / (level * level * settings.Quadratic + level * settings.Linear + 1.0)) + settings.Constant);
 }
Ejemplo n.º 2
0
        private static ISg LodBoxHierarchy(
            int level, Volume <ISg> vgsVolume, LevelOfDetailSettings settings, int maxLevel)
        {
            int detailCount = 1;

            if (vgsVolume.SX > 1)
            {
                detailCount *= 2;
            }
            if (vgsVolume.SY > 1)
            {
                detailCount *= 2;
            }
            if (vgsVolume.SZ > 1)
            {
                detailCount *= 2;
            }

            //detail count is 1 when space is not dividable
            #region detailCount == 1
            if (detailCount == 1)
            {
                //if level > 0 keep subsampling without subdivision
                if (level > 0) //|| ( level == 0 && (vgsVolume[0, 0, 0].TileSize.X > 256 || vgsVolume[0, 0, 0].TileSize.Y > 256)))
                {
                    var detailNodeList = LodBoxHierarchy(level - 1, vgsVolume, settings, maxLevel).IntoList();

                    var dist = DistanceFunc(level - 1, settings);

                    Report.Line("LOD.cs Level " + level + " " + dist);

                    var box = new Sg.LodBox()
                    {
                        Name        = "level" + level,
                        DetailNodes = detailNodeList,
                        Settings    = new LodBoxSettings
                        {
                            Distance           = dist,
                            DeciderCombination = "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => Distance",
                        },
                    };

                    box["TileLayout"] = GetTileLayout(vgsVolume.Dim);
                    return(box);
                }

                return(vgsVolume[0, 0, 0]);
            }
            #endregion

            var detailNodes = new List <ISg>(detailCount);
            for (int i = 0; i < 8; i++)
            {
                bool valid  = true;
                V3l  origin = V3l.Zero;
                V3l  length = vgsVolume.Size;

                //compute splitting dimensions for each axis
                for (int dim = 0; dim < 3; dim++)
                {
                    if ((i & (1 << dim)) == 0)
                    {
                        if (length[dim] > 1)
                        {
                            length[dim] /= 2;
                        }
                    }
                    else
                    {
                        if (length[dim] > 1)
                        {
                            origin[dim] = length[dim] / 2;
                            length[dim] = length[dim] - origin[dim];
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                }

                if (valid)
                {
                    ISg detailNode =
                        LodBoxHierarchy(level - 1, vgsVolume.SubVolume(origin, length), settings, maxLevel);
                    detailNodes.Add(detailNode);
                }
            }

            {
                var dist = LevelOfDetail.DistanceFunc(level - 1, settings);

                //Report.Line("LOD.cs Level " + level + " " + dist);

                bool isMax = false; // level == maxLevel;

                var box = new Sg.LodBox()
                {
                    Name        = "level" + level,
                    DetailNodes = detailNodes,
                    Pinned      = Sg.LodBox.PinnedOptions.Default,
                    Settings    = new LodBoxSettings
                    {
                        Distance           = dist,
                        DeciderCombination = !isMax ? "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => Distance"
                        : "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => false",
                    },
                };

                // s_numOfBoxes++;

                box["TileLayout"] = GetTileLayout(vgsVolume.Dim);

                //Report.Line("DIM: " + vgsVolume.Dim.ToString() + " "
                //    + box["TileLayout"].ToString() + " __lvl: "
                //    + level + " Desc.: " + box.DetailNodes.Count());

                var sg = Rsg.Apply(
                    new ResourcePinningEnabledValue()
                {
                    Value = level == maxLevel
                }, box);

                return(box);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a distance metric value for a given hierarchy level depending on the polynomial equation
 /// specified through the coefficients in the supplied LevelOfDetailSettings structure. Assumes level 0
 /// to have the smallest distance
 /// </summary>
 public static double QuadraticDistance(int level, LevelOfDetailSettings settings)
 {
     return(level * level * settings.Quadratic + level * settings.Linear + settings.Constant);
 }
Ejemplo n.º 4
0
        public static ISg CreateBottomUpLodBoxHierarchyDataInLeaves(Volume <ISg> vgsVolume, LevelOfDetailSettings settings)
        {
            var maxLevel = ComputeHierarchyDepth(vgsVolume.Size.XY.ToV2i());

            return(LodBoxHierarchy(maxLevel, vgsVolume, settings, maxLevel));
        }