The bsp model.
Наследование: IDisposable
Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpawnLoads"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 /// <param name="bsp">The BSP.</param>
 /// <param name="device">The device.</param>
 /// <remarks></remarks>
 public SpawnLoads(Map map, BSPModel bsp, Device device)
 {
     this.map = map;
     this.bsp = bsp;
     this.device = device;
     SpawnModel = new List<ParsedModel>();
     spawnmodelindex = new int[bsp.Spawns.Spawn.Count];
     BoundingBoxModel = new Mesh[bsp.Spawns.Spawn.Count];
 }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PortalViewer"/> class.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public PortalViewer(ref Meta meta)
        {
            // Set the initial size of our form
            this.ClientSize = new Size(
                Screen.PrimaryScreen.WorkingArea.Width - 4, Screen.PrimaryScreen.WorkingArea.Height - 4);

            // And its caption
            this.Text = "Model Viewer";

            this.MouseDown += ModelViewer_MouseDown;
            this.MouseMove += this.ModelViewer_MouseDownx;
            this.MouseUp += this.ModelViewer_MouseUp;

            portals = Portals.GetPortals(ref meta);

            bsp = new BSPModel(ref meta);

            faceCount = new int[bsp.BSPRawDataMetaChunks.Length];
            for (int x = 0; x < bsp.BSPRawDataMetaChunks.Length; x++)
            {
                faceCount[x] = bsp.BSPRawDataMetaChunks[x].FaceCount;
            }

            bsp.DrawBSPPermutations = false;

            Main();
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BSPShaderContainer"/> class.
 /// </summary>
 /// <param name="bsp">The BSP.</param>
 /// <param name="meta">The meta.</param>
 /// <remarks></remarks>
 public BSPShaderContainer(BSPModel bsp, ref Meta meta)
 {
     switch (meta.Map.HaloVersion)
     {
         case HaloVersionEnum.Halo2:
         case HaloVersionEnum.Halo2Vista:
             H2BSPShaderContainer(ref meta);
             break;
     }
 }
Пример #4
0
            /// <summary>
            /// The load shader textures.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <remarks></remarks>
            public static void LoadShaderTextures(ref Device device, ref BSPModel bsp)
            {
                for (int x = 0; x < bsp.Shaders.Shader.Length; x++)
                {
                    bsp.Shaders.Shader[x].MakeTextures(ref device);
                    bsp.Shaders.Shader[x].KillBitmaps();
                }

                // MessageBox.Show("test");
            }
Пример #5
0
            /// <summary>
            /// The load lightmap textures.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <remarks></remarks>
            public static void LoadLightmapTextures(ref Device device, ref BSPModel bsp)
            {
                bsp.LightMapTexture = new Texture[bsp.BSPRawDataMetaChunks.Length];
                for (int x = 0; x < bsp.LightMapBitmap.Length; x++)
                {
                    bsp.LightMapTexture[x] = ShaderInfo.CreateTexture(ref device, bsp.LightMapBitmap[x]);
                }

                bsp.SceneryLightMapTexture = new Texture[bsp.SceneryLightMapBitmap.Length];
                for (int x = 0; x < bsp.SceneryLightMapBitmap.Length; x++)
                {
                    bsp.SceneryLightMapTexture[x] = ShaderInfo.CreateTexture(ref device, bsp.SceneryLightMapBitmap[x]);
                }
            }
Пример #6
0
 /// <summary>
 /// The load direct x textures and buffers.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="bsp">The bsp.</param>
 /// <remarks></remarks>
 public static void LoadDirectXTexturesAndBuffers(ref Device device, ref BSPModel bsp)
 {
     CreateVertexBuffers(ref device, ref bsp);
     CreateIndexBuffers(ref device, ref bsp);
     LoadShaderTextures(ref device, ref bsp);
     LoadLightmapTextures(ref device, ref bsp);
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BSPViewer"/> class.
        /// </summary>
        /// <param name="tempbsp">The tempbsp.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public BSPViewer(BSPModel tempbsp, Map map)
        {
            // InitializeComponent
            InitializeComponent();

            dockControl1.LayoutSystem.Collapsed = true;
            dockControl2.LayoutSystem.Collapsed = true;
            dockControl3.LayoutSystem.Collapsed = true;
            dockControl4.LayoutSystem.Collapsed = true;
            dockControl5.LayoutSystem.Collapsed = true;

            Application.DoEvents();

            // Center label horizontal
            int tempnum1 = 155 / 2;
            int tempnum2 = Screen.PrimaryScreen.WorkingArea.Width / 2;
            int tempnum3 = tempnum2 - tempnum1;
            label3.Left = tempnum3;

            // Center label vertical
            int tempnum4 = 28 / 2;
            int tempnum5 = Screen.PrimaryScreen.WorkingArea.Height / 2;
            int tempnum6 = tempnum5 - tempnum4 - 30 - 25;
            label3.Top = tempnum6;

            this.BackColor = Color.Blue;

            #region Clear the labels
            toolStripLabel2.Text = "Camera Position: X: 0 • Y: 0 • Z: 0";
            tsLabel1.Text = "Type: <";
            tsButtonType.Text = string.Empty;
            tsLabel2.Text = "> (";
            tsLabelCount.Text = string.Empty;
            tsLabelX.Text = ") • X: ";
            tsTextBoxX.Text = string.Empty;
            tsLabelY.Text = " • Y: ";
            tsTextBoxY.Text = string.Empty;
            tsLabelZ.Text = " • Z: ";
            tsTextBoxZ.Text = string.Empty;

            tsLabelYaw.Text = string.Empty;
            tsTextBoxYaw.Text = string.Empty;
            tsLabelPitch.Text = string.Empty;
            tsTextBoxPitch.Text = string.Empty;
            tsLabelRoll.Text = string.Empty;
            tsTextBoxRoll.Text = string.Empty;
            #endregion

            // Set the initial size of our form
            // this.ClientSize = new System.Drawing.Size(800, 600);
            // And its caption
            this.Text = "BSP Viewer (" + tempbsp.Name + ")";

            Application.DoEvents();

            bsp = tempbsp;
            this.map = map;

            this.MouseDown += BSPViewer_MouseDown;
            this.MouseUp += BSPViewer_MouseUp;
            this.MouseMove += this.ModelViewer_MouseDown;
            this.MouseUp += this.ModelViewer_MouseUp;

            #region VisibleSpawns

            string[] strings = Enum.GetNames(typeof(SpawnInfo.SpawnType));

            treeView1.Sorted = true;
            treeView1.ShowNodeToolTips = true;

            int CameraCount = 0;
            int DeathZoneCount = 0;
            int ObjectiveCount = 0;
            int PlayerCount = 0;

            foreach (string s in strings)
            {
                // Add the type to the treeview
                TreeNode tn = new TreeNode();
                bool SpawnFound = false;
                for (int i = 0; i < bsp.Spawns.Spawn.Count; i++)
                {
                    if (s == bsp.Spawns.Spawn[i].Type.ToString())
                    {
                        // Only add spawns that exist on our map
                        if (!SpawnFound)
                        {
                            // Add the type the the CheckListBox
                            checkedListBox1.Items.Add(s);
                            SpawnFound = true;
                        }

                        TreeNode tn2 = new TreeNode();
                        tn2.Text = string.Empty;
                        tn2.ToolTipText = " X: " + bsp.Spawns.Spawn[i].X.ToString("#0.0##").PadRight(9) + "  Y: " +
                                          bsp.Spawns.Spawn[i].Y.ToString("#0.0##").PadRight(9) + "  Z: " +
                                          bsp.Spawns.Spawn[i].Z.ToString("#0.0##").PadRight(9);

                        if (bsp.Spawns.Spawn[i].Type.ToString() == "Collection")
                        {
                            switch (map.HaloVersion)
                            {
                                case HaloVersionEnum.Halo2:
                                case HaloVersionEnum.Halo2Vista:
                                    string[] temps = bsp.Spawns.Spawn[i].TagPath.Split('\\');
                                    tn2.Text = temps[temps.Length - 1];
                                    break;
                                case HaloVersionEnum.Halo1:
                                case HaloVersionEnum.HaloCE:
                                    SpawnInfo.H1Collection tempspawnx = (SpawnInfo.H1Collection)bsp.Spawns.Spawn[i];
                                    tn2.Text = tempspawnx.TagPath;
                                    break;
                            }
                        }

                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Obstacle") {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Weapon")   {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Scenery")  {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Machine")  {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Control")  {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Biped")    {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Equipment"){}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Vehicle")  {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Light")    {}
                            // else if (bsp.Spawns.Spawn[i].Type.ToString() == "Sound")    {}
                        else if (bsp.Spawns.Spawn[i].Type.ToString() == "Camera")
                        {
                            tn2.Text = bsp.Spawns.Spawn[i].Type + " {" + CameraCount + "}";
                            CameraCount += 1;
                        }
                        else if (bsp.Spawns.Spawn[i].Type.ToString() == "DeathZone")
                        {
                            SpawnInfo.DeathZone tempspawn = (SpawnInfo.DeathZone)bsp.Spawns.Spawn[i];
                            tn2.Text = tempspawn.Name;
                            tn2.ToolTipText += "\n Length: " + tempspawn.length.ToString("#0.0##") + "  Width: " +
                                               tempspawn.width.ToString("#0.0##") + " Height: " +
                                               tempspawn.height.ToString("#0.0##");
                            DeathZoneCount += 1;
                        }
                        else if (bsp.Spawns.Spawn[i].Type.ToString() == "Objective")
                        {
                            SpawnInfo.ObjectiveSpawn tempspawn = (SpawnInfo.ObjectiveSpawn)bsp.Spawns.Spawn[i];

                            // tn2.Text = bsp.Spawns.Spawn[i].Type.ToString() + " {" + ObjectiveCount.ToString() + "}";
                            tn2.Text = tempspawn.ObjectiveType + " (" + tempspawn.Team + ") #" + tempspawn.number;
                            tn2.ToolTipText += "\n Type: " + tempspawn.ObjectiveType + "  #" + tempspawn.number +
                                               "\n Team: " + tempspawn.Team;
                            ObjectiveCount += 1;
                        }
                        else if (bsp.Spawns.Spawn[i].Type.ToString() == "Player")
                        {
                            tn2.Text = bsp.Spawns.Spawn[i].Type + " {" + PlayerCount + "}";
                            PlayerCount += 1;
                        }
                        else if (bsp.Spawns.Spawn[i].Type.ToString() == "AI_Squads")
                        {
                            string[] temps = bsp.Spawns.Spawn[i].TagPath.Split('\\');
                            tn2.Text = "Squad " + ((HaloMap.Render.SpawnInfo.AI_Squads)bsp.Spawns.Spawn[i]).squadNumber
                                + ": " + temps[temps.Length - 1];
                        }
                        else if (bsp.Spawns.Spawn[i].Type.ToString() == "SpawnZone")
                        {
                            SpawnInfo.SpawnZone tempSpawnZone = (SpawnInfo.SpawnZone)bsp.Spawns.Spawn[i];
                            if (tempSpawnZone.Name == string.Empty)
                                tn2.Text = "(" + tempSpawnZone.ZoneType.ToString() + ") Spawn Zone";
                            else
                                tn2.Text = "(" + tempSpawnZone.ZoneType.ToString() + ") " + tempSpawnZone.Name;

                        }
                        else
                        {
                            // tn2.Text = bsp.Spawns.Spawn[i].Type.ToString();
                            string[] temps = bsp.Spawns.Spawn[i].TagPath.Split('\\');
                            tn2.Text = temps[temps.Length - 1];
                        }

                        if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                            map.HaloVersion == HaloVersionEnum.Halo2Vista)
                        {
                            #region BasicInfo For YawPitchRoll Rotations

                            if (bsp.Spawns.Spawn[i] is SpawnInfo.RotateYawPitchRollBaseSpawn)
                            {
                                SpawnInfo.RotateYawPitchRollBaseSpawn tempspawn =
                                    (SpawnInfo.RotateYawPitchRollBaseSpawn)bsp.Spawns.Spawn[i];
                                if (tn2.Text == null)
                                {
                                    string[] temps = tempspawn.TagPath.Split('\\');
                                    tn2.Text = temps[temps.Length - 1];
                                }

                                tn2.ToolTipText += "\n Yaw: " + tempspawn.Yaw.ToString("#0.0##") + "  Pitch: " +
                                                   tempspawn.Pitch.ToString("#0.0##") + " Roll: " +
                                                   tempspawn.Roll.ToString("#0.0##");
                            }

                                #endregion
                                #region BasicInfo For One Rotation
                            else if (bsp.Spawns.Spawn[i] is SpawnInfo.RotateDirectionBaseSpawn)
                            {
                                SpawnInfo.RotateDirectionBaseSpawn tempspawn =
                                    (SpawnInfo.RotateDirectionBaseSpawn)bsp.Spawns.Spawn[i];
                                if (tn2.Text == null)
                                {
                                    if (tempspawn.TagPath != null)
                                    {
                                        string[] temps = tempspawn.TagPath.Split('\\');
                                        tn2.Text = temps[temps.Length - 1];
                                    }
                                    else
                                    {
                                        tn2.Text = tempspawn.Type.ToString();
                                    }
                                }

                                tn2.ToolTipText += "\n Rotation: " + tempspawn.RotationDirection.ToString("#0.0##");
                            }

                            #endregion
                        }

                        tn2.Tag = i;
                        tn.Nodes.Add(tn2);
                    }
                }

                tn.Text = s;
                tn.Tag = -1;
                treeView1.Nodes.Add(tn);
            }

            #endregion

            #region Lightmaps

            Load_Lightmaps_Into_An_Array();
            int temppicboxX = 0;
            int temppicboxY = 0;
            int tempintforme = 0;
            for (int i = 0; i < map.BSP.sbsp[tempbsp.BspNumber].LightMap_Palettes.Count; i++)
            {
                PictureBox temppicbox = new PictureBox();
                temppicbox.Image = RenderLightmap(i);
                temppicbox.SizeMode = PictureBoxSizeMode.StretchImage;
                temppicbox.Width = 64;
                temppicbox.Height = 64;
                temppicbox.Location = new Point(temppicboxX, temppicboxY);
                temppicbox.Tag = i;
                temppicbox.Click += this.PictureBox_Click;
                panel1.Controls.Add(temppicbox);
                comboBox1.Items.Add(i);
                if (tempintforme <= 1)
                {
                    tempintforme += 1;
                    temppicboxX += 68;
                }
                else
                {
                    tempintforme = 0;
                    temppicboxX = 0;
                    temppicboxY += 68;
                }
            }

            #endregion

            if (map.HaloVersion == HaloVersionEnum.Halo2 ||
                map.HaloVersion == HaloVersionEnum.Halo2Vista)
            {
                this.NoCulling.Checked = false;
            }
            else
            {
                this.NoCulling.Checked = true;
            }

            Main();
        }
Пример #8
0
 /// <summary>
 /// The create index buffers.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="tempcoll">The tempcoll.</param>
 /// <remarks></remarks>
 private void CreateIndexBuffers(ref Device device, ref BSPModel.BSPCollision tempcoll)
 {
     ib = new IndexBuffer(typeof(short), tempcoll.Faces.Length, device, Usage.WriteOnly, Pool.Default);
     ib.SetData(tempcoll.Faces, 0, LockFlags.None);
     ib.Unlock();
 }
Пример #9
0
            /// <summary>
            /// The create vertex buffers.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <remarks></remarks>
            public static void CreateVertexBuffers(ref Device device, ref BSPModel bsp)
            {
                bsp.Display.vertexBuffer = new VertexBuffer[bsp.BSPRawDataMetaChunks.Length];
                for (int x = 0; x < bsp.BSPRawDataMetaChunks.Length; x++)
                {
                    int rawindex = x;
                    if (bsp.BSPRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0)
                    {
                        continue;
                    }

                    bsp.Display.vertexBuffer[rawindex] = new VertexBuffer(
                        typeof(HaloBSPVertex), 
                        bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                        device, 
                        Usage.WriteOnly, 
                        HaloBSPVertex.FVF, 
                        Pool.Managed);
                    HaloBSPVertex[] verts = (HaloBSPVertex[])bsp.Display.vertexBuffer[rawindex].Lock(0, 0);
                        // Lock the buffer (which will return our structs)
                    for (int i = 0; i < bsp.BSPRawDataMetaChunks[rawindex].VerticeCount; i++)
                    {
                        verts[i].Position = new Vector3(
                            bsp.BSPRawDataMetaChunks[rawindex].Vertices[i].X, 
                            bsp.BSPRawDataMetaChunks[rawindex].Vertices[i].Y, 
                            bsp.BSPRawDataMetaChunks[rawindex].Vertices[i].Z);
                        verts[i].Tu0 = bsp.BSPRawDataMetaChunks[rawindex].UVs[i].X;
                        verts[i].Tv0 = bsp.BSPRawDataMetaChunks[rawindex].UVs[i].Y;
                        verts[i].Normal = bsp.BSPRawDataMetaChunks[rawindex].Normals[i];

                        // verts[i].specular = 1;
                        verts[i].diffuse = 1;

                        verts[i].Tu1 = verts[i].Tu0;
                        verts[i].Tv1 = verts[i].Tv0;
                        if (bsp.BSPRawDataMetaChunks[rawindex].LightMapUVs.Count != 0)
                        {
                            verts[i].Tu2 = bsp.BSPRawDataMetaChunks[rawindex].LightMapUVs[i].X;
                            verts[i].Tv2 = bsp.BSPRawDataMetaChunks[rawindex].LightMapUVs[i].Y;
                        }
                        else
                        {
                            verts[i].Tu2 = verts[i].Tu0;
                            verts[i].Tv2 = verts[i].Tv0;
                        }

                        verts[i].Tu3 = verts[i].Tu0;
                        verts[i].Tv3 = verts[i].Tv0;
                    }

                    bsp.Display.vertexBuffer[rawindex].Unlock();
                }

                bsp.Display.permvertexBuffer = new VertexBuffer[bsp.BSPPermutationRawDataMetaChunks.Length];
                for (int x = 0; x < bsp.BSPPermutationRawDataMetaChunks.Length; x++)
                {
                    int rawindex = x;
                    if (bsp.BSPPermutationRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0)
                    {
                        continue;
                    }

                    bsp.Display.permvertexBuffer[rawindex] = new VertexBuffer(
                        typeof(HaloBSPVertex), 
                        bsp.BSPPermutationRawDataMetaChunks[rawindex].VerticeCount, 
                        device, 
                        Usage.WriteOnly, 
                        HaloBSPVertex.FVF, 
                        Pool.Managed);
                    HaloBSPVertex[] verts = (HaloBSPVertex[])bsp.Display.permvertexBuffer[rawindex].Lock(0, 0);
                        // Lock the buffer (which will return our structs)
                    for (int i = 0; i < bsp.BSPPermutationRawDataMetaChunks[rawindex].VerticeCount; i++)
                    {
                        verts[i].Position = new Vector3(
                            bsp.BSPPermutationRawDataMetaChunks[rawindex].Vertices[i].X, 
                            bsp.BSPPermutationRawDataMetaChunks[rawindex].Vertices[i].Y, 
                            bsp.BSPPermutationRawDataMetaChunks[rawindex].Vertices[i].Z);
                        verts[i].Tu0 = bsp.BSPPermutationRawDataMetaChunks[rawindex].UVs[i].X;
                        verts[i].Tv0 = bsp.BSPPermutationRawDataMetaChunks[rawindex].UVs[i].Y;
                        verts[i].Normal = bsp.BSPPermutationRawDataMetaChunks[rawindex].Normals[i];

                        // verts[i].specular = 1;
                        verts[i].diffuse = 1;
                        verts[i].Tu1 = verts[i].Tu0;
                        verts[i].Tv1 = verts[i].Tv0;
                        if (bsp.BSPPermutationRawDataMetaChunks[rawindex].LightMapUVs.Count != 0)
                        {
                            verts[i].Tu2 = bsp.BSPPermutationRawDataMetaChunks[rawindex].LightMapUVs[i].X;
                            verts[i].Tv2 = bsp.BSPPermutationRawDataMetaChunks[rawindex].LightMapUVs[i].Y;
                        }
                        else
                        {
                            verts[i].Tu2 = verts[i].Tu0;
                            verts[i].Tv2 = verts[i].Tv0;
                        }

                        verts[i].Tu3 = verts[i].Tu0;
                        verts[i].Tv3 = verts[i].Tv0;
                    }

                    bsp.Display.permvertexBuffer[rawindex].Unlock();
                }
            }
Пример #10
0
            /// <summary>
            /// The create index buffers.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <remarks></remarks>
            public static void CreateIndexBuffers(ref Device device, ref BSPModel bsp)
            {
                bsp.Display.indexBuffer = new IndexBuffer[bsp.BSPRawDataMetaChunks.Length];
                for (int x = 0; x < bsp.BSPRawDataMetaChunks.Length; x++)
                {
                    if (bsp.BSPRawDataMetaChunks[x].RawDataChunkInfo.Length == 0)
                    {
                        continue;
                    }

                    bsp.Display.indexBuffer[x] = new IndexBuffer(
                        typeof(short), bsp.BSPRawDataMetaChunks[x].IndiceCount, device, Usage.WriteOnly, Pool.Managed);
                    IndexBuffer ib = bsp.Display.indexBuffer[x];
                    ib.SetData(bsp.BSPRawDataMetaChunks[x].Indices, 0, LockFlags.None);
                    ib.Unlock();
                }

                bsp.Display.permindexBuffer = new IndexBuffer[bsp.BSPPermutationRawDataMetaChunks.Length];
                for (int x = 0; x < bsp.BSPPermutationRawDataMetaChunks.Length; x++)
                {
                    if (bsp.BSPPermutationRawDataMetaChunks[x].RawDataChunkInfo.Length == 0)
                    {
                        continue;
                    }

                    bsp.Display.permindexBuffer[x] = new IndexBuffer(
                        typeof(short), 
                        bsp.BSPPermutationRawDataMetaChunks[x].IndiceCount, 
                        device, 
                        Usage.WriteOnly, 
                        Pool.Managed);
                    IndexBuffer ib = bsp.Display.permindexBuffer[x];
                    ib.SetData(bsp.BSPPermutationRawDataMetaChunks[x].Indices, 0, LockFlags.None);
                    ib.Unlock();
                }
            }
Пример #11
0
        /// <summary>
        /// The load bsp. The BSP is loaded into memory.
        /// </summary>
        /// <param name="BSPNum">The bsp num.</param>
        /// <remarks></remarks>
        private void loadBSP(int BSPId)
        {
            this.Cursor = Cursors.WaitCursor;
            //// Load the BSP viewer
            Meta meta = new Meta(map);
            meta.TagIndex = BSPId; // load BSP into MemoryStream (MS)
            meta.ScanMetaItems(true, false);
            BSPModel bsp = new BSPModel(ref meta);
            this.Cursor = Cursors.Arrow;
            if (bsp.BspNumber != -1)
            {
                BSPViewer bv = new BSPViewer(bsp, map);
                bv.Dispose();
                bv = null;
            }

            meta.Dispose();
            GC.Collect();
        }
Пример #12
0
        /// <summary>
        /// The inject mesh from obj tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void injectMeshFromOBJToolStripMenuItem_Click(object sender, EventArgs e)
        {
            folderBrowserDialog.SelectedPath = Prefs.pathExtractsFolder;
            if (folderBrowserDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            Prefs.pathExtractsFolder = folderBrowserDialog.SelectedPath;

            Form tempForm = new Form();
            tempForm.ControlBox = false;
            tempForm.FormBorderStyle = FormBorderStyle.FixedDialog;
            tempForm.Size = new Size(250, 100);
            Label tempLabel = new Label();
            tempLabel.AutoSize = true;
            tempLabel.Location = new Point(20, 20);
            tempLabel.Text = "Loading BSP, please wait...";
            ProgressBar tempPB = new ProgressBar();
            tempPB.Location = new Point(20, 60);
            tempPB.Size = new Size(210, 20);
            tempPB.Minimum = 0;
            tempPB.Maximum = 100;
            tempForm.Controls.Add(tempLabel);
            tempForm.Controls.Add(tempPB);
            tempForm.Show();
            Application.DoEvents();

            BSPModel pm = new BSPModel(ref map.SelectedMeta);
            tempLabel.Text = "Loading Model...";
            tempPB.Value = 35;
            Application.DoEvents();
            Meta addme = pm.InjectModel(folderBrowserDialog.SelectedPath, map.SelectedMeta);

            /*
            addme.name += "(new)";
            addme.name = getNameDialog.Show("Choose injection name", "Meta Name:", addme.name, "OK");
            */
            ArrayList oi = new ArrayList();
            oi.Add(addme);

            tempLabel.Text = "Analyzing Layout...";
            tempPB.Value = 60;
            Application.DoEvents();

            MapAnalyzer analyze = new MapAnalyzer();
            MapLayout layout = analyze.ScanMapForLayOut(map, false);
            layout.ReadChunks(map);

            tempLabel.Text = "Rebuilding Map...";
            tempPB.Value = 70;
            Application.DoEvents();

            Builder build = new Builder();
            build.MapBuilder(oi, ref layout, map, false);

            tempLabel.Text = "Refreshing Map...";
            tempPB.Value = 95;
            Application.DoEvents();
            map = Map.Refresh(map);
            formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);
            this.Enabled = true;

            #region Remove form that shows progress

            tempForm.Dispose();

            #endregion

            MessageBox.Show("Done");
        }
Пример #13
0
        /// <summary>
        /// The export obj tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void exportOBJToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            BSPModel pm = new BSPModel(ref map.SelectedMeta);
            string[] temps = map.SelectedMeta.name.Split('\\');
            pm.Name = temps[temps.Length - 1];

            pm.ExtractModel(folderBrowserDialog.SelectedPath);

            MessageBox.Show("Done");
        }
