예제 #1
0
        private void LoadModel(bool required)
        {
            if (ofdLoadModel.ShowDialog(this) == DialogResult.OK)
            {
                m_ModelFileName = ofdLoadModel.FileName.Replace('/', '\\');
                m_ModelPath     = m_ModelFileName.Substring(0, m_ModelFileName.LastIndexOf('\\') + 1);
                m_ModelFormat   = ofdLoadModel.FileName.Substring(ofdLoadModel.FileName.Length - 3, 3).ToLower();

                ModelBase loadedModel = BMDImporter.LoadModel(m_ModelFileName);
                m_ImportedModel = BMDImporter.ConvertModelToBMD(ref m_ImportedModel.m_File,
                                                                m_ModelFileName, 1f, m_ModelImportSettings.m_ExtraOptions, false);
                m_Materials = loadedModel.m_Materials;

                m_MdlLoaded = true;

                PrerenderModel();

                glModelView.SetShowMarioReference(true);
                glModelView.Refresh();

                PopulateColTypes();

                tbModelName.Text = m_ModelFileName;
            }
            else if (required)
            {
                m_EarlyClosure = true;
                Close();
            }
        }
        private void btnImportAnimation_Click(object sender, EventArgs e)
        {
            if (m_BMD == null || m_BCA == null)
            {
                MessageBox.Show("Please select a valid model (BMD) and animation (BCA) to replace.");
                return;
            }
            if (txtInputAnimation.Text == null || txtInputAnimation.Text.Equals(""))
            {
                MessageBox.Show("Please select an animation file or model to import.");
                return;
            }

            float scale;

            if (!Helper.TryParseFloat(txtScale.Text, out scale))
            {
                MessageBox.Show("Please enter a valid Scale value as a decimal value, eg. 1.234");
                return;
            }

            string animationFormat = txtInputAnimation.Text.Substring(txtInputAnimation.Text.Length - 3).ToLowerInvariant();

            bool wasRunning = m_Running;

            StopTimer();

            try
            {
                ModelBase loadedModel = null;
                switch (animationFormat)
                {
                case "dae":
                {
                    if (txtInputModel.Text != null && !txtInputModel.Text.Equals(""))
                    {
                        loadedModel = BMDImporter.LoadModel(txtInputAnimation.Text, scale);
                        m_BMD       = BMDImporter.CallBMDWriter(ref m_BMD.m_File, loadedModel,
                                                                BMDImporter.BMDExtraImportOptions.DEFAULT, true);
                    }
                    // >>> TODO <<<
                    // Below line in necessary to an obscure bug with NARC files, if you have two file from the same
                    // NARC open and modify and save the first, when you then go to save the second, it won't have
                    // picked up the changes from the first file and when saved will write the original first file and
                    // the modified second file.
                    NitroFile animationFile = Program.m_ROM.GetFileFromName(m_BCA.m_FileName);
                    m_BCA = BMDImporter.ConvertAnimatedDAEToBCA(ref animationFile, txtInputAnimation.Text, m_BCAImportationOptions, true);
                }
                break;

                case "ica":
                {
                    if (txtInputModel.Text != null && !txtInputModel.Text.Equals(""))
                    {
                        loadedModel = BMDImporter.LoadModel(txtInputModel.Text, scale);
                        m_BMD       = BMDImporter.CallBMDWriter(ref m_BMD.m_File, loadedModel,
                                                                BMDImporter.BMDExtraImportOptions.DEFAULT, true);
                    }
                    NitroFile animationFile = Program.m_ROM.GetFileFromName(m_BCA.m_FileName);
                    m_BCA = BMDImporter.ConvertICAToBCA(ref animationFile, txtInputAnimation.Text, loadedModel,
                                                        scale, BMDImporter.BMDExtraImportOptions.DEFAULT, m_BCAImportationOptions, true);
                }
                break;
                }

                m_AnimationFrameNumber  = 0;
                m_AnimationNumFrames    = m_BCA.m_NumFrames;
                txtCurrentFrameNum.Text = "" + m_AnimationFrameNumber;
                txtNumFrames.Text       = "" + (m_BCA.m_NumFrames - 1);

                PrerenderModel();

                if (wasRunning)
                {
                    StartTimer();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: \n" + ex.Message + "\n\n" + ex.StackTrace);
                m_BMD = new BMD(Program.m_ROM.GetFileFromName(m_BMD.m_FileName));
                m_BCA = new BCA(Program.m_ROM.GetFileFromName(m_BCA.m_FileName));
            }
        }