public void DebugLoadBsp(TagFileName name)
 {
     m_activeBsp = new TagBsp();
     m_activeBsp.LoadTagBuffer(name);
     m_activeBsp.LoadTagData();
     SetPreviewMode(PreviewMode.Bsp);
     MdxRender.SetZbufRange(30.0f, 300.0f);
     MdxRender.Camera.UpdateCameraByCentroid(m_activeBsp.m_BoundingBox);
 }
        public void UpdateObjectColors()
        {
            TagBsp bsp = MdxRender.GetCurrentBsp;

            if (bsp != null)
            {
                float[] uv = new float[2];
                int     lightmap_index;

                for (int i = 0; i < this.Count; i++)
                {
                    bsp.GetBSPIntersect(this[i].Translation, new Vector3(0, 0, -1), out uv, out lightmap_index);

                    Color clr = MdxRender.SM.m_TextureManager.GetLightmapTexelColor(bsp.m_LightmapIndex, lightmap_index, uv[0], uv[1]);
                    this[i].ObjectColor = clr;
                    Trace.WriteLine(string.Format("instance[{0}]: lma = {4} u = {1} v = {2}, color = {3}", i, uv[0], uv[1], clr.ToString(), lightmap_index));
                }
            }
            //get location from 3d
        }
        static public void LoadBsp(TagFileName bsp_tfn, TagFileName sky_tfn)
        {
            if (bsp_tfn.Version == MapfileVersion.XHALO2)
            {
                Halo1_Bsp = null;
                //TODO: load Halo2 bsp
            }
            else
            {
                if (sky_tfn != null)
                {
                    int index = MdxRender.MM.RegisterModel(sky_tfn);
                    MdxRender.SkyBox = MdxRender.MM.GetModel(index);
                }
                //TODO: null out Halo2 bsp, clean up old resources

                Halo1_Bsp = new TagBsp();
                Halo1_Bsp.LoadTagBuffer(bsp_tfn);
                Halo1_Bsp.LoadTagData();
                MdxRender.Camera.UpdateCameraByCentroid(Halo1_Bsp.m_BoundingBox);
            }
        }
Beispiel #4
0
        public void AttachDecalToH1Bsp(TagBsp bsp)
        {
            //given coordinate, find nearest bsp surface and attach to it

            //
        }
        public void DrawScene()
        {
            if (m_ready)
            {
                m_FPS.BeginFrame();

                if (MdxRender.DeviceInfo.bDeviceLost)
                {
                    AttemptRecovery();
                }
                else
                {
                    try
                    {
                        MdxRender.Dev.Clear(ClearFlags.ZBuffer | ClearFlags.Target, ClearColor, 1.0f, 0);
                        MdxRender.Dev.Transform.View  = Camera.GetViewMatrix();
                        MdxRender.Dev.Transform.World = Matrix.Identity;

                        //todo: preview vs bsp mode
                        if (PreviewManager.Mode != PreviewMode.ProjectMode)
                        {
                            MdxRender.SetZbufRange(0.01f, 300.0f);
                            UpdateViewTransform();
                        }
                        else
                        {
                            SetZbufRange(30.0f, 100000.0f);
                            UpdateViewTransform();
                        }

                        MdxRender.Dev.BeginScene();

                        if (!m_isPaused)
                        {
                            MdxRender.Dev.Material = whiteMaterial;
                            //The beef of the matter
                            if (PreviewManager.Mode != PreviewMode.ProjectMode)
                            {
                                PreviewManager.RenderActivePreview();
                                //mapViewButton.DrawButton(true);
                            }
                            else
                            {
                                #region DrawProject
                                MdxRender.Dev.Material = whiteMaterial;
                                MdxRender.Dev.RenderState.DiffuseMaterialSource  = ColorSource.Material;
                                MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material;
                                MdxRender.Dev.RenderState.SpecularEnable         = false;

                                //Render the skybox if we are in map view mode
                                if (MdxRender.SkyBox != null)
                                {
                                    //turn lighting off for skybox
                                    //MdxRender.Dev.RenderState.Lighting = false;

                                    //turn off fog or you won't be able to see the skybox through it
                                    if (MdxRender.FogEnabled)
                                    {
                                        MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false);
                                    }

                                    //disable z-writing for the skybox since it is behind everything
                                    //and to get rid of that stupid clipping artifact
                                    MdxRender.Dev.RenderState.ZBufferWriteEnable = false;
                                    SkyBox.Render();
                                    MdxRender.Dev.RenderState.ZBufferWriteEnable = true;

                                    //turn fog back on
                                    if (MdxRender.FogEnabled)
                                    {
                                        MdxRender.Dev.SetRenderState(RenderStates.FogEnable, true);
                                    }
                                }
                                else
                                {
                                    //turn off fog when we are in model preview mode
                                    MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false);
                                }

                                //draw the map BSP
                                if (Halo1_Bsp != null)
                                {
                                    MdxRender.Dev.RenderState.Lighting = true;
                                    Halo1_Bsp.DrawBsp();
                                    TagBsp.Debug_RenderNearestNeighborVerts();
                                    MdxRender.lightmapDebugger.Render();
                                    //Halo1_Bsp.DrawWireframeBsp();
                                    //MdxRender.Dev.RenderState.FillMode = FillMode.Solid;
                                }

                                //turn on lighting for scenery
                                MdxRender.Dev.RenderState.Lighting = true;
                                MdxRender.SM.DisableBlend(); //this necessary?

                                //draw all ye map objects
                                //MdxRender.Dev.RenderState.DiffuseMaterialSource = ColorSource.Material;
                                //MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material;
                                //MdxRender.Dev.RenderState.SpecularEnable = true;
                                ProjectManager.MapSpawns.Render();
                                #endregion


                                if (m_showFPS)
                                {
                                    DrawFPS();
                                }
                            }
                        }
                        else
                        {
                            m_fontFPS.DrawText(null, "Rendering Paused", 3, 3, Color.White);
                            Thread.Sleep(250);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("Error during DrawScene(): " + e.Message);
                    }
                    finally
                    {
                        try
                        {
                            MdxRender.Dev.EndScene();
                            MdxRender.Dev.Present();
                            //SwapChain sc = MdxRender.Dev.GetSwapChain(0);
                            //sc.Present(Present.LinearContent);
                        }
                        catch (DeviceLostException)
                        {
                            MdxRender.DeviceInfo.bDeviceLost = true;
                            Trace.WriteLine("Device was lost.");
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine("Error during Device.Present(): " + e.Message);
                        }
                    }
                }
                m_FPS.EndFrame();
            }
        }