Overte C++ Documentation
KeyLightPropertyGroup.h
1 //
2 // KeyLightPropertyGroup.h
3 // libraries/entities/src
4 //
5 // Created by Sam Gateau on 2015/10/23.
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 
15 #ifndef hifi_KeyLightPropertyGroup_h
16 #define hifi_KeyLightPropertyGroup_h
17 
18 #include <stdint.h>
19 
20 #include <glm/glm.hpp>
21 
22 #include "EntityItemPropertiesMacros.h"
23 #include "PropertyGroup.h"
24 
26 class EncodeBitstreamParams;
27 class OctreePacketData;
28 class EntityTreeElementExtraEncodeData;
29 class ReadBitstreamToTreeParams;
30 class ScriptEngine;
31 class ScriptValue;
32 
33 /*@jsdoc
34  * A key light is defined by the following properties:
35  * @typedef {object} Entities.KeyLight
36  * @property {Color} color=255,255,255 - The color of the light.
37  * @property {number} intensity=1 - The intensity of the light.
38  * @property {Vec3} direction=0,-1,0 - The direction the light is shining.
39  * @property {boolean} castShadows=false - <code>true</code> if shadows are cast, <code>false</code> if they aren't. Shadows
40  * are cast by avatars, plus {@link Entities.EntityProperties-Model|Model} and
41  * {@link Entities.EntityProperties-Shape|Shape} entities that have their
42  * <code>{@link Entities.EntityProperties|canCastShadow}</code> property set to <code>true</code>.
43  * @property {number} shadowBias=0.5 - The bias of the shadows cast by the light, range <code>0.0</code> &ndash;
44  * <code>1.0</code>. This fine-tunes shadows cast by the light, to prevent shadow acne and peter panning.
45  * @property {number} shadowMaxDistance=40.0 - The maximum distance from the camera position at which shadows will be computed,
46  * range <code>1.0</code> &ndash; <code>250.0</code>. Higher values cover more of the scene but with less precision.
47  */
48 class KeyLightPropertyGroup : public PropertyGroup {
49 public:
50  // EntityItemProperty related helpers
51  virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties,
52  ScriptEngine* engine, bool skipDefaults,
53  EntityItemProperties& defaultEntityProperties, bool returnNothingOnEmptyPropertyFlags,
54  bool isMyOwnAvatarEntity) const override;
55  virtual void copyFromScriptValue(const ScriptValue& object, const QSet<QString> &namesSet, bool& _defaultSettings) override;
56 
57  void merge(const KeyLightPropertyGroup& other);
58 
59  virtual void debugDump() const override;
60  virtual void listChangedProperties(QList<QString>& out) override;
61 
62  virtual bool appendToEditPacket(OctreePacketData* packetData,
63  EntityPropertyFlags& requestedProperties,
64  EntityPropertyFlags& propertyFlags,
65  EntityPropertyFlags& propertiesDidntFit,
66  int& propertyCount,
67  OctreeElement::AppendState& appendState) const override;
68 
69  virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags,
70  const unsigned char*& dataAt, int& processedBytes) override;
71  virtual void markAllChanged() override;
72  virtual EntityPropertyFlags getChangedProperties() const override;
73 
74  // EntityItem related helpers
75  // methods for getting/setting all properties of an entity
76  virtual void getProperties(EntityItemProperties& propertiesOut) const override;
77 
79  virtual bool setProperties(const EntityItemProperties& properties) override;
80 
81  virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
82 
83  virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
84  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
85  EntityPropertyFlags& requestedProperties,
86  EntityPropertyFlags& propertyFlags,
87  EntityPropertyFlags& propertiesDidntFit,
88  int& propertyCount,
89  OctreeElement::AppendState& appendState) const override;
90 
91  virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
92  ReadBitstreamToTreeParams& args,
93  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
94  bool& somethingChanged) override;
95 
96  static const glm::u8vec3 DEFAULT_KEYLIGHT_COLOR;
97  static const float DEFAULT_KEYLIGHT_INTENSITY;
98  static const float DEFAULT_KEYLIGHT_AMBIENT_INTENSITY;
99  static const glm::vec3 DEFAULT_KEYLIGHT_DIRECTION;
100  static const bool DEFAULT_KEYLIGHT_CAST_SHADOWS;
101  static const float DEFAULT_KEYLIGHT_SHADOW_BIAS;
102  static const float DEFAULT_KEYLIGHT_SHADOW_MAX_DISTANCE;
103 
104  DEFINE_PROPERTY_REF(PROP_KEYLIGHT_COLOR, Color, color, glm::u8vec3, DEFAULT_KEYLIGHT_COLOR);
105  DEFINE_PROPERTY(PROP_KEYLIGHT_INTENSITY, Intensity, intensity, float, DEFAULT_KEYLIGHT_INTENSITY);
106  DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, Direction, direction, glm::vec3, DEFAULT_KEYLIGHT_DIRECTION);
107  DEFINE_PROPERTY(PROP_KEYLIGHT_CAST_SHADOW, CastShadows, castShadows, bool, DEFAULT_KEYLIGHT_CAST_SHADOWS);
108  DEFINE_PROPERTY(PROP_KEYLIGHT_SHADOW_BIAS, ShadowBias, shadowBias, float, DEFAULT_KEYLIGHT_SHADOW_BIAS);
109  DEFINE_PROPERTY(PROP_KEYLIGHT_SHADOW_MAX_DISTANCE, ShadowMaxDistance, shadowMaxDistance, float, DEFAULT_KEYLIGHT_SHADOW_MAX_DISTANCE);
110 };
111 
112 #endif // hifi_KeyLightPropertyGroup_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