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 ///
57  TfToken shadingTerminal = HdMeshReprDescTokens->surfaceShader,
58  bool flatShadingEnabled = true,
59  bool blendWireframeColor = true,
60  bool doubleSided = false,
61  float lineWidth = 0,
62  bool useCustomDisplacement = true,
63  bool enableScalarOverride = true)
73  {}
74 
75  bool IsEmpty() const {
77  }
78 
79  /// The rendering style: draw refined/unrefined, edge, points, etc.
81  /// The culling style: draw front faces, back faces, etc.
83  /// Specifies how the fragment color should be computed from surfaceShader;
84  /// this can be used to render a mesh lit, unlit, unshaded, etc.
86  /// Does this mesh want flat shading?
88  /// Should the wireframe color be blended into the color primvar?
90  /// Should this mesh be treated as double-sided? The resolved value is
91  /// (prim.doubleSided || repr.doubleSided).
93  /// How big (in pixels) should line drawing be?
94  float lineWidth;
95  /// Should this mesh use displacementShader() to displace points?
97  /// Should scalar override be allowed on this drawItem.
98  /// scalar override allows for visualization of a single float value
99  /// across a prim.
101 };
102 
103 /// Hydra Schema for a subdivision surface or poly-mesh object.
104 ///
105 class HdMesh : public HdRprim {
106 public:
107  HD_API
108  virtual ~HdMesh();
109 
110  ///
111  /// Render State
112  ///
113  inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
114  inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
115  inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
116 
117  ///
118  /// Topological accessors via the scene delegate
119  ///
120  inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
121  inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
122  inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
123 
124  /// Topology getter
125  virtual HdMeshTopologySharedPtr GetTopology() const;
126 
127  ///
128  /// Primvars Accessors
129  ///
130  inline VtValue GetPoints(HdSceneDelegate* delegate) const;
131  inline VtValue GetNormals(HdSceneDelegate* delegate) const;
132 
133  HD_API
134  TfTokenVector const & GetBuiltinPrimvarNames() const override;
135 
136  /// Configure the geometric style of the mesh for a given representation.
137  /// We currently allow up to 2 descriptors for a representation.
138  /// Example of when this may be useful:
139  /// Drawing the outline in addition to the surface for a mesh.
140  HD_API
141  static void ConfigureRepr(TfToken const &reprName,
142  HdMeshReprDesc desc1,
144 
145 protected:
146  /// Constructor. instancerId, if specified, is the instancer which uses
147  /// this mesh as a prototype.
148  HD_API
149  HdMesh(SdfPath const& id);
150 
151  // We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
153 
154  HD_API
155  static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
156 
157 private:
158 
159  // Class can not be default constructed or copied.
160  HdMesh() = delete;
161  HdMesh(const HdMesh &) = delete;
162  HdMesh &operator =(const HdMesh &) = delete;
163 
164  static _MeshReprConfig _reprDescConfig;
165 };
166 
167 inline bool
169 {
170  return delegate->GetDoubleSided(GetId());
171 }
172 
173 inline HdCullStyle
175 {
176  return delegate->GetCullStyle(GetId());
177 }
178 
179 inline VtValue
181 {
182  return delegate->GetShadingStyle(GetId());
183 }
184 
185 inline HdMeshTopology
187 {
188  return delegate->GetMeshTopology(GetId());
189 }
190 
191 inline HdDisplayStyle
193 {
194  return delegate->GetDisplayStyle(GetId());
195 }
196 
197 inline PxOsdSubdivTags
199 {
200  return delegate->GetSubdivTags(GetId());
201 }
202 
205 {
206  return HdMeshTopologySharedPtr();
207 }
208 
209 inline VtValue
211 {
212  return GetPrimvar(delegate, HdTokens->points);
213 }
214 
215 inline VtValue
217 {
218  return GetPrimvar(delegate, HdTokens->normals);
219 }
220 
221 
223 
224 #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:89
static HD_API void ConfigureRepr(TfToken const &reprName, HdMeshReprDesc desc1, HdMeshReprDesc desc2=HdMeshReprDesc())
VtValue GetShadingStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:180
#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:186
bool doubleSided
Definition: mesh.h:92
Definition: rprim.h:68
VtValue GetPrimvar(HdSceneDelegate *delegate, const TfToken &name) const
Definition: rprim.h:382
static HD_API _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName)
bool useCustomDisplacement
Should this mesh use displacementShader() to displace points?
Definition: mesh.h:96
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:288
bool IsDoubleSided(HdSceneDelegate *delegate) const
Definition: mesh.h:168
TfToken shadingTerminal
Definition: mesh.h:85
VtValue GetNormals(HdSceneDelegate *delegate) const
Definition: mesh.h:216
virtual HdMeshTopologySharedPtr GetTopology() const
Topology getter.
Definition: mesh.h:204
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:55
HD_API TfTokenVector const & GetBuiltinPrimvarNames() const override
_ReprDescConfigs< HdMeshReprDesc, 2 > _MeshReprConfig
Definition: mesh.h:152
HdDisplayStyle GetDisplayStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:192
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
SdfPath const & GetId() const
Definition: rprim.h:176
HdCullStyle GetCullStyle(HdSceneDelegate *delegate) const
Definition: mesh.h:174
virtual HD_API HdMeshTopology GetMeshTopology(SdfPath const &id)
Gets the topological mesh data for a given prim.
virtual HD_API ~HdMesh()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: mesh.h:105
PxOsdSubdivTags GetSubdivTags(HdSceneDelegate *delegate) const
Definition: mesh.h:198
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:80
bool flatShadingEnabled
Does this mesh want flat shading?
Definition: mesh.h:87
bool IsEmpty() const
Definition: mesh.h:75
std::array< DESC_TYPE, N > DescArray
Definition: rprim.h:332
virtual HD_API VtValue GetShadingStyle(SdfPath const &id)
Returns the shading style for the given prim.
bool enableScalarOverride
Definition: mesh.h:100
float lineWidth
How big (in pixels) should line drawing be?
Definition: mesh.h:94
Definition: value.h:168
HdCullStyle cullStyle
The culling style: draw front faces, back faces, etc.
Definition: mesh.h:82
VtValue GetPoints(HdSceneDelegate *delegate) const
Definition: mesh.h:210
virtual HD_API bool GetDoubleSided(SdfPath const &id)
Returns the doubleSided state for the given prim.