//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynterEngine.ObjectLib
{
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
#endregion
using Globals;
///
/// Store the name of the model, the texture map, the bump map and the actual model itself
///
public struct ModelInfo
{
///
/// Name of the model
///
public string subTypeName;
///
/// Texture applied to the model
///
public Texture2D currentTexture;
///
/// Bump map texture to be applied
///
public Texture2D bumpTexture;
///
/// Actual model
///
public Model model;
}
///
/// Manages all the the models loaded in game
///
public class ModelManager
{
private List modelInfoList;
private ModelInfo newModelInfo;
///
/// Constructor
///
public ModelManager()
{
modelInfoList = new List();
}
///
/// Retrieves model info from our list
///
/// Name of the model
/// Model info
public ModelInfo GetModelInfo(string modelName)
{
foreach (ModelInfo modelInfo in modelInfoList)
{
if (modelInfo.subTypeName == modelName)
{
return modelInfo;
}
}
return new ModelInfo();
}
///
/// Adds a new model to our model list
///
/// Name of the new model
/// The location on disk of the new model
/// The texture to be applied
/// The bump map texture to be applied
/// The Effect file used to render this model
/// True if model was successfully loaded
public bool AddNewModel(string newModelName,
string newModel,
string newTexture,
string newBumpTexture)
{
// Catch if bad XML fileName
try
{
// Its a new Model...
newModelInfo = new ModelInfo();
// ..so lets load it
newModelInfo.subTypeName = newModelName;
newModelInfo.model = Statics.SystemSettings.content.Load(newModel);
newModelInfo.currentTexture = Statics.SystemSettings.content.Load(newTexture);
newModelInfo.bumpTexture = Statics.SystemSettings.content.Load(newBumpTexture);
// Apply our own advanced Effect to the Model
foreach (ModelMesh mesh in newModelInfo.model.Meshes)
{
for (int i = 0; i < mesh.MeshParts.Count; i++)
{
// Add effect to mesh
mesh.MeshParts[i].Effect = ShaderParameters.effect_draw;
}
}
modelInfoList.Add(newModelInfo);
return true;
}
catch{
Console.WriteLine("Error Loading Model: " + newModelName );
return false;
}
}
}
}