Example #1
0
        public static void OpenVehicle(string path)
        {
            SceneManager.Current.SetCoordinateSystem(CoordinateSystem.LeftHanded);

            SceneManager.Current.Reset();

            string assetFolder = Path.GetDirectoryName(path);

            Model vehicle = (Model)SceneManager.Current.Add(SceneManager.Current.Content.Load <Model, CNTImporter>(Path.GetFileName(path), assetFolder));

            // Load supporting documents
            if (File.Exists(Path.Combine(assetFolder, "setup.lol")))
            {
                vehicle.SupportingDocuments["Setup"] = Setup.Load(Path.Combine(assetFolder, "setup.lol"));
            }
            if (File.Exists(Path.Combine(assetFolder, "Structure.xml")))
            {
                List <string> findMaterials(StructurePart part)
                {
                    List <string> materials = new List <string>();

                    materials.AddRange(part.DamageSettings.Methods.Where(m => m.Name == "CrushDamageMaterial" && m.HasBeenSet).Select(m => m.Parameters[2].Value.ToString()));

                    foreach (StructurePart child in part.Parts)
                    {
                        materials.AddRange(findMaterials(child));
                    }

                    return(materials);
                }

                Structure structure = Structure.Load(Path.Combine(assetFolder, "Structure.xml"));

                foreach (string material in findMaterials(structure.Root))
                {
                    SceneManager.Current.Content.Load <Material, MT2Importer>(material, assetFolder, true);
                }

                vehicle.SupportingDocuments["Structure"] = structure;
            }

            if (File.Exists(Path.Combine(assetFolder, "SystemsDamage.xml")))
            {
                vehicle.SupportingDocuments["SystemsDamage"] = SystemsDamage.Load(Path.Combine(assetFolder, "SystemsDamage.xml"));
            }

            if (File.Exists(Path.Combine(assetFolder, "vehicle_setup.cfg")))
            {
                vehicle.SupportingDocuments["VehicleSetupConfig"] = VehicleSetupConfig.Load(Path.Combine(assetFolder, "vehicle_setup.cfg"));

                foreach (VehicleMaterialMap materialMap in vehicle.GetSupportingDocument <VehicleSetupConfig>("VehicleSetupConfig").MaterialMaps)
                {
                    foreach (KeyValuePair <string, string> kvp in materialMap.Substitutions)
                    {
                        SceneManager.Current.Content.Load <Material, MT2Importer>(kvp.Value, assetFolder, true);
                    }
                }
            }

            if (File.Exists(Path.Combine(assetFolder, "vehicle_setup.lol")))
            {
                vehicle.SupportingDocuments["VehicleSetup"] = VehicleSetup.Load(Path.Combine(assetFolder, "vehicle_setup.lol"));
            }
            if (File.Exists(Path.Combine(assetFolder, "vfx_anchors.lol")))
            {
                vehicle.SupportingDocuments["VFXAnchors"] = VFXAnchors.Load(Path.Combine(assetFolder, "vfx_anchors.lol"));
            }

            if (File.Exists(Path.Combine(assetFolder, "collision.cnt")))
            {
                vehicle.SupportingDocuments["Collision"] = SceneManager.Current.Content.Load <Model, CNTImporter>("collision.cnt", assetFolder);
            }
            if (File.Exists(Path.Combine(assetFolder, "opponent_collision.cnt")))
            {
                vehicle.SupportingDocuments["OpponentCollision"] = SceneManager.Current.Content.Load <Model, CNTImporter>("opponent_collision.cnt", assetFolder);
            }

            //if (File.Exists(assetFolder + "CrashSoundsConfig_Car.xml")) { vehicle.SupportingDocuments["SystemsDamage"] = SystemsDamage.Load(assetFolder + "SystemsDamage.xml"); }

            foreach (ModelBone bone in vehicle.Bones)
            {
                string boneName = bone.Name.ToLower();

                // Name = bone.Name

                if (boneName.StartsWith("wheel_"))
                {
                    Core.Entities.Wheel wheel = new Core.Entities.Wheel();
                    wheel.LinkWith(bone);
                    SceneManager.Current.Entities.Add(wheel);
                }
                else if (boneName.StartsWith("vfx_"))
                {
                    VFX vfx = new VFX();
                    vfx.LinkWith(bone);
                    SceneManager.Current.Entities.Add(vfx);
                }
                else if (boneName.StartsWith("driver"))
                {
                    Driver driver = new Driver();
                    driver.LinkWith(bone);
                    SceneManager.Current.Entities.Add(driver);
                }
            }

            SceneManager.Current.SetContext("Carmageddon Max Damage", ContextMode.Car);
        }
Example #2
0
        public override void Export(Asset asset, string path)
        {
            var model = (asset as Model);

            if (model.SupportingDocuments.ContainsKey("VehicleSetupConfig"))
            {
                ((VehicleSetupConfig)model.SupportingDocuments["VehicleSetupConfig"]).Save(path);
            }
            else
            {
                var vehicleSetup = new VehicleSetupConfig();

                vehicleSetup.Attachments.Add(
                    new VehicleAttachment {
                    Type = VehicleAttachment.AttachmentType.DynamicsWheels
                }
                    );

                vehicleSetup.WheelModules.Add(
                    new VehicleWheelModule {
                    Type          = VehicleWheelModule.WheelModuleType.SkidMarks,
                    SkidMarkImage = "skidmark"
                }
                    );

                vehicleSetup.WheelModules.Add(
                    new VehicleWheelModule {
                    Type            = VehicleWheelModule.WheelModuleType.TyreParticles,
                    TyreParticleVFX = "effects.drift"
                }
                    );

                vehicleSetup.WheelModules.Add(
                    new VehicleWheelModule {
                    Type           = VehicleWheelModule.WheelModuleType.SkidNoise,
                    SkidNoiseSound = "sounds\\tyre\\skid1,sounds\\tyre\\skid2"
                }
                    );

                vehicleSetup.Attachments.Add(
                    new VehicleAttachment
                {
                    Type = VehicleAttachment.AttachmentType.Horn,
                    Horn = "generic02_horn"
                }
                    );

                vehicleSetup.WheelMaps.Add(
                    new VehicleWheelMap
                {
                    Name         = "default",
                    Localisation = string.Format("FE_CAR_{0}_RIM_DEFAULT", this.ExportSettings.GetSetting <string>("VehicleName")),
                    Wheels       = new VehicleAttachmentComplicatedWheels
                    {
                        FLWheel = "default_eagle_R",
                        FRWheel = "default_eagle_R",
                        RLWheel = "default_eagle_R",
                        RRWheel = "default_eagle_R"
                    }
                }
                    );

                vehicleSetup.Stats.TopSpeed    = 160;
                vehicleSetup.Stats.Time        = 3.00f;
                vehicleSetup.Stats.Weight      = 1.3f;
                vehicleSetup.Stats.Toughness   = 1.4f;
                vehicleSetup.Stats.UnlockLevel = 0;

                vehicleSetup.Save(path);
            }
        }