Exemplo n.º 1
0
        /// <summary>
        /// Processes a collision between photon and BSP.
        /// </summary>
        /// <param name="bsp">BSP to process.</param>
        /// <returns>If intersection occured.</returns>
        public bool ProcessCollision(List <IBsp> bsp, ITextureMapCollection textureCollection)
        {
            RadiosityIntersection radiosityIntersection;

            for (int i = 0; i < bsp.Count; i++)
            {
                if ((bool)(radiosityIntersection = bsp[i].RadiosityIntersect(this.m_position, this.m_direction)))
                {
                    if (radiosityIntersection.LightmapIndex >= 0)
                    {
                        if (!radiosityIntersection.WrongSide)
                        {
                            // Set the pixel in the texture collection to the value of the light colour.
                            textureCollection[radiosityIntersection.LightmapIndex].SetPixel(radiosityIntersection.U, radiosityIntersection.V, this.m_colour.ToArray(), textureCollection.Radius);
                        }
                    }

                    // Update current position to point of intersection with BSP.
                    this.m_position = radiosityIntersection.Position;

                    this.Color     = new RealColor(radiosityIntersection.TextureSampleColor);
                    this.Direction = radiosityIntersection.NewDirection;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private void LoadContentScript(XElement element)
        {
            var dataType = element.Attribute("type").Value;

            ITextureMapCollection data = dataType switch
            {
                "material" => new Material(),
                "envmap" => new EnvMap(),
                _ => null
            };

            if (data == null)
            {
                return;
            }

            string dataName    = element.Attribute("name").Value;
            var    mapElements = element.Elements("map");
            string outputPath  = element.Element("output").Attribute("path").Value;

            if (!Path.IsPathRooted(outputPath))
            {
                outputPath = Path.Combine(ScriptDirectory, outputPath);
            }

            foreach (var map in mapElements)
            {
                string name = map.Attribute("name").Value;
                string path = map.Attribute("path").Value;

                if (!Path.IsPathRooted(path))
                {
                    path = Path.Combine(ScriptDirectory, path);
                }

                int mipLevels = 1;
                if (map.Attribute("mips") != null)
                {
                    mipLevels = int.Parse(map.Attribute("mips").Value);
                }

                List <Image <Rgba64> > imgData = new List <Image <Rgba64> >();

                var importedImage = Image.Load <Rgba64>(path);
                imgData.Add(importedImage);

                for (int i = 1; i < mipLevels; i++)
                {
                    string directory = Path.GetDirectoryName(path);
                    string flname    = Path.GetFileNameWithoutExtension(path) + $"_{i}" + Path.GetExtension(path);

                    imgData.Add(Image.Load(Path.Combine(directory, flname)).CloneAs <Rgba64>());
                }


                data.AddMap(name, new TextureMap()
                {
                    Name = name,
                    Path = path,
                    Data = imgData
                });
            }

            Tasks.Add(new BuildScriptTask()
            {
                Name           = dataName,
                OutputFileName = outputPath,
                Source         = data
            });
        }