Пример #14
0
        /// <summary>
        /// The export mesh to obj tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void exportMeshToOBJToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveMetaDialog.InitialDirectory = Prefs.pathExtractsFolder;
            saveMetaDialog.DefaultExt = "obj";
            saveMetaDialog.FileName = map.SelectedMeta.name.Substring(map.SelectedMeta.name.LastIndexOf('\\') + 1);
            saveMetaDialog.Filter = "Object file (*.obj)|*.obj";
            if (saveMetaDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            Prefs.pathExtractsFolder = saveMetaDialog.FileName.Substring(
                0, saveMetaDialog.FileName.LastIndexOf('\\'));

            Form tempForm = new Form();
            tempForm.ControlBox = false;
            tempForm.FormBorderStyle = FormBorderStyle.FixedDialog;
            tempForm.Size = new Size(250, 100);
            Label tempLabel = new Label();
            tempLabel.AutoSize = true;
            tempLabel.Location = new Point(20, 20);
            tempLabel.Text = "Loading BSP, please wait...";
            ProgressBar tempPB = new ProgressBar();
            tempPB.Location = new Point(20, 60);
            tempPB.Size = new Size(210, 20);
            tempPB.Minimum = 0;
            tempPB.Maximum = 100;
            tempForm.Controls.Add(tempLabel);
            tempForm.Controls.Add(tempPB);
            tempForm.Show();
            Application.DoEvents();

            BSPModel pm = new BSPModel(ref map.SelectedMeta);
            string[] temps = saveMetaDialog.FileName.Split('\\');
            string[] temps2 = temps[temps.Length - 1].Split('.');
            pm.Name = temps2[0];

            // pm.LoadModelStructure(ref Map.SelectedMeta, map);
            // pm.LoadPermutations(ref Map.SelectedMeta, map);
            // pm.LoadUnknowns(ref Map.SelectedMeta, map);
            // pm.Shaders = new Entity.BSP.BSPModel.BSPShaderContainer( pm, ref Map.SelectedMeta, map);
            tempLabel.Text = "Extracting BSP as 2 files...";
            tempPB.Value = 80;
            Application.DoEvents();
            pm.ExtractModelAsSingleMesh(saveMetaDialog.FileName);
            pm.Dispose();

            #region Remove form that shows progress

            tempForm.Dispose();

            #endregion

            MessageBox.Show("Done");
        }
