private void btnOpen_Click(object sender, EventArgs e)
        {
            ofdBrowse.Filter = "All supported files|*.jpg;*.png;*.tif;*.tga;*.bmp;*.tdx|JPG (*.jpg)|*.jpg|PNG (*.png)|*.png|TIF (*.tif)|*.tif|TGA (*.tga)|*.tga|BMP (*.bmp)|*.bmp|TDX (*.tdx)|*.tdx";

            if (ofdBrowse.ShowDialog() == DialogResult.OK && File.Exists(ofdBrowse.FileName))
            {
                var fi = new FileInfo(ofdBrowse.FileName);

                switch (fi.Extension.ToLower())
                {
                    case ".bmp":
                        t = SceneManager.Current.Content.Load<Texture, BMPImporter>(fi.Name, fi.DirectoryName);
                        break;

                    case ".jpg":
                        t = SceneManager.Current.Content.Load<Texture, JPGImporter>(fi.Name, fi.DirectoryName);
                        break;

                    case ".png":
                        t = SceneManager.Current.Content.Load<Texture, PNGImporter>(fi.Name, fi.DirectoryName);
                        break;

                    case ".tif":
                        t = SceneManager.Current.Content.Load<Texture, TIFImporter>(fi.Name, fi.DirectoryName);
                        break;

                    case ".tga":
                        t = SceneManager.Current.Content.Load<Texture, TGAImporter>(fi.Name, fi.DirectoryName);
                        break;

                    case ".tdx":
                        t = SceneManager.Current.Content.Load<Texture, TDXImporter>(fi.Name, fi.DirectoryName);
                        break;
                }

                if (t != null)
                {
                    var b = t.GetBitmap();

                    pbPreview.Image = t.GetThumbnail(1024, false);
                    lblFile.Text = string.Format(lblFile.Tag.ToString(), fi.Name);
                    lblWidth.Text = string.Format(lblWidth.Tag.ToString(), b.Width);
                    lblHeight.Text = string.Format(lblHeight.Tag.ToString(), b.Height);
                    lblFileSize.Text = string.Format(lblFileSize.Tag.ToString(), fi.Length);
                }
            }
        }
Exemple #2
0
 public Material()
 {
     texture = new Texture();
 }
 private void SetTexture(Texture t)
 {
     txtTexture.Text = t.Name;
     pbPreview.Image = t.GetThumbnail();
     mi.SetThumbnail((Bitmap)pbPreview.Image);
 }
