i6engine  1.0
MeshAppearanceComponent.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_API_MESHAPPEARANCECOMPONENT_H__
26 #define __I6ENGINE_API_MESHAPPEARANCECOMPONENT_H__
27 
28 #include <mutex>
29 
32 
34 
35 namespace i6e {
36 namespace math {
37  class i6eVector4;
38 } /* namespace math */
39 } /* namespace i6e */
40 
42 
43 namespace i6e {
44 namespace modules {
45  class MeshComponent;
46 } /* namespace modules */
47 namespace api {
48 
49  typedef std::pair<Vec3, Quaternion> Transform;
50 
66  friend class modules::MeshComponent;
67 
68  public:
74  MeshAppearanceComponent(const int64_t id, const attributeMap & params);
75 
80 
84  Vec3 getPosition() const {
85  return _position;
86  }
87 
95  void setVisibility(const bool visible);
96 
104  void setMesh(const std::string & meshName);
105 
114  void setCustomParameter(uint32_t num, const Vec4 & value);
115 
123  inline bool getVisibility() const { return _isVisible; }
124 
132  inline std::string getMesh() const { return _meshName; }
133 
137  void setMaterial(const std::string & materialName);
138 
142  void playAnimation(const std::string & anim, bool looping, double offsetPercent);
143 
147  void setAnimationSpeed(double animationSpeed);
148 
152  void stopAnimation();
153 
157  attributeMap synchronize() const override;
158 
159  std::string getTemplateName() const override {
160  return "MeshAppearance";
161  }
162 
163  std::vector<componentOptions> getComponentOptions() override;
164 
168  void drawBoundingBox(const Vec3 & colour) const;
169 
173  void removeBoundingBox() const;
174 
178  void attachGameObjectToBone(const api::GOPtr & go, const std::string & boneName);
179 
183  void detachGameObjectFromBone(const api::GOPtr & go, const std::string & boneName);
184 
189  void addAnimationFrameEvent(uint64_t frameTime, const std::function<void(void)> & func) const;
190 
194  Transform getBoneTransform(const std::string & name) const;
195 
199  void setShadowCasting(bool enabled);
200 
201  private:
205  std::string _meshName;
206 
210  bool _isVisible;
211 
212  Vec3 _position;
213  Quaternion _rotation;
214  Vec3 _scale;
215 
216  std::string _material;
217 
218  bool _shadowCasting;
219 
220  mutable std::mutex _boneTransformLock;
221  std::map<std::string, Transform> _boneTransforms;
222 
223  void Init() override;
224 
225  void Finalize() override;
226 
227  virtual std::pair<AddStrategy, int64_t> howToAdd(const ComPtr & comp) const override;
228 
233  void sendUpdateMessage() const;
234 
235  void updateBoneTransforms(const std::map<std::string, Transform> & boneTransformMap);
236  };
237 
238 } /* namespace api */
239 } /* namespace i6e */
240 
241 #endif /* __I6ENGINE_API_MESHAPPEARANCECOMPONENT_H__ */
242 
std::string getMesh() const
Gets the GameObject's mesh name.
Implements 4-dimensional vectors.
Definition: i6eVector4.h:56
Class describing a 3d rotation.
Definition: i6eQuaternion.h:58
#define ISIXE_MODULES_API
std::map< std::string, std::string > attributeMap
Definition: attributeMap.h:42
Implements 3-dimensional vectors.
Definition: i6eVector.h:48
Vec3 getPosition() const
returns the position of the mesh
std::string getTemplateName() const override
returns the name this template was registered with
A shared pointer counting references and adds objects being not referenced any more to an internal li...
Definition: sharedPtr.h:50
Tells the engine what model/mesh to use when rendering the GameObject. For creating a MeshAppearanceC...
Handles all light related functionality.
Definition: MeshComponent.h:64
std::pair< Vec3, Quaternion > Transform
bool getVisibility() const
Gets the GameObject's visibility.
Component Base Class. All Components must derive from Component.
Definition: Component.h:97
i6e::math::i6eVector4 Vec4