Overte C++ Documentation
GrabPropertyGroup.h
1 //
2 // GrabPropertyGroup.h
3 // libraries/entities/src
4 //
5 // Created by Seth Alves on 2018-8-8.
6 // Copyright 2018 High Fidelity, Inc.
7 // Copyright 2023 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 // SPDX-License-Identifier: Apache-2.0
12 //
13 
14 #ifndef hifi_GrabPropertyGroup_h
15 #define hifi_GrabPropertyGroup_h
16 
17 #include <stdint.h>
18 
19 #include <glm/glm.hpp>
20 
21 #include "PropertyGroup.h"
22 #include "EntityItemPropertiesMacros.h"
23 
25 class EncodeBitstreamParams;
26 class OctreePacketData;
27 class ReadBitstreamToTreeParams;
28 class ScriptValue;
29 
30 static const bool INITIAL_GRABBABLE { true };
31 static const bool INITIAL_KINEMATIC { true };
32 static const bool INITIAL_FOLLOWS_CONTROLLER { true };
33 static const bool INITIAL_TRIGGERABLE { false };
34 static const bool INITIAL_EQUIPPABLE { false };
35 static const bool INITIAL_GRAB_DELEGATE_TO_PARENT { true };
36 static const glm::vec3 INITIAL_LEFT_EQUIPPABLE_POSITION { glm::vec3(0.0f) };
37 static const glm::quat INITIAL_LEFT_EQUIPPABLE_ROTATION { glm::quat() };
38 static const glm::vec3 INITIAL_RIGHT_EQUIPPABLE_POSITION { glm::vec3(0.0f) };
39 static const glm::quat INITIAL_RIGHT_EQUIPPABLE_ROTATION { glm::quat() };
40 static const glm::vec3 INITIAL_EQUIPPABLE_INDICATOR_SCALE { glm::vec3(1.0f) };
41 static const glm::vec3 INITIAL_EQUIPPABLE_INDICATOR_OFFSET { glm::vec3(0.0f) };
42 
43 
44 /*@jsdoc
45  * Grabbing behavior is defined by the following properties:
46  *
47  * @typedef {object} Entities.Grab
48  * @property {boolean} grabbable=true - <code>true</code> if the entity can be grabbed, <code>false</code> if it can't be.
49  * @property {boolean} grabKinematic=true - <code>true</code> if the entity will be updated in a kinematic manner when
50  * grabbed; <code>false</code> if it will be grabbed using a tractor action. A kinematic grab will make the item appear
51  * more tightly held but will cause it to behave poorly when interacting with dynamic entities.
52  * @property {boolean} grabFollowsController=true - <code>true</code> if the entity will follow the motions of the hand
53  * controller even if the avatar's hand can't get to the implied position, <code>false</code> if it will follow the motions
54  * of the avatar's hand. This should be set <code>true</code> for tools, pens, etc. and <code>false</code> for things meant
55 * to decorate the hand.
56  * @property {boolean} triggerable=false - <code>true</code> if the entity will receive calls to trigger
57  * {@link Controller|Controller entity methods}, <code>false</code> if it won't.
58  * @property {boolean} grabDelegateToParent=true - <code>true</code> if when the entity is grabbed, the grab will be
59  * transferred to its parent entity if there is one; <code>false</code> if the grab won't be transferred, so a child entity
60  * can be grabbed and moved relative to its parent.
61  * @property {boolean} equippable=true - <code>true</code> if the entity can be equipped, <code>false</code> if it cannot.
62  * @property {Vec3} equippableLeftPosition=0,0,0 - Positional offset from the left hand, when equipped.
63  * @property {Quat} equippableLeftRotation=0,0,0,1 - Rotational offset from the left hand, when equipped.
64  * @property {Vec3} equippableRightPosition=0,0,0 - Positional offset from the right hand, when equipped.
65  * @property {Quat} equippableRightRotation=0,0,0,1 - Rotational offset from the right hand, when equipped.
66  * @property {string} equippableIndicatorURL="" - If non-empty, this model will be used to indicate that an
67  * entity is equippable, rather than the default.
68  * @property {Vec3} equippableIndicatorScale=1,1,1 - If <code>equippableIndicatorURL</code> is non-empty, this controls the
69  scale of the displayed indicator.
70  * @property {Vec3} equippableIndicatorOffset=0,0,0 - If <code>equippableIndicatorURL</code> is non-empty, this controls the
71  relative offset of the displayed object from the equippable entity.
72  */
73 class GrabPropertyGroup : public PropertyGroup {
74 public:
75  // EntityItemProperty related helpers
76  virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
77  ScriptEngine* engine, bool skipDefaults,
78  EntityItemProperties& defaultEntityProperties, bool returnNothingOnEmptyPropertyFlags,
79  bool isMyOwnAvatarEntity) const override;
80  virtual void copyFromScriptValue(const ScriptValue& object, const QSet<QString> &namesSet, bool& _defaultSettings) override;
81 
82  void merge(const GrabPropertyGroup& other);
83 
84  virtual void debugDump() const override;
85  virtual void listChangedProperties(QList<QString>& out) override;
86 
87  virtual bool appendToEditPacket(OctreePacketData* packetData,
88  EntityPropertyFlags& requestedProperties,
89  EntityPropertyFlags& propertyFlags,
90  EntityPropertyFlags& propertiesDidntFit,
91  int& propertyCount,
92  OctreeElement::AppendState& appendState) const override;
93 
94  virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags,
95  const unsigned char*& dataAt, int& processedBytes) override;
96  virtual void markAllChanged() override;
97  virtual EntityPropertyFlags getChangedProperties() const override;
98 
99  // EntityItem related helpers
100  // methods for getting/setting all properties of an entity
101  virtual void getProperties(EntityItemProperties& propertiesOut) const override;
102 
103  // returns true if something changed
104  virtual bool setProperties(const EntityItemProperties& properties) override;
105 
106  virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
107 
108  virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
109  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
110  EntityPropertyFlags& requestedProperties,
111  EntityPropertyFlags& propertyFlags,
112  EntityPropertyFlags& propertiesDidntFit,
113  int& propertyCount,
114  OctreeElement::AppendState& appendState) const override;
115 
116  virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
117  ReadBitstreamToTreeParams& args,
118  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
119  bool& somethingChanged) override;
120 
121  // grab properties
122  DEFINE_PROPERTY(PROP_GRAB_GRABBABLE, Grabbable, grabbable, bool, INITIAL_GRABBABLE);
123  DEFINE_PROPERTY(PROP_GRAB_KINEMATIC, GrabKinematic, grabKinematic, bool, INITIAL_KINEMATIC);
124  DEFINE_PROPERTY(PROP_GRAB_FOLLOWS_CONTROLLER, GrabFollowsController, grabFollowsController, bool,
125  INITIAL_FOLLOWS_CONTROLLER);
126  DEFINE_PROPERTY(PROP_GRAB_TRIGGERABLE, Triggerable, triggerable, bool, INITIAL_TRIGGERABLE);
127  DEFINE_PROPERTY(PROP_GRAB_EQUIPPABLE, Equippable, equippable, bool, INITIAL_EQUIPPABLE);
128  DEFINE_PROPERTY(PROP_GRAB_DELEGATE_TO_PARENT, GrabDelegateToParent, grabDelegateToParent, bool,
129  INITIAL_GRAB_DELEGATE_TO_PARENT);
130  DEFINE_PROPERTY_REF(PROP_GRAB_LEFT_EQUIPPABLE_POSITION_OFFSET, EquippableLeftPosition, equippableLeftPosition,
131  glm::vec3, INITIAL_LEFT_EQUIPPABLE_POSITION);
132  DEFINE_PROPERTY_REF(PROP_GRAB_LEFT_EQUIPPABLE_ROTATION_OFFSET, EquippableLeftRotation, equippableLeftRotation,
133  glm::quat, INITIAL_LEFT_EQUIPPABLE_ROTATION);
134  DEFINE_PROPERTY_REF(PROP_GRAB_RIGHT_EQUIPPABLE_POSITION_OFFSET, EquippableRightPosition, equippableRightPosition,
135  glm::vec3, INITIAL_RIGHT_EQUIPPABLE_POSITION);
136  DEFINE_PROPERTY_REF(PROP_GRAB_RIGHT_EQUIPPABLE_ROTATION_OFFSET, EquippableRightRotation, equippableRightRotation,
137  glm::quat, INITIAL_RIGHT_EQUIPPABLE_ROTATION);
138  DEFINE_PROPERTY_REF(PROP_GRAB_EQUIPPABLE_INDICATOR_URL, EquippableIndicatorURL, equippableIndicatorURL, QString, "");
139  DEFINE_PROPERTY_REF(PROP_GRAB_EQUIPPABLE_INDICATOR_SCALE, EquippableIndicatorScale, equippableIndicatorScale,
140  glm::vec3, INITIAL_EQUIPPABLE_INDICATOR_SCALE);
141  DEFINE_PROPERTY_REF(PROP_GRAB_EQUIPPABLE_INDICATOR_OFFSET, EquippableIndicatorOffset, equippableIndicatorOffset,
142  glm::vec3, INITIAL_EQUIPPABLE_INDICATOR_OFFSET);
143 };
144 
145 #endif // hifi_GrabPropertyGroup_h
Definition: EntityItemProperties.h:106
Handles packing of the data portion of PacketType_OCTREE_DATA messages.
Definition: OctreePacketData.h:93
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40