Etterna 0.74.4
Loading...
Searching...
No Matches
Model.h
1/* Model - A 3D model. */
2
3#ifndef MODEL_H
4#define MODEL_H
5
6#include "Actor.h"
7#include "ModelTypes.h"
8#include <map>
9#include <vector>
10
13
14class Model : public Actor
15{
16 public:
17 Model();
18 ~Model() override;
19 [[nodiscard]] Model* Copy() const override;
20
21 void Clear();
22 void Load(const std::string& sFile);
23
24 void LoadPieces(const std::string& sMeshesPath,
25 const std::string& sMaterialsPath,
26 const std::string& sBomesPath);
27 void LoadMilkshapeAscii(const std::string& sFile);
28 void LoadMaterialsFromMilkshapeAscii(const std::string& sPath);
29 bool LoadMilkshapeAsciiBones(const std::string& sAniName,
30 const std::string& sPath);
31
32 void LoadFromNode(const XNode* pNode) override;
33
34 void PlayAnimation(const std::string& sAniName, float fPlayRate = 1);
35 void SetRate(float fRate) { m_fCurAnimationRate = fRate; }
36 void SetLoop(bool b) { m_bLoop = b; }
37 void SetPosition(float fSeconds);
38
39 void Update(float fDelta) override;
40 [[nodiscard]] bool EarlyAbortDraw() const override;
41 void DrawPrimitives() override;
42
43 void DrawCelShaded();
44 void SetCelShading(bool bShading) { m_bDrawCelShaded = bShading; }
45
46 [[nodiscard]] int GetNumStates() const override;
47 void SetState(int iNewState) override;
48
49 [[nodiscard]] float GetAnimationLengthSeconds() const override
50 {
51 return m_animation_length_seconds;
52 }
53 virtual void RecalcAnimationLengthSeconds();
54 void SetSecondsIntoAnimation(float fSeconds) override;
55
56 [[nodiscard]] std::string GetDefaultAnimation() const
57 {
58 return m_sDefaultAnimation;
59 };
60 void SetDefaultAnimation(const std::string& sAnimation,
61 float fPlayRate = 1);
62
63 [[nodiscard]] bool MaterialsNeedNormals() const;
64
65 // Lua
66 void PushSelf(lua_State* L) override;
67
68 private:
69 RageModelGeometry* m_pGeometry;
70
71 float m_animation_length_seconds;
72 std::vector<msMaterial> m_Materials;
73 std::map<std::string, msAnimation> m_mapNameToAnimation;
74 const msAnimation* m_pCurAnimation;
75
76 static void SetBones(const msAnimation* pAnimation,
77 float fFrame,
78 std::vector<myBone_t>& vpBones);
79 std::vector<myBone_t> m_vpBones;
80
81 // If any vertex has a bone weight, then then render from m_pTempGeometry.
82 // Otherwise, render directly from m_pGeometry.
83 RageCompiledGeometry* m_pTempGeometry;
84 void UpdateTempGeometry();
85
86 /* Keep a copy of the mesh data only if m_pTempGeometry is in use. The
87 * normal and position data will be changed; the rest is static and kept
88 * only to prevent making a complete copy. */
89 std::vector<msMesh> m_vTempMeshes;
90
91 void DrawMesh(int i) const;
92 void AdvanceFrame(float fDeltaTime);
93
94 float m_fCurFrame;
95 std::string m_sDefaultAnimation;
96 float m_fDefaultAnimationRate;
97 float m_fCurAnimationRate;
98 bool m_bLoop;
99 bool m_bDrawCelShaded; // for Lua models
100
101 Model& operator=(const Model& rhs);
102};
103
104#endif
Base class for all objects that appear on the screen.
Definition Actor.h:77
Definition Model.h:15
void DrawPrimitives() override
Draw the primitives of the Actor.
Definition Model.cpp:352
bool EarlyAbortDraw() const override
Allow the Actor to be aborted early.
Definition Model.cpp:327
Definition RageDisplay.h:34
Definition RageModelGeometry.h:13
Definition XmlFile.h:95
Definition ModelTypes.h:127