Ejemplo n.º 1
0
        private FrameObjectBase CreateSingleMesh()
        {
            FrameObjectBase mesh = new FrameObjectSingleMesh();

            Model model = new Model();

            model.FrameMesh = (mesh as FrameObjectSingleMesh);

            if (m2tBrowser.ShowDialog() == DialogResult.Cancel)
            {
                return(null);
            }

            if (m2tBrowser.FileName.ToLower().EndsWith(".m2t"))
            {
                model.ModelStructure.ReadFromM2T(new BinaryReader(File.Open(m2tBrowser.FileName, FileMode.Open)));
            }
            else if (m2tBrowser.FileName.ToLower().EndsWith(".fbx"))
            {
                if (model.ModelStructure.ReadFromFbx(m2tBrowser.FileName) == -1)
                {
                    return(null);
                }
            }

            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);

            dataGridView1.Rows.Add(ConvertEntryToDataGridView(model.FrameMaterial));
            dataGridView1.Rows.Add(ConvertEntryToDataGridView(model.FrameGeometry));

            //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]);

            return(mesh);
        }
Ejemplo n.º 2
0
        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();
        }