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();
            }
        }
Exemple #2
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();

                BMDImporter importer = new BMDImporter();
                m_ImportedModel = importer.ConvertModelToBMD(ref m_ImportedModel.m_File,
                                                             m_ModelFileName, Vector3.One, m_ExtraOptions, false);
                m_Materials = importer.GetModelMaterials(m_ModelFileName);

                m_MdlLoaded = true;

                PrerenderModel();

                PopulateColTypes();

                tbModelName.Text = m_ModelFileName;
            }
            else if (required)
            {
                m_EarlyClosure = true;
                Close();
            }
        }
Exemple #3
0
        private void ImportModel()
        {
            float faceSizeThreshold = 0.001f;

            if (txtThreshold.Text == "")
            {
                faceSizeThreshold = 0.001f;//Default value
            }
            else
            {
                try { faceSizeThreshold = float.Parse(txtThreshold.Text, Helper.USA); }
                catch { MessageBox.Show(txtThreshold.Text + "\nis not a valid float value. Please enter a value in format 0.123"); return; }
            }
            NitroFile kcl;//This'll hold the KCL file that is to be replaced, either a level's or an object's

            //If it's an object it'll be scaled down - need to get back to original value
            slStatus.Text = "Importing model...";
            glModelView.Refresh();
            BMDImporter importer = new BMDImporter();

            m_ImportedModel = importer.ConvertModelToBMD(ref m_ImportedModel.m_File,
                                                         m_ModelFileName, m_Scale, m_ExtraOptions, true);

            PrerenderModel();
            glModelView.Refresh();
            if (cbGenerateCollision.Checked)
            {
                float kclScale = (!chkInGamePreview.Checked) ? m_Scale.X : (m_Scale.X * m_InGameModelScale);
                slStatus.Text = "Importing collision map... This may take a few minutes, please be patient.";
                try
                {
                    kcl = Program.m_ROM.GetFileFromName(m_KCLName);
                    new KCLImporter().ConvertModelToKCL(kcl, m_ModelFileName, kclScale, faceSizeThreshold, m_MatColTypes);
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("NitroROM: cannot find file"))
                    {
                        MessageBox.Show("This object has no collision data, however the model will still be imported.");
                    }
                    else
                    {
                        MessageBox.Show("An error occurred importing the collision map:\n\n" +
                                        e.Message + "\n\n" + e.StackTrace);
                    }
                }
            }
            slStatus.Text = "Finished importing.";

            RefreshScale(1f);
            tbScale.Text = "1";

            try { ((LevelEditorForm)Owner).UpdateLevelModel(); }
            catch { }
        }
        private void ImportModel()
        {
            NitroFile kcl;//This'll hold the KCL file that is to be replaced, either a level's or an object's

            //If it's an object it'll be scaled down - need to get back to original value
            slStatus.Text = "Importing model...";
            glModelView.Refresh();
            m_ImportedModel = BMDImporter.ConvertModelToBMD(ref m_ImportedModel.m_File,
                                                            m_ModelFileName, m_ModelImportSettings.m_Scale, m_ModelImportSettings.m_ExtraOptions, true);

            PrerenderModel();
            glModelView.Refresh();
            if (m_ModelImportSettings.m_GenerateKCL)
            {
                float kclScale = (!chkInGamePreview.Checked) ? m_ModelImportSettings.m_Scale : (m_ModelImportSettings.m_Scale * m_ModelImportSettings.m_InGameModelScale);
                slStatus.Text = "Importing collision map... This may take a few minutes, please be patient.";
                try
                {
                    kcl = Program.m_ROM.GetFileFromName(m_KCLName);
                    KCLImporter.ConvertModelToKCL(kcl, m_ModelFileName, kclScale, m_ModelImportSettings.m_KCLMinimumFaceSize, m_MatColTypes);
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("NitroROM: cannot find file"))
                    {
                        MessageBox.Show("This object has no collision data, however the model will still be imported.");
                    }
                    else
                    {
                        new ExceptionMessageBox("Error importing collision map", e).ShowDialog();
                    }
                    return;
                }
            }
            slStatus.Text = "Finished importing.";

            m_SavedModelImportSettings[m_BMDName] = m_ModelImportSettings;
            m_SavedMaterialCollisionTypes[m_ModelPath + m_ModelFileName] = m_MatColTypes;

            RefreshScale(1f);
            tbScale.Text = "1";

            if (Owner != null)
            {
                try
                {
                    ((LevelEditorForm)Owner).UpdateLevelModel();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
        }
Exemple #5
0
        public BMDWriter(ModelBase model, ref NitroFile modelFile, BMDImporter.BMDExtraImportOptions extraOptions)
            : base(model, modelFile.m_Name)
        {
            m_ModelFile = modelFile;
            m_ConvertToTriangleStrips = extraOptions.m_ConvertToTriangleStrips;
            m_KeepVertexOrderDuringStripping = extraOptions.m_KeepVertexOrderDuringStripping;
            m_AlwaysWriteFullVertexCmd23h = extraOptions.m_AlwaysWriteFullVertexCmd23h;

            if (m_ConvertToTriangleStrips)
            {
                Stripify();
            }
        }
        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));
            }
        }
Exemple #7
0
 private void btnSaveChanges_Click(object sender, EventArgs e)
 {
     m_Model.m_ModelChunks[0].m_MatGroups[0].m_Alpha = 12;
     BMDImporter.CallBMDWriter(ref m_ModelFile, new BMDLoader(m_ModelName, m_Model).LoadModel(), BMDImporter.BMDExtraImportOptions.DEFAULT).m_File.SaveChanges();
 }