All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mesh.h
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 HD_MESH_H
25 #define 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"
31 #include "pxr/imaging/hd/meshTopology.h"
32 #include "pxr/imaging/hd/rprim.h"
33 #include "pxr/imaging/hd/tokens.h"
34 #include "pxr/imaging/pxOsd/subdivTags.h"
35 
36 PXR_NAMESPACE_OPEN_SCOPE
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,
48  HD_MESH_REPR_DESC_TOKENS);
49 
55  HdMeshReprDesc(HdMeshGeomStyle geomStyle = HdMeshGeomStyleInvalid,
56  HdCullStyle cullStyle = HdCullStyleDontCare,
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 {
76  return geomStyle == HdMeshGeomStyleInvalid;
77  }
78 
80  HdMeshGeomStyle geomStyle;
82  HdCullStyle cullStyle;
94  float lineWidth;
101 };
102 
105 class HdMesh : public HdRprim {
106 public:
107  HD_API
108  virtual ~HdMesh();
109 
113  inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
114  inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
115  inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
116 
120  inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
121  inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
122  inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
123 
125  virtual HdMeshTopologySharedPtr GetTopology() const;
126 
130  inline VtValue GetPoints(HdSceneDelegate* delegate) const;
131  inline VtValue GetNormals(HdSceneDelegate* delegate) const;
132 
137  HD_API
138  static void ConfigureRepr(TfToken const &reprName,
139  HdMeshReprDesc desc1,
141 
142 protected:
145  HD_API
146  HdMesh(SdfPath const& id,
147  SdfPath const& instancerId = SdfPath());
148 
149  // We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
150  typedef _ReprDescConfigs<HdMeshReprDesc, 2> _MeshReprConfig;
151 
152  HD_API
153  static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
154 
155 private:
156 
157  // Class can not be default constructed or copied.
158  HdMesh() = delete;
159  HdMesh(const HdMesh &) = delete;
160  HdMesh &operator =(const HdMesh &) = delete;
161 
162  static _MeshReprConfig _reprDescConfig;
163 };
164 
165 inline bool
167 {
168  return delegate->GetDoubleSided(GetId());
169 }
170 
171 inline HdCullStyle
172 HdMesh::GetCullStyle(HdSceneDelegate* delegate) const
173 {
174  return delegate->GetCullStyle(GetId());
175 }
176 
177 inline VtValue
178 HdMesh::GetShadingStyle(HdSceneDelegate* delegate) const
179 {
180  return delegate->GetShadingStyle(GetId());
181 }
182 
183 inline HdMeshTopology
185 {
186  return delegate->GetMeshTopology(GetId());
187 }
188 
189 inline HdDisplayStyle
190 HdMesh::GetDisplayStyle(HdSceneDelegate* delegate) const
191 {
192  return delegate->GetDisplayStyle(GetId());
193 }
194 
195 inline PxOsdSubdivTags
196 HdMesh::GetSubdivTags(HdSceneDelegate* delegate) const
197 {
198  return delegate->GetSubdivTags(GetId());
199 }
200 
201 inline HdMeshTopologySharedPtr
203 {
204  return HdMeshTopologySharedPtr();
205 }
206 
207 inline VtValue
209 {
210  return GetPrimvar(delegate, HdTokens->points);
211 }
212 
213 inline VtValue
214 HdMesh::GetNormals(HdSceneDelegate* delegate) const
215 {
216  return GetPrimvar(delegate, HdTokens->normals);
217 }
218 
219 
220 PXR_NAMESPACE_CLOSE_SCOPE
221 
222 #endif //HD_MESH_H
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:41
HdMeshTopology GetMeshTopology(HdSceneDelegate *delegate) const
Topological accessors via the scene delegate.
Definition: mesh.h:184
bool doubleSided
Should this mesh be treated as double-sided? The resolved value is (prim.doubleSided || repr...
Definition: mesh.h:92
bool enableScalarOverride
Should scalar override be allowed on this drawItem.
Definition: mesh.h:100
Descriptor to configure the drawItem(s) for a repr.
Definition: mesh.h:54
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:79
virtual HD_API VtValue GetShadingStyle(SdfPath const &id)
Returns the shading style for the given prim.
float lineWidth
How big (in pixels) should line drawing be?
Definition: mesh.h:94
bool flatShadingEnabled
Does this mesh want flat shading?
Definition: mesh.h:87
virtual HD_API bool GetDoubleSided(SdfPath const &id)
Returns the doubleSided state for the given prim.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
VtValue GetPoints(HdSceneDelegate *delegate) const
Primvars Accessors.
Definition: mesh.h:208
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:67
virtual HD_API HdCullStyle GetCullStyle(SdfPath const &id)
Returns the cullstyle for the given prim.
Adapter class providing data exchange with the client scene graph.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
static HD_API void ConfigureRepr(TfToken const &reprName, HdMeshReprDesc desc1, HdMeshReprDesc desc2=HdMeshReprDesc())
Configure the geometric style of the mesh for a given representation.
SdfPath const & GetId() const
Returns the identifier of this Rprim.
Definition: rprim.h:176
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
HdMeshGeomStyle geomStyle
The rendering style: draw refined/unrefined, edge, points, etc.
Definition: mesh.h:80
virtual HD_API HdMeshTopology GetMeshTopology(SdfPath const &id)
Gets the topological mesh data for a given prim.
bool useCustomDisplacement
Should this mesh use displacementShader() to displace points?
Definition: mesh.h:96
virtual HdMeshTopologySharedPtr GetTopology() const
Topology getter.
Definition: mesh.h:202
virtual HD_API PxOsdSubdivTags GetSubdivTags(SdfPath const &id)
Gets the subdivision surface tags (sharpness, holes, etc).
TfToken shadingTerminal
Specifies how the fragment color should be computed from surfaceShader; this can be used to render a ...
Definition: mesh.h:85
bool IsDoubleSided(HdSceneDelegate *delegate) const
Render State.
Definition: mesh.h:166
bool blendWireframeColor
Should the wireframe color be blended into the color primvar?
Definition: mesh.h:89
Hydra Schema for a subdivision surface or poly-mesh object.
Definition: mesh.h:105
virtual HD_API HdDisplayStyle GetDisplayStyle(SdfPath const &id)
Returns the refinement level for the given prim in the range [0,8].
Topology data for meshes.
Definition: meshTopology.h:55
HdCullStyle cullStyle
The culling style: draw front faces, back faces, etc.
Definition: mesh.h:82
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182