/ContentSystem/Rendering/ModelData.cs
C# | 137 lines | 66 code | 10 blank | 61 comment | 4 complexity | 345a59775cedc44b834726dcd3c615a9 MD5 | raw file
Possible License(s): Apache-2.0
- using System.Collections.Generic;
- using Delta.Utilities;
- using Delta.Utilities.Helpers;
-
- namespace Delta.ContentSystem.Rendering
- {
- /// <summary>
- /// Model data class, which combines a list of meshes and a list of mesh
- /// animations. Because models can have multiple meshes and animations they
- /// should be used for more complex 3d data. If you only need a static mesh
- /// just use the Mesh class, which is better optimized and can be used for
- /// level geometry with lots of extra optimizations and mesh merging than
- /// possibly than rendering everything as models.
- /// <para />
- /// Please note that Models just contain meshes and animations and have no
- /// data own their own (just meta data).
- /// </summary>
- public class ModelData : Content
- {
- #region Get (Static)
- /// <summary>
- /// Get and load content based on the content name. This method makes sure
- /// we do not load the same content twice (the constructor is protected).
- /// </summary>
- /// <param name="contentName">Content name we want to load, this is
- /// passed onto the Content System, which will do the actual loading with
- /// help of the Load method in this class.</param>
- /// <returns>The loaded Content object, always unique for the same
- /// name, this helps comparing data.</returns>
- public static ModelData Get(string contentName)
- {
- return Get<ModelData>(contentName, ContentType.Model);
- }
- #endregion
-
- #region Meshes (Public)
- /// <summary>
- /// List of meshes to be used for this model. Often is just one mesh.
- /// Please note that we also will load and link up the animations inside
- /// of each mesh (see load method below), this way it is easier to manage.
- /// </summary>
- public List<MeshData> Meshes = new List<MeshData>();
- #endregion
-
- #region InitialScale (Public)
- /// <summary>
- /// Provides the initial scale value as provided by the content meta data.
- /// Usually 1.0f, which means rendering is done normally. If this value is
- /// different the content model will be scaled accordingly (should rarely
- /// be needed, scaling has obviously performance impacts, it is currently
- /// also ignored for most content types including meshes).
- /// </summary>
- public float InitialScale
- {
- get
- {
- return data.InitialScale;
- }
- }
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create model data object with no data in it. Just add stuff to the
- /// Meshes and Animations fields.
- /// </summary>
- public ModelData()
- : base(EmptyName, ContentType.Model)
- {
- }
-
- /// <summary>
- /// Create mesh animation data by loading it from content, see Load below.
- /// Use the static Get method to call this.
- /// </summary>
- /// <param name="contentName">Name of the content.</param>
- protected ModelData(string contentName)
- : base(contentName, ContentType.Model)
- {
- }
- #endregion
-
- #region ToString (Public)
- /// <summary>
- /// To string, will display the model name with the meshes in it (plus
- /// optionally their animations if they have those).
- /// </summary>
- /// <returns>
- /// A <see cref="System.String"/> that represents this ModelData
- /// instance with the list of mesh names.
- /// </returns>
- public override string ToString()
- {
- return GetType().GetClassName() + " " + Name + ": " +
- "Meshes=" + Meshes.Write();
- }
- #endregion
-
- #region Methods (Private)
-
- #region Load
- /// <summary>
- /// Native load method, will just load meshes and animations contained in
- /// this content type (models have no data on their own).
- /// </summary>
- /// <param name="alreadyLoadedNativeData">Ignored here, can't be cloned.
- /// </param>
- protected override void Load(Content alreadyLoadedNativeData)
- {
- // Initialize a new list for all the mesh children
- Meshes.Clear();
- // Note: Only direct mesh children nodes are allowed, nothing else!
- foreach (ContentMetaData childrenData in data.Children)
- {
- if (childrenData.Type != ContentType.Mesh)
- {
- Log.Warning("Invalid children node for " + this + " found, only " +
- "mesh nodes are allowed: " + childrenData);
- // Skip this, maybe other data works
- continue;
- }
- // Note: We just add names, we don't want to load the images right away,
- // only when they need to be displayed they will be loaded (in the
- // Material class).
- Meshes.Add(MeshData.Get(childrenData.Name));
- }
- if (Meshes.Count == 0)
- {
- Log.Warning("No meshes found for " + this);
- }
- }
- #endregion
-
- #endregion
- }
- }
-