/// <summary>
        /// Added this to the unit class so if the TagEditor changes the palette,
        /// the spawns of that type can be updated to the new model.
        /// </summary>
        /// <param name="tfn"></param>
        public void SetModel(TagFileName tfn)
        {
            int index = MdxRender.MM.RegisterModel(tfn);

            m_Model = MdxRender.MM.GetModel(index);
        }
 public void SetModel(Model3D model)
 {
     m_Model = model;
 }
        public int RegisterModel(TagFileName tfn)
        {
            int  model_index = DEFAULT_MODEL;
            bool bModelFound = false;

            //TODO:  use hash table?
            for (model_index = 0; ((model_index < MaxElements) && (model_index < m_LookupCount)); model_index++)
            {
                if (m_LookupTable[model_index].name == tfn.RelativePath)
                {
                    bModelFound = true;
                    break;
                }
            }

            if (bModelFound == false)
            {
                try
                {
                    Model3D generic_model = null;

                    //load the model
                    if (tfn.Version == MapfileVersion.XHALO2)
                    {
                        TagHalo2Model H2model = new TagHalo2Model();
                        H2model.LoadTagBuffer(tfn);
                        H2model.LoadTagData();
                        Trace.WriteLine("Loading model: " + tfn.RelativePath);
                        //generic_model = H2model.GetModel3D(tfn.RelativePath);
                    }
                    else if ((tfn.Version == MapfileVersion.XHALO1) ||
                             (tfn.Version == MapfileVersion.HALOPC) ||
                             (tfn.Version == MapfileVersion.HALOCE))
                    {
                        TagModel H1model = new TagModel();
                        H1model.LoadTagBuffer(tfn);
                        H1model.LoadTagData();
                        Trace.WriteLine("Loading model: " + tfn.RelativePath);
                        generic_model = H1model.GetModel3D(tfn.RelativePath);
                    }

                    model_index = GetFirstAvailableIndex();

                    //insert the lookup element into the table
                    m_LookupTable[model_index]       = new ModelLookupElement();
                    m_LookupTable[model_index].name  = tfn.RelativePath;
                    m_LookupTable[model_index].model = generic_model;

                    if (model_index == m_LookupCount)
                    {
                        m_LookupCount++;
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine("ModelManager Exception: " + e.Message);
                }
            }

            return(model_index);
        }