Example #1
0
        private void CollisionMaterialTest(object sender, System.EventArgs e)
        {
            if (treeView1.SelectedNode.Tag == null)
            {
                return;
            }

            if (treeView1.SelectedNode.Tag.GetType() != typeof(Collision.NXSStruct))
            {
                return;
            }

            Collision.NXSStruct       data     = (Collision.NXSStruct)treeView1.SelectedNode.Tag;
            CollisionMaterials[]      mats     = data.Data.Materials;
            List <CollisionMaterials> typeList = new List <CollisionMaterials>();
            List <int> values = new List <int>();

            for (int x = 0; x != mats.Length; x++)
            {
                if (!typeList.Contains(mats[x]))
                {
                    typeList.Add(mats[x]);
                    values.Add(3);
                }
                else
                {
                    values[typeList.IndexOf(mats[x])] += 3;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Delete collision and placements.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDeleteCollision(object sender, System.EventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            Collision.NXSStruct col = treeView1.SelectedNode.Tag as Collision.NXSStruct;
            SceneData.Collisions.NXSData.Remove(col.Hash);

            for (int i = 0; i != SceneData.Collisions.Placements.Count; i++)
            {
                Collision.Placement placement = SceneData.Collisions.Placements[i];
                if (placement.Hash == col.Hash)
                {
                    SceneData.Collisions.Placements.Remove(placement);

                    TreeNode[] nodes = treeView1.Nodes.Find(placement.Hash.ToString(), true);

                    if (nodes.Length != 0)
                    {
                        for (int x = 0; x != nodes.Length; x++)
                        {
                            nodes[x].Remove();
                        }
                    }
                    i--;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Insert new mesh into the collision data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddCollisionModel(object sender, System.EventArgs e)
        {
            //make sure an actual model has been selected.
            if (openM2T.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("Failed to select an M2T model.", "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            M2TStructure colModel = new M2TStructure();

            if (openM2T.FileName.ToLower().EndsWith(".m2t"))
            {
                colModel.ReadFromM2T(new BinaryReader(File.Open(openM2T.FileName, FileMode.Open)));
            }
            else if (openM2T.FileName.ToLower().EndsWith(".fbx"))
            {
                colModel.ReadFromFbx(openM2T.FileName);
            }

            //crash happened/
            if (colModel.Lods[0] == null)
            {
                return;
            }

            Collision.NXSStruct nxsData = new Collision.NXSStruct();
            nxsData.Hash = FNV64.Hash(colModel.Name);
            nxsData.Data.BuildBasicCollision(colModel.Lods[0]);
            nxsData.Sections = new Collision.Section[colModel.Lods[0].Parts.Length];

            int curEdges = 0;

            for (int i = 0; i != nxsData.Sections.Length; i++)
            {
                nxsData.Sections[i]          = new Collision.Section();
                nxsData.Sections[i].Unk1     = (int)Enum.Parse(typeof(CollisionMaterials), colModel.Lods[0].Parts[i].Material) - 2;
                nxsData.Sections[i].Start    = curEdges;
                nxsData.Sections[i].NumEdges = (int)colModel.Lods[0].Parts[i].NumFaces * 3;
            }

            Collision.Placement placement = new Collision.Placement();
            placement.Hash     = nxsData.Hash;
            placement.Unk5     = 128;
            placement.Unk4     = -1;
            placement.Position = new Vector3(0, 0, 0);
            placement.Rotation = new Vector3(0);


            SceneData.Collisions.NXSData.Add(nxsData.Hash, nxsData);
            SceneData.Collisions.Placements.Add(placement);
            treeView1.Nodes.Clear();
            LoadInCollision();
        }
Example #4
0
        /// <summary>
        /// Insert all collisions into the editor.
        /// </summary>
        public void LoadInCollision()
        {
            treeView1.Nodes.Clear();
            for (int i = 0; i != SceneData.Collisions.NXSData.Count; i++)
            {
                Collision.NXSStruct nxsData = SceneData.Collisions.NXSData.ElementAt(i).Value;

                TreeNode node = new TreeNode(nxsData.Hash.ToString());
                node.Tag  = nxsData;
                node.Name = nxsData.Hash.ToString();
                //M2TStructure structure = new M2TStructure();
                //structure.BuildCollision(nxsData, node.Name);
                //structure.ExportCollisionToM2T(node.Name);
                //structure.ExportToFbx("Collisions" + "//", true);
                treeView1.Nodes.Add(node);
            }

            //CustomEDD frame = new CustomEDD();
            for (int i = 0; i != SceneData.Collisions.Placements.Count; i++)
            {
                Collision.Placement data = SceneData.Collisions.Placements[i];
                //CustomEDD.Entry entry = new CustomEDD.Entry();

                //entry.LodCount = 1;
                //entry.LODNames = new string[1];
                //entry.LODNames[0] = data.Hash.ToString();
                //entry.Position = data.Position;
                //entry.Rotation = new Matrix33();

                for (int x = 0; x != treeView1.Nodes.Count; x++)
                {
                    if (data.Hash.ToString() == treeView1.Nodes[x].Name)
                    {
                        TreeNode node = new TreeNode(treeView1.Nodes[x].Nodes.Count + 1.ToString());
                        node.Tag  = data;
                        node.Name = treeView1.Nodes[x].Nodes.Count + 1.ToString();

                        treeView1.Nodes[x].Nodes.Add(node);
                    }
                }
                //frame.Entries.Add(entry);
            }
            //frame.EntryCount = frame.Entries.Count;
            //using (BinaryWriter writer = new BinaryWriter(File.Create("collisions/frame.edd")))
            //{
            //    frame.WriteToFile(writer);
            //}
        }