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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_MESH_H
25 #define PXR_IMAGING_HD_MESH_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hd/enums.h"
32 #include "pxr/imaging/hd/rprim.h"
33 #include "pxr/imaging/hd/tokens.h"
35 
37 
38 #define HD_MESH_REPR_DESC_TOKENS \
39  (surfaceShader) \
40  (surfaceShaderUnlit) \
41  (surfaceShaderSheer) \
42  (surfaceShaderOutline) \
43  (constantColor) \
44  (hullColor) \
45  (pointColor)
46 
47 TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API,
49 
50 /// \class HdMeshReprDesc
51 ///
52 /// Descriptor to configure the drawItem(s) for a repr
53 ///
55 {
58  TfToken shadingTerminal = HdMeshReprDescTokens->surfaceShader,
59  bool flatShadingEnabled = true,
60  bool blendWireframeColor = true,
61  bool doubleSided = false,
62  float lineWidth = 0,
63  bool useCustomDisplacement = true,
64  bool enableScalarOverride = true)
74  {}
75 
76  bool IsEmpty() const {
78  }
79 
80  /// The rendering style: draw refined/unrefined, edge, points, etc.
82  /// The culling style: draw front faces, back faces, etc.
84  /// Specifies how the fragment color should be computed from surfaceShader;
85  /// this can be used to render a mesh lit, unlit, unshaded, etc.
87  /// Does this mesh want flat shading?
89  /// Should the wireframe color be blended into the color primvar?
91  /// Should this mesh be treated as double-sided? The resolved value is
92  /// (prim.doubleSided || repr.doubleSided).
94  /// How big (in pixels) should line drawing be?
95  float lineWidth;
96  /// Should this mesh use displacementShader() to displace points?
98  /// Should scalar override be allowed on this drawItem.
99  /// scalar override allows for visualization of a single float value
100  /// across a prim.
102 };
103 
104 /// Hydra Schema for a subdivision surface or poly-mesh object.
105 ///
106 class HdMesh : public HdRprim
107 {
108 public:
109  HD_API
110  ~HdMesh() override;
111 
112  ///
113  /// Render State
114  ///
115  inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
116  inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
117  inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
118 
119  ///
120  /// Topological accessors via the scene delegate
121  ///
122  inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
123  inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
124  inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
125 
126  /// Topology getter
127  virtual HdMeshTopologySharedPtr GetTopology() const;
128 
129  ///
130  /// Primvars Accessors
131  ///
132  inline VtValue GetPoints(HdSceneDelegate* delegate) const;
133  inline VtValue GetNormals(HdSceneDelegate* delegate) const;
134 
135  HD_API
136  TfTokenVector const & GetBuiltinPrimvarNames() const override;
137 
138  /// Configure the geometric style of the mesh for a given representation.
139  /// We currently allow up to 2 descriptors for a representation.
140  /// Example of when this may be useful:
141  /// Drawing the outline in addition to the surface for a mesh.
142  HD_API
143  static void ConfigureRepr(TfToken const &reprName,
144  HdMeshReprDesc desc1,
146 
147 protected:
148  /// Constructor. instancerId, if specified, is the instancer which uses
149  /// this mesh as a prototype.
150  HD_API
151  HdMesh(SdfPath const& id);
152 
153  // We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
155 
156  HD_API
157  static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
158 
159 private:
160 
161  // Class can not be default constructed or copied.
162  HdMesh() = delete;
163  HdMesh(const HdMesh &) = delete;
164  HdMesh &operator =(const HdMesh &) = delete;
165 
166  static _MeshReprConfig _reprDescConfig;
167 };
168 
169 inline bool
171 {
172  return delegate->GetDoubleSided(GetId());
173 }
174 
175 inline HdCullStyle
177 {
178  return delegate->GetCullStyle(GetId());
179 }
180 
181 inline VtValue
183 {
184  return delegate->GetShadingStyle(GetId());
185 }
186 
187 inline HdMeshTopology
189 {
190  return delegate->GetMeshTopology(GetId());
191 }
192 
193 inline HdDisplayStyle
195 {
196  return delegate->GetDisplayStyle(GetId());
197 }
198 
199 inline PxOsdSubdivTags
201 {
202  return delegate->GetSubdivTags(GetId());
203 }
204 
207 {
208  return HdMeshTopologySharedPtr();
209 }
210 
211 inline VtValue
213 {
214  return GetPrimvar(delegate, HdTokens->points);
215 }
216 
217 inline VtValue
219 {
220  return GetPrimvar(delegate, HdTokens->normals);
221 }
222 
223 
225 
226 #endif //PXR_IMAGING_HD_MESH_H
#define HD_MESH_REPR_DESC_TOKENS
Definition: mesh.h:38
HdCullStyle
Definition: enums.h:122
bool blendWireframeColor
Should the wireframe color be blended into the color primvar?
Definition: mesh.h:90
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:182
#define HD_API
Definition: api.h:40
std::shared_ptr< class HdMeshTopology > HdMeshTopologySharedPtr
Definition: meshTopology.h:45
virtual HD_API PxOsdSubdivTags GetSubdivTags(SdfPath const &id)
Gets the subdivision surface tags (sharpness, holes, etc).
Definition: token.h:87
virtual HD_API HdDisplayStyle GetDisplayStyle(SdfPath const &id)
HdMeshTopology GetMeshTopology(HdSceneDelegate *delegate) const
Definition: mesh.h:188
bool doubleSided
Definition: mesh.h:93
Definition: rprim.h:54
VtValue GetPrimvar(HdSceneDelegate *delegate, const TfToken &name) const
Definition: rprim.h:371
static HD_API _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName)
bool useCustomDisplacement
Should this mesh use displacementShader() to displace points?
Definition: mesh.h:97
HdMeshGeomStyle
Definition: enums.h:147
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API, HD_MESH_REPR_DESC_TOKENS)
Definition: path.h:291
bool IsDoubleSided(HdSceneDelegate *delegate) const
Definition: mesh.h:170
TfToken shadingTerminal
Definition: mesh.h:86
VtValue GetNormals(HdSceneDelegate *delegate) const
Definition: mesh.h:218
virtual HdMeshTopologySharedPtr GetTopology() const
Topology getter.
Definition: mesh.h:206
HdMeshReprDesc(HdMeshGeomStyle geomStyle=HdMeshGeomStyleInvalid, HdCullStyle cullStyle=HdCullStyleDontCare, TfToken shadingTerminal=HdMeshReprDescTokens->surfaceShader, bool flatShadingEnabled=true, bool blendWireframeColor=true, bool doubleSided=false, float lineWidth=0, bool useCustomDisplacement=true, bool enableScalarOverride=true)
Definition: mesh.h:56
HD_API TfTokenVector const & GetBuiltinPrimvarNames() const override
HdDisplayStyle GetDisplayStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:194
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
SdfPath const & GetId() const
Definition: rprim.h:163
HdCullStyle GetCullStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:176
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:321
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: mesh.h:106
PxOsdSubdivTags GetSubdivTags(HdSceneDelegate *delegate) const
Definition: mesh.h:200
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:81
bool flatShadingEnabled
Does this mesh want flat shading?
Definition: mesh.h:88
bool IsEmpty() const
Definition: mesh.h:76
virtual HD_API VtValue GetShadingStyle(SdfPath const &id)
Returns the shading style for the given prim.
bool enableScalarOverride
Definition: mesh.h:101
float lineWidth
How big (in pixels) should line drawing be?
Definition: mesh.h:95
Definition: value.h:167
HdCullStyle cullStyle
The culling style: draw front faces, back faces, etc.
Definition: mesh.h:83
VtValue GetPoints(HdSceneDelegate *delegate) const
Definition: mesh.h:212
virtual HD_API bool GetDoubleSided(SdfPath const &id)
Returns the doubleSided state for the given prim.