Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ModelComponent.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using SiliconStudio.Core.Serialization.Converters;
4 using SiliconStudio.Paradox.Effects;
5 using SiliconStudio.Paradox.EntityModel;
6 using SiliconStudio.Core;
7 
8 namespace SiliconStudio.Paradox.Engine
9 {
10  /// <summary>
11  /// Add a <see cref="Model"/> to an <see cref="Entity"/>, that will be used during rendering.
12  /// </summary>
13  [DataConverter(AutoGenerate = true)]
14  [DataContract("ModelComponent")]
16  {
18 
19  private Model model;
20 
21  /// <summary>
22  /// Initializes a new instance of the <see cref="ModelComponent"/> class.
23  /// </summary>
24  public ModelComponent() : this(null)
25  {
26  }
27 
28  /// <summary>
29  /// Initializes a new instance of the <see cref="ModelComponent"/> class.
30  /// </summary>
31  /// <param name="model">The model.</param>
32  public ModelComponent(Model model)
33  {
34  Enabled = true;
35  Parameters = new ParameterCollection();
36  Model = model;
37  }
38 
39  /// <summary>
40  /// Gets or sets the model.
41  /// </summary>
42  /// <value>
43  /// The model.
44  /// </value>
45  [DataMemberConvert]
46  [DataMemberCustomSerializer]
47  public Model Model
48  {
49  get
50  {
51  return model;
52  }
53  set
54  {
55  model = value;
56  ModelUpdated();
57  }
58  }
59 
60  [DataMemberIgnore]
61  public ModelViewHierarchyUpdater ModelViewHierarchy
62  {
63  get;
64  internal set;
65  }
66 
67  /// <summary>
68  /// Gets or sets a value indicating whether rendering is enabled.
69  /// </summary>
70  /// <value>
71  /// <c>true</c> if rendering is enabled; otherwise, <c>false</c>.
72  /// </value>
73  [DataMemberConvert]
74  public bool Enabled { get; set; }
75 
76  /// <summary>
77  /// Gets or sets the draw order (from lowest to highest).
78  /// </summary>
79  /// <value>
80  /// The draw order.
81  /// </value>
82  [DataMemberConvert]
83  public float DrawOrder { get; set; }
84 
85  /// <summary>
86  /// Gets the parameters used to render this mesh.
87  /// </summary>
88  /// <value>The parameters.</value>
89  [DataMemberConvert]
90  public ParameterCollection Parameters { get; private set; }
91 
92  private void ModelUpdated()
93  {
94  if (model != null)
95  {
96  if (ModelViewHierarchy != null)
97  {
98  // Reuse previous ModelViewHierarchy
99  ModelViewHierarchy.Initialize(model);
100  }
101  else
102  {
103  ModelViewHierarchy = new ModelViewHierarchyUpdater(model);
104  }
105  }
106  }
107 
108  public override PropertyKey DefaultKey
109  {
110  get { return Key; }
111  }
112  }
113 }
ModelComponent(Model model)
Initializes a new instance of the ModelComponent class.
Base class for converters to/from a data type.
ModelComponent()
Initializes a new instance of the ModelComponent class.
Instance of a model with its parameters.
Add a Model to an Entity, that will be used during rendering.
Performs hierarchical updates for a given Model.
A class that represents a tag propety.
Definition: PropertyKey.cs:17
Collection of Mesh, each one usually being a different LOD of the same Model. The effect system will ...
Definition: Model.cs:23
A container to handle a hierarchical collection of effect variables.