Overte C++ Documentation
MaterialEntityItem.h
1 //
2 // Created by Sam Gondelman on 1/12/18
3 // Copyright 2018 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #ifndef hifi_MaterialEntityItem_h
10 #define hifi_MaterialEntityItem_h
11 
12 #include "EntityItem.h"
13 
14 #include "MaterialMappingMode.h"
15 
16 class MaterialEntityItem : public EntityItem {
17  using Pointer = std::shared_ptr<MaterialEntityItem>;
18 public:
19  static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
20 
21  MaterialEntityItem(const EntityItemID& entityItemID);
22 
23  ALLOW_INSTANTIATION // This class can be instantiated
24 
25  // methods for getting/setting all properties of an entity
26  virtual EntityItemProperties getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const override;
27  virtual bool setSubClassProperties(const EntityItemProperties& properties) override;
28 
29  virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
30 
31  virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
32  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
33  EntityPropertyFlags& requestedProperties,
34  EntityPropertyFlags& propertyFlags,
35  EntityPropertyFlags& propertiesDidntFit,
36  int& propertyCount,
37  OctreeElement::AppendState& appendState) const override;
38 
39 
40  virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
41  ReadBitstreamToTreeParams& args,
42  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
43  bool& somethingChanged) override;
44 
45  void debugDump() const override;
46 
47  virtual void setUnscaledDimensions(const glm::vec3& value) override;
48 
49  QString getMaterialURL() const;
50  void setMaterialURL(const QString& materialURL);
51 
52  QString getMaterialData() const;
53  void setMaterialData(const QString& materialData);
54 
55  MaterialMappingMode getMaterialMappingMode() const;
56  void setMaterialMappingMode(MaterialMappingMode mode);
57 
58  bool getMaterialRepeat() const;
59  void setMaterialRepeat(bool repeat);
60 
61  quint16 getPriority() const;
62  void setPriority(quint16 priority);
63 
64  QString getParentMaterialName() const;
65  void setParentMaterialName(const QString& parentMaterialName);
66 
67  void setParentID(const QUuid& parentID) override;
68 
69  glm::vec2 getMaterialMappingPos() const;
70  void setMaterialMappingPos(const glm::vec2& materialMappingPos);
71  glm::vec2 getMaterialMappingScale() const;
72  void setMaterialMappingScale(const glm::vec2& materialMappingScale);
73  float getMaterialMappingRot() const;
74  void setMaterialMappingRot(float materialMappingRot);
75 
76  AACube calculateInitialQueryAACube(bool& success) override;
77 
78  void setHasVertexShader(bool hasVertexShader);
79 
80 private:
81  // URL for this material. Currently, only JSON format is supported. Set to "materialData" to use the material data to live edit a material.
82  // The following fields are supported in the JSON:
83  // materialVersion: a uint for the version of this network material (currently, only 1 is supported)
84  // materials, which is either an object or an array of objects, each with the following properties:
85  // strings:
86  // name (NOT YET USED), model (NOT YET USED, should use "hifi_pbr")
87  // floats:
88  // opacity, roughness, metallic, scattering
89  // bool:
90  // unlit
91  // colors (arrays of 3 floats 0-1. Optional fourth value in array can be a boolean isSRGB):
92  // emissive, albedo
93  // urls to textures:
94  // emissiveMap, albedoMap (set opacityMap = albedoMap for transparency), metallicMap or specularMap, roughnessMap or glossMap,
95  // normalMap or bumpMap, occlusionMap, lightMap (broken, FIXME), scatteringMap (only works if normal mapped)
96  QString _materialURL;
97  // Type of material. "uv" or "projected".
98  MaterialMappingMode _materialMappingMode { UV };
99  bool _materialRepeat { true };
100  glm::vec3 _desiredDimensions;
101  // Priority for this material when applying it to its parent. Only the highest priority material will be used. Materials with the same priority are (essentially) randomly sorted.
102  // Base materials that come with models always have priority 0.
103  quint16 _priority { 0 };
104  // An identifier for choosing a submesh or submeshes within a parent. If in the format "mat::<string>", all submeshes with material name "<string>" will be replaced. Otherwise,
105  // parentMaterialName will be parsed as an unsigned int (strings not starting with "mat::" will parse to 0), representing the mesh index to modify.
106  QString _parentMaterialName { "0" };
107  // Offset position in UV-space of top left of material, (0, 0) to (1, 1)
108  glm::vec2 _materialMappingPos { 0, 0 };
109  // How much to scale this material within its parent's UV-space
110  glm::vec2 _materialMappingScale { 1, 1 };
111  // How much to rotate this material within its parent's UV-space (degrees)
112  float _materialMappingRot { 0 };
113  QString _materialData;
114 
115  bool _hasVertexShader { false };
116 
117 };
118 
119 #endif // hifi_MaterialEntityItem_h
Definition: EntityItem.h:82
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