ScummVM API documentation
te_model.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TETRAEDGE_TE_TE_MODEL_H
23 #define TETRAEDGE_TE_TE_MODEL_H
24 
25 #include "common/array.h"
26 #include "common/ptr.h"
27 #include "common/stream.h"
28 #include "tetraedge/te/te_timer.h"
29 #include "tetraedge/te/te_trs.h"
30 #include "tetraedge/te/te_mesh.h"
31 #include "tetraedge/te/te_model_animation.h"
32 #include "tetraedge/te/te_model_vertex_animation.h"
33 #include "tetraedge/te/te_tiled_texture.h"
34 #include "tetraedge/te/te_intrusive_ptr.h"
35 #include "tetraedge/te/te_quaternion.h"
36 #include "tetraedge/te/te_resource.h"
37 
38 namespace Tetraedge {
39 
40 class TeModelVertexAnimation;
41 class TeModelAnimation;
42 class TeMesh;
43 
44 class TeModel : public Te3DObject2, public TeResource {
45 public:
46  class BonesBlender {
47  public:
48  // Note: original takes a TeModel & but ignores it.
50  float coef();
51 
53  TeTimer _timer;
54  float _seconds;
55  };
56 
57  class MeshBlender {
58  public:
59  MeshBlender(const Common::String &s1, const Common::String &s2, float amount, TeModel *model);
60  Common::String _name;
61  uint _meshNo;
62  float _amount;
63  TeTimer _timer;
64  };
65 
66  struct Bone {
67  Common::String _name;
68  short _parentBone;
69  TeTRS _trs;
70  };
71 
72  struct weightElement {
73  float _weight;
74  unsigned short _x;
75  };
76 
77  TeModel();
78  virtual ~TeModel();
79 
80  void addMesh(Common::SharedPtr<TeMesh> mesh) {
81  _meshes.push_back(mesh);
82  }
84  return _modelAnim;
85  }
86 
87  void blendAnim(TeIntrusivePtr<TeModelAnimation>& anim, float amount, bool repeat);
88  void blendMesh(const Common::String &s1, const Common::String &s2, float amount);
89 
90  int checkFileType(Common::SeekableReadStream &instream) const;
91 
92  void create();
93  void destroy();
94 
95  void draw() override;
96 
97  int findModelBone(const Common::String &bname);
98  int findOrAddWeights(const Common::Array<weightElement> &weights);
99  void forceMatrix(const TeMatrix4x4 &matrix);
100  TeTRS getBone(TeIntrusivePtr<TeModelAnimation> anim, uint num);
101  void invertNormals();
102 
103  /* Align the stream to the nearest 4 byte boudary*/
104  static void loadAlign(Common::SeekableReadStream &stream);
105  static void saveAlign(Common::SeekableWriteStream &stream);
106 
107  bool load(const Common::Path &path);
108  bool load(Common::SeekableReadStream &stream);
109 
110  bool loadWeights(Common::ReadStream &stream, Common::Array<weightElement> &weights);
111  bool loadMesh(Common::SeekableReadStream &stream, TeMesh &mesh);
112 
113  void removeAnim();
114  void update();
115 
116  void saveBone(Common::SeekableWriteStream &stream, uint boneno);
117  void saveMesh(Common::SeekableWriteStream &stream, const TeMesh &mesh);
118  void saveModel(Common::SeekableWriteStream &stream, uint num);
119  void saveWeights(Common::SeekableWriteStream &stream, const Common::Array<weightElement> weights);
120 
121  void setAnim(TeIntrusivePtr<TeModelAnimation> &anim, bool repeat);
122  virtual void setColor(const TeColor &col) override;
123  void setQuad(const TeIntrusivePtr<Te3DTexture> &tex, const Common::Array<TeVector3f32> &verts, const TeColor &col);
124  void setVertexAnim(TeIntrusivePtr<TeModelVertexAnimation> &anim, bool repeat);
125  void setVisibleByName(const Common::String &mname, bool vis);
126 
127  TeMatrix4x4 skinOffset(uint boneno) const;
128 
129  static Common::SeekableReadStream *tryLoadZlibStream(Common::SeekableReadStream &instr);
130 
131  TeSignal2Param<const Common::String &, TeMatrix4x4 &> &bonesUpdatedSignal() { return _bonesUpdatedSignal; }
132  Common::Array<BonesBlender *> &boneBlenders() { return _boneBlenders; }
133  Common::Array<Common::SharedPtr<TeMesh>> &meshes() { return _meshes; }
134  TeIntrusivePtr<TeTiledTexture> tiledTexture() { return _tiledTexture; }
135 
136  void setEnableLights(bool val) { _enableLights = val; }
137  void setTexturePath(const Common::Path &path) { _texturePath = path; }
138  void setMeshCount(uint count);
139 
140 protected:
141  TeMatrix4x4 lerpElementsMatrix(uint weightNum, const Common::Array<TeMatrix4x4> &matricies);
142 
143  Common::Path _texturePath;
144  TeIntrusivePtr<TeTiledTexture> _tiledTexture;
145 
146  bool _enableLights;
147  bool _matrixForced;
148  bool _skipSkinOffsets;
149 
150  TeMatrix4x4 _forcedMatrix;
151  Common::Array<BonesBlender *> _boneBlenders;
152  Common::Array<MeshBlender *> _meshBlenders;
153  Common::Array<Bone> _bones;
154  Common::Array<TeMatrix4x4> _skinOffsets;
155  Common::Array<TeMatrix4x4> _boneMatricies;
156  Common::Array<TeMatrix4x4> _lerpedElements;
159 
160  TeQuaternion _boneRotation;
161 
164 
166 };
167 
168 } // end namespace Tetraedge
169 
170 #endif // TETRAEDGE_TE_TE_MODEL_H
Definition: te_model.h:72
Definition: str.h:59
Definition: detection.h:27
Definition: te_mesh.h:43
Definition: te_quaternion.h:32
Definition: array.h:52
Definition: te_resource.h:31
Definition: te_color.h:30
Definition: path.h:52
Definition: stream.h:745
Definition: te_model.h:44
Definition: te_timer.h:33
Definition: te_matrix4x4.h:37
Definition: te_model.h:57
Definition: te_model.h:66
Definition: te_3d_object2.h:36
Definition: te_trs.h:31
Definition: te_intrusive_ptr.h:31
Definition: te_signal.h:119
Definition: stream.h:351
Definition: stream.h:385
Definition: te_model.h:46
Definition: ptr.h:159