示例#1
0
文件: MainForm.cs 项目: shff/gk3tools
        private void calculateLightmapsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult r = MessageBox.Show("Are you sure you want to generate lightmaps for this scene? It might take a while...", "Really?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (r == System.Windows.Forms.DialogResult.Yes)
                {
                    string lightingInfo = Gk3Main.SceneManager.CurrentRoom.NameWithoutExtension + "_lighting.xml";
                    Gk3Main.Game.LightmapSpecs specs = null;

                    if (System.IO.File.Exists(lightingInfo) == false)
                    {
                        LightingXml lighting = new LightingXml();

                        foreach (Gk3Main.Graphics.BspSurface surface in Gk3Main.SceneManager.CurrentRoom.Surfaces)
                        {
                            lighting.Surfaces.Add(new SurfaceXml((int)surface.index,
                                                                 System.Math.Max(Gk3Main.SceneManager.CurrentLightmaps.Maps[surface.index].Width, 4),
                                                                 System.Math.Max(Gk3Main.SceneManager.CurrentLightmaps.Maps[surface.index].Height, 4)));
                        }

                        lighting.Skylight = new SkylightXml(new ColorXml(100.0f, 100.0f, 100.0f));

                        lighting.Write(lightingInfo);

                        specs = LightingXml.GenerateSpecs(lighting);
                    }
                    else
                    {
                        LightingXml lighting = LightingXml.Load(lightingInfo);
                        specs = LightingXml.GenerateSpecs(lighting);

                        // hide all hidden surfaces
                        foreach (SurfaceXml surface in lighting.Surfaces)
                        {
                            if (surface.Visible == false)
                            {
                                Gk3Main.SceneManager.CurrentRoom.SetSurfaceVisibility(surface.Index, false);
                            }
                        }
                    }



                    Gk3Main.SceneManager.CalculateLightmaps(specs);

                    MessageBox.Show("All done!");

                    // Gk3Main.Game.Radiosity.Init(Gk3Main.SceneManager.renderRadiosityCallback);
                    // _renderHemicube = true;
                }
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show("Unable to find the radiosity calculator library.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        public static LightingXml Load(string filename)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(LightingXml));
            TextReader    reader     = new StreamReader(filename);
            LightingXml   lighting   = (LightingXml)serializer.Deserialize(reader);

            reader.Close();

            return(lighting);
        }
示例#3
0
        public static Gk3Main.Game.LightmapSpecs GenerateSpecs(LightingXml lighting)
        {
            Gk3Main.Game.LightmapSpecs specs = new Gk3Main.Game.LightmapSpecs();

            Gk3Main.Math.Vector3 skyColor;
            skyColor.X = lighting.Skylight.AmbientColor.Red;
            skyColor.Y = lighting.Skylight.AmbientColor.Green;
            skyColor.Z = lighting.Skylight.AmbientColor.Blue;

            specs.SkyColor = skyColor;

            Gk3Main.Math.Vector3 sunColor;
            sunColor.X         = lighting.Skylight.SunColor.Red;
            sunColor.Y         = lighting.Skylight.SunColor.Green;
            sunColor.Z         = lighting.Skylight.SunColor.Blue;
            specs.SunColor     = sunColor;
            specs.SunDirection = new Gk3Main.Math.Vector3(lighting.Skylight.SunDirection.X, lighting.Skylight.SunDirection.Y, lighting.Skylight.SunDirection.Z);

            foreach (OmniXml omni in lighting.Omnis)
            {
                Gk3Main.Game.LightmapSpecs.OmniLight o = new Gk3Main.Game.LightmapSpecs.OmniLight();
                o.Radius   = omni.Radius;
                o.Position = new Gk3Main.Math.Vector3(omni.Position.X, omni.Position.Y, omni.Position.Z);
                o.Color    = new Gk3Main.Math.Vector3(omni.Color.Red, omni.Color.Green, omni.Color.Blue);
                specs.OmniLights.Add(o);
            }

            // TODO: this ignores the index and assumes they'll be ordered in the spec file!
            foreach (SurfaceXml surface in lighting.Surfaces)
            {
                Gk3Main.Game.LightmapSpecs.SurfaceLightmap lm = new Gk3Main.Game.LightmapSpecs.SurfaceLightmap();
                lm.Width  = surface.Width;
                lm.Height = surface.Height;
                specs.Surfaces.Add(lm);
            }

            return(specs);
        }