Пример #15
0
        /// <summary>
        /// The h 2 bsp write raw data meta chunk.
        /// </summary>
        /// <param name="chunknumber">The chunknumber.</param>
        /// <param name="bsp">The bsp.</param>
        /// <param name="BSPNum">The bsp num.</param>
        /// <remarks></remarks>
        public void H2BSPWriteRawDataMetaChunk(int chunknumber, ref BSPModel bsp, int BSPNum)
        {
            BSPModel.BSPRawDataMetaChunk bspChunk = bsp.BSPRawDataMetaChunks[chunknumber];

            int BSPId = map.Functions.ForMeta.FindMetaByID(map.BSP.sbsp[BSPNum].ident);

            Meta meta = new Meta(map);
            meta.TagIndex = BSPId; // decides which tag to load into MemoryStream (MS)
            meta.ScanMetaItems(true, false);

            BinaryWriter BW = new BinaryWriter(meta.MS);
            BinaryReader BR = new BinaryReader(meta.MS);
            int temp = 0;

            BW.BaseStream.Position = bsp.BSPRawDataMetaChunksOffset;
            BW.Write(bspChunk.VerticeCount);
            BW.Write(bspChunk.FaceCount);
            BW.BaseStream.Position = bsp.BSPRawDataMetaChunksOffset + 48;
            BW.Write(bspChunk.HeaderSize - 8);

            BW.BaseStream.Position = bsp.BSPRawDataMetaChunksOffset + 52;
            temp = BR.ReadInt32(); // I dunno what this is or what value it is supposed to be! #1232
            BW.BaseStream.Position = bsp.BSPRawDataMetaChunksOffset + 52;
            BW.Write(temp); // I dunno what this is or what value it is supposed to be!

            BW.BaseStream.Position = bsp.BSPRawDataMetaChunksOffset + 56;
            BW.Write(bspChunk.RawDataChunkInfo.Length);

            BW.Write(bspChunk.rawdatainfooffset + meta.magic + meta.offset);

            // SO FAR SO GOOD UP TILL NOW!
            // this.RawDataChunkInfo = new RawDataOffsetChunk[tempc];
            int tempr = bspChunk.rawdatainfooffset;
            for (int x = 0; x < bspChunk.RawDataChunkInfo.Length; x++)
            {
                // this.RawDataChunkInfo[x] = new RawDataOffsetChunk();
                BW.BaseStream.Position = tempr + (x * 16) + 6;
                BW.Write((UInt16)bspChunk.RawDataChunkInfo[x].ChunkSize);
                BW.Write(bspChunk.RawDataChunkInfo[x].Size);

                // I think this may be a safety for a messed up map?
                // if (bspChunk.RawDataChunkInfo[x].ChunkSize == bspChunk.RawDataChunkInfo[x].Size) { bspChunk.RawDataChunkInfo[x].ChunkSize = 0; }
                BW.Write(bspChunk.RawDataChunkInfo[x].Offset);
            }

            BW = map.BW;
            BW.BaseStream.Position = meta.offset;
            BW.Write(meta.MS.GetBuffer(), 0, meta.size);

            if (bspChunk.RawDataChunkInfo.Length == 0)
            {
                return;
            }

            /*
                BW = new BinaryWriter(((RawDataChunk)meta.raw.rawChunks[chunknumber]).MS);
                bspChunk.SubMeshInfo = new ModelSubMeshInfo[bspChunk.RawDataChunkInfo[0].ChunkCount];
                for (int x = 0; x < bspChunk.RawDataChunkInfo[0].ChunkCount; x++)
                {
                    bspChunk.SubMeshInfo[x] = new ModelSubMeshInfo();
                    BR.BaseStream.Position = bspChunk.HeaderSize + bspChunk.RawDataChunkInfo[0].Offset + (x * 72) + 4;
                    bspChunk.SubMeshInfo[x].ShaderNumber = BR.ReadUInt16();
                    bspChunk.SubMeshInfo[x].IndiceStart = BR.ReadUInt16();
                    bspChunk.SubMeshInfo[x].IndiceCount = BR.ReadUInt16();

                }

                BR.BaseStream.Position = 40;
                bspChunk.IndiceCount = BR.ReadUInt16();
                int indicechunk = 0;
                int verticechunk = 0;
                int uvchunk = 0;
                for (int x = 0; x < RawDataChunkInfo.Length; x++)
                {
                    if (RawDataChunkInfo[x].ChunkSize == 2)
                    {
                        indicechunk = x;
                        break;
                    }
                }
                int normalchunk = 0;
                for (int x = indicechunk; x < RawDataChunkInfo.Length; x++)
                {
                    if (RawDataChunkInfo[x].ChunkCount == 1)
                    {
                        verticechunk = x;
                        uvchunk = x + 1;
                        normalchunk = x + 2;
                        break;
                    }
                }
                bspChunk.Indices = new short[bspChunk.RawDataChunkInfo[indicechunk].ChunkCount];
                BR.BaseStream.Position = bspChunk.HeaderSize + bspChunk.RawDataChunkInfo[indicechunk].Offset;
                for (int x = 0; x < bspChunk.IndiceCount; x++)
                {
                    bspChunk.Indices[x] = (short)BR.ReadUInt16();

                }

                bspChunk.RawDataChunkInfo[verticechunk].ChunkSize = bspChunk.RawDataChunkInfo[verticechunk].Size / VerticeCount;
                for (int x = 0; x < bspChunk.VerticeCount; x++)
                {
                    Vector3 vec = new Vector3();
                    BR.BaseStream.Position = bspChunk.HeaderSize + bspChunk.RawDataChunkInfo[verticechunk].Offset + (bspChunk.RawDataChunkInfo[verticechunk].ChunkSize * x);
                    vec.X = BR.ReadSingle();
                    vec.Y = BR.ReadSingle();
                    vec.Z = BR.ReadSingle();
                    Vertices.Add(vec);
                }

                bspChunk.RawDataChunkInfo[uvchunk].ChunkSize = 8;
                for (int x = 0; x < bspChunk.VerticeCount; x++)
                {
                    Vector2 tempuv = new Vector2();
                    BR.BaseStream.Position = bspChunk.HeaderSize + bspChunk.RawDataChunkInfo[uvchunk].Offset + (bspChunk.RawDataChunkInfo[uvchunk].ChunkSize * x);
                    tempuv.X = BR.ReadSingle();
                    tempuv.Y = BR.ReadSingle();
                    bspChunk.UVs.Add(tempuv);
                }

                bspChunk.RawDataChunkInfo[normalchunk].ChunkSize = 12;
                for (int x = 0; x < bspChunk.VerticeCount; x++)
                {
                    Vector2 tempuv = new Vector2();
                    BR.BaseStream.Position = bspChunk.HeaderSize + bspChunk.RawDataChunkInfo[normalchunk].Offset + (bspChunk.RawDataChunkInfo[normalchunk].ChunkSize * x);
                    Vector3 normal = Raw.ParsedModel.DecompressNormal(BR.ReadInt32());
                    bspChunk.Normals.Add(normal);
                    Vector3 binormal = Raw.ParsedModel.DecompressNormal(BR.ReadInt32());
                    bspChunk.Binormals.Add(binormal);
                    Vector3 tangent = Raw.ParsedModel.DecompressNormal(BR.ReadInt32());
                    bspChunk.Tangents.Add(tangent);
                }

                int lightmapuvchunk = -1;
                for (int x = normalchunk + 1; x < RawDataChunkInfo.Length; x++)
                {
                    if (RawDataChunkInfo[x].ChunkSize == 3)
                    {
                        lightmapuvchunk = x;
                        break;
                    }
                }

                if (lightmapuvchunk == -1) return;
                RawDataChunkInfo[lightmapuvchunk].ChunkSize = 4;
                for (int x = 0; x < bspChunk.VerticeCount; x++)
                {
                    Vector2 tempuv = new Vector2();
                    BR.BaseStream.Position = bspChunk.HeaderSize + bspChunk.RawDataChunkInfo[lightmapuvchunk].Offset + (bspChunk.RawDataChunkInfo[lightmapuvchunk].ChunkSize * x);
                    short testx = BR.ReadInt16();
                    float u = DecompressVertice(Convert.ToSingle(testx), -1, 1);
                    testx = BR.ReadInt16();
                    float v = DecompressVertice(Convert.ToSingle(testx), -1, 1);
                     Vector2 uv2 = new Vector2(u, v);
                    bspChunk.LightMapUVs.Add(uv2);
                }
            */
        }
