Overte C++ Documentation
HazePropertyGroup.h
1 //
2 // HazePropertyGroup.h
3 // libraries/entities/src
4 //
5 // Created by Nissim hadar on 9/21/17.
6 // Copyright 2013 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_HazePropertyGroup_h
15 #define hifi_HazePropertyGroup_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 EntityTreeElementExtraEncodeData;
28 class ReadBitstreamToTreeParams;
29 class ScriptEngine;
30 class ScriptValue;
31 
32 static const float INITIAL_HAZE_RANGE{ 1000.0f };
33 static const glm::u8vec3 initialHazeGlareColor { 255, 229, 179 };
34 static const glm::u8vec3 initialHazeColor { 128, 154, 179 };
35 static const float INITIAL_HAZE_GLARE_ANGLE{ 20.0f };
36 
37 static const float INITIAL_HAZE_BASE_REFERENCE{ 0.0f };
38 static const float INITIAL_HAZE_HEIGHT{ 200.0f };
39 
40 static const float INITIAL_HAZE_BACKGROUND_BLEND{ 0.0f };
41 
42 static const float INITIAL_KEY_LIGHT_RANGE{ 1000.0f };
43 static const float INITIAL_KEY_LIGHT_ALTITUDE{ 200.0f };
44 
45 // FIXME: Document hazeAttenuationKeyLight, hazeKeyLightRange, and hazeKeyLightAltitude once they're working and are provided
46 // in the Create app's UI.
47 /*@jsdoc
48  * Haze is defined by the following properties:
49  * @typedef {object} Entities.Haze
50  *
51  * @property {number} hazeRange=1000 - The horizontal distance at which visibility is reduced to 95%; i.e., 95% of each pixel's
52  * color is haze.
53  * @property {Color} hazeColor=128,154,179 - The color of the haze when looking away from the key light.
54  * @property {boolean} hazeEnableGlare=false - <code>true</code> if the haze is colored with glare from the key light,
55  * <code>false</code> if it isn't. If <code>true</code>, then <code>hazeGlareColor</code> and <code>hazeGlareAngle</code>
56  * are used.
57  * @property {Color} hazeGlareColor=255,299,179 - The color of the haze when looking towards the key light.
58  * @property {number} hazeGlareAngle=20 - The angle in degrees across the circle around the key light that the glare color and
59  * haze color are blended 50/50.
60  *
61  * @property {boolean} hazeAltitudeEffect=false - <code>true</code> if haze decreases with altitude as defined by the
62  * entity's local coordinate system, <code>false</code> if it doesn't. If <code>true</code>, then <code>hazeBaseRef</code>
63  * and <code>hazeCeiling</code> are used.
64  * @property {number} hazeBaseRef=0 - The y-axis value in the entity's local coordinate system at which the haze density starts
65  * reducing with altitude.
66  * @property {number} hazeCeiling=200 - The y-axis value in the entity's local coordinate system at which the haze density has
67  * reduced to 5%.
68  *
69  * @property {number} hazeBackgroundBlend=0 - The proportion of the skybox image to show through the haze: <code>0.0</code>
70  * displays no skybox image; <code>1.0</code> displays no haze.
71  *
72  * @property {boolean} hazeAttenuateKeyLight=false - <code>true</code> if the haze attenuates the key light, <code>false</code>
73  * if it doesn't. If <code>true</code>, then <code>hazeKeyLightRange</code> and <code>hazeKeyLightAltitude</code> are used.
74  * @property {number} hazeKeyLightRange=1000 - The distance at which the haze attenuates the key light by 95%.
75  * @property {number} hazeKeyLightAltitude=200 - The altitude at which the haze starts attenuating the key light (i.e., the
76  * altitude at which the distance starts being calculated).
77  */
78 class HazePropertyGroup : public PropertyGroup {
79 public:
80  // EntityItemProperty related helpers
81  virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
82  ScriptEngine* engine, bool skipDefaults,
83  EntityItemProperties& defaultEntityProperties, bool returnNothingOnEmptyPropertyFlags,
84  bool isMyOwnAvatarEntity) const override;
85  virtual void copyFromScriptValue(const ScriptValue& object, const QSet<QString> &namesSet, bool& _defaultSettings) override;
86 
87  void merge(const HazePropertyGroup& other);
88 
89  virtual void debugDump() const override;
90  virtual void listChangedProperties(QList<QString>& out) override;
91 
92  virtual bool appendToEditPacket(OctreePacketData* packetData,
93  EntityPropertyFlags& requestedProperties,
94  EntityPropertyFlags& propertyFlags,
95  EntityPropertyFlags& propertiesDidntFit,
96  int& propertyCount,
97  OctreeElement::AppendState& appendState) const override;
98 
99  virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags,
100  const unsigned char*& dataAt, int& processedBytes) override;
101  virtual void markAllChanged() override;
102  virtual EntityPropertyFlags getChangedProperties() const override;
103 
104  // EntityItem related helpers
105  // methods for getting/setting all properties of an entity
106  virtual void getProperties(EntityItemProperties& propertiesOut) const override;
107 
109  virtual bool setProperties(const EntityItemProperties& properties) override;
110 
111  virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
112 
113  virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
114  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
115  EntityPropertyFlags& requestedProperties,
116  EntityPropertyFlags& propertyFlags,
117  EntityPropertyFlags& propertiesDidntFit,
118  int& propertyCount,
119  OctreeElement::AppendState& appendState) const override;
120 
121  virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
122  ReadBitstreamToTreeParams& args,
123  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
124  bool& somethingChanged) override;
125 
126  // Range only parameters
127  DEFINE_PROPERTY(PROP_HAZE_RANGE, HazeRange, hazeRange, float, INITIAL_HAZE_RANGE);
128  DEFINE_PROPERTY_REF(PROP_HAZE_COLOR, HazeColor, hazeColor, glm::u8vec3, initialHazeColor);
129  DEFINE_PROPERTY_REF(PROP_HAZE_GLARE_COLOR, HazeGlareColor, hazeGlareColor, glm::u8vec3, initialHazeGlareColor);
130  DEFINE_PROPERTY(PROP_HAZE_ENABLE_GLARE, HazeEnableGlare, hazeEnableGlare, bool, false);
131  DEFINE_PROPERTY_REF(PROP_HAZE_GLARE_ANGLE, HazeGlareAngle, hazeGlareAngle, float, INITIAL_HAZE_GLARE_ANGLE);
132 
133  // Altitude parameters
134  DEFINE_PROPERTY(PROP_HAZE_ALTITUDE_EFFECT, HazeAltitudeEffect, hazeAltitudeEffect, bool, false);
135  DEFINE_PROPERTY_REF(PROP_HAZE_CEILING, HazeCeiling, hazeCeiling, float, INITIAL_HAZE_BASE_REFERENCE + INITIAL_HAZE_HEIGHT);
136  DEFINE_PROPERTY_REF(PROP_HAZE_BASE_REF, HazeBaseRef, hazeBaseRef, float, INITIAL_HAZE_BASE_REFERENCE);
137 
138  // Background (skybox) blend value
139  DEFINE_PROPERTY_REF(PROP_HAZE_BACKGROUND_BLEND, HazeBackgroundBlend, hazeBackgroundBlend, float, INITIAL_HAZE_BACKGROUND_BLEND);
140 
141  // hazeDirectional light attenuation
142  DEFINE_PROPERTY(PROP_HAZE_ATTENUATE_KEYLIGHT, HazeAttenuateKeyLight, hazeAttenuateKeyLight, bool, false);
143  DEFINE_PROPERTY_REF(PROP_HAZE_KEYLIGHT_RANGE, HazeKeyLightRange, hazeKeyLightRange, float, INITIAL_KEY_LIGHT_RANGE);
144  DEFINE_PROPERTY_REF(PROP_HAZE_KEYLIGHT_ALTITUDE, HazeKeyLightAltitude, hazeKeyLightAltitude, float, INITIAL_KEY_LIGHT_ALTITUDE);
145 };
146 
147 #endif // hifi_HazePropertyGroup_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