public vxModel LoadBasicEffectModel(string PathToModel, ContentManager Content, Effect ShadowEffect, Effect UtilityEffect) { vxConsole.WriteVerboseLine(" Importing Basic Effect Model: " + PathToModel); // Create the Model Object to return vxModel newModel = new vxModel(Engine); // Next Load in the Main Model. newModel.ModelMain = Content.Load <Model>(PathToModel); DoModelFileCheck(PathToModel, Content); // Now load in the textures newModel.LoadTextures(Content, PathToModel); // Now load the shadow model. newModel.ModelShadow = LoadShadowModel(PathToModel, Content, ShadowEffect); // Now load the utility model. newModel.ModelUtility = LoadUtilityModel(PathToModel, Content, UtilityEffect); // Add a tag of the Path to the model for debuging newModel.ModelMain.Tag = PathToModel; return(newModel); }
/// <summary> /// This Loads Models at Run time performing a number of functions. See remarks for full details. /// </summary> /// <remarks> /// Model Loading /// ============================= /// This loads a vxModel with a Specified Effect as well as applies the CascadeShadowEffect to /// the vxModel's internal Shadow Model as well. XNA and potentially other back ends do not allow /// multiple loading of the same asset, therefore if a Shadow Model.xnb is not found, then it is created /// from a copy of the main model as 'mainmodelname_shdw.xnb'. /// /// /// Texture Loading /// ============================= /// Furthermore, Textures are loaded based off of the name of the model mesh name. /// /// For Example /// ------------- /// ModelMesh Name = "ship" /// /// Then the content importer will look for textures under the following names: /// /// Diffuse Texture: ship_dds /// Normal Map: ship_nm /// Specular Map: ship_sm /// /// The path to each of these is saved in the vxModel as well too allow for reloading of /// other resolution packs later on. /// </remarks> /// <returns>The model.</returns> /// <param name="PathToModel">Path to model.</param> /// <param name="Content">Content.</param> /// <param name="EffectToSet">Effect to set.</param> /// <param name="ShadowEffect">Shadow effect.</param> /// <param name="UtilityEffect">Utility effect.</param> public vxModel LoadModel(string PathToModel, ContentManager Content, Effect EffectToSet, Effect ShadowEffect, Effect UtilityEffect) { vxConsole.WriteVerboseLine(" Importing Model: " + PathToModel); // Create the Model Object to return vxModel newModel = new vxModel(Engine); // Next Load in the Main Model. newModel.ModelMain = Content.Load <Model>(PathToModel); DoModelFileCheck(PathToModel, Content); #region Main Model Loading /*********************************************************************************/ // MAIN MODEL /*********************************************************************************/ // // Now Apply and Initialise the New Effect on the MainModel Object using the speceified Effect. // // Table mapping the original effects to our replacement versions. Dictionary <Effect, Effect> effectMapping = new Dictionary <Effect, Effect>(); foreach (ModelMesh mesh in newModel.ModelMain.Meshes) { vxConsole.WriteVerboseLine(" Mesh Name: " + mesh.Name); mesh.Tag = PathToModel; // Scan over all the effects currently on the mesh. foreach (Effect oldEffect in mesh.Effects) { // If we haven't already seen this effect... if (!effectMapping.ContainsKey(oldEffect)) { // Make a clone of our replacement effect. We can't just use // it directly, because the same effect might need to be // applied several times to different parts of the model using // a different texture each time, so we need a fresh copy each // time we want to set a different texture into it. Effect newEffect = EffectToSet.Clone(); //First Load in the Texture packs based off of the mesh name newModel.LoadTextures(Content, PathToModel); if (newEffect.Parameters["TextureEnabled"] != null) { newEffect.Parameters["TextureEnabled"].SetValue(true); } if (newEffect.Parameters["IsSun"] != null) { newEffect.Parameters["IsSun"].SetValue(false); } Vector4[] ShadowSplitColors = new[] { new Vector4(255, 0, 0, 255), new Vector4(0, 255, 0, 255), new Vector4(0, 0, 255, 255), new Vector4(160, 32, 240, 255) }; if (newEffect.Parameters["SplitColors"] != null) { newEffect.Parameters["SplitColors"].SetValue(ShadowSplitColors); } if (newEffect.Parameters["AlphaValue"] != null) { newEffect.Parameters["AlphaValue"].SetValue(1); } if (newEffect.Parameters["ShadowBrightness"] != null) { newEffect.Parameters["ShadowBrightness"].SetValue(0.25f); } if (newEffect.Parameters["LightDirection"] != null) { newEffect.Parameters["LightDirection"].SetValue(Vector3.Normalize(new Vector3(100, 130, 0))); } if (newEffect.Parameters["LightColor"] != null) { newEffect.Parameters["LightColor"].SetValue(new Vector4(0.8f, 0.8f, 0.8f, 1.0f)); } if (newEffect.Parameters["AmbientLightColor"] != null) { newEffect.Parameters["AmbientLightColor"].SetValue(new Vector4(0.2f, 0.2f, 0.2f, 1.0f)); } effectMapping.Add(oldEffect, newEffect); } } // Now that we've found all the effects in use on this mesh, // update it to use our new replacement versions. foreach (ModelMeshPart meshPart in mesh.MeshParts) { meshPart.Effect = effectMapping[meshPart.Effect]; } } #endregion // Now load the shadow model. newModel.ModelShadow = LoadShadowModel(PathToModel, Content, ShadowEffect); // Now load the utility model. newModel.ModelUtility = LoadUtilityModel(PathToModel, Content, UtilityEffect); // Add a tag of the Path to the model for debuging newModel.ModelMain.Tag = PathToModel; return(newModel); }