This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mesh.h
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"
14#include "pxr/imaging/hd/meshTopology.h"
15#include "pxr/imaging/hd/rprim.h"
16#include "pxr/imaging/hd/tokens.h"
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21#define HD_MESH_REPR_DESC_TOKENS \
22 (surfaceShader) \
23 (surfaceShaderUnlit) \
24 (surfaceShaderSheer) \
25 (surfaceShaderOutline) \
26 (constantColor) \
27 (hullColor) \
28 (pointColor)
29
30TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API,
31 HD_MESH_REPR_DESC_TOKENS);
32
38{
39 HdMeshReprDesc(HdMeshGeomStyle geomStyle = HdMeshGeomStyleInvalid,
40 HdCullStyle cullStyle = HdCullStyleDontCare,
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 {
64 return geomStyle == HdMeshGeomStyleInvalid;
65 }
66
68 HdMeshGeomStyle geomStyle;
70 HdCullStyle cullStyle;
90 float lineWidth;
97};
98
101class HdMesh : public HdRprim
102{
103public:
104 HD_API
105 ~HdMesh() override;
106
110 inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
111 inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
112 inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
113
117 inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
118 inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
119 inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
120
122 virtual HdMeshTopologySharedPtr GetTopology() const;
123
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
137 HD_API
138 static void ConfigureRepr(TfToken const &reprName,
139 HdMeshReprDesc desc1,
141
142protected:
145 HD_API
146 HdMesh(SdfPath const& id);
147
148 // We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
149 using _MeshReprConfig = _ReprDescConfigs<HdMeshReprDesc, 2>;
150
151 HD_API
152 static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
153
154private:
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
164inline bool
166{
167 return delegate->GetDoubleSided(GetId());
168}
169
170inline HdCullStyle
171HdMesh::GetCullStyle(HdSceneDelegate* delegate) const
172{
173 return delegate->GetCullStyle(GetId());
174}
175
176inline VtValue
177HdMesh::GetShadingStyle(HdSceneDelegate* delegate) const
178{
179 return delegate->GetShadingStyle(GetId());
180}
181
182inline HdMeshTopology
184{
185 return delegate->GetMeshTopology(GetId());
186}
187
188inline HdDisplayStyle
189HdMesh::GetDisplayStyle(HdSceneDelegate* delegate) const
190{
191 return delegate->GetDisplayStyle(GetId());
192}
193
194inline PxOsdSubdivTags
195HdMesh::GetSubdivTags(HdSceneDelegate* delegate) const
196{
197 return delegate->GetSubdivTags(GetId());
198}
199
200inline HdMeshTopologySharedPtr
202{
203 return HdMeshTopologySharedPtr();
204}
205
206inline VtValue
208{
209 return GetPrimvar(delegate, HdTokens->points);
210}
211
212inline VtValue
213HdMesh::GetNormals(HdSceneDelegate* delegate) const
214{
215 return GetPrimvar(delegate, HdTokens->normals);
216}
217
218
219PXR_NAMESPACE_CLOSE_SCOPE
220
221#endif //PXR_IMAGING_HD_MESH_H
Hydra Schema for a subdivision surface or poly-mesh object.
Definition: mesh.h:102
HD_API HdMesh(SdfPath const &id)
Constructor.
virtual HdMeshTopologySharedPtr GetTopology() const
Topology getter.
Definition: mesh.h:201
VtValue GetPoints(HdSceneDelegate *delegate) const
Primvars Accessors.
Definition: mesh.h:207
HD_API TfTokenVector const & GetBuiltinPrimvarNames() const override
Returns the names of built-in primvars, i.e.
static HD_API void ConfigureRepr(TfToken const &reprName, HdMeshReprDesc desc1, HdMeshReprDesc desc2=HdMeshReprDesc())
Configure the geometric style of the mesh for a given representation.
HdMeshTopology GetMeshTopology(HdSceneDelegate *delegate) const
Topological accessors via the scene delegate.
Definition: mesh.h:183
bool IsDoubleSided(HdSceneDelegate *delegate) const
Render State.
Definition: mesh.h:165
Topology data for meshes.
Definition: meshTopology.h:38
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:38
SdfPath const & GetId() const
Returns the identifier of this Rprim.
Definition: rprim.h:146
Adapter class providing data exchange with the client scene graph.
virtual HD_API HdDisplayStyle GetDisplayStyle(SdfPath const &id)
Returns the refinement level for the given prim in the range [0,8].
virtual HD_API VtValue GetShadingStyle(SdfPath const &id)
Returns the shading style for the given prim.
virtual HD_API bool GetDoubleSided(SdfPath const &id)
Returns the doubleSided state for the given prim.
virtual HD_API HdMeshTopology GetMeshTopology(SdfPath const &id)
Gets the topological mesh data for a given prim.
virtual HD_API PxOsdSubdivTags GetSubdivTags(SdfPath const &id)
Gets the subdivision surface tags (sharpness, holes, etc).
virtual HD_API HdCullStyle GetCullStyle(SdfPath const &id)
Returns the cullstyle for the given prim.
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:26
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:81
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:64
Descriptor to configure the drawItem(s) for a repr.
Definition: mesh.h:38
bool flatShadingEnabled
Does this mesh want flat shading?
Definition: mesh.h:75
HdCullStyle cullStyle
The culling style: draw front faces, back faces, etc.
Definition: mesh.h:70
bool enableScalarOverride
Should scalar override be allowed on this drawItem.
Definition: mesh.h:96
HdMeshGeomStyle geomStyle
The rendering style: draw refined/unrefined, edge, points, etc.
Definition: mesh.h:68
bool forceOpaqueEdges
If the geom style includes edges, should those edges be forced to be fully opaque,...
Definition: mesh.h:81
bool surfaceEdgeIds
Generate edge ids for surface and hull geom styles that do not otherwise render edges,...
Definition: mesh.h:85
bool doubleSided
Should this mesh be treated as double-sided? The resolved value is (prim.doubleSided || repr....
Definition: mesh.h:88
float lineWidth
How big (in pixels) should line drawing be?
Definition: mesh.h:90
TfToken shadingTerminal
Specifies how the fragment color should be computed from surfaceShader; this can be used to render a ...
Definition: mesh.h:73
bool useCustomDisplacement
Should this mesh use displacementShader() to displace points?
Definition: mesh.h:92
bool blendWireframeColor
Should the wireframe color be blended into the color primvar?
Definition: mesh.h:77
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440