Cafu Engine
ModelDocument.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_MODELEDITOR_MODEL_DOCUMENT_HPP_INCLUDED
8 #define CAFU_MODELEDITOR_MODEL_DOCUMENT_HPP_INCLUDED
9 
10 #include "ObserverPattern.hpp"
11 #include "ElementTypes.hpp"
12 #include "Math3D/BoundingBox.hpp"
13 #include "Math3D/Vector3.hpp"
14 #include "Models/AnimPose.hpp"
15 #include "Templates/Array.hpp"
16 #include "wx/wx.h"
17 
18 
19 class CafuModelT;
20 class CameraT;
21 class GameConfigT;
22 class EditorMaterialI;
23 class MapBrushT;
24 namespace cf { class UniScriptStateT; }
25 namespace cf { namespace GuiSys { class GuiImplT; } }
26 
27 
28 namespace ModelEditor
29 {
30  class ModelDocumentT : public SubjectT
31  {
32  public:
33 
35  {
36  public:
37 
38  LightSourceT(bool IsOn_, bool CastShadows_, const Vector3fT& Pos_, float Radius_, const wxColour& Color_)
39  : IsOn(IsOn_), CastShadows(CastShadows_), Pos(Pos_), Radius(Radius_), Color(Color_) { }
40 
41  bool IsOn; ///< Whether this light source is currently on / active / being used.
42  bool CastShadows; ///< Whether this light source casts shadows.
43  Vector3fT Pos; ///< The light sources position in world space.
44  float Radius; ///< The light sources radius in world space.
45  wxColour Color; ///< The light sources color (used for both the diffuse and specular component).
46  };
47 
48  class AnimStateT
49  {
50  public:
51 
52  AnimStateT(const CafuModelT& Model);
53 
54  IntrusivePtrT<AnimExprStandardT> LastStdAE; ///< The last (most recent) "standard" anim expression that we set in the anim pose.
55  AnimPoseT Pose; ///< The current pose of the model, as defined by sequence and frame number.
56  float Speed; ///< The speed (relative to clock time) with which the animation is advanced, usually 0 for stop or 1 for playback.
57  bool Loop; ///< When playing the sequence, loop automatically when its end has been reached?
58  };
59 
60  class SubmodelT
61  {
62  public:
63 
64  SubmodelT(CafuModelT* Submodel);
65  ~SubmodelT();
66 
67  const CafuModelT* GetSubmodel() const { return m_Submodel; }
68  AnimPoseT& GetPose() { return m_Pose; }
69 
70 
71  private:
72 
73  SubmodelT(const SubmodelT&); ///< Use of the Copy Constructor is not allowed.
74  void operator = (const SubmodelT&); ///< Use of the Assignment Operator is not allowed.
75 
76  CafuModelT* m_Submodel; ///< The submodel that is shown with the main model.
77  AnimPoseT m_Pose; ///< The pose of the submodel.
78  };
79 
80 
81  /// The constructor.
82  /// @throws ModelT::LoadError if the model could not be loaded or imported.
83  ModelDocumentT(GameConfigT* GameConfig, const wxString& FileName);
84 
85  /// The destructor.
87 
88  const CafuModelT* GetModel() const { return m_Model; }
89  const ArrayT<unsigned int>& GetSelection(ModelElementTypeT Type) const { wxASSERT(Type<6); return m_Selection[Type]; }
90  const BoundingBox3fT& GetSequenceBB() const { return m_SequenceBB; }
91  int GetSelSkinNr() const; ///< Return the index number of the currently selected skin, or -1 when no skin (that is, the default skin) is selected.
92  wxString GetSelSkinString() const; ///< Returns a string representation for the currently selected skin.
93  const ArrayT<EditorMaterialI*>& GetEditorMaterials() const { return m_EditorMaterials; }
94  const AnimStateT& GetAnimState() const { return m_AnimState; }
95  const ArrayT<SubmodelT*>& GetSubmodels() const { return m_Submodels; }
97  const MapBrushT* GetGround() const { return m_Ground; }
98  const ArrayT<CameraT*>& GetCameras() const { return m_Cameras; }
99  const ArrayT<LightSourceT*>& GetLightSources() const { return m_LightSources; }
100  const GameConfigT* GetGameConfig() const { return m_GameConfig; }
101 
102  CafuModelT* GetModel() { return m_Model; }
103  void SetSelection(ModelElementTypeT Type, const ArrayT<unsigned int>& NewSel);
104  AnimStateT& GetAnimState() { return m_AnimState; }
105  void LoadSubmodel(const wxString& FileName);
106  void UnloadSubmodel(unsigned long SubmodelNr);
107  MapBrushT* GetGround() { return m_Ground; }
108  GameConfigT* GetGameConfig() { return m_GameConfig; }
109 
110  ArrayT<unsigned int> GetSelection_NextAnimSequ() const; ///< Returns the suggested selection set for activating the next animation sequence.
111  ArrayT<unsigned int> GetSelection_PrevAnimSequ() const; ///< Returns the suggested selection set for activating the previous animation sequence.
112  void AdvanceTime(float Time);
113  void SetAnimSpeed(float NewSpeed);
114 
115 
116  private:
117 
118  ModelDocumentT(const ModelDocumentT&); ///< Use of the Copy Constructor is not allowed.
119  void operator = (const ModelDocumentT&); ///< Use of the Assignment Operator is not allowed.
120 
121  static CafuModelT* LoadModel(const wxString& FileName);
122 
123  CafuModelT* m_Model; ///< The model that is being edited.
124  ArrayT<unsigned int> m_Selection[6]; ///< The selected joints, meshes, animations, channels, skins and GUI fixtures.
125  ArrayT<EditorMaterialI*> m_EditorMaterials; ///< One editor material for each material in the model (its material manager).
126  AnimStateT m_AnimState; ///< The current state of the model animation.
127  BoundingBox3fT m_SequenceBB; ///< The bounding-box encompassing all frames of the currently selected animation sequence(s).
128  ArrayT<SubmodelT*> m_Submodels; ///< The submodels that are shown with the main model.
129  cf::UniScriptStateT* m_ScriptState; ///< The script state that the m_Gui is bound to and lives in.
130  IntrusivePtrT<cf::GuiSys::GuiImplT> m_Gui; ///< The GUI that is rendered where the model has GUI fixtures.
131  MapBrushT* m_Ground; ///< The ground brush.
132  ArrayT<CameraT*> m_Cameras; ///< The cameras in the scene (used by the 3D views for rendering), there is always at least one.
133  ArrayT<LightSourceT*> m_LightSources; ///< The light sources that exist in the scene.
134  GameConfigT* m_GameConfig; ///< The game configuration that the model is used with.
135  };
136 }
137 
138 #endif
This class represents a native Cafu model.
Definition: Model_cmdl.hpp:45
wxString GetSelSkinString() const
Returns a string representation for the currently selected skin.
Definition: ModelDocument.cpp:161
AnimPoseT Pose
The current pose of the model, as defined by sequence and frame number.
Definition: ModelDocument.hpp:55
ModelDocumentT(GameConfigT *GameConfig, const wxString &FileName)
The constructor.
Definition: ModelDocument.cpp:61
This class implements a camera.
Definition: Camera.hpp:17
float Radius
The light sources radius in world space.
Definition: ModelDocument.hpp:44
ArrayT< unsigned int > GetSelection_PrevAnimSequ() const
Returns the suggested selection set for activating the previous animation sequence.
Definition: ModelDocument.cpp:258
float Speed
The speed (relative to clock time) with which the animation is advanced, usually 0 for stop or 1 for ...
Definition: ModelDocument.hpp:56
IntrusivePtrT< AnimExprStandardT > LastStdAE
The last (most recent) "standard" anim expression that we set in the anim pose.
Definition: ModelDocument.hpp:54
wxColour Color
The light sources color (used for both the diffuse and specular component).
Definition: ModelDocument.hpp:45
Definition: MapBrush.hpp:15
Vector3fT Pos
The light sources position in world space.
Definition: ModelDocument.hpp:43
Definition: ObserverPattern.hpp:104
This file provides the classes for the Observer pattern as described in the book by the GoF...
Definition: ModelDocument.hpp:60
~ModelDocumentT()
The destructor.
Definition: ModelDocument.cpp:128
Definition: EditorMaterial.hpp:21
bool IsOn
Whether this light source is currently on / active / being used.
Definition: ModelDocument.hpp:41
The class describes the settings for a game/MOD.
Definition: GameConfig.hpp:32
Definition: ModelDocument.hpp:34
bool Loop
When playing the sequence, loop automatically when its end has been reached?
Definition: ModelDocument.hpp:57
Definition: ModelDocument.hpp:48
bool CastShadows
Whether this light source casts shadows.
Definition: ModelDocument.hpp:42
int GetSelSkinNr() const
Return the index number of the currently selected skin, or -1 when no skin (that is, the default skin) is selected.
Definition: ModelDocument.cpp:155
ArrayT< unsigned int > GetSelection_NextAnimSequ() const
Returns the suggested selection set for activating the next animation sequence.
Definition: ModelDocument.cpp:246
This class describes a specific pose of an associated model.
Definition: AnimPose.hpp:35
This class represents the state of a script: the underlying Lua state, pending coroutines, metatables for C++ class hierarchies, etc.
Definition: UniScriptState.hpp:214
Definition: ModelDocument.hpp:30
This class represents an axis-aligned bounding-box ("AABB") in 3-dimensional space.
Definition: BoundingBox.hpp:23