Exemple #4
0
        private void menuCarmageddon2Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;

            SceneManager.Current.SetCoordinateSystem(SceneManager.CoordinateSystem.RightHanded);

            switch (mi.Text)
            {
                case "Actor":
                    ofdBrowse.Filter = "Carmageddon 2 ACTOR (*.act)|*.act";

                    if (ofdBrowse.ShowDialog() == DialogResult.OK && File.Exists(ofdBrowse.FileName))
                    {
                        SceneManager.Current.Content.Load<Model, ACTImporter>(Path.GetFileNameWithoutExtension(ofdBrowse.FileName), Path.GetDirectoryName(ofdBrowse.FileName), true);
                    }
                    break;

                case "Race":
                    ofdBrowse.Filter = "Carmageddon 2 Race (*.act)|*.act";

                    if (ofdBrowse.ShowDialog() == DialogResult.OK && File.Exists(ofdBrowse.FileName))
                    {
                        string txtFile = Path.Combine(Path.GetDirectoryName(ofdBrowse.FileName), Path.GetFileNameWithoutExtension(ofdBrowse.FileName) + ".txt");

                        Model race = SceneManager.Current.Content.Load<Model, ACTImporter>(Path.GetFileNameWithoutExtension(ofdBrowse.FileName), Path.GetDirectoryName(ofdBrowse.FileName), true);
                        //if (File.Exists(txtFile)) { race.SupportingDocuments["TXT"] = ToxicRagers.Carmageddon2.Formats.Map.Load(txtFile); }

                        SceneManager.Current.SetContext(ContextGame.Carmageddon_2, ContextMode.Level);
                    }
                    break;

                case "Process Level for Carmageddon Reincarnation":
                    {
                        if (SceneManager.Current.Models.Count == 0) { return; }

                        var bones = SceneManager.Current.Models[0].Bones[0].AllChildren();

                        SceneManager.Current.UpdateProgress("Applying Carmageddon Reincarnation scale");

                        ModelManipulator.Scale(bones, Matrix4.CreateScale(6.9f, 6.9f, -6.9f), true);
                        ModelManipulator.FlipFaces(bones, true);

                        SceneManager.Current.UpdateProgress("Fixing material names");

                        foreach (var material in SceneManager.Current.Materials)
                        {
                            if (material.Name.Contains(".")) { material.Name = material.Name.Substring(0, material.Name.IndexOf(".")); }
                            material.Name = material.Name.Replace("\\", "");

                            MATMaterial m = (material.SupportingDocuments["Source"] as MATMaterial);
                            if (!m.HasTexture)
                            {
                                using (Bitmap bmp = new Bitmap(16, 16))
                                using (Graphics g = Graphics.FromImage(bmp))
                                {
                                    g.FillRectangle(new SolidBrush(Color.FromArgb(m.DiffuseColour[3], m.DiffuseColour[0], m.DiffuseColour[1], m.DiffuseColour[2])), 0, 0, 16, 16);

                                    Texture t = new Texture();
                                    t.CreateFromBitmap(bmp, string.Format("{4}_R{0:x2}G{1:x2}B{2:x2}A{3:x2}", m.DiffuseColour[0], m.DiffuseColour[1], m.DiffuseColour[2], m.DiffuseColour[3], material.Name));
                                    material.Texture = t;
                                }
                            }
                        }

                        SceneManager.Current.UpdateProgress("Processing powerups and accessories");

                        for (int i = bones.Count - 1; i >= 0; i--)
                        {
                            var bone = bones[i];

                            if (bone.Name.StartsWith("&"))
                            {
                                var entity = new Entity();

                                if (bone.Name.StartsWith("&£"))
                                {
                                    string key = bone.Name.Substring(2, 2);

                                    entity.UniqueIdentifier = "errol_B00BIE" + key + "_" + i.ToString("000");
                                    entity.EntityType = EntityType.Powerup;

                                    var pup = ToxicRagers.Carmageddon2.Powerups.LookupID(int.Parse(key));

                                    if (pup.InCR)
                                    {
                                        entity.Name = "pup_" + pup.Name;
                                        entity.Tag = pup.Model;
                                    }
                                    else
                                    {
                                        entity.Name = "pup_Credits";
                                        entity.Tag = pup.Model;
                                    }
                                }
                                else
                                {
                                    // accessory
                                    entity.UniqueIdentifier = "errol_HEAD00" + bone.Name.Substring(1, 2) + "_" + i.ToString("000");
                                    entity.EntityType = EntityType.Accessory;
                                    entity.Name = "C2_" + bone.Mesh.Name.Substring(3);
                                }

                                entity.Transform = bone.CombinedTransform;
                                entity.AssetType = AssetType.Sprite;
                                SceneManager.Current.Entities.Add(entity);

                                SceneManager.Current.Models[0].RemoveBone(bone.Index);
                            }
                        }

                        SceneManager.Current.UpdateProgress("Processing complete!");

                        SceneManager.Current.SetCoordinateSystem(SceneManager.CoordinateSystem.LeftHanded);

                        SceneManager.Current.Change(ChangeType.Munge, -1);

                        SceneManager.Current.SetContext(ContextGame.Carmageddon_Reincarnation, ContextMode.Level);
                    }
                    break;

                case "Process Car for Carmageddon Reincarnation":
                    {
                        if (SceneManager.Current.Models.Count == 0) { return; }

                        var model = SceneManager.Current.Models[0];
                        var bones = SceneManager.Current.Models[0].Bones[0].AllChildren();

                        SceneManager.Current.UpdateProgress("Applying Carmageddon Reincarnation scale");

                        ModelManipulator.Scale(bones, Matrix4.CreateScale(6.9f, 6.9f, -6.9f), true);
                        ModelManipulator.FlipFaces(bones, true);

                        SceneManager.Current.UpdateProgress("Fixing material names");

                        foreach (var material in SceneManager.Current.Materials)
                        {
                            if (material.Name.Contains(".")) { material.Name = material.Name.Substring(0, material.Name.IndexOf(".")); }
                            material.Name = material.Name.Replace("\\", "");
                        }

                        SceneManager.Current.UpdateProgress("Munging parts and fixing wheels");

                        Single scale;

                        for (int i = 0; i < bones.Count; i++)
                        {
                            var bone = bones[i];

                            if (i == 0)
                            {
                                bone.Name = "c_Body";
                                bone.Mesh.Name = "c_Body";
                            }
                            else
                            {
                                bone.Name = Path.GetFileNameWithoutExtension(bone.Name);
                            }

                            switch (bone.Name.ToUpper())
                            {
                                case "C_BODY":
                                    break;

                                case "FLPIVOT":
                                case "FRPIVOT":
                                    bone.Name = "Hub_" + bone.Name.ToUpper().Substring(0, 2);

                                    if (bone.Transform.Position() == Vector3.Zero)
                                    {
                                        ModelManipulator.MungeMeshWithBone(bone.Children[0].Mesh, false);

                                        var m = bone.Transform;
                                        m.Row3 = bone.Children[0].Transform.Row3;
                                        bone.Transform = m;

                                        model.SetTransform(Matrix4.Identity, bone.Children[0].Index);
                                    }
                                    break;

                                case "FLWHEEL":
                                    scale = bone.CombinedTransform.ExtractTranslation().Y / 0.35f;

                                    bone.Name = "Wheel_FL";
                                    model.ClearMesh(bone.Index);
                                    model.SetTransform(Matrix4.CreateScale(scale) * Matrix4.CreateRotationY(MathHelper.DegreesToRadians(180)), bone.Index);
                                    break;

                                case "FRWHEEL":
                                    scale = bone.CombinedTransform.ExtractTranslation().Y / 0.35f;

                                    bone.Name = "Wheel_FR";
                                    model.ClearMesh(bone.Index);
                                    model.SetTransform(Matrix4.CreateScale(scale), bone.Index);
                                    break;

                                case "RLWHEEL":
                                case "RRWHEEL":
                                    string suffix = bone.Name.ToUpper().Substring(0, 2);

                                    bone.Name = "Hub_" + suffix;

                                    if (bone.Transform.Position() == Vector3.Zero) { ModelManipulator.MungeMeshWithBone(bone.Mesh, false); }
                                    model.ClearMesh(bone.Index);

                                    scale = bone.CombinedTransform.ExtractTranslation().Y / 0.35f;

                                    int newBone = model.AddMesh(null, bone.Index);
                                    model.SetName("Wheel_" + suffix, newBone);
                                    model.SetTransform(Matrix4.CreateScale(scale) * (suffix == "RL" ? Matrix4.CreateRotationY(MathHelper.DegreesToRadians(180)) : Matrix4.Identity), newBone);
                                    break;

                                case "DRIVER":
                                    bone.Name = "Dryver";
                                    goto default;

                                default:
                                    if (bone.Type == BoneType.Mesh) { ModelManipulator.MungeMeshWithBone(bone.Mesh, false); }
                                    break;
                            }
                        }

                        SceneManager.Current.UpdateProgress("Processing complete!");

                        SceneManager.Current.SetCoordinateSystem(SceneManager.CoordinateSystem.LeftHanded);

                        SceneManager.Current.Change(ChangeType.Munge, -1);

                        SceneManager.Current.SetContext(ContextGame.Carmageddon_Reincarnation, ContextMode.Car);
                    }
                    break;
            }
        }