Пример #1
0
        private void applyTransforms()
        {
            var bones = (chkHierarchy.Checked ? SceneManager.Current.Models[modelIndex].Bones[boneIndex].AllChildren() : new ModelBoneCollection {
                SceneManager.Current.Models[modelIndex].Bones[boneIndex]
            });

            if (rdoScaling.Checked)
            {
                OpenTK.Matrix4 scaleMatrix = OpenTK.Matrix4.Identity;

                if (rdoScaleWholeModel.Checked)
                {
                    scaleMatrix = OpenTK.Matrix4.CreateScale(
                        txtScaleWholeModel.Text.ToSingle(),
                        txtScaleWholeModel.Text.ToSingle(),
                        txtScaleWholeModel.Text.ToSingle()
                        );
                }
                else if (rdoScaleByAxis.Checked)
                {
                    scaleMatrix = OpenTK.Matrix4.CreateScale(
                        txtScaleAxisX.Text.ToSingle(),
                        txtScaleAxisY.Text.ToSingle(),
                        txtScaleAxisZ.Text.ToSingle()
                        );
                }

                ModelManipulator.Scale(bones, scaleMatrix, chkHierarchy.Checked);
            }
            else if (rdoMunging.Checked)
            {
                if (rdoInvert.Checked)
                {
                    ModelManipulator.FlipAxis(SceneManager.Current.Models[modelIndex].Bones[boneIndex].Mesh, cboInvertAxis.SelectedItem.ToString().ToEnum <Axis>(), chkHierarchy.Checked);
                }
                else if (rdoMeshBoneSwap.Checked)
                {
                    ModelManipulator.MungeMeshWithBone(bones);
                }
                else if (rdoFlipWindingOrder.Checked)
                {
                    ModelManipulator.FlipFaces(bones, chkHierarchy.Checked);
                }
            }
        }
Пример #2
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;
            }
        }