Overte C++ Documentation
ModelEntityItem.h
1 //
2 // ModelEntityItem.h
3 // libraries/entities/src
4 //
5 // Created by Brad Hefta-Gaub on 12/4/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_ModelEntityItem_h
13 #define hifi_ModelEntityItem_h
14 
15 #include "EntityItem.h"
16 #include <JointData.h>
17 #include <ThreadSafeValueCache.h>
18 #include "AnimationPropertyGroup.h"
19 
20 #include "BlendshapeConstants.h"
21 
22 class ModelEntityItem : public EntityItem {
23 public:
24  static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
25 
26  ModelEntityItem(const EntityItemID& entityItemID);
27 
28  ALLOW_INSTANTIATION // This class can be instantiated
29 
30  // methods for getting/setting all properties of an entity
31  virtual EntityItemProperties getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const override;
32  virtual bool setSubClassProperties(const EntityItemProperties& properties) override;
33 
34  virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
35 
36  virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
37  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
38  EntityPropertyFlags& requestedProperties,
39  EntityPropertyFlags& propertyFlags,
40  EntityPropertyFlags& propertiesDidntFit,
41  int& propertyCount,
42  OctreeElement::AppendState& appendState) const override;
43 
44 
45  virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
46  ReadBitstreamToTreeParams& args,
47  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
48  bool& somethingChanged) override;
49 
50 
51  virtual void update(const quint64& now) override;
52  bool needsToCallUpdate() const override { return isAnimatingSomething(); }
53 
54  virtual void debugDump() const override;
55 
56  void setShapeType(ShapeType type) override;
57  virtual ShapeType getShapeType() const override;
58 
59  // TODO: Move these to subclasses, or other appropriate abstraction
60  // getters/setters applicable to models and particles
61  glm::u8vec3 getColor() const;
62  void setColor(const glm::u8vec3& value);
63 
64  bool hasModel() const;
65  virtual bool hasCompoundShapeURL() const;
66 
67  static const QString DEFAULT_MODEL_URL;
68  QString getModelURL() const;
69 
70  virtual glm::vec3 getScaledDimensions() const override;
71  virtual void setScaledDimensions(const glm::vec3& value) override;
72 
73  virtual const Transform getTransform(bool& success, int depth = 0) const override;
74  virtual const Transform getTransformWithOnlyLocalRotation(bool& success, int depth = 0) const override;
75  virtual const Transform getTransform() const override;
76 
77  static const QString DEFAULT_COMPOUND_SHAPE_URL;
78  QString getCompoundShapeURL() const;
79 
80  // model related properties
81  virtual void setModelURL(const QString& url);
82  virtual void setCompoundShapeURL(const QString& url);
83 
84  // Animation related items...
85  AnimationPropertyGroup getAnimationProperties() const;
86  bool hasAnimation() const;
87  QString getAnimationURL() const;
88  void setAnimationCurrentFrame(float value);
89  float getAnimationCurrentFrame() const;
90  bool getAnimationAllowTranslation() const;
91  bool isAnimatingSomething() const;
92 
93  void setRelayParentJoints(bool relayJoints);
94  bool getRelayParentJoints() const;
95 
96  void setGroupCulled(bool value);
97  bool getGroupCulled() const;
98 
99  static const QString DEFAULT_TEXTURES;
100  const QString getTextures() const;
101  void setTextures(const QString& textures);
102 
103  virtual void setJointRotations(const QVector<glm::quat>& rotations);
104  virtual void setJointRotationsSet(const QVector<bool>& rotationsSet);
105  virtual void setJointTranslations(const QVector<glm::vec3>& translations);
106  virtual void setJointTranslationsSet(const QVector<bool>& translationsSet);
107 
108  virtual void setAnimationJointsData(const QVector<EntityJointData>& jointsData);
109 
110  QVector<glm::quat> getJointRotations() const;
111  QVector<bool> getJointRotationsSet() const;
112  QVector<glm::vec3> getJointTranslations() const;
113  QVector<bool> getJointTranslationsSet() const;
114 
115  glm::vec3 getModelScale() const;
116  void setModelScale(const glm::vec3& modelScale);
117 
118  QString getBlendshapeCoefficients() const;
119  void setBlendshapeCoefficients(const QString& blendshapeCoefficients);
120  bool blendshapesChanged() const { return _blendshapesChanged; }
121  QVector<float> getBlendshapeCoefficientVector();
122 
123  bool getUseOriginalPivot() const;
124  void setUseOriginalPivot(bool useOriginalPivot);
125 
126 private:
127  void setAnimationSettings(const QString& value); // only called for old bitstream format
128  bool applyNewAnimationProperties(AnimationPropertyGroup newProperties);
129 
130 protected:
131  void resizeJointArrays(int newSize);
132 
133  // these are used:
134  // - to bounce joint data from an animation into the model/rig.
135  // - to relay changes from scripts to model/rig.
136  // - to relay between network and model/rig
137  // they aren't currently updated from data in the model/rig, and they don't have a direct effect
138  // on what's rendered.
139  ReadWriteLockable _jointDataLock;
140 
141  bool _jointRotationsExplicitlySet { false }; // were the joints set as a property or just side effect of animations
142  bool _jointTranslationsExplicitlySet{ false }; // were the joints set as a property or just side effect of animations
143 
144  struct ModelJointData {
145  EntityJointData joint;
146  bool rotationDirty { false };
147  bool translationDirty { false };
148  };
149 
150  QVector<ModelJointData> _localJointData;
151  int _lastKnownCurrentFrame{-1};
152 
153  glm::u8vec3 _color;
154  glm::vec3 _modelScale { 1.0f };
155  QString _modelURL;
156  bool _relayParentJoints;
157  bool _groupCulled { false };
158  QVariantMap _blendshapeCoefficientsMap;
159  bool _useOriginalPivot { false };
160 
161  ThreadSafeValueCache<QString> _compoundShapeURL;
162 
163  AnimationPropertyGroup _animationProperties;
164 
165  QString _textures;
166 
167  ShapeType _shapeType { SHAPE_TYPE_NONE };
168 
169 private:
170  uint64_t _lastAnimated{ 0 };
171  float _currentFrame{ -1.0f };
172 
173  QVector<float> _blendshapeCoefficientsVector;
174  bool _blendshapesChanged { false };
175 };
176 
177 #endif // hifi_ModelEntityItem_h
Definition: EntityItem.h:82
virtual glm::vec3 getScaledDimensions() const
Dimensions in meters (0.0 - TREE_SCALE)
Definition: EntityItem.cpp:1910
virtual ShapeType getShapeType() const
return preferred shape type (actual physical shape may differ)
Definition: EntityItem.h:390
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: EntityItemProperties.h:106
Handles packing of the data portion of PacketType_OCTREE_DATA messages.
Definition: OctreePacketData.h:93