Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="scene">Scene</param>
 /// <param name="description">Ground description</param>
 protected Ground(Scene scene, GroundDescription description)
     : base(scene, description)
 {
 }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="scene">Scene</param>
        /// <param name="description">Terrain description</param>
        public Scenery(Scene scene, GroundDescription description)
            : base(scene, description)
        {
            ModelContent content;

            if (!string.IsNullOrEmpty(description.Content.ModelContentFilename))
            {
                var contentDesc = Helper.DeserializeFromFile <ModelContentDescription>(Path.Combine(description.Content.ContentFolder, description.Content.ModelContentFilename));
                var loader      = contentDesc.GetLoader();
                var t           = loader.Load(description.Content.ContentFolder, contentDesc);
                content = t.First();
            }
            else if (description.Content.ModelContentDescription != null)
            {
                var loader = description.Content.ModelContentDescription.GetLoader();
                var t      = loader.Load(description.Content.ContentFolder, description.Content.ModelContentDescription);
                content = t.First();
            }
            else if (description.Content.HeightmapDescription != null)
            {
                content = ModelContent.FromHeightmap(
                    description.Content.HeightmapDescription.ContentPath,
                    description.Content.HeightmapDescription.HeightmapFileName,
                    description.Content.HeightmapDescription.Textures.TexturesLR,
                    description.Content.HeightmapDescription.CellSize,
                    description.Content.HeightmapDescription.MaximumHeight);
            }
            else if (description.Content.ModelContent != null)
            {
                content = description.Content.ModelContent;
            }
            else
            {
                throw new EngineException("No geometry found in description.");
            }

            #region Patches

            this.groundPickingQuadtree = new PickingQuadTree <Triangle>(content.GetTriangles(), description.Quadtree.MaximumDepth);

            var nodes = this.groundPickingQuadtree.GetLeafNodes();

            foreach (var node in nodes)
            {
                var patch = SceneryPatch.CreatePatch(this.Game, this.BufferManager, content, node);

                this.patchDictionary.Add(node.Id, patch);
            }

            #endregion

            #region Lights

            List <SceneLight> lights = new List <SceneLight>();

            foreach (var key in content.Lights.Keys)
            {
                var l = content.Lights[key];

                if (l.LightType == LightContentTypes.Point)
                {
                    lights.Add(l.CreatePointLight());
                }
                else if (l.LightType == LightContentTypes.Spot)
                {
                    lights.Add(l.CreateSpotLight());
                }
            }

            this.Lights = lights.ToArray();

            #endregion
        }