24 #ifndef PXR_IMAGING_HD_ST_MESH_H
25 #define PXR_IMAGING_HD_ST_MESH_H
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hd/changeTracker.h"
31 #include "pxr/imaging/hd/drawingCoord.h"
32 #include "pxr/imaging/hd/mesh.h"
33 #include "pxr/imaging/hd/perfLog.h"
35 #include "pxr/usd/sdf/path.h"
40 PXR_NAMESPACE_OPEN_SCOPE
46 using Hd_VertexAdjacencySharedPtr = std::shared_ptr<class Hd_VertexAdjacency>;
47 using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
48 using HdSt_MeshTopologySharedPtr = std::shared_ptr<class HdSt_MeshTopology>;
50 using HdStResourceRegistrySharedPtr =
51 std::shared_ptr<class HdStResourceRegistry>;
58 HF_MALLOC_TAG_NEW(
"new HdStMesh");
69 HdDirtyBits *dirtyBits,
70 TfToken const &reprToken)
override;
80 HdMeshTopologySharedPtr
GetTopology()
const override;
96 HdDirtyBits *dirtyBitsState);
98 HdBufferArrayRangeSharedPtr
99 _GetSharedPrimvarRange(uint64_t primvarId,
100 HdBufferSpecVector
const &updatedOrAddedSpecs,
101 HdBufferSpecVector
const &removedSpecs,
102 HdBufferArrayRangeSharedPtr
const &curRange,
103 bool * isFirstInstance,
104 HdStResourceRegistrySharedPtr
const &resourceRegistry)
const;
107 HdSt_MeshTopologySharedPtr
const & topology)
const;
109 bool _UseLimitRefinement(
const HdRenderIndex &renderIndex)
const;
111 bool _UseSmoothNormals(HdSt_MeshTopologySharedPtr
const& topology)
const;
117 HdStDrawItem *drawItem,
118 HdDirtyBits *dirtyBits,
120 bool requireSmoothNormals,
121 bool requireFlatNormals);
125 HdStDrawItem *drawItem,
130 bool updateMaterialShader,
131 bool updateGeometricShader);
135 HdStDrawItem *drawItem,
136 HdDirtyBits *dirtyBits,
139 void _PopulateAdjacency(
140 HdStResourceRegistrySharedPtr
const &resourceRegistry);
143 HdStDrawItem *drawItem,
144 HdDirtyBits *dirtyBits,
146 HdSt_MeshTopologySharedPtr topology);
150 HdStDrawItem *drawItem,
151 HdDirtyBits *dirtyBits,
152 bool requireSmoothNormals);
156 HdStDrawItem *drawItem,
157 HdDirtyBits *dirtyBits,
162 HdStDrawItem *drawItem,
163 HdDirtyBits *dirtyBits,
164 bool requireFlatNormals);
173 class _FvarTopologyTracker
176 const TopologyToPrimvarVector & GetTopologyToPrimvarVector()
const {
181 void AddOrUpdateTopology(
const TfToken &primvar,
182 const VtIntArray &topology) {
183 for (
size_t i = 0; i < _topologies.size(); ++i) {
185 if (_topologies[i].first == topology) {
187 if (std::find(_topologies[i].second.begin(),
188 _topologies[i].second.end(),
189 primvar) == _topologies[i].second.end()) {
191 RemovePrimvar(primvar);
192 _topologies[i].second.push_back(primvar);
199 RemovePrimvar(primvar);
200 _topologies.push_back(
201 std::pair<VtIntArray, std::vector<TfToken>>(
202 topology, {primvar}));
206 void RemovePrimvar(
const TfToken &primvar) {
207 for (
size_t i = 0; i < _topologies.size(); ++i) {
208 _topologies[i].second.erase(std::find(
209 _topologies[i].second.begin(),
210 _topologies[i].second.end(),
211 primvar), _topologies[i].second.end());
218 void RemoveUnusedTopologies() {
219 _topologies.erase(std::remove_if(
220 _topologies.begin(), _topologies.end(), NoPrimvars),
226 int GetChannelFromPrimvar(
const TfToken &primvar)
const {
227 for (
size_t i = 0; i < _topologies.size(); ++i) {
228 if (std::find(_topologies[i].second.begin(),
229 _topologies[i].second.end(),
231 _topologies[i].second.end()) {
239 std::vector<VtIntArray> GetFvarTopologies()
const {
240 std::vector<VtIntArray> fvarTopologies;
241 for (
const auto& it : _topologies) {
242 fvarTopologies.push_back(it.first);
244 return fvarTopologies;
247 size_t GetNumTopologies()
const {
248 return _topologies.size();
254 static bool NoPrimvars(
const std::pair<VtIntArray, std::vector<TfToken>>
256 return topology.second.empty();
259 TopologyToPrimvarVector _topologies;
264 HullTopology = HdDrawingCoord::CustomSlotsBegin,
269 enum DirtyBits : HdDirtyBits {
270 DirtySmoothNormals = HdChangeTracker::CustomBitsBegin,
271 DirtyFlatNormals = (DirtySmoothNormals << 1),
272 DirtyIndices = (DirtyFlatNormals << 1),
273 DirtyHullIndices = (DirtyIndices << 1),
274 DirtyPointsIndices = (DirtyHullIndices << 1)
277 HdSt_MeshTopologySharedPtr _topology;
278 Hd_VertexAdjacencySharedPtr _vertexAdjacency;
280 HdTopology::ID _topologyId;
281 HdTopology::ID _vertexPrimvarId;
282 HdDirtyBits _customDirtyBitsInUse;
284 HdType _pointsDataType;
285 HdInterpolation _sceneNormalsInterpolation;
286 HdCullStyle _cullStyle;
287 bool _hasMirroredTransform : 1;
288 bool _doubleSided : 1;
289 bool _flatShadingEnabled : 1;
290 bool _displacementEnabled : 1;
291 bool _limitNormals : 1;
292 bool _sceneNormals : 1;
293 bool _hasVaryingTopology : 1;
295 bool _displayOpacity : 1;
296 bool _occludedSelectionShowsThrough : 1;
298 std::unique_ptr<_FvarTopologyTracker> _fvarTopologyTracker;
302 PXR_NAMESPACE_CLOSE_SCOPE
304 #endif // PXR_IMAGING_HD_ST_MESH_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override
This callback from Rprim gives the prim an opportunity to set additional dirty bits based on those al...
Descriptor to configure the drawItem(s) for a repr.
HDST_API void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override
Initialize the given representation of this Rprim.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Token for efficient comparison, assignment, and hashing of known strings.
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
A subdivision surface or poly-mesh object.
HDST_API HdMeshTopologySharedPtr GetTopology() const override
Topology (member) getter.
Hydra Schema for a subdivision surface or poly-mesh object.
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the set of dirty bits that should be added to the change tracker for this prim...
HDST_API void Finalize(HdRenderParam *renderParam) override
Finalizes object resources.
HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
Pull invalidated scene data and prepare/update the renderable representation.
static HDST_API bool IsEnabledPackedNormals()
Returns whether packed (10_10_10 bits) normals to be used.