コード例 #1
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;
            }
        }
コード例 #2
0
ファイル: CarmageddonClassic.cs プロジェクト: q4a/Flummery
        public static void ProcessLevelForCarmageddonMaxDamage()
        {
            if (SceneManager.Current.Models.Count == 0)
            {
                return;
            }

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

            SceneManager.Current.UpdateProgress("Applying Carmageddon: Max Damage scale");

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

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

            foreach (Material 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--)
            {
                ModelBone bone = bones[i];

                if (bone.Name.StartsWith("&"))
                {
                    if (bone.Name.StartsWith("&£"))
                    {
                        C2Powerup pup     = Powerups.LookupID(int.Parse(bone.Name.Substring(2, 2)));
                        Powerup   powerup = new Powerup();

                        if (pup.InMD)
                        {
                            powerup.Name = $"pup_{pup.Name}";
                            powerup.Tag  = pup.Model;
                        }
                        else
                        {
                            powerup.Name = "pup_Credits";
                            powerup.Tag  = pup.Model;
                        }

                        powerup.Transform = bone.CombinedTransform;

                        SceneManager.Current.Entities.Add(powerup);
                    }
                    else
                    {
                        Accessory accessory = new Accessory
                        {
                            Name = $"C2_{bone.Mesh.Name.Substring(3)}"
                        };

                        SceneManager.Current.Entities.Add(accessory);
                    }

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

            if (SceneManager.Current.Models[0].SupportingDocuments.ContainsKey("TXT"))
            {
                Map map = SceneManager.Current.Models[0].GetSupportingDocument <Map>("TXT");

                StartingGrid grid = new StartingGrid
                {
                    Transform = Matrix4D.CreateTranslation(map.GridPosition.X * 6.9f, map.GridPosition.Y * 6.9f, map.GridPosition.Z * -6.9f)
                };

                SceneManager.Current.Entities.Add(grid);
            }

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

            SceneManager.Current.SetCoordinateSystem(CoordinateSystem.LeftHanded);

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

            SceneManager.Current.SetContext("Carmageddon Max Damage", ContextMode.Level);
        }