Пример #16
0
            /// <summary>
            /// The draw.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <param name="Textured">The textured.</param>
            /// <param name="cam">The cam.</param>
            /// <param name="shaderx">The shaderx.</param>
            /// <remarks></remarks>
            public static void Draw(
                ref Device device, ref BSPModel bsp, bool Textured, ref Camera2 cam, DXShader shaderx)
            {

                Optimization opt = new Optimization(device);

                int count = 0;
                for (int x = 0; x < bsp.BSPRawDataMetaChunks.Length; x++)
                {
                    // Check if we are to render chunk
                    if (!bsp.BSPRawDataMetaChunks[x].render)
                        continue;

                    int rawindex = x;
                    // FaceCount is set to 0 when BSP sections are unselected
                    if (bsp.BSPRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0 ||
                        bsp.BSPRawDataMetaChunks[rawindex].FaceCount == 0)
                    {
                        continue;
                    }

                    if (bsp.cameraCulling && !opt.IsInViewFrustum(bsp.BSPRawDataMetaChunks[rawindex]))
                        continue;

                    device.SetStreamSource(0, bsp.Display.vertexBuffer[rawindex], 0);
                    device.VertexFormat = HaloBSPVertex.FVF;
                    device.Indices = bsp.Display.indexBuffer[rawindex];
                    for (int xx = 0; xx < bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++)
                    {
                        ResetTextureStates(ref device);
                        int tempshade = bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber;

                        #region AlphaBlending

                        Renderer.SetAlphaBlending(bsp.Shaders.Shader[tempshade].Alpha, ref device);

                        #endregion

                        #region ChooseTexture

                        if (Textured)
                        {
                            if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("water!") != -1)
                            {
                                for (int u = 0; u < bsp.Shaders.Shader[tempshade].BitmapTextures.Length; u++)
                                {
                                    if (bsp.Shaders.Shader[tempshade].BitmapNames[u].IndexOf("reflection") != -1 ||
                                        bsp.Shaders.Shader[tempshade].BitmapNames[u].IndexOf("mask") != -1)
                                    {
                                        device.SetTexture(0, bsp.Shaders.Shader[tempshade].BitmapTextures[u]);

                                        if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("mip") != -1)
                                        {
                                            device.SetTexture(0, bsp.Shaders.Shader[tempshade].BitmapTextures[u]);
                                            device.SetTexture(1, bsp.Shaders.Shader[tempshade].BitmapTextures[u]);
                                        }
                                        else
                                        {
                                            device.SetTexture(1, bsp.Shaders.Shader[tempshade].MainTexture);
                                        }

                                        device.TextureState[0].ColorOperation = TextureOperation.BumpEnvironmentMap;
                                        device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                                        device.TextureState[0].ColorArgument2 = TextureArgument.Current;
                                        float r = 0.07F;
                                        device.TextureState[0].BumpEnvironmentMaterial00 = r *
                                                                                           (float)
                                                                                           Math.Cos(
                                                                                               (Environment.TickCount /
                                                                                                4) * 11.0F);
                                        device.TextureState[0].BumpEnvironmentMaterial01 = -r *
                                                                                           (float)
                                                                                           Math.Sin(
                                                                                               (Environment.TickCount /
                                                                                                4) * 11.0F);
                                        device.TextureState[0].BumpEnvironmentMaterial10 = r *
                                                                                           (float)
                                                                                           Math.Sin(
                                                                                               (Environment.TickCount /
                                                                                                4) * 11.0F);
                                        device.TextureState[0].BumpEnvironmentMaterial11 = r *
                                                                                           (float)
                                                                                           Math.Cos(
                                                                                               (Environment.TickCount /
                                                                                                4) * 11.0F);

                                        device.TextureState[1].ColorOperation = TextureOperation.Modulate;
                                        device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                                        device.TextureState[1].ColorArgument2 = TextureArgument.Current;

                                        if (bsp.LightMapTexture[x] != null &&
                                            bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0)
                                        {
                                            // device.SetTexture(2, bsp.LightMapTexture[x]);
                                            // device.TextureState[2].ColorOperation = TextureOperation.Modulate2X;
                                            // device.TextureState[2].ColorArgument1 = TextureArgument.TextureColor;
                                            // device.TextureState[2].ColorArgument2 = TextureArgument.Current;
                                        }

                                        break;
                                    }

                                    if (u == bsp.Shaders.Shader[tempshade].BitmapTextures.Length - 1)
                                    {
                                        device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture);
                                        device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                                        device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                                        device.TextureState[0].ColorArgument2 = TextureArgument.Current;
                                    }
                                }
                            }
                            else if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("ground!") != -1)
                            {
                                if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("unwrapped") != -1)
                                {
                                    // device.SamplerState[0].AddressU = TextureAddress.Clamp;
                                    // device.SamplerState[0].AddressV = TextureAddress.Clamp;
                                }

                                device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture);
                                device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                                device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                                device.TextureState[0].ColorArgument2 = TextureArgument.Current;
                                device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
                                device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                                // device.TextureState[0].ResultArgument = TextureArgument.Current;
                                device.TextureState[1].TextureTransform = TextureTransform.Count2;
                                device.Transform.Texture1 =
                                    Matrix.Scaling(
                                        bsp.Shaders.Shader[tempshade].primarydetailuscale, 
                                        bsp.Shaders.Shader[tempshade].primarydetailvscale, 
                                        bsp.Shaders.Shader[tempshade].primarydetailwscale);
                                // device.Transform.Texture1 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].secondarydetailuscale, bsp.Shaders.Shader[tempshade].secondarydetailvscale, bsp.Shaders.Shader[tempshade].secondarydetailwscale);
                                device.SetTexture(1, bsp.Shaders.Shader[tempshade].BitmapTextures[2]);
                                device.TextureState[1].ColorOperation = TextureOperation.Modulate2X;
                                device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                                device.TextureState[1].ColorArgument2 = TextureArgument.Current;
                                device.TextureState[1].AlphaOperation = TextureOperation.Add;
                                device.TextureState[1].AlphaArgument1 = TextureArgument.Current;

                                device.TextureState[2].TextureTransform = TextureTransform.Count2;
                                device.Transform.Texture2 =
                                    Matrix.Scaling(
                                        bsp.Shaders.Shader[tempshade].secondarydetailuscale, 
                                        bsp.Shaders.Shader[tempshade].secondarydetailvscale, 
                                        bsp.Shaders.Shader[tempshade].secondarydetailwscale);
                                device.SetTexture(2, bsp.Shaders.Shader[tempshade].BitmapTextures[3]);
                                device.TextureState[2].ColorOperation = TextureOperation.Modulate2X;
                                device.TextureState[2].ColorArgument1 = TextureArgument.TextureColor;
                                device.TextureState[2].ColorArgument2 = TextureArgument.Current;
                                device.TextureState[2].TextureCoordinateIndex = 3;

                                if (bsp.LightMapTexture[x] != null && bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0)
                                {
                                    device.SetTexture(3, bsp.LightMapTexture[x]);
                                    device.TextureState[3].ColorOperation = TextureOperation.Modulate2X;
                                    device.TextureState[3].ColorArgument1 = TextureArgument.TextureColor;
                                    device.TextureState[3].ColorArgument2 = TextureArgument.Current;
                                    device.TextureState[3].TextureCoordinateIndex = 2;
                                }
                            }
                            else
                            {
                                device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture);

                                device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                                device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                                device.TextureState[0].ColorArgument2 = TextureArgument.Current;
                                device.TextureState[0].AlphaOperation = TextureOperation.BlendTextureAlpha;
                                device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                                device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;

                                /*
                                            if (bsp.Shaders.Shader[tempshade].microdetailName != null)
                                            {

                                                device.TextureState[1].TextureTransform = TextureTransform.Count2;
                                                device.Transform.Texture1 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].microdetailuscale, bsp.Shaders.Shader[tempshade].microdetailvscale, bsp.Shaders.Shader[tempshade].microdetailwscale);
                                                device.SetTexture(1, bsp.Shaders.Shader[tempshade].microdetailTexture);
                                                device.TextureState[1].ColorOperation = TextureOperation.Modulate2X;
                                                device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                                                device.TextureState[1].ColorArgument2 = TextureArgument.Current;
                                                device.TextureState[1].AlphaOperation = TextureOperation.BlendCurrentAlpha;
                                                device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
                                            }

                                          
                                if (bsp.Shaders.Shader[tempshade].primarydetailTexture != null)
                              {

                                  device.TextureState[1].TextureTransform = TextureTransform.Count2;
                                  device.Transform.Texture1 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].primarydetailuscale, bsp.Shaders.Shader[tempshade].primarydetailvscale, bsp.Shaders.Shader[tempshade].primarydetailwscale);
                               device.SetTexture(1, bsp.Shaders.Shader[tempshade].primarydetailTexture);
                               device.TextureState[1].ColorOperation = TextureOperation.Lerp;
                               device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                                  device.TextureState[1].ColorArgument2 = TextureArgument.Current;
                                 device.TextureState[1].AlphaOperation = TextureOperation.Modulate;
                                 device.TextureState[1].AlphaArgument1 = TextureArgument.TextureColor;
                              }
                           
                                if (bsp.Shaders.Shader[tempshade].secondarydetailTexture != null)
                                {
                      
                                    device.TextureState[2].TextureTransform = TextureTransform.Count2;
                                    device.Transform.Texture2 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].secondarydetailuscale, bsp.Shaders.Shader[tempshade].secondarydetailvscale, bsp.Shaders.Shader[tempshade].secondarydetailwscale);
                                    device.SetTexture(2, bsp.Shaders.Shader[tempshade].secondarydetailTexture);
                                    device.TextureState[2].ColorOperation = TextureOperation.Lerp;
                                    device.TextureState[2].ColorArgument1 = TextureArgument.TextureColor;
                                    device.TextureState[2].ColorArgument2 = TextureArgument.Current;
                                    device.TextureState[2].TextureCoordinateIndex = 3;
                                    //device.TextureState[2].AlphaOperation = TextureOperation.BlendCurrentAlpha;
                                    //device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
                   
                                }

                                */
                                if (bsp.LightMapTexture != null)
                                {
                                    if (bsp.LightMapTexture[x] != null &&
                                        bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0 && bsp.RenderBSPLighting)
                                    {
                                        device.SetTexture(1, bsp.LightMapTexture[x]);
                                        device.TextureState[1].ColorOperation = TextureOperation.Modulate2X;
                                        device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                                        device.TextureState[1].ColorArgument2 = TextureArgument.Current;
                                        device.TextureState[1].TextureCoordinateIndex = 2;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // If not Textured
                            device.SetTexture(0, null);
                            device.SetTexture(1, null);

                            if (bsp.LightMapTexture != null)
                            {
                                if (bsp.LightMapTexture[x] != null && bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0 &&
                                    bsp.RenderBSPLighting)
                                {
                                    device.SetTexture(0, bsp.LightMapTexture[x]);
                                    device.TextureState[0].ColorOperation = TextureOperation.Modulate2X;
                                    device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                                    device.TextureState[0].ColorArgument2 = TextureArgument.Current;
                                    device.TextureState[0].TextureCoordinateIndex = 2;
                                }
                            }
                        }

                        #endregion

                        PrimitiveType pt;
                        // if (bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount != (bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount/3)*3)
                        if (bsp.BSPRawDataMetaChunks[rawindex].FaceCount * 3 !=
                            bsp.BSPRawDataMetaChunks[rawindex].IndiceCount)
                        {
                            pt = PrimitiveType.TriangleStrip;
                            device.RenderState.FillMode = FillMode.Solid;
                            Material mm = new Material();
                            mm.Diffuse = Color.White;
                            mm.Ambient = Color.White;
                            // if (x == 1) { mm.Diffuse = System.Drawing.Color.Red; mm.Ambient = System.Drawing.Color.Red; }
                            device.Material = mm;
                            device.DrawIndexedPrimitives(
                                pt, 
                                0, 
                                0, 
                                bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                                bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                                bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount);
                        }
                        else
                        {
                            count++;
                            pt = PrimitiveType.TriangleList;

                            device.RenderState.FillMode = FillMode.Solid;
                            Material mm = new Material();
                            mm.Diffuse = Color.White;
                            mm.Ambient = Color.White;
                            // if (x == 1) { mm.Diffuse = System.Drawing.Color.Red; mm.Ambient = System.Drawing.Color.Red; }
                            device.Material = mm;

                            device.DrawIndexedPrimitives(
                                pt, 
                                0, 
                                0, 
                                bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                                bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                                bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);
                        }

                        #region RenderToScene

                        #region WireFrame

                        if (Textured == false)
                        {
                            Material m = new Material();
                            m.Diffuse = Color.Black;
                            m.Ambient = Color.Black;
                            device.Material = m;
                            device.RenderState.FillMode = FillMode.WireFrame;
                            device.DrawIndexedPrimitives(
                                pt, 
                                0, 
                                0, 
                                bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                                bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                                bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);
                        }

                        #endregion

                        #endregion
                    }
                }

                

                #region BSPPermutationMesh

                if (bsp.DrawBSPPermutations)
                {
                    for (int x = 0; x < bsp.PermutationInfo.Length; x++)
                    {
                        // continue;
                        int rawindex = bsp.PermutationInfo[x].sceneryIndex;
                        if (bsp.BSPPermutationRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0)
                        {
                            continue;
                        }

                        device.Transform.World = bsp.PermutationInfo[x].mat;
                        device.SetStreamSource(0, bsp.Display.permvertexBuffer[rawindex], 0);
                        device.VertexFormat = HaloVertex.FVF;
                        device.Indices = bsp.Display.permindexBuffer[rawindex];
                        for (int xx = 0; xx < bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++)
                        {
                            ResetTextureStates(ref device);
                            int tempshade = bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber;

                            #region AlphaBlending

                            if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaBlend)
                            {
                                device.RenderState.AlphaBlendEnable = true;
                                device.RenderState.AlphaTestEnable = false;
                            }
                            else if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaTest)
                            {
                                device.RenderState.AlphaBlendEnable = false;
                                device.RenderState.AlphaTestEnable = true;
                            }
                            else
                            {
                                device.RenderState.AlphaBlendEnable = false;
                                device.RenderState.AlphaTestEnable = false;
                            }

                            #endregion

                            #region ChooseTexture

                            device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture);

                            device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                            device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                            device.TextureState[0].ColorArgument2 = TextureArgument.Current;

                            // device.SetTexture(1, bsp.Shaders.Shader[tempshade].BumpMapTexture);
                            // device.TextureState[1].ColorOperation = TextureOperation.BumpEnvironmentMap;
                            // device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                            // device.TextureState[1].ColorArgument2 = TextureArgument.Current;
                            if (bsp.SceneryLightMapTexture != null)
                            {
                                if (bsp.SceneryLightMapTexture[x] != null &&
                                    bsp.BSPPermutationRawDataMetaChunks[rawindex].LightMapUVs.Count != 0)
                                {
                                    device.SetTexture(1, bsp.SceneryLightMapTexture[x]);
                                    device.TextureState[1].ColorOperation = TextureOperation.Modulate;
                                    device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
                                    device.TextureState[1].ColorArgument2 = TextureArgument.Current;
                                    device.TextureState[1].TextureCoordinateIndex = 2;
                                }
                                else
                                {
                                    // device.TextureState[0].ColorOperation = TextureOperation.Disable;
                                    device.TextureState[0].ColorOperation = TextureOperation.Modulate2X;
                                    device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                                    device.TextureState[0].ColorArgument2 = TextureArgument.Current;
                                }
                            }

                            #endregion

                            #region RenderToScene

                            PrimitiveType pt;
                            pt = PrimitiveType.TriangleList;
                            device.RenderState.FillMode = FillMode.Solid;
                            Material mm = new Material();
                            mm.Diffuse = Color.White;
                            mm.Ambient = Color.White;
                            device.Material = mm;
                            device.DrawIndexedPrimitives(
                                pt, 
                                0, 
                                0, 
                                bsp.BSPPermutationRawDataMetaChunks[rawindex].VerticeCount, 
                                bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                                bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);

                            #region WireFrame

                            if (Textured == false)
                            {
                                Material m = new Material();
                                m.Diffuse = Color.Red;
                                m.Ambient = Color.Red;
                                device.Material = m;
                                device.RenderState.FillMode = FillMode.WireFrame;
                                device.DrawIndexedPrimitives(
                                    pt, 
                                    0, 
                                    0, 
                                    bsp.BSPPermutationRawDataMetaChunks[rawindex].VerticeCount, 
                                    bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                                    bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);
                            }

                            #endregion

                            #endregion
                        }
                    }
                }

                #endregion

                ResetTextureStates(ref device);
            }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DirectXBSPCollision"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="tempcoll">The tempcoll.</param>
 /// <remarks></remarks>
 public DirectXBSPCollision(ref Device device, ref BSPModel.BSPCollision tempcoll)
 {
     CreateVertexBuffers(ref device, ref tempcoll);
     CreateIndexBuffers(ref device, ref tempcoll);
     verticeCount = tempcoll.Vertices.Length;
     faceCount = tempcoll.Faces.Length;
 }
