HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mesh.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_MESH_H
8 #define PXR_IMAGING_HD_MESH_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/version.h"
13 #include "pxr/imaging/hd/enums.h"
15 #include "pxr/imaging/hd/rprim.h"
16 #include "pxr/imaging/hd/tokens.h"
18 
20 
21 #define HD_MESH_REPR_DESC_TOKENS \
22  (surfaceShader) \
23  (surfaceShaderUnlit) \
24  (surfaceShaderSheer) \
25  (surfaceShaderOutline) \
26  (constantColor) \
27  (hullColor) \
28  (pointColor)
29 
30 TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API,
32 
33 /// \class HdMeshReprDesc
34 ///
35 /// Descriptor to configure the drawItem(s) for a repr
36 ///
38 {
41  TfToken shadingTerminal = HdMeshReprDescTokens->surfaceShader,
42  bool flatShadingEnabled = false,
43  bool blendWireframeColor = true,
44  bool forceOpaqueEdges = true,
45  bool surfaceEdgeIds = false,
46  bool doubleSided = false,
47  float lineWidth = 0,
48  bool useCustomDisplacement = true,
49  bool enableScalarOverride = true)
61  {}
62 
63  bool IsEmpty() const {
65  }
66 
67  /// The rendering style: draw refined/unrefined, edge, points, etc.
69  /// The culling style: draw front faces, back faces, etc.
71  /// Specifies how the fragment color should be computed from surfaceShader;
72  /// this can be used to render a mesh lit, unlit, unshaded, etc.
74  /// Does this mesh want flat shading?
76  /// Should the wireframe color be blended into the color primvar?
78  /// If the geom style includes edges, should those edges be forced
79  /// to be fully opaque, ignoring any applicable opacity inputs.
80  /// Does not apply to patch edges.
82  /// Generate edge ids for surface and hull geom styles that do not
83  /// otherwise render edges, e.g. to support picking and highlighting
84  /// of edges with these mesh geom styles.
86  /// Should this mesh be treated as double-sided? The resolved value is
87  /// (prim.doubleSided || repr.doubleSided).
89  /// How big (in pixels) should line drawing be?
90  float lineWidth;
91  /// Should this mesh use displacementShader() to displace points?
93  /// Should scalar override be allowed on this drawItem.
94  /// scalar override allows for visualization of a single float value
95  /// across a prim.
97 };
98 
99 /// Hydra Schema for a subdivision surface or poly-mesh object.
100 ///
101 class HdMesh : public HdRprim
102 {
103 public:
104  HD_API
105  ~HdMesh() override;
106 
107  ///
108  /// Render State
109  ///
110  inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
111  inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
112  inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
113 
114  ///
115  /// Topological accessors via the scene delegate
116  ///
117  inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
118  inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
119  inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
120 
121  /// Topology getter
122  virtual HdMeshTopologySharedPtr GetTopology() const;
123 
124  ///
125  /// Primvars Accessors
126  ///
127  inline VtValue GetPoints(HdSceneDelegate* delegate) const;
128  inline VtValue GetNormals(HdSceneDelegate* delegate) const;
129 
130  HD_API
131  TfTokenVector const & GetBuiltinPrimvarNames() const override;
132 
133  /// Configure the geometric style of the mesh for a given representation.
134  /// We currently allow up to 2 descriptors for a representation.
135  /// Example of when this may be useful:
136  /// Drawing the outline in addition to the surface for a mesh.
137  HD_API
138  static void ConfigureRepr(TfToken const &reprName,
139  HdMeshReprDesc desc1,
141 
142 protected:
143  /// Constructor. instancerId, if specified, is the instancer which uses
144  /// this mesh as a prototype.
145  HD_API
146  HdMesh(SdfPath const& id);
147 
148  // We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
150 
151  HD_API
152  static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
153 
154 private:
155 
156  // Class can not be default constructed or copied.
157  HdMesh() = delete;
158  HdMesh(const HdMesh &) = delete;
159  HdMesh &operator =(const HdMesh &) = delete;
160 
161  static _MeshReprConfig _reprDescConfig;
162 };
163 
164 inline bool
166 {
167  return delegate->GetDoubleSided(GetId());
168 }
169 
170 inline HdCullStyle
172 {
173  return delegate->GetCullStyle(GetId());
174 }
175 
176 inline VtValue
178 {
179  return delegate->GetShadingStyle(GetId());
180 }
181 
182 inline HdMeshTopology
184 {
185  return delegate->GetMeshTopology(GetId());
186 }
187 
188 inline HdDisplayStyle
190 {
191  return delegate->GetDisplayStyle(GetId());
192 }
193 
194 inline PxOsdSubdivTags
196 {
197  return delegate->GetSubdivTags(GetId());
198 }
199 
202 {
203  return HdMeshTopologySharedPtr();
204 }
205 
206 inline VtValue
208 {
209  return GetPrimvar(delegate, HdTokens->points);
210 }
211 
212 inline VtValue
214 {
215  return GetPrimvar(delegate, HdTokens->normals);
216 }
217 
218 
220 
221 #endif //PXR_IMAGING_HD_MESH_H
#define HD_MESH_REPR_DESC_TOKENS
Definition: mesh.h:21
HdCullStyle
Definition: enums.h:105
bool forceOpaqueEdges
Definition: mesh.h:81
bool blendWireframeColor
Should the wireframe color be blended into the color primvar?
Definition: mesh.h:77
HD_API ~HdMesh() override
static HD_API void ConfigureRepr(TfToken const &reprName, HdMeshReprDesc desc1, HdMeshReprDesc desc2=HdMeshReprDesc())
VtValue GetShadingStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:177
#define HD_API
Definition: api.h:23
HdMeshReprDesc(HdMeshGeomStyle geomStyle=HdMeshGeomStyleInvalid, HdCullStyle cullStyle=HdCullStyleDontCare, TfToken shadingTerminal=HdMeshReprDescTokens->surfaceShader, bool flatShadingEnabled=false, bool blendWireframeColor=true, bool forceOpaqueEdges=true, bool surfaceEdgeIds=false, bool doubleSided=false, float lineWidth=0, bool useCustomDisplacement=true, bool enableScalarOverride=true)
Definition: mesh.h:39
std::shared_ptr< class HdMeshTopology > HdMeshTopologySharedPtr
Definition: meshTopology.h:28
virtual HD_API PxOsdSubdivTags GetSubdivTags(SdfPath const &id)
Gets the subdivision surface tags (sharpness, holes, etc).
Definition: token.h:70
bool surfaceEdgeIds
Definition: mesh.h:85
virtual HD_API HdDisplayStyle GetDisplayStyle(SdfPath const &id)
Returns the display style for the given prim.
HdMeshTopology GetMeshTopology(HdSceneDelegate *delegate) const
Definition: mesh.h:183
bool doubleSided
Definition: mesh.h:88
Definition: rprim.h:37
VtValue GetPrimvar(HdSceneDelegate *delegate, const TfToken &name) const
Definition: rprim.h:354
static HD_API _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName)
bool useCustomDisplacement
Should this mesh use displacementShader() to displace points?
Definition: mesh.h:92
HdMeshGeomStyle
Definition: enums.h:130
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API, HD_MESH_REPR_DESC_TOKENS)
Definition: path.h:273
bool IsDoubleSided(HdSceneDelegate *delegate) const
Definition: mesh.h:165
TfToken shadingTerminal
Definition: mesh.h:73
VtValue GetNormals(HdSceneDelegate *delegate) const
Definition: mesh.h:213
virtual HdMeshTopologySharedPtr GetTopology() const
Topology getter.
Definition: mesh.h:201
HD_API TfTokenVector const & GetBuiltinPrimvarNames() const override
HdDisplayStyle GetDisplayStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:189
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
SdfPath const & GetId() const
Definition: rprim.h:146
HdCullStyle GetCullStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:171
virtual HD_API HdMeshTopology GetMeshTopology(SdfPath const &id)
Gets the topological mesh data for a given prim.
std::array< DESC_TYPE, N > DescArray
Definition: rprim.h:304
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: mesh.h:101
PxOsdSubdivTags GetSubdivTags(HdSceneDelegate *delegate) const
Definition: mesh.h:195
virtual HD_API HdCullStyle GetCullStyle(SdfPath const &id)
Returns the cullstyle for the given prim.
HdMeshGeomStyle geomStyle
The rendering style: draw refined/unrefined, edge, points, etc.
Definition: mesh.h:68
bool flatShadingEnabled
Does this mesh want flat shading?
Definition: mesh.h:75
bool IsEmpty() const
Definition: mesh.h:63
virtual HD_API VtValue GetShadingStyle(SdfPath const &id)
Returns the shading style for the given prim.
bool enableScalarOverride
Definition: mesh.h:96
float lineWidth
How big (in pixels) should line drawing be?
Definition: mesh.h:90
Definition: value.h:146
HdCullStyle cullStyle
The culling style: draw front faces, back faces, etc.
Definition: mesh.h:70
VtValue GetPoints(HdSceneDelegate *delegate) const
Definition: mesh.h:207
virtual HD_API bool GetDoubleSided(SdfPath const &id)
Returns the doubleSided state for the given prim.