Exemple #1
0
        private void AddMaterial(object sender, EventArgs e)
        {
            //ask user for material name.
            NewObjectForm form = new NewObjectForm(true);

            form.SetLabel(Language.GetString("$QUESTION_NAME_OF_MAT"));
            form.LoadOption(new MaterialAddOption());
            form.ShowDialog();
            if (form.type == -1)
            {
                return;
            }

            if (mtl.Materials.ContainsKey(FNV64.Hash(form.GetInputText())))
            {
                MessageBox.Show("Found duplicate material. Will not be adding new material!");
                return;
            }

            //create material with new name.
            Material mat = new Material();

            mat.SetName(form.GetInputText());

            mtl.Materials.Add(mat.MaterialHash, mat);
            dataGridView1.Rows.Add(BuildRowData(mat));
            //cleanup and reload.
            form.Dispose();
        }
Exemple #2
0
        private void AddMaterial(object sender, EventArgs e)
        {
            if (!Panel_Main.Visible)
            {
                return;
            }

            // Ask user for material name.
            NewObjectForm form = new NewObjectForm(true);

            form.SetLabel(Language.GetString("$QUESTION_NAME_OF_MAT"));
            form.LoadOption(new MaterialAddOption());

            if (form.ShowDialog() == DialogResult.OK)
            {
                if (mtl.Materials.ContainsKey(FNV64.Hash(form.GetInputText())))
                {
                    MessageBox.Show("Found duplicate material. Will not be adding new material!", "Toolkit");
                    return;
                }

                // Create material with new name.
                IMaterial mat = MaterialFactory.ConstructMaterial(mtl.Version);
                mat.SetName(form.GetInputText());

                mtl.Materials.Add(mat.GetMaterialHash(), mat);
                dataGridView1.Rows.Add(BuildRowData(mat));
            }

            // Cleanup and reload.
            form.Dispose();
        }