Пример #18
0
            /// <summary>
            /// The draw cluster.
            /// </summary>
            /// <param name="rawindex">The rawindex.</param>
            /// <param name="outlinecolor">The outlinecolor.</param>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <param name="Textured">The textured.</param>
            /// <param name="WireFrame">The wire frame.</param>
            /// <param name="cam">The cam.</param>
            /// <remarks></remarks>
            public static void DrawCluster(
                int rawindex, 
                Color outlinecolor, 
                ref Device device, 
                ref BSPModel bsp, 
                bool Textured, 
                bool WireFrame, 
                ref Camera2 cam)
            {
                

                if (bsp.BSPRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0)
                {
                    return;
                }

                // Vector3 tempv = new Vector3();
                // tempv.X = bsp.Spawns.Spawn[x].X;
                // tempv.Y = bsp.Spawns.Spawn[x].Y;
                // tempv.Z = bsp.Spawns.Spawn[x].Z;
                // if (!cam.SphereInFrustum(tempv, 10f)) { continue; }
                device.SetStreamSource(0, bsp.Display.vertexBuffer[rawindex], 0);
                device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
                device.Indices = bsp.Display.indexBuffer[rawindex];
                for (int xx = 0; xx < bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++)
                {
                    int tempshade = bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber;

                    #region AlphaBlending

                    if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaBlend)
                    {
                        // MessageBox.Show("test");
                        device.RenderState.AlphaBlendEnable = true;
                        device.RenderState.AlphaTestEnable = false;
                    }
                    else if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaTest)
                    {
                        // MessageBox.Show("test2");
                        device.RenderState.AlphaBlendEnable = false;
                        device.RenderState.AlphaTestEnable = true;
                    }
                    else
                    {
                        device.RenderState.AlphaBlendEnable = false;
                        device.RenderState.AlphaTestEnable = false;
                    }

                    #endregion

                    #region ChooseTexture

                    if (Textured)
                    {
                        // device.TextureState[0] = device.TextureState[2];
                        device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture);
                    }
                    else
                    {
                        device.SetTexture(0, null);
                    }

                    #endregion

                    #region RenderToScene

                    PrimitiveType pt;
                    pt = PrimitiveType.TriangleList;
                    device.RenderState.FillMode = FillMode.Solid;
                    Material mm = new Material();
                    mm.Diffuse = Color.Black;
                    mm.Ambient = Color.Black;
                    device.Material = mm;
                    device.DrawIndexedPrimitives(
                        pt, 
                        0, 
                        0, 
                        bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                        bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                        bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);

                    #region WireFrame

                    if (WireFrame)
                    {
                        Material m = new Material();
                        m.Diffuse = outlinecolor;
                        m.Ambient = outlinecolor;
                        device.Material = m;
                        device.RenderState.FillMode = FillMode.WireFrame;
                        device.DrawIndexedPrimitives(
                            pt, 
                            0, 
                            0, 
                            bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                            bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                            bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);
                    }

                    #endregion

                    #endregion
                }

                
            }
