Пример #1
0
        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);
        }
Пример #2
0
        public static void ProcessCarForCarmageddonMaxDamage()
        {
            if (SceneManager.Current.Models.Count == 0)
            {
                return;
            }

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

            SceneManager.Current.UpdateProgress("Applying Carmageddon Reincarnation 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("\\", "");
            }

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

            float scale;

            for (int i = 0; i < bones.Count; i++)
            {
                ModelBone 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.ExtractTranslation() == Vector3.Zero)
                    {
                        ModelManipulator.MungeMeshWithBone(bone.Children[0].Mesh, false);

                        Matrix4D m = bone.Transform;
                        m.M31          = bone.Children[0].Transform.M31;
                        m.M32          = bone.Children[0].Transform.M32;
                        m.M33          = bone.Children[0].Transform.M33;
                        bone.Transform = m;

                        model.SetTransform(Matrix4D.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(Matrix4D.CreateScale(scale) * Matrix4D.CreateRotationY(Maths.DegreesToRadians(180)), bone.Index);
                    break;

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

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

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

                    bone.Name = "Hub_" + suffix;

                    if (bone.Transform.ExtractTranslation() == 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(Matrix4D.CreateScale(scale) * (suffix == "RL" ? Matrix4D.CreateRotationY(Maths.DegreesToRadians(180)) : Matrix4D.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(CoordinateSystem.LeftHanded);

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

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