Ejemplo n.º 1
0
        /// <summary>
        /// Remove a strategy from the manager with a specified name.
        /// </summary>
        /// <remarks>
        /// The removed strategy is returned so the user can control
        /// how it is destroyed.
        /// </remarks>
        /// <param name="name"></param>
        /// <returns></returns>
        public LodStrategy RemoveStrategy(string name)
        {
            LodStrategy ret = null;

            if (this._strategies.TryGetValue(name, out ret))
            {
                this._strategies.Remove(name);
                return(ret);
            }
            return(ret);
        }
Ejemplo n.º 2
0
            public void Assign(QueuedSubMesh qsm)
            {
                this.queuedSubMeshes.Add(qsm);

                // update lod distances
                var mesh        = qsm.submesh.Parent;
                var lodStrategy = mesh.LodStrategy;

                if (this.lodStrategy == null)
                {
                    this.lodStrategy = lodStrategy;
                    // First LOD mandatory, and always from base lod value
                    this.lodValues.Add(this.lodStrategy.BaseValue);
                }
                else
                {
                    if (this.lodStrategy != lodStrategy)
                    {
                        throw new AxiomException("Lod strategies do not match.");
                    }
                }

                var lodLevels = mesh.LodLevelCount;

                if (qsm.geometryLodList.Count != lodLevels)
                {
                    var msg = string.Format("QueuedSubMesh '{0}' lod count of {1} does not match parent count of {2}",
                                            qsm.submesh.Name, qsm.geometryLodList.Count, lodLevels);
                    throw new AxiomException(msg);
                }

                while (this.lodValues.Count < lodLevels)
                {
                    this.lodValues.Add(0.0f);
                }
                // Make sure LOD levels are max of all at the requested level
                for (ushort lod = 1; lod < lodLevels; ++lod)
                {
                    var meshLod = qsm.submesh.Parent.GetLodLevel(lod);
                    this.lodValues[lod] = Utility.Max((float)this.lodValues[lod], meshLod.Value);
                }

                // update bounds
                // Transform world bounds relative to our center
                var localBounds = new AxisAlignedBox(qsm.worldBounds.Minimum - this.center, qsm.worldBounds.Maximum - this.center);

                this.aabb.Merge(localBounds);
                foreach (var corner in localBounds.Corners)
                {
                    this.boundingRadius = Utility.Max(this.boundingRadius, corner.Length);
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a strategy to the manager.
        /// </summary>
        /// <param name="strategy"></param>
        public void AddStrategy(LodStrategy strategy)
        {
            // Check for invalid strategy name
            if (strategy.Name.ToLower() == "default")
            {
                throw new AxiomException("Lod strategy name must not be 'default'", new object[]
                {
                });
            }

            // Insert the strategy into the map with its name as the key
            this._strategies.Add(strategy.Name, strategy);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get the strategy with the specified name.
        /// </summary>
        /// <param name="name">name of the strategy</param>
        /// <returns>strategy with the given name</returns>
        public LodStrategy GetStrategy(string name)
        {
            // If name is "default", return the default strategy instead of performing a lookup
            if (name.ToLower() == "default")
            {
                return(DefaultStrategy);
            }

            LodStrategy ret = null;

            this._strategies.TryGetValue(name, out ret);

            return(ret);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public LodStrategyManager()
            : base()
        {
            // Add default (distance) strategy
            var distanceStrategy = new DistanceLodStrategy();

            AddStrategy(distanceStrategy);

            // Add new pixel-count strategy
            var pixelCountStrategy = new PixelCountStrategy();

            AddStrategy(pixelCountStrategy);

            // Set the default strategy
            DefaultStrategy = distanceStrategy;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Set the default strategy by name.
 /// </summary>
 /// <param name="name"></param>
 public void SetDefaultStrategy(string name)
 {
     DefaultStrategy = GetStrategy(name);
 }