Пример #19
0
        /// <summary>
        /// The create vertex buffers.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="tempcoll">The tempcoll.</param>
        /// <remarks></remarks>
        private void CreateVertexBuffers(ref Device device, ref BSPModel.BSPCollision tempcoll)
        {
            vb = new VertexBuffer(
                typeof(CustomVertex.PositionColored),
                tempcoll.Vertices.Length,
                device,
                Usage.WriteOnly,
                CustomVertex.PositionColored.Format,
                Pool.Default);
            CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vb.Lock(0, 0);

            // Lock the buffer (which will return our structs)
            for (int i = 0; i < tempcoll.Vertices.Length; i++)
            {
                verts[i].Position = new Vector3(tempcoll.Vertices[i].X, tempcoll.Vertices[i].Y, tempcoll.Vertices[i].Z);
            }

            // Unlock (and copy) the data
            vb.Unlock();
        }
Пример #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BSPCollisionViewer"/> class.
        /// </summary>
        /// <param name="tempcoll">The tempcoll.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public BSPCollisionViewer(BSPModel.BSPCollision tempcoll, Map map)
        {
            //InitializeComponent
            InitializeComponent();

            this.map = map;
            coll = tempcoll;

            // Set the initial size of our form
            this.ClientSize = new Size(800, 600);

            // And its caption
            this.Text = "BSP Viewer";

            // Load our points/edges & build polygons for surface detection / modifying
            LoadMeta();

            Main();
        }