Exemple #3
0
        private void AddItemButton_Click(object sender, System.EventArgs e)
        {
            NewObjectForm objectForm = new NewObjectForm(true);

            objectForm.SetLabel("$SELECT_TYPE_AND_NAME");
            ActorItemAddOption optionControl = new ActorItemAddOption();

            objectForm.LoadOption(optionControl);

            if (objectForm.ShowDialog() == DialogResult.OK)
            {
                ActorTypes type  = optionControl.GetSelectedType();
                ActorEntry entry = actors.CreateActorEntry(type, objectForm.GetInputText());

                TreeNode node = new TreeNode(entry.EntityName);
                node.Text = entry.EntityName;
                node.Tag  = entry;

                TreeNode child = new TreeNode("Extra Data");
                child.Tag = actors.ExtraData[entry.DataID];
                node.Nodes.Add(child);
                items.Nodes.Add(node);
            }

            objectForm.Dispose();
        }
        private void AddFrameSingleMesh_Click(object sender, EventArgs e)
        {
            NewObjectForm form = new NewObjectForm(true);

            form.SetLabel(Language.GetString("$QUESTION_FRADD"));
            form.LoadOption(new FrameResourceAddOption());
            form.ShowDialog();

            int selection;

            if (form.type != -1)
            {
                selection = (form.control as FrameResourceAddOption).GetSelectedType();
            }
            else
            {
                return;
            }

            CreateNewEntry(selection, form.GetInputText());
        }
        private void importFrameEDDButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Warning! This is a very WIP feature and has not been tested. \n\nIf you want to use it, select an FBX file with multiple objects. They will be converted and added into the Frame Resource as objects. \n The M2FBX tool will export each model into seperate files, so you'll have to manually delete them afterwards. \n");
            NewObjectForm form = new NewObjectForm(false);

            form.SetLabel(Language.GetString("$QUESTION_NOT_NEEDED"));
            form.LoadOption(new FrameResourceSceneOption());
            form.ShowDialog();

            if (form.type == -1)
            {
                return;
            }

            FrameResourceSceneOption control = form.control as FrameResourceSceneOption;
            Vector3 offsetVector             = control.GetOffset();

            control.Dispose();
            form.Dispose();

            //check if the user cancels.
            if (eddBrowser.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            CustomEDD frameData            = new CustomEDD();
            string    frameParentDirectory = "";

            //check if the filename is correct.
            if (eddBrowser.FileName.ToLower().EndsWith(".edd"))
            {
                FileInfo file = new FileInfo(eddBrowser.FileName);

                //check if the file actually exists.
                if (!file.Exists)
                {
                    return;
                }

                frameParentDirectory = file.Directory.FullName;

                using (BinaryReader reader = new BinaryReader(File.Open(file.FullName, FileMode.Open)))
                {
                    frameData.ReadFromFile(reader);
                }
            }
            else if (eddBrowser.FileName.ToLower().EndsWith(".fbx"))
            {
                FileInfo file = new FileInfo(eddBrowser.FileName);

                //check if the file actually exists.
                if (!file.Exists)
                {
                    return;
                }

                frameParentDirectory = file.Directory.FullName;
                frameData.ReadFromFbx(file);
            }

            int done = 0;

            foreach (CustomEDD.Entry entry in frameData.Entries)
            {
                FrameObjectSingleMesh mesh = new FrameObjectSingleMesh();
                Model model = new Model();
                model.FrameMesh = mesh;

                string path = frameParentDirectory + "//" + entry.LODNames[0] + ".m2t";

                using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)))
                {
                    model.ModelStructure.ReadFromM2T(reader);
                }

                mesh.Name.Set(model.ModelStructure.Name);
                model.CreateObjectsFromModel();
                mesh.AddRef(FrameEntryRefTypes.Mesh, model.FrameGeometry.RefID);
                mesh.AddRef(FrameEntryRefTypes.Material, model.FrameMaterial.RefID);
                SceneData.FrameResource.FrameMaterials.Add(model.FrameMaterial.RefID, model.FrameMaterial);
                SceneData.FrameResource.FrameGeometries.Add(model.FrameGeometry.RefID, model.FrameGeometry);
                DataGridViewRow row = new DataGridViewRow();
                row.Tag = mesh;
                row.CreateCells(dataGridView1, new object[] { dataGridView1.Rows.Count - 1, model.FrameMaterial.ToString() });
                dataGridView1.Rows.Add(row);
                row     = new DataGridViewRow();
                row.Tag = mesh;
                row.CreateCells(dataGridView1, new object[] { dataGridView1.Rows.Count - 1, model.FrameGeometry.ToString() });
                dataGridView1.Rows.Add(row);

                //Check for existing buffer; if it exists, remove so we can add one later.
                if (SceneData.IndexBufferPool.SearchBuffer(model.IndexBuffers[0].Hash) != null)
                {
                    SceneData.IndexBufferPool.RemoveBuffer(model.IndexBuffers[0]);
                }

                //do the same for vertexbuffer pools.
                if (SceneData.VertexBufferPool.SearchBuffer(model.VertexBuffers[0].Hash) != null)
                {
                    SceneData.VertexBufferPool.RemoveBuffer(model.VertexBuffers[0]);
                }

                SceneData.IndexBufferPool.AddBuffer(model.IndexBuffers[0]);
                SceneData.VertexBufferPool.AddBuffer(model.VertexBuffers[0]);

                mesh.UpdateNode();

                FrameHeaderScene scene = SceneData.FrameResource.FrameScenes.ElementAt(0).Value;
                mesh.SubRef(FrameEntryRefTypes.Parent2);
                mesh.AddRef(FrameEntryRefTypes.Parent2, scene.RefID);
                mesh.ParentIndex2.Index  = 0;
                mesh.ParentIndex2.RefID  = scene.RefID;
                mesh.ParentIndex2.Name   = scene.Name.String;
                mesh.IsOnFrameTable      = true;
                mesh.FrameNameTableFlags = 0;

                mesh.Matrix.Position  = entry.Position;
                mesh.Matrix.Position += offsetVector;
                //entry.Rotation.ChangeHandedness();
                mesh.Matrix.Rotation = entry.Rotation;

                treeView1.Nodes.Add(CreateTreeNode(mesh));
                SceneData.FrameResource.FrameObjects.Add(mesh.RefID, mesh);
                row     = new DataGridViewRow();
                row.Tag = mesh;
                row.CreateCells(dataGridView1, new object[] { dataGridView1.Rows.Count - 1, mesh.Name.String });
                dataGridView1.Rows.Add(row);
                done++;
                Console.WriteLine("Done number {0}/{1} {2}", done, frameData.EntryCount, mesh.Name.String);
            }
            PopulateForm();
        }